From c4d7ae743d12b96cfef22dc47a22da766b3c32cd Mon Sep 17 00:00:00 2001 From: Lan Le Date: Wed, 5 Jun 2024 10:48:09 +0200 Subject: [PATCH] feat: process DSC layout --- chem_spectra/controller/helper/share.py | 2 + chem_spectra/lib/composer/ni.py | 42 ++++++++---------- chem_spectra/lib/converter/jcamp/base.py | 4 ++ .../lib/converter/jcamp/data_type.json | 3 +- .../converter/jcamp/data_type.json.example | 3 +- chem_spectra/lib/converter/jcamp/ni.py | 4 +- chem_spectra/lib/converter/share.py | 4 ++ tests/fixtures/source/bagit/dsc/dsc.zip | Bin 0 -> 13972 bytes .../bagit/test_bagit_base_converter.py | 10 +++++ tests/lib/converter/test_share.py | 6 +++ 10 files changed, 51 insertions(+), 27 deletions(-) create mode 100644 tests/fixtures/source/bagit/dsc/dsc.zip diff --git a/chem_spectra/controller/helper/share.py b/chem_spectra/controller/helper/share.py index 684ac6f8..3ae0ff55 100644 --- a/chem_spectra/controller/helper/share.py +++ b/chem_spectra/controller/helper/share.py @@ -107,6 +107,7 @@ def extract_params(request): list_file_names = request.form.getlist('list_file_names[]') data_type_mapping = request.form.get('data_type_mapping', default='') detector = request.form.get('detector', default=None) + dsc_meta_data = request.form.get('dsc_meta_data', default=None) params = { 'peaks_str': request.form.get('peaks_str', default=None), @@ -131,6 +132,7 @@ def extract_params(request): 'axesUnits': axesUnits, 'data_type_mapping': data_type_mapping, 'detector': detector, + 'dsc_meta_data': dsc_meta_data, } has_params = ( params.get('peaks_str') or diff --git a/chem_spectra/lib/composer/ni.py b/chem_spectra/lib/composer/ni.py index 59edd683..cb8e530c 100644 --- a/chem_spectra/lib/composer/ni.py +++ b/chem_spectra/lib/composer/ni.py @@ -140,6 +140,22 @@ def __gen_header_sec(self): result.append(key_str) return result + def __gen_header_user_input_meta_data(self): + if self.core.is_dsc: + dsc_meta_data = self.core.params.get('dsc_meta_data', None) + melting_point, tg_value = '', '' + if dsc_meta_data is not None: + melting_point = dsc_meta_data.get('meltingPoint', '') + tg_value = dsc_meta_data.get('tg', '') + else: + melting_point = self.core.dic.get('MELTINGPOINT', '') + tg_value = self.core.dic.get('TG', '') + return [ + f'##MELTINGPOINT={melting_point}\n', + f'##TG={tg_value}\n' + ] + return [] + def __get_xy_of_peak(self, peak): if peak is None: return '', '' @@ -213,6 +229,7 @@ def __compose(self): meta.extend(self.__gen_headers_spectrum_orig()) if self.core.is_sec: meta.extend(self.__gen_header_sec()) + meta.extend(self.__gen_header_user_input_meta_data()) meta.extend(self.gen_spectrum_orig()) meta.extend(self.__gen_headers_im()) meta.extend(self.__gen_headers_integration()) @@ -242,35 +259,12 @@ def __compose(self): return meta def __plt_nbins(self): - typ = self.core.typ - if 'NMR' == typ: - return 20 - elif 'INFRARED' == typ: - return 20 - elif 'RAMAN' == typ: - return 20 - elif 'UVVIS' == typ: - return 20 - elif 'THERMOGRAVIMETRIC ANALYSIS' == typ: - return 20 - elif 'MS' == typ: - return 20 return 20 def __fakto(self): typ = self.core.typ - if 'NMR' == typ: - return 1 - elif 'MS' == typ: - return 1 - elif 'INFRARED' == typ: + if 'INFRARED' == typ: return -1 - elif 'RAMAN' == typ: - return 1 - elif 'UVVIS' == typ: - return 1 - elif 'THERMOGRAVIMETRIC ANALYSIS' == typ: - return 1 return 1 def tf_img(self): diff --git a/chem_spectra/lib/converter/jcamp/base.py b/chem_spectra/lib/converter/jcamp/base.py index 846c3610..78621ecd 100644 --- a/chem_spectra/lib/converter/jcamp/base.py +++ b/chem_spectra/lib/converter/jcamp/base.py @@ -34,6 +34,7 @@ def __init__(self, path, params=False): self.is_emissions = self.__is_emissions() self.is_dls_acf = self.__is_dls_acf() self.is_dls_intensity = self.__is_dls_intensity() + self.is_dsc = self.__is_dsc() self.non_nmr = self.__non_nmr() self.ncl = self.__ncl() self.simu_peaks = self.__read_simu_peaks() @@ -156,6 +157,9 @@ def __is_dls_acf(self): def __is_dls_intensity(self): return self.typ in ['DLS intensity'] + + def __is_dsc(self): + return self.typ in ['DIFFERENTIAL SCANNING CALORIMETRY'] def __ncl(self): try: diff --git a/chem_spectra/lib/converter/jcamp/data_type.json b/chem_spectra/lib/converter/jcamp/data_type.json index bd90604f..8cccc47f 100644 --- a/chem_spectra/lib/converter/jcamp/data_type.json +++ b/chem_spectra/lib/converter/jcamp/data_type.json @@ -14,6 +14,7 @@ "SORPTION-DESORPTION MEASUREMENT": ["SORPTION-DESORPTION MEASUREMENT"], "Emissions": ["Emissions", "EMISSIONS", "FLUORESCENCE SPECTRUM", "FL SPECTRUM"], "DLS ACF": ["DLS ACF"], - "DLS intensity": ["DLS INTENSITY", "DLS intensity"] + "DLS intensity": ["DLS INTENSITY", "DLS intensity"], + "DIFFERENTIAL SCANNING CALORIMETRY": ["DIFFERENTIAL SCANNING CALORIMETRY"] } } diff --git a/chem_spectra/lib/converter/jcamp/data_type.json.example b/chem_spectra/lib/converter/jcamp/data_type.json.example index 5c135ad6..26b5ff20 100644 --- a/chem_spectra/lib/converter/jcamp/data_type.json.example +++ b/chem_spectra/lib/converter/jcamp/data_type.json.example @@ -14,6 +14,7 @@ "SORPTION-DESORPTION MEASUREMENT": ["SORPTION-DESORPTION MEASUREMENT"], "Emissions": ["Emissions", "EMISSIONS", "FLUORESCENCE SPECTRUM", "FL SPECTRUM"], "DLS ACF": ["DLS ACF"], - "DLS intensity": ["DLS INTENSITY", "DLS intensity"] + "DLS intensity": ["DLS INTENSITY", "DLS intensity"], + "DIFFERENTIAL SCANNING CALORIMETRY": ["DIFFERENTIAL SCANNING CALORIMETRY"] } } diff --git a/chem_spectra/lib/converter/jcamp/ni.py b/chem_spectra/lib/converter/jcamp/ni.py index ce2bc6e8..7e016917 100644 --- a/chem_spectra/lib/converter/jcamp/ni.py +++ b/chem_spectra/lib/converter/jcamp/ni.py @@ -43,6 +43,7 @@ def __init__(self, base): self.is_emissions = base.is_emissions if hasattr(base, 'is_emissions') else False self.is_dls_acf = base.is_dls_acf if hasattr(base, 'is_dls_acf') else False self.is_dls_intensity = base.is_dls_intensity if hasattr(base, 'is_dls_intensity') else False + self.is_dsc = base.is_dsc if hasattr(base, 'is_dsc') else False self.non_nmr = base.non_nmr self.ncl = base.ncl self.is_dept = base.is_dept @@ -98,7 +99,8 @@ def __thres(self): "CYCLIC VOLTAMMETRY": THRESHOLD_XRD, "SORPTION-DESORPTION MEASUREMENT": THRESHOLD_XRD, "DLS intensity": THRESHOLD_XRD, - "Emissions": THRESHOLD_EMISSION + "Emissions": THRESHOLD_EMISSION, + "DIFFERENTIAL SCANNING CALORIMETRY": THRESHOLD_TGA, } if self.params.get('user_data_type_mapping'): diff --git a/chem_spectra/lib/converter/share.py b/chem_spectra/lib/converter/share.py index 7766d420..e98563d4 100644 --- a/chem_spectra/lib/converter/share.py +++ b/chem_spectra/lib/converter/share.py @@ -25,6 +25,7 @@ def parse_params(params): 'jcamp_idx': 0, 'axesUnits': None, 'detector': None, + 'dsc_meta_data': None, } select_x = params.get('select_x', None) @@ -68,6 +69,8 @@ def parse_params(params): user_data_type_mapping = params.get('data_type_mapping') detector = params.get('detector') detector = json.loads(detector) if detector else None + dsc_meta_data = params.get('dsc_meta_data') + dsc_meta_data = json.loads(dsc_meta_data) if dsc_meta_data else None if (cyclicvolta is not None): spectraList = cyclicvolta['spectraList'] if (len(spectraList) > 0): @@ -101,6 +104,7 @@ def parse_params(params): 'axesUnits': axesUnits, 'user_data_type_mapping': user_data_type_mapping, 'detector': detector, + 'dsc_meta_data': dsc_meta_data, } diff --git a/tests/fixtures/source/bagit/dsc/dsc.zip b/tests/fixtures/source/bagit/dsc/dsc.zip new file mode 100644 index 0000000000000000000000000000000000000000..63079a3965fc4e35792237fe98fd5defb53ea883 GIT binary patch literal 13972 zcmeHOTW?!g70xgWh)6sjka*on2dSm8bN1!jGWa2NoYpjPBHQUCOdvX!eNxZFb`(2R zN25yf!V?JbGZ5l|5zoBvEBFCOJo5|^eCzm8!z4kuey6)TZ&eM0l z`GW;|^?vf_yCm2*qLUMGUzTOrd4MkKYwb1B z-ruQJ*6SM^wP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_RcF-GQ$1pQ?R<3FIy&=1y+SdUPR^O=A=3i?f<%*3jw?9E`)hE_ z>_$hsI?ylJ|FAs*7%o_6PZz9czRm)VEtKeq7yVFx3x*9Rrpr|-8)b3LlQc$|E5A+i z1Uka}#WY4SviPc48#VadzklhWCW_wQ!8?wQI>YkthtInHAwh9O0Adl(@yVbRqVDmO2JIw)xW;z{`C(Sl-}RRyBqa7nH>yEgXfV# zjU677rOM58j9OXcgw{6+YAiC1fYW{!%0R|8GpW=`tYVdUZfdPUae8Ex&ivGI{k-a{ z@Y9+_<0&gqGOuiGbrdNtwXyQ8N`gRTNt*d8PW>cGW#VZk46U>#L9J$-S)HQXOp8nE z!)Ap0(SG!&<#!eq=shbO%I8Tq9cPhAq?fs22}DJp8dzB_=c~GmzJf@NknBK#`3KX>F(zpKrkTJo( literal 0 HcmV?d00001 diff --git a/tests/lib/converter/bagit/test_bagit_base_converter.py b/tests/lib/converter/bagit/test_bagit_base_converter.py index 9a0edbde..2e798168 100644 --- a/tests/lib/converter/bagit/test_bagit_base_converter.py +++ b/tests/lib/converter/bagit/test_bagit_base_converter.py @@ -10,6 +10,7 @@ emissions_layout_path = target_dir + 'emissions/emissions.zip' dls_acf_layout_path = target_dir + 'dls_acf/dls_acf.zip' dls_intensity_layout_path = target_dir + 'dls_intensity/dls_intensity.zip' +dsc_layout_path = target_dir + 'dsc/dsc.zip' def assertFileType(file, mimeStr): assert mimetypes.guess_type(file.name)[0] == mimeStr @@ -144,3 +145,12 @@ def test_bagit_has_one_file_no_combined_image(): converter = BagItConveter(td) assert converter.combined_image is None + +def test_bagit_convert_to_jcamp_dsc_layout(): + with tempfile.TemporaryDirectory() as td: + with zipfile.ZipFile(dsc_layout_path, 'r') as z: + z.extractall(td) + + converter = BagItConveter(td) + jcamp = converter.data[0] + assertJcampContent(jcamp, '##DATA TYPE=DIFFERENTIAL SCANNING CALORIMETRY') diff --git a/tests/lib/converter/test_share.py b/tests/lib/converter/test_share.py index cd19ba11..afde62d8 100644 --- a/tests/lib/converter/test_share.py +++ b/tests/lib/converter/test_share.py @@ -28,6 +28,7 @@ def expected_default_params(): 'jcamp_idx': 0, 'axesUnits': None, 'detector': None, + 'dsc_meta_data': None, } def test_parse_params_without_params(expected_default_params): @@ -222,6 +223,11 @@ def test_parse_params_detector(): def test_parse_solvent(): #TODO: need to be updated assert 1==1 + +def test_parse_dsc_meta_data(): + params = {'dsc_meta_data': '{"meltingPoint": "1.0", "tg": "1.0"}'} + parsed_data = parse_params(params) + assert parsed_data['dsc_meta_data'] == {"meltingPoint": "1.0", "tg": "1.0"} def test_reduce_pts_when_does_not_have_any_x(): array_data = []