Skip to content

Commit

Permalink
fix: data normalization and improve handling of runs in JcampMSConver…
Browse files Browse the repository at this point in the history
…ter (#220)

* Fix data normalization and improve handling of runs in JcampMSConverter

* Add unit test for JCAMP single point handling in the last line

* Update requirements.txt to use specific branch of nmrglue

* Change nmrglue version for unit test in CI
  • Loading branch information
Nicolass67 authored Nov 28, 2024
1 parent fbaa71f commit e7e517b
Show file tree
Hide file tree
Showing 5 changed files with 877 additions and 4 deletions.
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

0 comments on commit e7e517b

Please sign in to comment.