From 6cde0e94e283632e2f88b7750b4f48cfa573a8d4 Mon Sep 17 00:00:00 2001 From: mkuehbach Date: Thu, 7 Dec 2023 13:36:11 +0100 Subject: [PATCH] Passing pycodestyle, pylinting, mypy now locally using py3.10.13 conda --- .../readers/em/concepts/nexus_concepts.py | 4 ++-- .../readers/em/geometry/convention_mapper.py | 4 ++-- .../readers/em/subparsers/hfive_bruker.py | 13 +++++++------ .../readers/em/subparsers/hfive_ebsd.py | 12 ++++++------ .../dataconverter/readers/em/utils/get_sqr_grid.py | 11 ++++++----- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/pynxtools/dataconverter/readers/em/concepts/nexus_concepts.py b/pynxtools/dataconverter/readers/em/concepts/nexus_concepts.py index e00bcf807..15ae33019 100644 --- a/pynxtools/dataconverter/readers/em/concepts/nexus_concepts.py +++ b/pynxtools/dataconverter/readers/em/concepts/nexus_concepts.py @@ -49,10 +49,10 @@ def __init__(self): def parse(self, template: dict, entry_id: int = 1, cmd_line_args: List = []) -> dict: """Parse application definition.""" - for nx_path, modifier in NxEmRoot.items(): + for nx_path, value in NxEmRoot.items(): if (nx_path != "IGNORE") and (nx_path != "UNCLEAR"): trg = variadic_path_to_specific_path(nx_path, [entry_id]) - res = apply_modifier(modifier, modifier) + res = value if res is not None: template[trg] = res if cmd_line_args != [] and all(isinstance(item, str) for item in cmd_line_args): diff --git a/pynxtools/dataconverter/readers/em/geometry/convention_mapper.py b/pynxtools/dataconverter/readers/em/geometry/convention_mapper.py index 7e08427c5..9ce968bda 100644 --- a/pynxtools/dataconverter/readers/em/geometry/convention_mapper.py +++ b/pynxtools/dataconverter/readers/em/geometry/convention_mapper.py @@ -68,10 +68,10 @@ def __init__(self, file_name: str, entry_id: int = 1): # , pattern_simulation: def parse(self, template: dict) -> dict: """Extract metadata from generic ELN text file to respective NeXus objects.""" print("Parsing conventions...") - for nx_path, modifier in NxEmConventions.items(): + for nx_path, value in NxEmConventions.items(): if (nx_path != "IGNORE") and (nx_path != "UNCLEAR"): trg = variadic_path_to_specific_path(nx_path, [self.entry_id]) - res = apply_modifier(modifier, modifier) + res = value if res is not None: template[trg] = res return template diff --git a/pynxtools/dataconverter/readers/em/subparsers/hfive_bruker.py b/pynxtools/dataconverter/readers/em/subparsers/hfive_bruker.py index 2c8f5a8b3..291bdcfef 100644 --- a/pynxtools/dataconverter/readers/em/subparsers/hfive_bruker.py +++ b/pynxtools/dataconverter/readers/em/subparsers/hfive_bruker.py @@ -195,11 +195,12 @@ def parse_and_normalize_group_ebsd_data(self, fp, ckey: str): raise ValueError(f"Unable to parse {grp_name}/{req_field} !") # Euler - n_pts = (np.shape(fp[f"{grp_name}/phi1"][:])[0], - np.shape(fp[f"{grp_name}/PHI"][:])[0], - np.shape(fp[f"{grp_name}/phi2"][:])[0]) - if all_equal(n_pts) is True and n_pts[0] == (self.tmp[ckey]["n_x"] * self.tmp[ckey]["n_y"]): - self.tmp[ckey]["euler"] = np.zeros((n_pts[0], 3), np.float32) + n_pts_probe = (np.shape(fp[f"{grp_name}/phi1"][:])[0], + np.shape(fp[f"{grp_name}/PHI"][:])[0], + np.shape(fp[f"{grp_name}/phi2"][:])[0]) + n_pts = None + if all_equal(n_pts_probe) is True and n_pts_probe[0] == (self.tmp[ckey]["n_x"] * self.tmp[ckey]["n_y"]): + self.tmp[ckey]["euler"] = np.zeros((n_pts_probe[0], 3), np.float32) column_id = 0 for angle in ["phi1", "PHI", "phi2"]: # TODO::available examples support that Bruker reports Euler triplets in degree @@ -207,7 +208,7 @@ def parse_and_normalize_group_ebsd_data(self, fp, ckey: str): = np.asarray(fp[f"{grp_name}/{angle}"][:], np.float32) / 180. * np.pi column_id += 1 self.tmp[ckey]["euler"] = format_euler_parameterization(self.tmp[ckey]["euler"]) - n_pts = n_pts[0] + n_pts = n_pts_probe[0] # index of phase, 0 if not indexed # no normalization needed, also in NXem_ebsd the null model notIndexed is phase_identifier 0 diff --git a/pynxtools/dataconverter/readers/em/subparsers/hfive_ebsd.py b/pynxtools/dataconverter/readers/em/subparsers/hfive_ebsd.py index 0de0c79d7..173ce7ad4 100644 --- a/pynxtools/dataconverter/readers/em/subparsers/hfive_ebsd.py +++ b/pynxtools/dataconverter/readers/em/subparsers/hfive_ebsd.py @@ -199,11 +199,11 @@ def parse_and_normalize_group_ebsd_data(self, fp, ckey: str): raise ValueError(f"Unable to parse {grp_name}/{req_field} !") # Euler - n_pts = (np.shape(fp[f"{grp_name}/phi1"][:])[0], - np.shape(fp[f"{grp_name}/PHI"][:])[0], - np.shape(fp[f"{grp_name}/phi2"][:])[0]) - if all_equal(n_pts) is True and n_pts[0] == (self.tmp[ckey]["n_x"] * self.tmp[ckey]["n_y"]): - self.tmp[ckey]["euler"] = np.zeros((n_pts[0], 3), np.float32) + n_pts_probe = (np.shape(fp[f"{grp_name}/phi1"][:])[0], + np.shape(fp[f"{grp_name}/PHI"][:])[0], + np.shape(fp[f"{grp_name}/phi2"][:])[0]) + if all_equal(n_pts_probe) is True and n_pts_probe[0] == (self.tmp[ckey]["n_x"] * self.tmp[ckey]["n_y"]): + self.tmp[ckey]["euler"] = np.zeros((n_pts_probe[0], 3), np.float32) column_id = 0 for angle in ["phi1", "PHI", "phi2"]: # TODO::available examples support that community H5EBSD reports Euler triplets in degree @@ -211,7 +211,7 @@ def parse_and_normalize_group_ebsd_data(self, fp, ckey: str): = np.asarray(fp[f"{grp_name}/{angle}"][:], np.float32) / 180. * np.pi column_id += 1 self.tmp[ckey]["euler"] = format_euler_parameterization(self.tmp[ckey]["euler"]) - n_pts = n_pts[0] + n_pts = n_pts_probe[0] # index of phase, 0 if not indexed # no normalization needed, also in NXem_ebsd the null model notIndexed is phase_identifier 0 diff --git a/pynxtools/dataconverter/readers/em/utils/get_sqr_grid.py b/pynxtools/dataconverter/readers/em/utils/get_sqr_grid.py index 573962e8a..5370aae1e 100644 --- a/pynxtools/dataconverter/readers/em/utils/get_sqr_grid.py +++ b/pynxtools/dataconverter/readers/em/utils/get_sqr_grid.py @@ -110,15 +110,16 @@ def get_scan_points_with_mark_data_discretized_on_sqr_grid(src_grid: dict, # rebuild src_grid container with only the relevant src_grida selected from src_grid for key in src_grid.keys(): if key == "euler": - trg_grid[key] = np.zeros((np.shape(trg_xy)[0], 3), np.float32) - trg_grid[key] = np.nan + trg_grid[key] = np.empty((np.shape(trg_xy)[0], 3), np.float32) + trg_grid[key].fill(np.nan) trg_grid[key] = src_grid["euler"][idx, :] if np.isnan(trg_grid[key]).any() is True: raise ValueError(f"Downsampling of the point cloud left " f"pixels without mark data {key} !") print(f"final np.shape(trg_grid[{key}]) {np.shape(trg_grid[key])}") elif key == "phase_id" or key == "bc": - trg_grid[key] = np.zeros((np.shape(trg_xy)[0],), np.int32) - 2 + trg_grid[key] = np.empty((np.shape(trg_xy)[0],), np.int32) + trg_grid[key].fill(np.int32(-2)) # pyxem_id is at least -1, bc is typically positive trg_grid[key] = src_grid[key][idx] if np.sum(trg_grid[key] == -2) > 0: @@ -126,8 +127,8 @@ def get_scan_points_with_mark_data_discretized_on_sqr_grid(src_grid: dict, f"pixels without mark data {key} !") print(f"final np.shape(trg_grid[{key}]) {np.shape(trg_grid[key])}") elif key == "ci" or key == "mad": - trg_grid[key] = np.zeros((np.shape(trg_xy)[0],), np.float32) - trg_grid[key] = np.nan + trg_grid[key] = np.empty((np.shape(trg_xy)[0],), np.float32) + trg_grid[key].fill(np.nan) trg_grid[key] = src_grid[key][idx] print(f"final np.shape(trg_grid[{key}]) {np.shape(trg_grid[key])}") if np.isnan(trg_grid[key]).any() is True: