From 777ac32cf184bd94a9a9cff14f29e296a7bb7b73 Mon Sep 17 00:00:00 2001 From: Oscar Branson Date: Tue, 25 May 2021 11:08:36 +0100 Subject: [PATCH 1/5] dev version bump --- latools/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/latools/__init__.py b/latools/__init__.py index 294f8a1..8b8af37 100644 --- a/latools/__init__.py +++ b/latools/__init__.py @@ -17,7 +17,7 @@ from .helpers import chemistry from . import preprocessing -__version__ = '0.3.21' +__version__ = '0.3.22_dev' def cite(output='text'): """ From 1453702598d48b74793a53c2a8cc513bbfb01e90 Mon Sep 17 00:00:00 2001 From: Oscar Branson Date: Thu, 27 May 2021 10:21:53 +0100 Subject: [PATCH 2/5] handling of uncalibrated elements in analyte_checker new split_analyte_ratios function to parse out individual analyte names --- latools/helpers/helpers.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/latools/helpers/helpers.py b/latools/helpers/helpers.py index 6ef1d69..491c3d0 100644 --- a/latools/helpers/helpers.py +++ b/latools/helpers/helpers.py @@ -515,11 +515,7 @@ def analyte_checker(self, analytes=None, check_ratios=True, single=False): analytes = [analytes] out = set() - if self.focus_stage not in ['ratios', 'calibrated'] or not check_ratios: - if analytes is None: - analytes = self.analytes - out = self.analytes.intersection(analytes) - else: + if self.focus_stage in ['ratios', 'calibrated'] and check_ratios: if analytes is None: analytes = self.analyte_ratios # case 1: provided analytes are an exact match for items in analyte_ratios @@ -527,6 +523,16 @@ def analyte_checker(self, analytes=None, check_ratios=True, single=False): # case 2: provided analytes are in numerator of ratios valid2 = [a for a in self.analyte_ratios if a.split('_')[0] in analytes] out = valid1.union(valid2) + else: + if analytes is None: + analytes = self.analytes + out = self.analytes.intersection(analytes) + + if len(self.uncalibrated) > 0: + if self.focus_stage in ['ratios', 'calibrated'] and check_ratios: + out.difference_update(self.uncalibrated) + else: + out.difference_update([u.split('_')[0] for u in self.uncalibrated]) if len(out) == 0: raise ValueError(f'{analytes} does not match any valid analyte names.') @@ -536,4 +542,14 @@ def analyte_checker(self, analytes=None, check_ratios=True, single=False): raise ValueError(f'{analytes} matches more than one valid analyte ({out}). Please be more specific.') return out.pop() + return out + +def split_analyte_ratios(ratios): + out = set() + if isinstance(ratios, str): + out.update(ratios.split('_')) + elif ratios is None: + return out + else: + out.update(*map(split_analyte_ratios, ratios)) return out \ No newline at end of file From 58efe2f568e6f46a912dfa59370652146c451652 Mon Sep 17 00:00:00 2001 From: Oscar Branson Date: Thu, 27 May 2021 10:22:44 +0100 Subject: [PATCH 3/5] fixed handling of uncalibrated elements in calibration and minimal export functions --- latools/D_obj.py | 3 ++- latools/latools.py | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/latools/D_obj.py b/latools/D_obj.py index 1919937..ca99b4d 100644 --- a/latools/D_obj.py +++ b/latools/D_obj.py @@ -127,7 +127,8 @@ def __init__(self, data_file=None, dataformat=None, errorhunt=False, cmap=None, # set for recording calculated ratios self.analyte_ratios = set() - + self.uncalibrated = set() + # calculate total counts self.data['total_counts'] = sum(self.data['rawdata'].values()) diff --git a/latools/latools.py b/latools/latools.py index 563386c..384a86c 100644 --- a/latools/latools.py +++ b/latools/latools.py @@ -39,7 +39,7 @@ from .helpers.helpers import (rolling_window, enumerate_bool, un_interp1d, get_date, unitpicker, rangecalc, Bunch, calc_grads, - get_total_time_span, analyte_checker) + get_total_time_span, analyte_checker, split_analyte_ratios) from .helpers import logging from .helpers.logging import _log from .helpers.config import read_configuration, config_locator @@ -1560,11 +1560,8 @@ def srm_id_auto(self, srms_used=['NIST610', 'NIST612', 'NIST614'], analytes=None # TODO: srm_id_plot! if isinstance(srms_used, str): srms_used = [srms_used] - - # compile measured SRM data - self.srm_compile_measured(n_min) - # load SRM database + # reload SRM database (if reloard_srm_databse=True) self.srm_load_database(srms_used, reload_srm_database) analytes = self._analyte_checker(analytes) @@ -1651,6 +1648,12 @@ def calibrate(self, analytes=None, drift_correct=True, ------- None """ + # load SRM database + self.srm_load_database(srms_used, reload_srm_database) + + # compile measured SRM data + self.srm_compile_measured(n_min) + analytes = self._analyte_checker(analytes) if isinstance(srms_used, str): @@ -1744,6 +1747,7 @@ def calibrate(self, analytes=None, drift_correct=True, with self.pbar.set(total=len(self.data), desc='Applying Calibrations') as prog: for d in self.data.values(): d.calibrate(self.calib_ps, analytes) + d.uncalibrated = self.uncalibrated prog.update() # record SRMs used for plotting @@ -1756,7 +1760,6 @@ def calibrate(self, analytes=None, drift_correct=True, self.stages_complete.update(['calibrated']) self.focus_stage = 'calibrated' - return # data filtering @@ -1780,6 +1783,7 @@ def get_sample_list(self, save_as=None, overwrite=False): empty = pd.DataFrame(index=self.samples, columns=['int_stand_massfrac']) empty.to_csv(save_as) + self.internal_standard_concs = empty print(self._wrap_text('Sample List saved to {} \nPlease modify and re-import using read_internal_standard_concs()'.format(save_as))) def read_internal_standard_concs(self, sample_concs=None): @@ -4175,9 +4179,7 @@ def minimal_export(self, target_analytes=None, path=None): os.mkdir(path) # parse minimal analytes (exclude ratios, include target_analytes) - export_analytes = target_analytes - for a in self.minimal_analytes.difference([None]): - export_analytes.update(a.split('_')) + export_analytes = target_analytes.union(split_analyte_ratios(self.minimal_analytes)) export_analytes = self.analytes_sorted(export_analytes, check_ratios=False) # export data From 36247625207b825d44d52ec17cb6e8eb83a911dc Mon Sep 17 00:00:00 2001 From: Oscar Branson Date: Thu, 27 May 2021 10:34:28 +0100 Subject: [PATCH 4/5] get_focus now uses analyte checkers --- latools/latools.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/latools/latools.py b/latools/latools.py index 384a86c..4fa53fa 100644 --- a/latools/latools.py +++ b/latools/latools.py @@ -2966,10 +2966,7 @@ def get_focus(self, filt=False, samples=None, subset=None, nominal=False): focus = {'uTime': []} - if self.focus_stage not in ['ratios', 'calibrated']: - columns = self.analytes - else: - columns = self.analyte_ratios + columns = self._analyte_checker() focus.update({a: [] for a in columns}) From 7597cd6ef9dc66bc5d914410d4e8aefe47f6eb9e Mon Sep 17 00:00:00 2001 From: Oscar Branson Date: Thu, 27 May 2021 10:37:17 +0100 Subject: [PATCH 5/5] 0.3.22 changelog & version bump --- CHANGELOG.md | 5 +++++ latools/__init__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 237d0f5..e2ae894 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog All significant changes to the software will be documented here. +## [0.3.22] 27/05/2021 + +### Changed +- Fixes to handling of uncalibrated elements in _analyte_checker, which effects calibration, minimal_export and plotting after calibration. + ## [0.3.21] 25/05/2021 ### Changed diff --git a/latools/__init__.py b/latools/__init__.py index 8b8af37..314b1cc 100644 --- a/latools/__init__.py +++ b/latools/__init__.py @@ -17,7 +17,7 @@ from .helpers import chemistry from . import preprocessing -__version__ = '0.3.22_dev' +__version__ = '0.3.22' def cite(output='text'): """