Skip to content

Commit

Permalink
PR advices from lukas
Browse files Browse the repository at this point in the history
  • Loading branch information
Ron Hildebrandt authored and Ron Hildebrandt committed Dec 10, 2024
1 parent 3c430d5 commit 934c890
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
52 changes: 21 additions & 31 deletions src/pynxtools_raman/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ def __init__(self, *args, **kwargs):
".rod": self.handle_rod_file,
}

# only required if multiple file types are present
# for ext in RamanReader.__prmt_file_ext__:
# self.extensions[ext] = self.handle_data_file

def set_config_file(self, file_path: Path) -> Dict[str, Any]:
if self.config_file is not None:
logger.info(
Expand All @@ -83,32 +79,6 @@ def handle_eln_file(self, file_path: str) -> Dict[str, Any]:

return {}

def get_attr(self, key: str, path: str) -> Any:
"""
Get the metadata that was stored in the main file.
"""
return self.get_metadata(self.raman_data, path, self.callbacks.entry_name)

def read(
self,
template: dict = None,
file_paths: Tuple[str] = None,
objects: Tuple[Any] = None,
**kwargs,
) -> dict:
template = super().read(template, file_paths, objects, suppress_warning=True)
# set default data

if self.missing_meta_data:
for key in self.missing_meta_data:
template[
f"/ENTRY[{self.callbacks.entry_name}]/COLLECTION[unused_rod_keys]/{key}"
] = f"{self.missing_meta_data[key]}"

template["/@default"] = "entry"

return template

def handle_rod_file(self, filepath) -> Dict[str, Any]:
# specify default config file for rod files
reader_dir = Path(__file__).parent
Expand Down Expand Up @@ -171,7 +141,7 @@ def handle_txt_file(self, filepath):
def get_eln_data(self, key: str, path: str) -> Any:
"""
Returns data from the eln file. This is done via the file: "config_file.json".
There are two suations:
There are two sitations:
1. The .json file has only a key assigned
2. The .json file has a key AND a value assigned.
The assigned value should be a "path", which reflects another entry in the eln file.
Expand Down Expand Up @@ -239,5 +209,25 @@ def get_data(self, key: str, path: str) -> Any:
else:
logger.warning(f"No axis name corresponding to the path {path}.")

def read(
self,
template: dict = None,
file_paths: Tuple[str] = None,
objects: Tuple[Any] = None,
**kwargs,
) -> dict:
template = super().read(template, file_paths, objects, suppress_warning=True)
# set default data

if self.missing_meta_data:
for key in self.missing_meta_data:
template[
f"/ENTRY[{self.callbacks.entry_name}]/COLLECTION[unused_rod_keys]/{key}"
] = f"{self.missing_meta_data[key]}"

template["/@default"] = "entry"

return template


READER = RamanReader
7 changes: 4 additions & 3 deletions src/pynxtools_raman/rod/rod_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from pathlib import Path

logger = logging.getLogger("pynxtools")


class RodParser:
"""
Expand All @@ -14,7 +16,6 @@ def __init__(self, *args, **kwargs):
self.cif_doc = None
self.cif_block = None
self.lines = []
self.n_headerlines = 12

def _read_lines(self, file: Union[str, Path]):
"""
Expand Down Expand Up @@ -42,7 +43,7 @@ def get_string_position(self, string_element: str, check_only_pos_zero=False):
line_positions_of_str_element.append(line_number)
else:
if rod_lines is None:
print("rod_lines_is_none")
logger.info(f"Problem during reading .rod file. 'rod_line' is None.")
else:
for line_number, lines in enumerate(rod_lines):
if string_element in lines:
Expand Down Expand Up @@ -77,7 +78,7 @@ def get_keys_and_loop_boolean(self, key_positions, key_pos_in_loops):
if len(key_positions) == len(cif_key_loop_boolean_dict):
return cif_key_loop_boolean_dict
else:
print(".cif file parsing warning: Not all cif-keys were parsed.")
logger.info(f".rod file parsing warning: Not all rod-keys were parsed.")
return cif_key_loop_boolean_dict

def key_pos_after_loop(self, loop_pos_lists, key_pos_list):
Expand Down

0 comments on commit 934c890

Please sign in to comment.