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/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/__init__.py b/latools/__init__.py index 294f8a1..314b1cc 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' def cite(output='text'): """ 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 diff --git a/latools/latools.py b/latools/latools.py index 563386c..4fa53fa 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): @@ -2962,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}) @@ -4175,9 +4176,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