Skip to content

Commit

Permalink
Equalized all call lines for individual parsers, removed deprecated t…
Browse files Browse the repository at this point in the history
…erm subparser
  • Loading branch information
atomprobe-tc committed Aug 18, 2024
1 parent 5ead6be commit 30502d3
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/pynxtools_em/parsers/image_png_protochips.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Subparser for exemplar reading of raw PNG files collected on a TEM with Protochip heating_chip."""
"""Parser for exemplar reading of raw PNG files collected on a TEM with Protochip heating_chip."""

import datetime
import mmap
Expand Down
6 changes: 2 additions & 4 deletions src/pynxtools_em/parsers/image_tiff_hitachi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Subparser for harmonizing Hitachi-specific content in TIFF files."""
"""Parser for harmonizing Hitachi-specific content in TIFF files."""

import mmap
from tokenize import TokenError
Expand Down Expand Up @@ -199,7 +199,5 @@ def process_event_data_em_metadata(self, template: dict) -> dict:
# we assume for now dynamic quantities can just be repeated
identifier = [self.entry_id, self.event_id, 1]
for cfg in [HITACHI_VARIOUS_DYNAMIC_TO_NX_EM, HITACHI_VARIOUS_STATIC_TO_NX_EM]:
add_specific_metadata_pint(
cfg, self.flat_dict_meta, identifier, template
)
add_specific_metadata_pint(cfg, self.flat_dict_meta, identifier, template)
return template
9 changes: 3 additions & 6 deletions src/pynxtools_em/parsers/image_tiff_jeol.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Subparser for harmonizing JEOL specific content in TIFF files."""
"""Parser for harmonizing JEOL specific content in TIFF files."""

import mmap
from typing import Dict, List
Expand Down Expand Up @@ -111,8 +111,7 @@ def check_if_tiff_jeol(self):
print(f"{key}______{type(value)}____{value}")

if all(
key in self.flat_dict_meta
for key in ["SEM_DATA_VERSION", "CM_LABEL"]
key in self.flat_dict_meta for key in ["SEM_DATA_VERSION", "CM_LABEL"]
):
if (self.flat_dict_meta["SEM_DATA_VERSION"] == 1) and (
self.flat_dict_meta["CM_LABEL"] == "JEOL"
Expand Down Expand Up @@ -178,9 +177,7 @@ def process_event_data_em_data(self, template: dict) -> dict:
# JEOL-specific conversion for micron bar pixel to physical length
resolution = int(self.flat_dict_meta["SM_MICRON_BAR"])
physical_length = (
self.flat_dict_meta["SM_MICRON_MARKER"]
.to(ureg.meter)
.magnitude
self.flat_dict_meta["SM_MICRON_MARKER"].to(ureg.meter).magnitude
)
# resolution many pixel represent physical_length scanned surface
# assuming square pixel
Expand Down
12 changes: 8 additions & 4 deletions src/pynxtools_em/parsers/image_tiff_point_electronic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Subparser for harmonizing point electronic DISS specific content in TIFF files."""
"""Parser for harmonizing point electronic DISS specific content in TIFF files."""

