Skip to content

Commit

Permalink
fixing ci/cd workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Oct 20, 2023
1 parent 2d866ba commit 76677f6
Showing 1 changed file with 36 additions and 40 deletions.
76 changes: 36 additions & 40 deletions pynxtools/dataconverter/readers/xrd/xrd_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os # for file path operations
from pathlib import Path
import warnings
from pynxtools.dataconverter.helpers import transform_to_intended_dt, remove_namespace_from_tag
from pynxtools.dataconverter.readers.xrd.xrd_helper import feed_xrdml_to_template
import os # for file path operations
import xml.etree.ElementTree as ET # for XML parsing
from xrayutilities.io.panalytical_xml import XRDMLFile # for reading XRDML files
from pynxtools.dataconverter.helpers import transform_to_intended_dt, remove_namespace_from_tag
from pynxtools.dataconverter.readers.xrd.xrd_helper import feed_xrdml_to_template


def fill_slash_sep_dict_from_nested_dict(parent_path, nested_dict, slash_sep_dict):
Expand All @@ -44,7 +44,7 @@ def fill_slash_sep_dict_from_nested_dict(parent_path, nested_dict, slash_sep_dic
Returns
-------
_None
None
"""
for key, val in nested_dict.items():
slash_sep_path = parent_path + key
Expand All @@ -56,7 +56,6 @@ def fill_slash_sep_dict_from_nested_dict(parent_path, nested_dict, slash_sep_dic

class IgnoreNodeTextWarning(Warning):
"""Special class to warn node text skip."""
pass


class XRDMLParser:
Expand All @@ -69,11 +68,16 @@ def __init__(self, file_path):
----------
file_path : str
"""
import xml.etree.ElementTree as ET
# In future it can be utilised later it different versions of file
self.__version = None
# self.__version = None
self.__xrd_dict = {}
self.__file_path = file_path
# Important note for key-val pair separator list: preceding elements have precedence on the
# on the following elements
self.key_val_pair_sprtr = (';', ',')
# Important note for key-val separator list: preceding elements have precedence on the
# on the following elements
self.key_val_sprtr = ('=', ':')

def get_slash_separated_xrd_dict(self):
"""Return a dict with slash separated key and value from xrd file.
Expand All @@ -97,13 +101,6 @@ def handle_with_panalytical_module(self):
comes with xml file.
"""
xml_root = ET.parse(self.__file_path).getroot()

# Important note for key-val pair separator list: preceding elements have precedence on the
# on the following elements
self.key_val_pair_sprtr = (';', ',')
# Important note for key-val separator list: preceding elements have precedence on the
# on the following elements
self.key_val_sprtr = ('=', ':')
self.parse_each_elm(parent_path='/', xml_node=xml_root)

# Extract other numerical data e.g. 'hkl', 'Omega', '2Theta', CountTime etc
Expand Down Expand Up @@ -142,7 +139,7 @@ def process_node_text(self, parent_path, node_txt):
else:
try:
self.__xrd_dict[parent_path] = transform_to_intended_dt(node_txt)
except Exception:
except ValueError:
warnings.warn(f'Element text {node_txt} is ignored from parseing!',
IgnoreNodeTextWarning)

Expand Down Expand Up @@ -238,69 +235,67 @@ class FormatParser:
"""A class to identify and parse different file formats."""

def __init__(self, file_path):
"""Construct obj.
"""Construct FormatParser obj.
Parameters
----------
file_path : str
XRD file to be parsed.
"""
self.file_path = file_path

def get_file_format(self):
'''Identifies the format of a given file.
"""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()
"""
file_extension = ''.join(Path(self.file_path).suffixes)
return file_extension

def parse_xrdml(self):
'''Parses a Panalytical XRDML file.
"""Parses a Panalytical XRDML file.
Returns:
dict: A dictionary containing the parsed XRDML
data.
'''
"""
return XRDMLParser(self.file_path).get_slash_separated_xrd_dict()

def parse_panalytical_udf(self):
'''Parse the Panalytical .udf file.
"""Parse the Panalytical .udf file.
Returns:
None: Placeholder for parsing .udf files.
'''
pass
"""

def parse_bruker_raw(self):
'''Parse the Bruker .raw file.
"""Parse the Bruker .raw file.
Returns:
None: Placeholder for parsing .raw files.
'''
pass
"""

def parse_bruker_xye(self):
'''Parse the Bruker .xye file.
"""Parse the Bruker .xye file.
Returns:
None: Placeholder for parsing .xye files.
'''
pass
"""

def parser_and_populate_template(self, template, config_dict, eln_dict):
"""_summary_
"""Parse xrd file into dict and fill the template.
Parameters
----------
template : _type_
_description_
xrd_file : _type_
_description_
config_dict : _type_
_description_
eln_dict : _type_
_description_
template : Template
NeXus template generated from NeXus application definitions.
xrd_file : str
Name of the xrd file.
config_dict : dict
A dict geenerated from python
eln_dict : dict
A dict generatd from eln yaml file.
"""
file_format = self.get_file_format()
if file_format == ".xrdml":
Expand All @@ -319,7 +314,7 @@ def parse(self):
file_format = self.get_file_format()

if file_format == ".xrdml":
return self.parse_xrdml()
slash_sep_dict = self.parse_xrdml()
# elif file_format == ".udf":
# return self.parse_panalytical_udf()
# elif file_format == ".raw":
Expand All @@ -328,6 +323,7 @@ def parse(self):
# return self.parse_bruker_xye()
# else:
# raise ValueError(f"Unsupported file format: {file_format}")
return slash_sep_dict


def parse_and_fill_template(template, xrd_file, config_dict, eln_dict):
Expand Down

0 comments on commit 76677f6

Please sign in to comment.