Skip to content

Commit

Permalink
Merge pull request #66 from oscarbranson/dev
Browse files Browse the repository at this point in the history
0.3.22
  • Loading branch information
oscarbranson authored May 27, 2021
2 parents 1295ace + 7597cd6 commit c012a70
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion latools/D_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
2 changes: 1 addition & 1 deletion latools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .helpers import chemistry
from . import preprocessing

__version__ = '0.3.21'
__version__ = '0.3.22'

def cite(output='text'):
"""
Expand Down
26 changes: 21 additions & 5 deletions latools/helpers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,18 +515,24 @@ 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
valid1 = self.analyte_ratios.intersection(analytes)
# 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.')
Expand All @@ -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
25 changes: 12 additions & 13 deletions latools/latools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -1756,7 +1760,6 @@ def calibrate(self, analytes=None, drift_correct=True,

self.stages_complete.update(['calibrated'])
self.focus_stage = 'calibrated'

return

# data filtering
Expand All @@ -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):
Expand Down Expand Up @@ -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})

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c012a70

Please sign in to comment.