Skip to content

Commit

Permalink
Em nomad fixes (#16)
Browse files Browse the repository at this point in the history
* Made consistent that a dimensionless quantity does not have a unit for sure not one that is %

* Removed obsolete writing of NeXus definition and its version, and fixed bug that cmd_line_arguments are written as an array of strings

* Resolved function name conflict

* Fixed incorrect unit px for NXms_ipf legend NXdata instance axes

---------

Co-authored-by: mkuehbach <[email protected]>
  • Loading branch information
mkuehbach and atomprobe-tc authored May 15, 2024
1 parent 37eae22 commit 5f30337
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 105 deletions.
21 changes: 2 additions & 19 deletions pynxtools_em/concepts/concept_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import numpy as np
import pytz

from pynxtools_em.concepts.mapping_functors import variadic_path_to_specific_path
from pynxtools_em.utils.string_conversions import string_to_number


Expand Down Expand Up @@ -98,25 +99,7 @@ def apply_modifier(modifier, dct: dict):
return None


def variadic_path_to_specific_path(path: str, instance_identifier: list):
"""Transforms a variadic path to an actual path with instances."""
if (path is not None) and (path != ""):
narguments = path.count("*")
if narguments == 0: # path is not variadic
return path
if len(instance_identifier) >= narguments:
tmp = path.split("*")
if len(tmp) == narguments + 1:
nx_specific_path = ""
for idx in range(0, narguments):
nx_specific_path += f"{tmp[idx]}{instance_identifier[idx]}"
idx += 1
nx_specific_path += f"{tmp[-1]}"
return nx_specific_path
return None


def add_specific_metadata(
def add_specific_metadata_deprecate(
concept_mapping: dict, orgmeta: fd.FlatDict, identifier: list, template: dict
) -> dict:
"""Map specific concept src on specific NeXus concept trg.
Expand Down
31 changes: 3 additions & 28 deletions pynxtools_em/concepts/nxs_concepts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,14 @@
#
"""Implement NeXus-specific groups and fields to document software and versions used."""

from pynxtools_em.concepts.mapping_functors import (
add_specific_metadata,
variadic_path_to_specific_path,
)
from pynxtools_em.utils.versioning import (
NX_EM_ADEF_NAME,
NX_EM_EXEC_NAME,
NX_EM_EXEC_VERSION,
)

EM_APPDEF_TO_NEXUS = {
"prefix_trg": "/ENTRY[entry*]",
"use": [
("definition", NX_EM_ADEF_NAME),
(
"definition/@version",
"Redundant, see metadata in NXroot header, the specific version of pynxtools has only one specific set of definitions with its version.",
),
],
}

from pynxtools_em.concepts.mapping_functors import add_specific_metadata
from pynxtools_em.utils.versioning import NX_EM_EXEC_NAME, NX_EM_EXEC_VERSION

EM_PYNX_TO_NEXUS = {
"prefix_trg": "/ENTRY[entry*]/profiling",
"use": [
("PROGRAM[program1]/program", NX_EM_EXEC_NAME),
("PROGRAM[program1]/program/@version", NX_EM_EXEC_VERSION),
# ("definition", NX_EM_ADEF_NAME),
# (
# "definition/@version",
# "Redundant, see metadata in NXroot header, the specific version of pynxtools has only one specific set of definitions with its version.",
# ),
],
}

Expand All @@ -64,11 +40,10 @@ def parse(
) -> dict:
"""Parse application definition."""
identifier = [entry_id]
add_specific_metadata(EM_APPDEF_TO_NEXUS, {}, identifier, template)
add_specific_metadata(EM_PYNX_TO_NEXUS, {}, identifier, template)

if cmd_line_args != () and all(isinstance(item, str) for item in cmd_line_args):
template[f"/ENTRY[entry{entry_id}]/profiling/command_line_call"] = (
template[f"/ENTRY[entry{entry_id}]/profiling/command_line_call"] = " ".join(
cmd_line_args
)
return template
26 changes: 12 additions & 14 deletions pynxtools_em/subparsers/image_png_protochips.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
import xmltodict
from PIL import Image

from pynxtools_em.concepts.concept_mapper import (
add_specific_metadata,
variadic_path_to_specific_path,
)
from pynxtools_em.concepts.concept_mapper import add_specific_metadata_deprecate
from pynxtools_em.concepts.mapping_functors import variadic_path_to_specific_path
from pynxtools_em.config.image_png_protochips_cfg import (
AXON_AUX_DYNAMIC_TO_NX_EM,
AXON_CHIP_DYNAMIC_TO_NX_EM,
Expand Down Expand Up @@ -271,7 +269,7 @@ def sort_event_data_em(self) -> List:

def add_detector_static_metadata(self, file_name: str, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
AXON_DETECTOR_STATIC_TO_NX_EM,
self.tmp["meta"][file_name],
identifier,
Expand All @@ -281,7 +279,7 @@ def add_detector_static_metadata(self, file_name: str, template: dict) -> dict:

def add_stage_static_metadata(self, file_name: str, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
AXON_STAGE_STATIC_TO_NX_EM,
self.tmp["meta"][file_name],
identifier,
Expand All @@ -291,7 +289,7 @@ def add_stage_static_metadata(self, file_name: str, template: dict) -> dict:

def add_stage_dynamic_metadata(self, file_name: str, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
AXON_STAGE_DYNAMIC_TO_NX_EM,
self.tmp["meta"][file_name],
identifier,
Expand All @@ -301,7 +299,7 @@ def add_stage_dynamic_metadata(self, file_name: str, template: dict) -> dict:

def add_chip_dynamic_metadata(self, file_name: str, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
AXON_CHIP_DYNAMIC_TO_NX_EM,
self.tmp["meta"][file_name],
identifier,
Expand All @@ -311,14 +309,14 @@ def add_chip_dynamic_metadata(self, file_name: str, template: dict) -> dict:

def add_aux_dynamic_metadata(self, file_name: str, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
AXON_AUX_DYNAMIC_TO_NX_EM, self.tmp["meta"][file_name], identifier, template
)
return template

def add_various_dynamic_metadata(self, file_name: str, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
AXON_VARIOUS_DYNAMIC_TO_NX_EM,
self.tmp["meta"][file_name],
identifier,
Expand Down Expand Up @@ -398,10 +396,10 @@ def process_event_data_em_data(self, template: dict) -> dict:
template[f"{trg}/intensity/@long_name"] = f"Signal"

sxy = {"x": 1.0, "y": 1.0}
scan_unit = {
"x": "px",
"y": "px",
} # TODO::get AXON image calibration
scan_unit = {"x": "px", "y": "px"}
# TODO::get AXON image calibration
# "ImagerSettings.ImagePhysicalSize.X" / "ImagerSettings.ImagePixels.X"
# "ImagerSettings.ImagePhysicalSize.Y" / "ImagerSettings.ImagePixels.Y"
nxy = {"x": np.shape(nparr)[1], "y": np.shape(nparr)[0]}
del nparr
# TODO::we assume here a very specific coordinate system
Expand Down
19 changes: 10 additions & 9 deletions pynxtools_em/subparsers/image_tiff_tfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from PIL import Image
from PIL.TiffTags import TAGS

from pynxtools_em.concepts.concept_mapper import add_specific_metadata
from pynxtools_em.concepts.concept_mapper import add_specific_metadata_deprecate
from pynxtools_em.config.image_tiff_tfs_cfg import (
TFS_APERTURE_STATIC_TO_NX_EM,
TFS_DETECTOR_STATIC_TO_NX_EM,
Expand Down Expand Up @@ -233,7 +233,8 @@ def process_event_data_em_data(self, template: dict) -> dict:
"x": self.tmp["meta"]["EScan/PixelWidth"],
"y": self.tmp["meta"]["EScan/PixelHeight"],
}
scan_unit = {"x": "px", "y": "px"}
else:
print("WARNING: Assuming pixel width and height unit is meter!")
nxy = {"x": np.shape(np.array(fp))[1], "y": np.shape(np.array(fp))[0]}
# TODO::be careful we assume here a very specific coordinate system
# however the TIFF file gives no clue, TIFF just documents in which order
Expand Down Expand Up @@ -265,49 +266,49 @@ def process_event_data_em_data(self, template: dict) -> dict:

def add_aperture_static_metadata(self, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
TFS_APERTURE_STATIC_TO_NX_EM, self.tmp["meta"], identifier, template
)
return template

def add_detector_static_metadata(self, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
TFS_DETECTOR_STATIC_TO_NX_EM, self.tmp["meta"], identifier, template
)
return template

def add_various_static_metadata(self, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
TFS_VARIOUS_STATIC_TO_NX_EM, self.tmp["meta"], identifier, template
)
return template

def add_optics_dynamic_metadata(self, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
TFS_OPTICS_DYNAMIC_TO_NX_EM, self.tmp["meta"], identifier, template
)
return template

def add_stage_dynamic_metadata(self, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
TFS_STAGE_DYNAMIC_TO_NX_EM, self.tmp["meta"], identifier, template
)
return template

def add_scan_dynamic_metadata(self, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
TFS_SCAN_DYNAMIC_TO_NX_EM, self.tmp["meta"], identifier, template
)
return template

def add_various_dynamic_metadata(self, template: dict) -> dict:
identifier = [self.entry_id, self.event_id, 1]
add_specific_metadata(
add_specific_metadata_deprecate(
TFS_VARIOUS_DYNAMIC_TO_NX_EM, self.tmp["meta"], identifier, template
)
return template
Expand Down
9 changes: 3 additions & 6 deletions pynxtools_em/subparsers/nxs_pyxem.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,7 @@ def onthefly_process_roi_ipfs_phases_twod(
n_pts_indexed = np.sum(inp["phase_id"] != 0)
print(f"n_pts {n_pts}, n_pts_indexed {n_pts_indexed}")
template[f"{prfx}/number_of_scan_points"] = np.uint32(n_pts)
template[f"{prfx}/indexing_rate"] = np.float64(100.0 * n_pts_indexed / n_pts)
template[f"{prfx}/indexing_rate/@units"] = f"%"
template[f"{prfx}/indexing_rate"] = np.float64(n_pts_indexed / n_pts)
grp_name = f"{prfx}/phaseID[phase{nxem_phase_id}]"
template[f"{grp_name}/number_of_scan_points"] = np.uint32(
np.sum(inp["phase_id"] == 0)
Expand Down Expand Up @@ -619,9 +618,8 @@ def process_roi_phase_ipfs_twod(
"strength": 1,
}
template[f"{lgd}/AXISNAME[axis_{dim}]/@long_name"] = (
f"Pixel along {dim[0]}-axis"
f"Pixel coordinate along {dim[0]}-axis"
)
template[f"{lgd}/AXISNAME[axis_{dim}]/@units"] = "px"
return template

def onthefly_process_roi_ipfs_phases_threed(
Expand All @@ -638,8 +636,7 @@ def onthefly_process_roi_ipfs_phases_threed(
n_pts_indexed = np.sum(inp["phase_id"] != 0)
print(f"n_pts {n_pts}, n_pts_indexed {n_pts_indexed}")
template[f"{prfx}/number_of_scan_points"] = np.uint32(n_pts)
template[f"{prfx}/indexing_rate"] = np.float64(100.0 * n_pts_indexed / n_pts)
template[f"{prfx}/indexing_rate/@units"] = f"%"
template[f"{prfx}/indexing_rate"] = np.float64(n_pts_indexed / n_pts)
grp_name = f"{prfx}/phaseID[phase{nxem_phase_id}]"
template[f"{grp_name}/number_of_scan_points"] = np.uint32(
np.sum(inp["phase_id"] == 0)
Expand Down
Loading

0 comments on commit 5f30337

Please sign in to comment.