Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mappings #25

Merged
merged 6 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions pynxtools_mpes/mappings.py

This file was deleted.

22 changes: 6 additions & 16 deletions pynxtools_mpes/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
from pynxtools.dataconverter.readers.multi.reader import MultiFormatReader
from pynxtools.dataconverter.readers.utils import parse_yml

from pynxtools_mpes.mappings import CONVERT_DICT, DEFAULT_UNITS, REPLACE_NESTED

logger = logging.getLogger("pynxtools")


Expand Down Expand Up @@ -121,15 +119,15 @@ def h5_to_xarray(faddr: str, mode: str = "r") -> xr.DataArray:
f"ax{axis}"
].attrs["unit"]
except (KeyError, TypeError):
xarray[bin_names[axis]].attrs["unit"] = DEFAULT_UNITS[bin_names[axis]]
xarray[bin_names[axis]].attrs["unit"] = ""
try:
xarray.attrs["units"] = h5_file["binned"]["BinnedData"].attrs["units"]
xarray.attrs["long_name"] = h5_file["binned"]["BinnedData"].attrs[
"long_name"
]
except (KeyError, TypeError):
xarray.attrs["units"] = "counts"
xarray.attrs["long_name"] = "photoelectron counts"
xarray.attrs["units"] = ""
xarray.attrs["long_name"] = ""

if metadata is not None:
xarray.attrs["metadata"] = metadata
Expand All @@ -146,8 +144,7 @@ def iterate_dictionary(dic, key_string):
if not len(keys) == 1:
return iterate_dictionary(dic[keys[0]], keys[1])
else:
raise KeyError
return None
return None


def rgetattr(obj, attr):
Expand Down Expand Up @@ -196,8 +193,6 @@ def set_config_file(self, file_path: str) -> Dict[str, Any]:
def handle_eln_file(self, file_path: str) -> Dict[str, Any]:
self.eln_data = parse_yml(
file_path,
convert_dict=CONVERT_DICT,
replace_nested=REPLACE_NESTED,
parent_key="/ENTRY",
)

Expand All @@ -208,9 +203,7 @@ def get_eln_data(self, key: str, path: str) -> Any:
if self.eln_data is None:
return None

return self.eln_data.get(
key.replace(f"/ENTRY[{self.callbacks.entry_name}]", "/ENTRY")
)
return self.eln_data.get(path)

def handle_objects(self, objects: Tuple[Any]) -> Dict[str, Any]:
if isinstance(objects, xr.DataArray):
Expand Down Expand Up @@ -253,10 +246,7 @@ def get_data_dims(self, key: str, path: str) -> List[str]:
return list(map(str, self.data_xarray.dims))

def get_attr(self, key: str, path: str) -> Any:
try:
return iterate_dictionary(self.data_xarray.attrs, path)
except KeyError:
logger.info(f"Path {path} not found. Skipping the entry.")
return iterate_dictionary(self.data_xarray.attrs, path)


READER = MPESReader
Binary file modified tests/data/xarray_saved_small_calibration.h5
Binary file not shown.