diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..6f761b39 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "submodules/pynxtools"] + path = submodules/pynxtools + url = https://github.com/FAIRmat-NFDI/pynxtools.git diff --git a/pyproject.toml b/pyproject.toml index 392b9d58..e60b0c69 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = [ "setuptools>=61.0.0",] +requires = [ "setuptools>=61.0.0"] build-backend = "setuptools.build_meta" [project] @@ -10,14 +10,17 @@ readme = "README.md" requires-python = ">=3.9" classifiers = [ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.9",] dependencies = [ - "nomad-lab>=1.2.1.dev,<1.2.2", - "pytest", "structlog==22.3.0", - "xrayutilities>=1.7.4", -] + "xrayutilities>=1.7.4"] + + +[project.optional-dependencies] +dev = ["pytest", + "pip-tools"] [project.license] file = "LICENSE" [tool.setuptools.packages.find] -where = [ "src",] +where = ["src"] + diff --git a/setup.py b/setup.py index 7f1a1763..f840852f 100644 --- a/setup.py +++ b/setup.py @@ -2,3 +2,4 @@ if __name__ == "__main__": setup() + diff --git a/src/nomad_measurements/xrd/parser.py b/src/nomad_measurements/xrd/parser.py index 635b119e..d018dae5 100644 --- a/src/nomad_measurements/xrd/parser.py +++ b/src/nomad_measurements/xrd/parser.py @@ -50,9 +50,11 @@ def __init__(self): ) def parse(self, mainfile: str, archive: EntryArchive, logger) -> None: + from pathlib import Path data_file = mainfile.split('/')[-1] entry = ELNXRayDiffraction.m_from_dict(ELNXRayDiffraction.m_def.a_template) entry.data_file = data_file file_name = f'{data_file[:-6]}.archive.json' - archive.data = XRDDataFile(measurement=create_archive(entry,archive,file_name)) - archive.metadata.entry_name = data_file[:-6] + ' data file' \ No newline at end of file + measurement=create_archive(entry, archive, file_name) + archive.data = XRDDataFile(measurement=measurement) + archive.metadata.entry_name = data_file[:-6] + ' data file' diff --git a/src/nomad_measurements/xrd/schema.py b/src/nomad_measurements/xrd/schema.py index fdfd4182..cd913eee 100644 --- a/src/nomad_measurements/xrd/schema.py +++ b/src/nomad_measurements/xrd/schema.py @@ -17,12 +17,15 @@ # import numpy as np +from pynxtools.dataconverter.convert import transfer_data_into_template +from nomad.datamodel.metainfo.eln.nexus_data_converter import populate_nexus_subsection from nomad.datamodel.metainfo.basesections import ( Measurement, MeasurementResult, CompositeSystemReference, ReadableIdentifiers, ) +from memory_profiler import profile from structlog.stdlib import ( BoundLogger, ) @@ -60,65 +63,12 @@ XRDMethod, ) -from nomad_measurements.xrd.xrd_parser import parse_and_convert_file +from nomad_measurements.xrd.xrd_helper import (calculate_two_theta_or_scattering_vector, + estimate_kalpha_wavelengths) m_package = Package(name='nomad-measurements') -def calculate_two_theta_or_scattering_vector(q=None, two_theta=None, wavelength=None): - """ - Calculate the two-theta array from the scattering vector (q) or vice-versa, - given the wavelength of the X-ray source. - - Args: - q (array-like, optional): Array of scattering vectors, in angstroms^-1. - two_theta (array-like, optional): Array of two-theta angles, in degrees. - wavelength (float): Wavelength of the X-ray source, in angstroms. - - Returns: - numpy.ndarray: Array of two-theta angles, in degrees. - """ - if q is not None: - return 2 * np.arcsin(q * wavelength / (4 * np.pi)) - elif two_theta is not None: - return (4 * np.pi / wavelength) * np.sin(np.deg2rad(two_theta) / 2) - else: - raise ValueError("Either q or two_theta must be provided.") - - -def estimate_kalpha_wavelengths(source_material): - """ - Estimate the K-alpha1 and K-alpha2 wavelengths of an X-ray source given the material - of the source. - - Args: - source_material (str): Material of the X-ray source, such as 'Cu', 'Fe', 'Mo', - 'Ag', 'In', 'Ga', etc. - - Returns: - Tuple[float, float]: Estimated K-alpha1 and K-alpha2 wavelengths of the X-ray - source, in angstroms. - """ - # Dictionary of K-alpha1 and K-alpha2 wavelengths for various X-ray source materials, - # in angstroms - kalpha_wavelengths = { - 'Cr': (2.2910, 2.2936), - 'Fe': (1.9359, 1.9397), - 'Cu': (1.5406, 1.5444), - 'Mo': (0.7093, 0.7136), - 'Ag': (0.5594, 0.5638), - 'In': (0.6535, 0.6577), - 'Ga': (1.2378, 1.2443) - } - - try: - kalpha1_wavelength, kalpha2_wavelength = kalpha_wavelengths[source_material] - except KeyError: - raise ValueError("Unknown X-ray source material.") - - return kalpha1_wavelength, kalpha2_wavelength - - class XRayTubeSource(ArchiveSection): ''' X-ray tube source used in conventional diffractometers. @@ -188,13 +138,13 @@ def derive_n_values(self): return len(self.two_theta) else: return 0 - + n_values = Quantity( type=int, derived=derive_n_values, ) two_theta = Quantity( - type=np.dtype(np.float64), shape=['n_values'], + type=np.dtype(np.float64), shape=['n_values'], unit='deg', description='The 2-theta range of the difractogram', a_plot={ @@ -272,6 +222,7 @@ class XRayDiffraction(Measurement): xrd_settings = SubSection( section_def=XRDSettings, ) + data_file = Quantity( type=str, description='Data file containing the difractogram', @@ -279,6 +230,15 @@ class XRayDiffraction(Measurement): component='FileEditQuantity', ), ) + # Note: Include a_browser option in nexus_output if we add read ability from nxs type file. + # a_browser=dict(adaptor='RawFileAdaptor'), + nexus_output = Quantity( + type=str, + description=('NeXus file for data and metadata according to NeXus application definitions' + 'NXxrd_pan. (Optional)'), + a_eln=dict(component='StringEditQuantity'), + default="" + ) diffraction_method_name = Quantity( type=MEnum( [ @@ -319,33 +279,60 @@ def normalize(self, archive, logger: BoundLogger) -> None: # Use the xrd parser to populate the schema reading the data file if not self.data_file: return - + import os result = XRDResult() settings = XRDSettings() + nxdl_name = 'NXxrd_pan' + raw_dir = archive.m_context.raw_path() + # instance could be different name. + xrd_template = transfer_data_into_template(nxdl_name=nxdl_name, input_file=os.path.join(raw_dir, self.data_file), reader='xrd') with archive.m_context.raw_file(self.data_file) as file: - xrd_dict = parse_and_convert_file(file.name) - result.intensity = xrd_dict.get('detector', None) - result.two_theta = xrd_dict['2Theta'] * ureg('degree') if '2Theta' in xrd_dict and xrd_dict['2Theta'] is not None else None - result.omega = xrd_dict['Omega'] * ureg('degree') if 'Omega' in xrd_dict and xrd_dict['Omega'] is not None else None - result.chi = xrd_dict['Chi'] * ureg('degree') if 'Chi' in xrd_dict and xrd_dict['Chi'] is not None else None + # archive.m_context.process_upload_raw_file(archive.data.output, allow_modify=True) + # Comes from detector + intensity = "/ENTRY[entry]/DATA[q_plot]/intensity" + result.intensity = xrd_template.get(intensity, None) + two_theta = "/ENTRY[entry]/2theta_plot/two_theta" + result.two_theta = xrd_template.get(two_theta, None) * ureg('degree') if xrd_template.get(two_theta, None) is not None else None + omega = "/ENTRY[entry]/2theta_plot/omega" + result.omega = xrd_template.get(omega, None) * ureg('degree') if xrd_template.get(omega, None) is not None else None + chi = "/ENTRY[entry]/2theta_plot/chi" + result.chi = xrd_template.get(chi, None) * ureg('degree') if xrd_template.get(chi, None) is not None else None if settings.source is None: settings.source = XRayTubeSource() - metadata_dict = xrd_dict.get('metadata', {}) - source_dict = metadata_dict.get('source', {}) - settings.source.xray_tube_material = source_dict.get('anode_material', None) - settings.source.kalpha_one = source_dict.get('kAlpha1', None) - settings.source.kalpha_two = source_dict.get('kAlpha2', None) - settings.source.ratio_kalphatwo_kalphaone = source_dict.get('ratioKAlpha2KAlpha1', None) - settings.source.kbeta = source_dict.get('kBeta', None) - settings.source.xray_tube_voltage = source_dict.get('voltage', None) - settings.source.xray_tube_current = source_dict.get('current', None) - result.scan_axis = metadata_dict.get('scan_axis', None) - result.integration_time = xrd_dict['countTime'] * ureg('second') if xrd_dict['countTime'] is not None else None - samples=CompositeSystemReference() - samples.lab_id=xrd_dict['metadata']["sample_id"] + xray_tb_mat = "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/xray_tube_material" + settings.source.xray_tube_material = xrd_template.get(xray_tb_mat, None) + alpha_one = "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/k_alpha_one" + settings.source.kalpha_one = xrd_template.get(alpha_one, None) + alpha_two = "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/k_alpha_two" + settings.source.kalpha_two = xrd_template.get(alpha_two, None) + one_to_ratio = "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/ratio_k_alphatwo_k_alphaone" + settings.source.ratio_kalphatwo_kalphaone = xrd_template.get(one_to_ratio, None) + kbeta = "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/kbeta" + settings.source.kbeta = xrd_template.get(kbeta, None) + voltage = "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/xray_tube_voltage" + settings.source.xray_tube_voltage = xrd_template.get(voltage, None) + current = "/ENTRY[entry]/INSTRUMENT[instrument]/SOURCE[source]/xray_tube_current" + settings.source.xray_tube_current = xrd_template.get(current, None) + scan_axis = "/ENTRY[entry]/INSTRUMENT[instrument]/DETECTOR[detector]/scan_axis" + result.scan_axis = xrd_template.get(scan_axis, None) + count_time = "/ENTRY[entry]/COLLECTION[collection]/count_time" + result.integration_time = xrd_template.get(count_time, None) + samples = CompositeSystemReference() + sample_id = "/ENTRY[entry]/SAMPLE[sample]/sample_id" + samples.lab_id = xrd_template.get(sample_id, None) samples.normalize(archive, logger) - self.samples=[samples] - + self.samples = [samples] + if self.nexus_output: + if not self.nexus_output.endswith('.nxs'): + self.nexus_output = self.nexus_output + ".nxs" + populate_nexus_subsection(template=xrd_template, app_def=nxdl_name, archive=archive, + logger=logger, output_file_path=self.nexus_output, + write_in_memory=False,) + else: + populate_nexus_subsection(template=xrd_template, app_def=nxdl_name, archive=archive, + logger=logger, output_file_path=self.nexus_output, + write_in_memory=True) + if settings.source.xray_tube_material is not None: xray_tube_material = settings.source.xray_tube_material settings.source.kalpha_one, settings.source.kalpha_two = estimate_kalpha_wavelengths(source_material=xray_tube_material) @@ -367,6 +354,7 @@ def normalize(self, archive, logger: BoundLogger) -> None: two_theta=result.two_theta, wavelength=result.source_peak_wavelength) except Exception: logger.warning("Unable to convert from two_theta to q_vector vice-versa") + self.xrd_settings = settings self.results = [result] @@ -376,7 +364,7 @@ def normalize(self, archive, logger: BoundLogger) -> None: archive.results.properties = Properties() if not archive.results.properties.structural: archive.results.properties.structural = StructuralProperties( - diffraction_patterns=[DiffractionPattern( + diffraction_pattern=[DiffractionPattern( incident_beam_wavelength=result.source_peak_wavelength, two_theta_angles=result.two_theta, intensity=result.intensity, diff --git a/src/nomad_measurements/xrd/xrd_helper.py b/src/nomad_measurements/xrd/xrd_helper.py new file mode 100644 index 00000000..ffe743e7 --- /dev/null +++ b/src/nomad_measurements/xrd/xrd_helper.py @@ -0,0 +1,59 @@ +""" +Gethering of functions and classes that are needed to calculate +some properties, features and to map data into nomad. +""" +import numpy as np + + +def calculate_two_theta_or_scattering_vector(q=None, two_theta=None, wavelength=None): + """ + Calculate the two-theta array from the scattering vector (q) or vice-versa, + given the wavelength of the X-ray source. + + Args: + q (array-like, optional): Array of scattering vectors, in angstroms^-1. + two_theta (array-like, optional): Array of two-theta angles, in degrees. + wavelength (float): Wavelength of the X-ray source, in angstroms. + + Returns: + numpy.ndarray: Array of two-theta angles, in degrees. + """ + if q is not None: + return 2 * np.arcsin(q * wavelength / (4 * np.pi)) + elif two_theta is not None: + return (4 * np.pi / wavelength) * np.sin(np.deg2rad(two_theta) / 2) + else: + raise ValueError("Either q or two_theta must be provided.") + + +def estimate_kalpha_wavelengths(source_material): + """ + Estimate the K-alpha1 and K-alpha2 wavelengths of an X-ray source given the material + of the source. + + Args: + source_material (str): Material of the X-ray source, such as 'Cu', 'Fe', 'Mo', + 'Ag', 'In', 'Ga', etc. + + Returns: + Tuple[float, float]: Estimated K-alpha1 and K-alpha2 wavelengths of the X-ray + source, in angstroms. + """ + # Dictionary of K-alpha1 and K-alpha2 wavelengths for various X-ray source materials, + # in angstroms + kalpha_wavelengths = { + 'Cr': (2.2910, 2.2936), + 'Fe': (1.9359, 1.9397), + 'Cu': (1.5406, 1.5444), + 'Mo': (0.7093, 0.7136), + 'Ag': (0.5594, 0.5638), + 'In': (0.6535, 0.6577), + 'Ga': (1.2378, 1.2443) + } + + try: + kalpha1_wavelength, kalpha2_wavelength = kalpha_wavelengths[source_material] + except KeyError as exc: + raise ValueError("Unknown X-ray source material.") from exc + + return kalpha1_wavelength, kalpha2_wavelength diff --git a/src/nomad_measurements/xrd/xrd_parser.py b/src/nomad_measurements/xrd/xrd_parser.py index 43ef261e..ca642abb 100644 --- a/src/nomad_measurements/xrd/xrd_parser.py +++ b/src/nomad_measurements/xrd/xrd_parser.py @@ -5,213 +5,214 @@ from nomad.units import ureg -class FileReader: - '''A class to read files from a given file path.''' - def __init__(self, file_path): - ''' - Args: - file_path (str): The path of the file to be read. - ''' - self.file_path = file_path - - def read_file(self): - '''Reads the content of a file from the given file path. +# This code part is irrelavaent as parsgin is getting done inside xrd reader +# class FileReader: +# '''A class to read files from a given file path.''' +# def __init__(self, file_path): +# ''' +# Args: +# file_path (str): The path of the file to be read. +# ''' +# self.file_path = file_path + +# def read_file(self): +# '''Reads the content of a file from the given file path. - Returns: - str: The content of the file. - ''' - with open(self.file_path, 'r', encoding='utf-8') as file: - content = file.read() - return content +# Returns: +# str: The content of the file. +# ''' +# with open(self.file_path, 'r', encoding='utf-8') as file: +# content = file.read() +# return content -class PanalyticalXRDMLParser: - '''A class to parse Panalytical XRDML files.''' +# class PanalyticalXRDMLParser: +# '''A class to parse Panalytical XRDML files.''' - def __init__(self, file_path): - ''' - Args: - file_path (str): The path of the XRDML file to be parsed. - ''' - self.file_path = file_path +# def __init__(self, file_path): +# ''' +# Args: +# file_path (str): The path of the XRDML file to be parsed. +# ''' +# self.file_path = file_path - def parse_metadata(self): - '''Parses the metadata of the XRDML file.''' +# def parse_metadata(self): +# '''Parses the metadata of the XRDML file.''' - with open(self.file_path, 'r', encoding='utf-8') as file: - content = file.read() +# with open(self.file_path, 'r', encoding='utf-8') as file: +# content = file.read() - # Remove the XML encoding declaration if it exists - content = re.sub(r'<\?xml.*\?>', '', content) +# # Remove the XML encoding declaration if it exists +# content = re.sub(r'<\?xml.*\?>', '', content) - root = ET.fromstring(content) +# root = ET.fromstring(content) - ns_version = root.tag.split("}")[0].strip("{") - ns = {'xrd': ns_version} +# ns_version = root.tag.split("}")[0].strip("{") +# ns = {'xrd': ns_version} - xrd_measurement = root.find("xrd:xrdMeasurement", ns) - xrd_sample = root.find("xrd:sample", ns) +# xrd_measurement = root.find("xrd:xrdMeasurement", ns) +# xrd_sample = root.find("xrd:sample", ns) - def find_float(path): - result = xrd_measurement.find(path, ns) - if result is not None: - unit = result.get('unit', '') - if unit == 'Angstrom': - unit = 'angstrom' - return float(result.text) * ureg(unit) - else: - return None - - metadata = { - "sample_id": xrd_sample.find(".//{*}id", ns).text if xrd_sample.find(".//{*}id", ns) is not None else None, - "measurement_type": xrd_measurement.get("measurementType", None), - "sample_mode": xrd_measurement.get("sampleMode", None), - "source": { - "voltage": find_float("xrd:incidentBeamPath/xrd:xRayTube/xrd:tension"), - "kAlpha1": find_float("xrd:usedWavelength/xrd:kAlpha1"), - "kAlpha2": find_float("xrd:usedWavelength/xrd:kAlpha2"), - "kBeta": find_float("xrd:usedWavelength/xrd:kBeta"), - "ratioKAlpha2KAlpha1": find_float("xrd:usedWavelength/xrd:ratioKAlpha2KAlpha1"), - "anode_material": xrd_measurement.find("xrd:incidentBeamPath/xrd:xRayTube/xrd:anodeMaterial", ns).text if xrd_measurement.find("xrd:incidentBeamPath/xrd:xRayTube/xrd:anodeMaterial", ns) is not None else None, - }, - - "scan_mode": xrd_measurement.find("xrd:scan", ns).get("mode") if xrd_measurement.find("xrd:scan", ns) is not None else None, - "scan_axis": xrd_measurement.find("xrd:scan", ns).get("scanAxis") if xrd_measurement.find("xrd:scan", ns) is not None else None, - } - return metadata - - - def parse_xrdml(self): - '''Parses the XRDML file using xrayutilities. - - Returns: - dict: A dictionary containing the parsed XRDML data. - ''' - # Read the XRDML file using xrayutilities - xrd_data = XRDMLFile(self.file_path) - result = xrd_data.scan.ddict - - - # Add the scanmotname, material, hkl to the dictionary - result["scanmotname"] = xrd_data.scan.scanmotname - result["material"] = xrd_data.scan.material - result["hkl"] = xrd_data.scan.hkl - # add the metadata to the dictionary - result["metadata"] = self.parse_metadata() - - return result - - -class FormatParser: - '''A class to identify and parse different file formats.''' - - def __init__(self, file_path): - ''' - Args: - file_path (str): The path of the file to be identified and parsed. - ''' - self.file_path = file_path - - def identify_format(self): - '''Identifies the format of a given file. +# def find_float(path): +# result = xrd_measurement.find(path, ns) +# if result is not None: +# unit = result.get('unit', '') +# if unit == 'Angstrom': +# unit = 'angstrom' +# return float(result.text) * ureg(unit) +# else: +# return None + +# metadata = { +# "sample_id": xrd_sample.find(".//{*}id", ns).text if xrd_sample.find(".//{*}id", ns) is not None else None, +# "measurement_type": xrd_measurement.get("measurementType", None), +# "sample_mode": xrd_measurement.get("sampleMode", None), +# "source": { +# "voltage": find_float("xrd:incidentBeamPath/xrd:xRayTube/xrd:tension"), +# "kAlpha1": find_float("xrd:usedWavelength/xrd:kAlpha1"), +# "kAlpha2": find_float("xrd:usedWavelength/xrd:kAlpha2"), +# "kBeta": find_float("xrd:usedWavelength/xrd:kBeta"), +# "ratioKAlpha2KAlpha1": find_float("xrd:usedWavelength/xrd:ratioKAlpha2KAlpha1"), +# "anode_material": xrd_measurement.find("xrd:incidentBeamPath/xrd:xRayTube/xrd:anodeMaterial", ns).text if xrd_measurement.find("xrd:incidentBeamPath/xrd:xRayTube/xrd:anodeMaterial", ns) is not None else None, +# }, + +# "scan_mode": xrd_measurement.find("xrd:scan", ns).get("mode") if xrd_measurement.find("xrd:scan", ns) is not None else None, +# "scan_axis": xrd_measurement.find("xrd:scan", ns).get("scanAxis") if xrd_measurement.find("xrd:scan", ns) is not None else None, +# } +# return metadata + + +# def parse_xrdml(self): +# '''Parses the XRDML file using xrayutilities. + +# Returns: +# dict: A dictionary containing the parsed XRDML data. +# ''' +# # Read the XRDML file using xrayutilities +# xrd_data = XRDMLFile(self.file_path) +# result = xrd_data.scan.ddict + + +# # Add the scanmotname, material, hkl to the dictionary +# result["scanmotname"] = xrd_data.scan.scanmotname +# result["material"] = xrd_data.scan.material +# result["hkl"] = xrd_data.scan.hkl +# # add the metadata to the dictionary +# result["metadata"] = self.parse_metadata() + +# return result + + +# class FormatParser: +# '''A class to identify and parse different file formats.''' + +# def __init__(self, file_path): +# ''' +# Args: +# file_path (str): The path of the file to be identified and parsed. +# ''' +# self.file_path = file_path + +# def identify_format(self): +# '''Identifies the format of a given file. - Returns: - str: The file extension of the file. - ''' - file_extension = os.path.splitext(self.file_path)[1].lower() - return file_extension - - def parse_panalytical_xrdml(self): - '''Parses a Panalytical XRDML file. - - Returns: - dict: A dictionary containing the parsed XRDML - data. - ''' - xrdml_parser = PanalyticalXRDMLParser(self.file_path) - return xrdml_parser.parse_xrdml() - - def parse_panalytical_udf(self): - '''Parse the Panalytical .udf file. - - Returns: - None: Placeholder for parsing .udf files. - ''' - pass - - def parse_bruker_raw(self): - '''Parse the Bruker .raw file. - - Returns: - None: Placeholder for parsing .raw files. - ''' - pass - - def parse_bruker_xye(self): - '''Parse the Bruker .xye file. - - Returns: - None: Placeholder for parsing .xye files. - ''' - pass - - def parse(self): - '''Parses the file based on its format. - - Returns: - dict: A dictionary containing the parsed data. - - Raises: - ValueError: If the file format is unsupported. - ''' - file_format = self.identify_format() - - if file_format == ".xrdml": - return self.parse_panalytical_xrdml() - elif file_format == ".udf": - return self.parse_panalytical_udf() - elif file_format == ".raw": - return self.parse_bruker_raw() - elif file_format == ".xye": - return self.parse_bruker_xye() - else: - raise ValueError(f"Unsupported file format: {file_format}") - - -class DataConverter: - '''A class to convert parsed data into a common dictionary format.''' - - def __init__(self, parsed_data): - ''' - Args: - parsed_data (dict): The parsed data to be converted. - ''' - self.parsed_data = parsed_data - - def convert(self): - '''Converts the parsed data into a common dictionary format. - - Returns: - dict: The converted data in a common dictionary format. - ''' - # In this case, the parsed_data is already in the common dictionary format - # If you need additional conversion or data processing, implement it here - return self.parsed_data - -def parse_and_convert_file(file_path): - '''The main function to parse and convert a file. - Args: - file_path (str): The path of the file to be parsed and converted. - - Returns: - dict: The parsed and converted data in a common dictionary format. - ''' - file_path = os.path.abspath(file_path) - - format_parser = FormatParser(file_path) - parsed_data = format_parser.parse() - - data_converter = DataConverter(parsed_data) - common_data = data_converter.convert() - - return common_data +# Returns: +# str: The file extension of the file. +# ''' +# file_extension = os.path.splitext(self.file_path)[1].lower() +# return file_extension + +# def parse_panalytical_xrdml(self): +# '''Parses a Panalytical XRDML file. + +# Returns: +# dict: A dictionary containing the parsed XRDML +# data. +# ''' +# xrdml_parser = PanalyticalXRDMLParser(self.file_path) +# return xrdml_parser.parse_xrdml() + +# def parse_panalytical_udf(self): +# '''Parse the Panalytical .udf file. + +# Returns: +# None: Placeholder for parsing .udf files. +# ''' +# pass + +# def parse_bruker_raw(self): +# '''Parse the Bruker .raw file. + +# Returns: +# None: Placeholder for parsing .raw files. +# ''' +# pass + +# def parse_bruker_xye(self): +# '''Parse the Bruker .xye file. + +# Returns: +# None: Placeholder for parsing .xye files. +# ''' +# pass + +# def parse(self): +# '''Parses the file based on its format. + +# Returns: +# dict: A dictionary containing the parsed data. + +# Raises: +# ValueError: If the file format is unsupported. +# ''' +# file_format = self.identify_format() + +# if file_format == ".xrdml": +# return self.parse_panalytical_xrdml() +# elif file_format == ".udf": +# return self.parse_panalytical_udf() +# elif file_format == ".raw": +# return self.parse_bruker_raw() +# elif file_format == ".xye": +# return self.parse_bruker_xye() +# else: +# raise ValueError(f"Unsupported file format: {file_format}") + + +# class DataConverter: +# '''A class to convert parsed data into a common dictionary format.''' + +# def __init__(self, parsed_data): +# ''' +# Args: +# parsed_data (dict): The parsed data to be converted. +# ''' +# self.parsed_data = parsed_data + +# def convert(self): +# '''Converts the parsed data into a common dictionary format. + +# Returns: +# dict: The converted data in a common dictionary format. +# ''' +# # In this case, the parsed_data is already in the common dictionary format +# # If you need additional conversion or data processing, implement it here +# return self.parsed_data + +# def parse_and_convert_file(file_path): +# '''The main function to parse and convert a file. +# Args: +# file_path (str): The path of the file to be parsed and converted. + +# Returns: +# dict: The parsed and converted data in a common dictionary format. +# ''' +# file_path = os.path.abspath(file_path) + +# format_parser = FormatParser(file_path) +# parsed_data = format_parser.parse() + +# data_converter = DataConverter(parsed_data) +# common_data = data_converter.convert() + +# return common_data diff --git a/submodules/pynxtools b/submodules/pynxtools new file mode 160000 index 00000000..469b95f7 --- /dev/null +++ b/submodules/pynxtools @@ -0,0 +1 @@ +Subproject commit 469b95f73d4511a5d1f78091b3e1cf636534215c