import mmap
from typing import Dict
Expand All @@ -38,9 +38,13 @@ def __init__(self, file_path: str = "", entry_id: int = 1, verbose: bool = False
self.event_id = 1
self.verbose = verbose
self.tmp: Dict = {"data": None, "flat_dict_meta": fd.FlatDict({})}
self.version: Dict = {"trg": {"tech_partner": ["point electronic"],
"schema_name": ["DISS"],
"schema_version": ["5.15.31.0"]}}
self.version: Dict = {
"trg": {
"tech_partner": ["point electronic"],
"schema_name": ["DISS"],
"schema_version": ["5.15.31.0"],
}
}
self.supported = False
self.check_if_tiff_point_electronic()

Expand Down
2 changes: 1 addition & 1 deletion src/pynxtools_em/parsers/image_tiff_tescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Subparser for harmonizing TESCAN-specific content in TIFF files."""
"""Parser for harmonizing TESCAN-specific content in TIFF files."""

import mmap
from typing import Dict, List
Expand Down
11 changes: 8 additions & 3 deletions src/pynxtools_em/parsers/image_tiff_tfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Subparser for harmonizing ThermoFisher-specific content in TIFF files."""
"""Parser for harmonizing ThermoFisher-specific content in TIFF files."""

import mmap
from typing import Dict
Expand All @@ -24,6 +24,7 @@
import numpy as np
from PIL import Image
from PIL.TiffTags import TAGS

# https://www.loc.gov/preservation/digital/formats/content/tiff_tags.shtml
from pynxtools_em.concepts.mapping_functors import add_specific_metadata
from pynxtools_em.configurations.image_tiff_tfs_cfg import (
Expand Down Expand Up @@ -137,9 +138,13 @@ def get_metadata(self):
if value != "":
# execution order of the check here matters!
if value.isdigit() is True:
self.flat_dict_meta[f"{parent}/{term}"] = np.int64(value)
self.flat_dict_meta[f"{parent}/{term}"] = np.int64(
value
)
elif if_str_represents_float(value) is True:
self.flat_dict_meta[f"{parent}/{term}"] = np.float64(value)
self.flat_dict_meta[f"{parent}/{term}"] = (
np.float64(value)
)
else:
self.flat_dict_meta[f"{parent}/{term}"] = value
else:
Expand Down
18 changes: 10 additions & 8 deletions src/pynxtools_em/parsers/image_tiff_zeiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Subparser for harmonizing Zeiss-specific content in TIFF files."""
"""Parser for harmonizing Zeiss-specific content in TIFF files."""

import mmap
import re
Expand Down Expand Up @@ -46,9 +46,13 @@ def __init__(self, file_path: str = "", entry_id: int = 1, verbose: bool = False
self.event_id = 1
self.verbose = verbose
self.flat_dict_meta = fd.FlatDict({}, "/")
self.version: Dict = {"trg": {"tech_partner": ["Zeiss"],
"schema_name": ["Zeiss"],
"schema_version": ["V06.03.00.00 : 15-Dec-17"]}}
self.version: Dict = {
"trg": {
"tech_partner": ["Zeiss"],
"schema_name": ["Zeiss"],
"schema_version": ["V06.03.00.00 : 15-Dec-17"],
}
}
self.supported = False
self.check_if_tiff_zeiss()

Expand Down Expand Up @@ -91,7 +95,7 @@ def get_metadata(self, payload: str):
elif len(tmp) == 2 and tmp[1] == "X":
self.flat_dict_meta[line] = ureg.Quantity(tmp[0])
elif len(tmp) == 3 and tmp[1] == "K" and tmp[2] == "X":
self.flat_dict_meta[line] = (ureg.Quantity(tmp[0]) * 1000.0)
self.flat_dict_meta[line] = ureg.Quantity(tmp[0]) * 1000.0
else:
try:
self.flat_dict_meta[line] = ureg.Quantity(token[1])
Expand Down Expand Up @@ -198,9 +202,7 @@ def process_event_data_em_data(self, template: dict) -> dict:
scan_unit = {"i": "m", "j": "m"}
if "APImagePixelSize" in self.flat_dict_meta:
pixel_size = (
self.flat_dict_meta["APImagePixelSize"]
.to(ureg.meter)
.magnitude
self.flat_dict_meta["APImagePixelSize"].to(ureg.meter).magnitude
)
sxy = {"i": pixel_size, "j": pixel_size}
else:
Expand Down
6 changes: 3 additions & 3 deletions src/pynxtools_em/parsers/nxs_imgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
class NxEmImagesParser:
"""Map content from different type of image files on an instance of NXem."""

def __init__(self, entry_id: int = 1, file_path: str = "", verbose: bool = False):
def __init__(self, file_path: str = "", entry_id: int = 1, verbose: bool = False):
"""Overwrite constructor of the generic reader."""
self.file_path = file_path
if entry_id > 0:
self.entry_id = entry_id
else:
self.entry_id = 1
self.file_path = file_path
self.cache = {"is_filled": False}
self.verbose = verbose
self.cache = {"is_filled": False}

def identify_image_type(self):
"""Identify if image matches known mime type and has content for which parser exists."""
Expand Down
6 changes: 3 additions & 3 deletions src/pynxtools_em/parsers/nxs_mtex.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ def hfive_to_template(payload):
class NxEmNxsMTexParser:
"""Map content from *.nxs.mtex files on an instance of NXem."""

def __init__(self, entry_id: int = 1, file_path: str = "", verbose: bool = False):
def __init__(self, file_path: str = "", entry_id: int = 1, verbose: bool = False):
self.file_path = file_path
if entry_id > 0:
self.entry_id = entry_id
else:
self.entry_id = 1
self.file_path = file_path
self.supported = False
self.verbose = verbose
self.supported = False
self.check_if_mtex_nxs()

def check_if_mtex_nxs(self):
Expand Down
10 changes: 4 additions & 6 deletions src/pynxtools_em/parsers/nxs_nion.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,19 @@
class NionProjectParser:
"""Parse (zip-compressed archive of a) nionswift project with its content."""

def __init__(
self, entry_id: int = 1, input_file_path: str = "", verbose: bool = True
):
def __init__(self, file_path: str = "", entry_id: int = 1, verbose: bool = True):
"""Class wrapping swift parser."""
if input_file_path is not None and input_file_path != "":
self.file_path = input_file_path
if file_path is not None and file_path != "":
self.file_path = file_path
if entry_id > 0:
self.entry_id = entry_id
else:
self.entry_id = 1
self.event_id = 1
self.verbose = verbose
# counters which keep track of how many instances of NXevent_data_em have
# been instantiated, this implementation currently maps each display_items
# onto an own NXevent_data_em instance
self.verbose = verbose
self.file_path_sha256 = None
self.tmp: Dict = {}
self.proj_file_dict: Dict = {}
Expand Down
6 changes: 3 additions & 3 deletions src/pynxtools_em/parsers/nxs_pyxem.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ def get_ipfdir_legend(ipf_key):
class NxEmNxsPyxemParser:
"""Map content from different type of *.h5 files on an instance of NXem."""

def __init__(self, entry_id: int = 1, file_path: str = "", verbose: bool = False):
def __init__(self, file_path: str = "", entry_id: int = 1, verbose: bool = False):
"""Overwrite constructor of the generic reader."""
self.file_path = file_path
if entry_id > 0:
self.entry_id = entry_id
else:
self.entry_id = 1
self.file_path = file_path
self.verbose = verbose
self.id_mgn = {
"event": 1,
"event_img": 1,
Expand All @@ -121,7 +122,6 @@ def __init__(self, entry_id: int = 1, file_path: str = "", verbose: bool = False
"eds_img": 1,
}
self.cache = {"is_filled": False}
self.verbose = verbose

def parse(self, template: dict) -> dict:
hfive_parser_type = self.identify_hfive_type()
Expand Down
1 change: 0 additions & 1 deletion src/pynxtools_em/parsers/rsciio_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,3 @@ def __init__(self, file_path: str = ""):
if file_path is not None and file_path != "":
self.file_path = file_path
self.tmp: Dict = {}
self.file_path_sha256 = None
2 changes: 1 addition & 1 deletion src/pynxtools_em/parsers/rsciio_gatan.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
class RsciioGatanParser(RsciioBaseParser):
"""Read Gatan Digital Micrograph dm3/dm4 formats."""

def __init__(self, entry_id: int = 1, file_path: str = "", verbose: bool = False):
def __init__(self, file_path: str = "", entry_id: int = 1, verbose: bool = False):
super().__init__(file_path)
if entry_id > 0:
self.entry_id = entry_id
Expand Down
18 changes: 11 additions & 7 deletions src/pynxtools_em/parsers/rsciio_velox.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,29 @@
class RsciioVeloxParser(RsciioBaseParser):
"""Read Velox EMD File Format emd."""

def __init__(self, entry_id: int = 1, file_path: str = "", verbose: bool = False):
def __init__(self, file_path: str = "", entry_id: int = 1, verbose: bool = False):
super().__init__(file_path)
if entry_id > 0:
self.entry_id = entry_id
else:
self.entry_id = 1
self.verbose = verbose
self.id_mgn: Dict = {
"event": 1,
"event_img": 1,
"event_spc": 1,
"roi": 1,
"eds_img": 1,
}
self.verbose = verbose
self.tmp: Dict = {}
self.version: Dict = {"trg": {"Core/MetadataDefinitionVersion": ["7.9"],
"Core/MetadataSchemaVersion": ["v1/2013/07"]},
"src": {"Core/MetadataDefinitionVersion": None,
"Core/MetadataSchemaVersion": None}
self.version: Dict = {
"trg": {
"Core/MetadataDefinitionVersion": ["7.9"],
"Core/MetadataSchemaVersion": ["v1/2013/07"],
},
"src": {
"Core/MetadataDefinitionVersion": None,
"Core/MetadataSchemaVersion": None,
},
}
self.obj_idx_supported: List = []
self.supported = False
Expand Down
14 changes: 7 additions & 7 deletions src/pynxtools_em/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,25 @@ def read(

print("Parse and map pieces of information within files from tech partners...")
if len(case.dat) == 1: # no sidecar file
images = NxEmImagesParser(entry_id, case.dat[0], verbose=False)
images = NxEmImagesParser(case.dat[0], entry_id, verbose=False)
images.parse(template)

velox = RsciioVeloxParser(entry_id, case.dat[0], verbose=False)
velox = RsciioVeloxParser(case.dat[0], entry_id, verbose=False)
velox.parse(template)

gatan = RsciioGatanParser(entry_id, case.dat[0], verbose=False)
gatan = RsciioGatanParser(case.dat[0], entry_id, verbose=False)
gatan.parse(template)

nxs_mtex = NxEmNxsMTexParser(entry_id, case.dat[0], verbose=False)
nxs_mtex = NxEmNxsMTexParser(case.dat[0], entry_id, verbose=False)
nxs_mtex.parse(template)

nxs_pyxem = NxEmNxsPyxemParser(entry_id, case.dat[0], verbose=False)
nxs_pyxem = NxEmNxsPyxemParser(case.dat[0], entry_id, verbose=False)
nxs_pyxem.parse(template)

nxs_nion = NionProjectParser(entry_id, case.dat[0], verbose=False)
nxs_nion = NionProjectParser(case.dat[0], entry_id, verbose=False)
nxs_nion.parse(template)

# zip_parser = NxEmOmZipEbsdParser(case.dat[0], entry_id)
# zip_parser = NxEmOmZipEbsdParser(case.dat[0], entry_id, verbose=False)
# zip_parser.parse(template)
if len(case.dat) >= 1: # optional sidecar file
tescan = TescanTiffParser(case.dat, entry_id)
Expand Down

0 comments on commit 30502d3

Please sign in to comment.