Skip to content

Commit

Permalink
Fix data normalization and improve handling of runs in JcampMSConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolass67 committed Nov 22, 2024
1 parent 3cf1088 commit ce636ac
Showing 1 changed file with 10 additions and 2 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

0 comments on commit ce636ac

Please sign in to comment.