diff --git a/chem_spectra/lib/composer/ni.py b/chem_spectra/lib/composer/ni.py index 6d30bd0..fb52f32 100644 --- a/chem_spectra/lib/composer/ni.py +++ b/chem_spectra/lib/composer/ni.py @@ -130,6 +130,16 @@ def __gen_header_cyclic_voltammetry(self): '$$ === CHEMSPECTRA CYCLIC VOLTAMMETRY ===\n', ] + def __gen_header_sec(self): + core_dic = self.core.dic + sec_data_key = ['MN', 'MW', 'MP', 'D'] + result = [] + for key in sec_data_key: + dic_value = core_dic.get(key, []) + key_str = f"##{key}={dic_value[0]}\n" if len(dic_value) > 0 else f'##{key}=\n' + result.append(key_str) + return result + def __get_xy_of_peak(self, peak): if peak is None: return '', '' @@ -201,6 +211,8 @@ def __compose(self): meta.extend(self.gen_headers_root()) meta.extend(self.__gen_headers_spectrum_orig()) + if self.core.is_sec: + meta.extend(self.__gen_header_sec()) meta.extend(self.gen_spectrum_orig()) meta.extend(self.__gen_headers_im()) meta.extend(self.__gen_headers_integration()) diff --git a/tests/fixtures/source/sec/SEC-ExFile.zip b/tests/fixtures/source/sec/SEC-ExFile.zip new file mode 100644 index 0000000..cabf0d4 Binary files /dev/null and b/tests/fixtures/source/sec/SEC-ExFile.zip differ diff --git a/tests/lib/composer/test_ni_composer.py b/tests/lib/composer/test_ni_composer.py index 44b9a4a..bf47110 100644 --- a/tests/lib/composer/test_ni_composer.py +++ b/tests/lib/composer/test_ni_composer.py @@ -1,13 +1,17 @@ import json import pytest import numpy as np +import tempfile +import zipfile from chem_spectra.lib.converter.jcamp.base import JcampBaseConverter from chem_spectra.lib.converter.jcamp.ni import JcampNIConverter from chem_spectra.lib.composer.ni import NIComposer +from chem_spectra.lib.converter.bagit.base import BagItBaseConverter as BagItConveter source_nmr = './tests/fixtures/source/1H.dx' source_nmr_edit = './tests/fixtures/source/1H.edit.jdx' source_ir = './tests/fixtures/source/IR.dx' +source_sec = './tests/fixtures/source/sec/SEC-ExFile.zip' @pytest.fixture def data_schema(): @@ -29,6 +33,10 @@ def jcamp_file_1h_edit(): def jcamp_file_ir(): return source_ir +@pytest.fixture +def bagit_file_sec(): + return source_sec + def test_init_ni_composer_failed(): with pytest.raises(Exception) as error: _ = NIComposer(None) @@ -203,3 +211,19 @@ def test_ni_composer_generate_nmrium(jcamp_file_1h): y_value = xy_points['re'] assert len(x_values) == 65536 assert len(y_value) == 65536 + +def test_ni_composer_generate_jcamp(bagit_file_sec): + with tempfile.TemporaryDirectory() as td: + with zipfile.ZipFile(bagit_file_sec, 'r') as z: + z.extractall(td) + + converter = BagItConveter(td) + for jcamp_file in converter.data: + base_converter = JcampBaseConverter(jcamp_file.name) + ni_converter = JcampNIConverter(base=base_converter) + ni_composer = NIComposer(core=ni_converter) + headers = ni_composer._NIComposer__gen_header_sec() + assert headers in [ + ['##MN=1.287E+3\n', '##MW=1.465E+3\n', '##MP=1.345E+3\n', '##D=1.139E+0\n'], + ['##MN=\n', '##MW=\n', '##MP=\n', '##D=\n'] + ] \ No newline at end of file