Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: data normalization and improve handling of runs in JcampMSConverter #220

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions chem_spectra/lib/converter/jcamp/ms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from chem_spectra.lib.converter.jcamp.data_parse import make_ms_data_xsys
from chem_spectra.lib.converter.share import reduce_pts
import numpy as np

MARGIN = 1
THRESHOLD_MS = 0.05
Expand Down Expand Up @@ -78,12 +79,19 @@ def __get_ratio(self, spc):

return ratio, noise_ratio

# Guarantees that the data passed to `reduce_pts` and subsequent operations
# conforms to the expected structure.
def __normalize_data(self, data):
if isinstance(data, np.ndarray) and data.ndim == 3 and data.shape[0] == 1:
return data[0]
return data

def __decode(self, runs):
spectra = []
best_ratio, best_idx, backup_ratio, backup_idx = 0, 0, 0, 0
for idx, data in enumerate(runs):
data = self.__normalize_data(data)
spectra.append(reduce_pts(data))

ratio, noise_ratio = self.__get_ratio(data)
if (best_ratio < ratio) and (noise_ratio <= 50.0):
best_idx = idx
Expand Down Expand Up @@ -117,4 +125,4 @@ def __set_datatables(self):
)
)
dts.append({'dt': dt, 'pts': pts})
return dts
return dts
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ dependencies:
- werkzeug==3.0.3
- wrapt==1.16.0
- zipp==3.19.2
- -e git+https://github.com/ComPlat/nmrglue.git@e6e8a63b1848ae0525f07de0a6ec0cfdb900ba60#egg=nmrglue
- -e git+https://github.com/ComPlat/nmrglue.git@Refactor-parse_xy_xy-standardize-output-3D-arrays#egg=nmrglue
prefix: /home/eln/anaconda3/envs/python-v38
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ matplotlib==3.7.3
mccabe==0.6.1
more-itertools==7.2.0
# -e git+https://github.com/ComPlat/nmrglue.git@e6e8a63b1848ae0525f07de0a6ec0cfdb900ba60#egg=nmrglue
-e git+https://github.com/ComPlat/nmrglue.git@stable_version#egg=nmrglue
-e git+https://github.com/ComPlat/nmrglue.git@Refactor-parse_xy_xy-standardize-output-3D-arrays#egg=nmrglue
netCDF4==1.5.3
numpy==1.22.4
olefile==0.46
Expand Down
Loading
Loading