Skip to content

Commit

Permalink
update mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
f-idiris committed Sep 26, 2023
1 parent cbe0786 commit 48521b1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 56 deletions.
36 changes: 27 additions & 9 deletions chem_spectra/lib/converter/jcamp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import json

from chem_spectra.lib.converter.share import parse_params, parse_solvent
import os

data_type_json = os.path.join(os.path.dirname(__file__), 'data_type.json')


class JcampBaseConverter:
Expand Down Expand Up @@ -44,21 +47,37 @@ def __read(self, path):

def __set_datatype(self):
dts = self.datatypes
dt_dict = {
'NMR': 'NMR SPECTRUM',
'INFRARED': 'INFRARED SPECTRUM',
'RAMAN': 'RAMAN SPECTRUM',
'MS': 'MASS SPECTRUM',
'HPLC UVVIS': 'HPLC UV/VIS SPECTRUM',
'UVVIS': 'UV/VIS SPECTRUM',
}

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]
if dt in dt_dict:
return dt_dict[dt]

with open(data_type_json, 'r') as mapping_file:
data_type_mappings = json.load(mapping_file)["datatypes"]
for key, values in data_type_mappings.items():
for dt in dts:
if dt in values:
return key
return ''

def __typ(self):
dt = self.datatype

with open('data_type.json', 'r') as mapping_file:
with open(data_type_json, 'r') as mapping_file:
data_type_mappings = json.load(mapping_file)["datatypes"]

return data_type_mappings.get(dt, '')
for key, values in data_type_mappings.items():
if dt in values:
return key
return ''

def __set_dataclass(self):
data_class = self.dataclasses
Expand All @@ -79,10 +98,9 @@ def __is_em_wave(self):
return self.typ in ['INFRARED', 'RAMAN', 'UVVIS']

def __non_nmr(self):
with open('data_type.json', 'r') as mapping_file:
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')
dts = [dt for dt in data_type_mappings.keys() if dt != 'NMR']
return self.typ in dts

def __is_ir(self):
Expand Down
40 changes: 16 additions & 24 deletions chem_spectra/lib/converter/jcamp/data_type.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
{
"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"
"datatypes": {
"NMR": ["NMR SPECTRUM", "NMRSPECTRUM"],
"INFRARED": ["INFRARED SPECTRUM"],
"RAMAN": ["RAMAN SPECTRUM"],
"MS": ["MASS SPECTRUM"],
"HPLC UVVIS": ["HPLC UV/VIS SPECTRUM", "HPLC UV-VIS"],
"UV/VIS SPECTRUM": ["UV/VIS SPECTRUM", "UV-VIS", "ULTRAVIOLET SPECTRUM"],
"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", "FLUORESCENCE SPECTRUM", "FL SPECTRUM"],
"DLS ACF": ["DLS ACF"],
"DLS intensity": ["DLS INTENSITY", "DLS intensity"]
}
}
49 changes: 26 additions & 23 deletions chem_spectra/lib/converter/jcamp/ni.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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
import os

THRESHOLD_IR = 0.93
THRESHOLD_RAMAN = 0.07
Expand All @@ -14,7 +15,7 @@
THRESHOLD_TGA = 1.05
THRESHOLD_XRD = 1.00
THRESHOLD_EMISSION = 0.5

data_type_json = os.path.join(os.path.dirname(__file__), 'data_type.json')

class JcampNIConverter: # nmr & IR
def __init__(self, base):
Expand Down Expand Up @@ -74,31 +75,33 @@ def __init__(self, base):

def __thres(self):
dt = self.datatype
with open('data_type.json', 'r') as mapping_file:
threshold_values = {
"NMR": THRESHOLD_NMR,
"INFRARED": THRESHOLD_IR,
"RAMAN": THRESHOLD_RAMAN,
"MS": THRESHOLD_MS,
"HPLC UVVIS": THRESHOLD_UVVIS,
"UVVIS": THRESHOLD_UVVIS,
"THERMOGRAVIMETRIC ANALYSIS": THRESHOLD_TGA,
"DLS ACF": THRESHOLD_TGA,
"X-RAY DIFFRACTION": THRESHOLD_XRD,
"CIRCULAR DICHROISM SPECTROSCOPY": THRESHOLD_XRD,
"CYCLIC VOLTAMMETRY": THRESHOLD_XRD,
"SORPTION-DESORPTION MEASUREMENT": THRESHOLD_XRD,
"DLS intensity": THRESHOLD_XRD,
"Emissions": THRESHOLD_EMISSION
}
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 data_type_mappings.get(dt) == "INFRARED":
return THRESHOLD_IR
elif data_type_mappings.get(dt) == "RAMAN":
return THRESHOLD_RAMAN
elif data_type_mappings.get(dt) == "MS":
return THRESHOLD_MS
elif data_type_mappings.get(dt) in ["HPLC UVVIS", 'UVVIS']:
return THRESHOLD_UVVIS
elif data_type_mappings.get(dt) in ['THERMOGRAVIMETRIC ANALYSIS', 'DLS ACF']:
return THRESHOLD_TGA
elif data_type_mappings.get(dt) in ['X-RAY DIFFRACTION', 'CIRCULAR DICHROISM SPECTROSCOPY', 'CYCLIC VOLTAMMETRY',
'SORPTION-DESORPTION MEASUREMENT', 'DLS intensity']:
return THRESHOLD_XRD
elif data_type_mappings.get(dt) in ['Emissions']:
return THRESHOLD_EMISSION
return 0.5
key = next((k for k, v in data_type_mappings.items() if dt in v), None)

return threshold_values.get(key, 0.5)


def __index_target(self):
with open('data_type.json', 'r') as mapping_file:
target_topics = json.load(mapping_file).get("datatypes")
with open(data_type_json, 'r') as mapping_file:
target = json.load(mapping_file).get("datatypes").values()
target_topics = [value for values in target for value in values]

for tp in target_topics:
if tp in self.datatypes:
Expand Down

0 comments on commit 48521b1

Please sign in to comment.