diff --git a/chem_spectra/lib/converter/jcamp/base.py b/chem_spectra/lib/converter/jcamp/base.py index ee80506d..fdaea8a3 100644 --- a/chem_spectra/lib/converter/jcamp/base.py +++ b/chem_spectra/lib/converter/jcamp/base.py @@ -1,4 +1,5 @@ import nmrglue as ng +import json from chem_spectra.lib.converter.share import parse_params, parse_solvent @@ -43,83 +44,21 @@ def __read(self, path): def __set_datatype(self): dts = self.datatypes - if 'NMR SPECTRUM' in dts: - return 'NMR SPECTRUM' - elif 'NMRSPECTRUM' in dts: # MNova - return 'NMR SPECTRUM' - elif 'INFRARED SPECTRUM' in dts: - return 'INFRARED SPECTRUM' - elif 'RAMAN SPECTRUM' in dts: - return 'RAMAN SPECTRUM' - elif 'MASS SPECTRUM' in dts: - return 'MASS SPECTRUM' - elif 'HPLC UV/VIS SPECTRUM' in dts: - return 'HPLC UV/VIS SPECTRUM' - elif 'HPLC UV-VIS' in dts: - return 'HPLC UV/VIS SPECTRUM' - elif 'UV/VIS SPECTRUM' in dts: - return 'UV/VIS SPECTRUM' - elif 'UV-VIS' in dts: - return 'UV/VIS SPECTRUM' - elif 'ULTRAVIOLET SPECTRUM' in dts: - return 'UV/VIS SPECTRUM' - elif 'THERMOGRAVIMETRIC ANALYSIS' in dts: - return 'THERMOGRAVIMETRIC ANALYSIS' - elif 'X-RAY DIFFRACTION' in dts: - return 'X-RAY DIFFRACTION' - elif 'CYCLIC VOLTAMMETRY' in dts: - return 'CYCLIC VOLTAMMETRY' - elif 'SIZE EXCLUSION CHROMATOGRAPHY' in dts: - return 'SIZE EXCLUSION CHROMATOGRAPHY' - elif 'CIRCULAR DICHROISM SPECTROSCOPY' in dts: - return 'CIRCULAR DICHROISM SPECTROSCOPY' - elif 'SORPTION-DESORPTION MEASUREMENT' in dts: - return 'SORPTION-DESORPTION MEASUREMENT' - elif 'Emissions' in dts or 'EMISSIONS' in dts or 'FLUORESCENCE SPECTRUM' in dts or 'FL SPECTRUM' in dts: - return 'Emissions' - elif 'DLS ACF' in dts: - return 'DLS ACF' - elif 'DLS INTENSITY' in dts or 'DLS intensity' in dts: - return 'DLS intensity' + + with open('data_type.json', 'r') as mapping_file: + data_type_mappings = json.load(mapping_file)["datatypes"] + for dt in dts: + if dt in data_type_mappings: + return data_type_mappings[dt] return '' def __typ(self): dt = self.datatype - if 'NMR SPECTRUM' == dt: - return 'NMR' - elif 'NMRSPECTRUM' == dt: # MNova - return 'NMR' - elif 'INFRARED SPECTRUM' == dt: - return 'INFRARED' # TBD - elif 'RAMAN SPECTRUM' == dt: - return 'RAMAN' # TBD - elif 'MASS SPECTRUM' == dt: - return 'MS' - elif 'HPLC UV/VIS SPECTRUM' == dt: - return 'HPLC UVVIS' - elif 'HPLC UV-VIS' == dt: - return 'HPLC UVVIS' - elif 'UV/VIS SPECTRUM' == dt or 'UV-VIS' == dt or 'ULTRAVIOLET SPECTRUM' == dt: - return 'UVVIS' - elif 'THERMOGRAVIMETRIC ANALYSIS' == dt: - return 'THERMOGRAVIMETRIC ANALYSIS' - elif 'X-RAY DIFFRACTION' == dt: - return 'X-RAY DIFFRACTION' - elif 'CYCLIC VOLTAMMETRY' in dt: - return 'CYCLIC VOLTAMMETRY' - elif 'SIZE EXCLUSION CHROMATOGRAPHY' in dt: - return 'SIZE EXCLUSION CHROMATOGRAPHY' - elif 'CIRCULAR DICHROISM SPECTROSCOPY' in dt: - return 'CIRCULAR DICHROISM SPECTROSCOPY' - elif 'SORPTION-DESORPTION MEASUREMENT' in dt: - return 'SORPTION-DESORPTION MEASUREMENT' - elif 'Emissions' in dt or 'EMISSIONS' in dt or 'FLUORESCENCE SPECTRUM' in dt or 'FL SPECTRUM' in dt: - return 'Emissions' - elif 'DLS ACF' in dt: - return 'DLS ACF' - elif 'DLS INTENSITY' in dt or 'DLS intensity' in dt: - return 'DLS intensity' - return '' + + with open('data_type.json', 'r') as mapping_file: + data_type_mappings = json.load(mapping_file)["datatypes"] + + return data_type_mappings.get(dt, '') def __set_dataclass(self): data_class = self.dataclasses @@ -140,12 +79,11 @@ def __is_em_wave(self): return self.typ in ['INFRARED', 'RAMAN', 'UVVIS'] def __non_nmr(self): - return self.typ in [ - 'INFRARED', 'RAMAN', 'UVVIS', 'HPLC UVVIS', - 'THERMOGRAVIMETRIC ANALYSIS', 'MS', 'X-RAY DIFFRACTION', - 'CYCLIC VOLTAMMETRY', 'SIZE EXCLUSION CHROMATOGRAPHY', - 'CIRCULAR DICHROISM SPECTROSCOPY', 'SORPTION-DESORPTION MEASUREMENT', 'Emissions', - 'DLS ACF', 'DLS intensity'] + with open('data_type.json', 'r') as mapping_file: + data_type_mappings = json.load(mapping_file).get("datatypes") + dts = set(data_type_mappings.values()) + dts.discard('NMR') + return self.typ in dts def __is_ir(self): return self.typ in ['INFRARED'] @@ -175,13 +113,13 @@ def __is_aif(self): return self.typ in ['SORPTION-DESORPTION MEASUREMENT'] def __is_emissions(self): - return self.typ in ['Emissions', 'EMISSIONS', 'FLUORESCENCE SPECTRUM', 'FL SPECTRUM'] + return self.typ in ['Emissions'] def __is_dls_acf(self): return self.typ in ['DLS ACF'] def __is_dls_intensity(self): - return self.typ in ['DLS INTENSITY', 'DLS intensity'] + return self.typ in ['DLS intensity'] def __ncl(self): try: diff --git a/chem_spectra/lib/converter/jcamp/data_type.json b/chem_spectra/lib/converter/jcamp/data_type.json new file mode 100644 index 00000000..adcfbb46 --- /dev/null +++ b/chem_spectra/lib/converter/jcamp/data_type.json @@ -0,0 +1,27 @@ +{ + "datatypes": { + "NMR SPECTRUM": "NMR", + "NMRSPECTRUM": "NMR", + "INFRARED SPECTRUM": "INFRARED", + "RAMAN SPECTRUM": "RAMAN", + "MASS SPECTRUM": "MS", + "HPLC UV/VIS SPECTRUM": "HPLC UVVIS", + "HPLC UV-VIS": "HPLC UVVIS", + "UV/VIS SPECTRUM": "UVVIS", + "UV-VIS": "UVVIS", + "ULTRAVIOLET SPECTRUM": "UVVIS", + "THERMOGRAVIMETRIC ANALYSIS": "THERMOGRAVIMETRIC ANALYSIS", + "X-RAY DIFFRACTION": "X-RAY DIFFRACTION", + "CYCLIC VOLTAMMETRY": "CYCLIC VOLTAMMETRY", + "SIZE EXCLUSION CHROMATOGRAPHY": "SIZE EXCLUSION CHROMATOGRAPHY", + "CIRCULAR DICHROISM SPECTROSCOPY": "CIRCULAR DICHROISM SPECTROSCOPY", + "SORPTION-DESORPTION MEASUREMENT": "SORPTION-DESORPTION MEASUREMENT", + "Emissions": "Emissions", + "EMISSIONS": "Emissions", + "FLUORESCENCE SPECTRUM": "Emissions", + "FL SPECTRUM": "Emissions", + "DLS ACF": "DLS ACF", + "DLS INTENSITY": "DLS intensity", + "DLS intensity": "DLS intensity" + } +} diff --git a/chem_spectra/lib/converter/jcamp/ni.py b/chem_spectra/lib/converter/jcamp/ni.py index 9ffec181..e859c4ff 100644 --- a/chem_spectra/lib/converter/jcamp/ni.py +++ b/chem_spectra/lib/converter/jcamp/ni.py @@ -4,7 +4,7 @@ from chem_spectra.lib.converter.datatable import DatatableModel from chem_spectra.lib.shared.calc import to_float from chem_spectra.lib.converter.jcamp.data_parse import make_ni_data_ys, make_ni_data_xs - +import json THRESHOLD_IR = 0.93 THRESHOLD_RAMAN = 0.07 @@ -74,42 +74,32 @@ def __init__(self, base): def __thres(self): dt = self.datatype - if 'NMR SPECTRUM' == dt: - return THRESHOLD_NMR - elif 'NMRSPECTRUM' == dt: # MNova + with open('data_type.json', 'r') as mapping_file: + data_type_mappings = json.load(mapping_file)["datatypes"] + + if data_type_mappings.get(dt) == "NMR": return THRESHOLD_NMR - elif 'INFRARED SPECTRUM' == dt: + elif data_type_mappings.get(dt) == "INFRARED": return THRESHOLD_IR - elif 'RAMAN SPECTRUM' == dt: + elif data_type_mappings.get(dt) == "RAMAN": return THRESHOLD_RAMAN - elif 'MASS SPECTRUM' == dt: + elif data_type_mappings.get(dt) == "MS": return THRESHOLD_MS - elif 'HPLC UV/VIS SPECTRUM' == dt: - return THRESHOLD_UVVIS - elif 'HPLC UV-VIS' == dt: - return THRESHOLD_UVVIS - elif dt in ['UV/VIS SPECTRUM', 'UV-VIS', 'ULTRAVIOLET SPECTRUM']: + elif data_type_mappings.get(dt) in ["HPLC UVVIS", 'UVVIS']: return THRESHOLD_UVVIS - elif dt in ['THERMOGRAVIMETRIC ANALYSIS', 'DLS ACF']: + elif data_type_mappings.get(dt) in ['THERMOGRAVIMETRIC ANALYSIS', 'DLS ACF']: return THRESHOLD_TGA - elif dt in ['X-RAY DIFFRACTION', 'CIRCULAR DICHROISM SPECTROSCOPY', 'CYCLIC VOLTAMMETRY', 'SORPTION-DESORPTION MEASUREMENT', - 'DLS INTENSITY', 'DLS intensity']: + elif data_type_mappings.get(dt) in ['X-RAY DIFFRACTION', 'CIRCULAR DICHROISM SPECTROSCOPY', 'CYCLIC VOLTAMMETRY', + 'SORPTION-DESORPTION MEASUREMENT', 'DLS intensity']: return THRESHOLD_XRD - elif dt in ['Emissions', 'EMISSIONS', 'FLUORESCENCE SPECTRUM', 'FL SPECTRUM']: + elif data_type_mappings.get(dt) in ['Emissions']: return THRESHOLD_EMISSION return 0.5 def __index_target(self): - target_topics = [ - 'NMR SPECTRUM', 'NMRSPECTRUM', - 'INFRARED SPECTRUM', 'RAMAN SPECTRUM', - 'MASS SPECTRUM', 'UV/VIS SPECTRUM', 'UV-VIS', 'ULTRAVIOLET SPECTRUM', - 'HPLC UV-VIS', 'HPLC UV/VIS SPECTRUM', - 'THERMOGRAVIMETRIC ANALYSIS', 'X-RAY DIFFRACTION', - 'CYCLIC VOLTAMMETRY', 'SIZE EXCLUSION CHROMATOGRAPHY', - 'CIRCULAR DICHROISM SPECTROSCOPY', 'SORPTION-DESORPTION MEASUREMENT', - 'Emissions', 'EMISSIONS', 'FLUORESCENCE SPECTRUM', 'FL SPECTRUM', 'DLS ACF', 'DLS INTENSITY', 'DLS intensity' - ] + with open('data_type.json', 'r') as mapping_file: + target_topics = json.load(mapping_file).get("datatypes") + for tp in target_topics: if tp in self.datatypes: idx = self.datatypes.index(tp)