Skip to content

Commit

Permalink
Added rosettasciio, added skeleton for refactoring EDS, EELS, ADF usi…
Browse files Browse the repository at this point in the history
…ng rosettasciio, collected feedback from the discussion with Robert Kernke (IKZ), next steps i) complete mapping of all detector modes for Robert, ii) complete EDS, EELS, ADF
  • Loading branch information
atomprobe-tc committed Dec 13, 2023
1 parent 5aa9977 commit 49fb0a3
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 8 deletions.
17 changes: 15 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,21 @@ comm==0.2.0
contourpy==1.1.1
# via matplotlib
coverage[toml]==7.3.2
# via pytest-cov
# via
# coverage
# pytest-cov
cycler==0.12.1
# via matplotlib
cython==3.0.6
# via tables
dask[array]==2023.5.0
# via
# dask
# hyperspy
# kikuchipy
# orix
# pyxem
# rosettasciio
debugpy==1.8.0
# via ipykernel
decorator==5.1.1
Expand Down Expand Up @@ -282,6 +286,7 @@ numpy==1.24.4
# pywavelets
# pyxem
# radioactivedecay
# rosettasciio
# scikit-image
# scikit-learn
# scipy
Expand Down Expand Up @@ -332,7 +337,9 @@ pillow==10.0.1
# nionswift
# scikit-image
pint==0.21.1
# via hyperspy
# via
# hyperspy
# rosettasciio
pip-tools==7.3.0
# via pynxtools (pyproject.toml)
platformdirs==4.0.0
Expand Down Expand Up @@ -388,13 +395,16 @@ pytest-cov==4.1.0
# via pynxtools (pyproject.toml)
pytest-timeout==2.2.0
# via pynxtools (pyproject.toml)
python-box==6.1.0
# via rosettasciio
python-dateutil==2.8.2
# via
# hyperspy
# ipyparallel
# jupyter-client
# matplotlib
# pandas
# rosettasciio
pytz==2023.3.post1
# via
# nionswift
Expand All @@ -412,6 +422,7 @@ pyyaml==6.0.1
# hyperspy
# kikuchipy
# pynxtools (pyproject.toml)
# rosettasciio
pyzmq==25.1.1
# via
# ipykernel
Expand All @@ -427,6 +438,8 @@ requests==2.31.0
# requests-cache
requests-cache==1.1.1
# via pynxtools (pyproject.toml)
rosettasciio==0.2
# via pynxtools (pyproject.toml)
scikit-image==0.20.0
# via
# hyperspy
Expand Down
11 changes: 9 additions & 2 deletions imgs.batch.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#!/bin/bash

datasource="../../../../paper_paper_paper/scidat_nomad_ebsd/bb_analysis/data/production_imgs/"
datasource="../../../../paper_paper_paper/scidat_nomad_ebsd/bb_analysis/data/development_imgs/"

# comments is detector mode
examples="kit/FeMoOx_AntiA_04_1k5x_CN.tif"
examples="ikz_robert/0c8nA_3deg_003_AplusB_test.tif" # T1
examples="ikz_martin/ALN_baoh_021.tif" # T2
examples="ikz_robert/T3_image.tif"
examples="ikz_robert/ETD_image.tif" # ETD
examples="ikz_martin/NavCam_normal_vis_light_ccd.tif" # NavCam

examples="ALN_baoh_021.tif" # FeMoOx_AntiA_04_1k5x_CN.tif"

for example in $examples; do
echo $example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from typing import List
from pynxtools.dataconverter.readers.em.concepts.concept_mapper \
import variadic_path_to_specific_path, apply_modifier
import variadic_path_to_specific_path


PYNXTOOLS_VERSION = "n/a"
Expand Down
41 changes: 41 additions & 0 deletions pynxtools/dataconverter/readers/em/concepts/nxs_em_image_r_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""NXem spectrum set (element of a labelled property graph) to store instance data."""

# pylint: disable=no-member,too-few-public-methods


from typing import Dict

from pynxtools.dataconverter.readers.em.concepts.nxs_object import NxObject


NX_EM_IMAGE_REAL_SPACE_SET_HDF_PATH = []
# this one needs an update !


class NxEmImageRealSpaceSet():
def __init__(self):
self.tmp: Dict = {}
for entry in NX_EM_IMAGE_REAL_SPACE_SET_HDF_PATH:
if entry.endswith("-field") is True:
self.tmp[entry[0:len(entry)-len("-field")]] = NxObject(eqv_hdf="dset")
elif entry.endswith("-attribute") is True:
self.tmp[entry[0:len(entry)-len("-attribute")]] = NxObject(eqv_hdf="attr")
else:
self.tmp[entry[0:len(entry)-len("-group")]] = NxObject(eqv_hdf="grp")
70 changes: 70 additions & 0 deletions pynxtools/dataconverter/readers/em/concepts/nxs_em_spectrum_set.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""NXem spectrum set (element of a labelled property graph) to store instance data."""

# pylint: disable=no-member,too-few-public-methods


from typing import Dict

from pynxtools.dataconverter.readers.em.concepts.nxs_object import NxObject


NX_EM_SPECTRUM_SET_HDF_PATH = [
"PROCESS-group",
"PROCESS/detector_identifier-field",
"PROCESS/source-group",
"PROCESS/source/algorithm-field",
"PROCESS/source/checksum-field",
"PROCESS/source/path-field",
"PROCESS/source/type-field",
"stack-group",
"stack/axis_energy-field",
"stack/axis_energy@long_name-attribute",
"stack/axis_x-field",
"stack/axis_x@long_name-attribute",
"stack/axis_y-field",
"stack/axis_y@long_name-attribute",
"stack/intensity-field",
"stack/intensity@long_name-attribute",
"stack/title-field",
"stack@axes-attribute",
"stack@AXISNAME_indices-attribute",
"stack@long_name-attribute",
"stack@signal-attribute",
"summary-group",
"summary/axis_energy-field",
"summary/axis_energy@long_name-attribute",
"summary/title-field",
"summary@axes-attribute",
"summary@AXISNAME_indices-attribute",
"summary@long_name-attribute",
"summary@signal-attribute"]
# this one needs an update !


class NxEmSpectrumSet():
def __init__(self):
self.tmp: Dict = {}
for entry in NX_EM_SPECTRUM_SET_HDF_PATH:
if entry.endswith("-field") is True:
self.tmp[entry[0:len(entry)-len("-field")]] = NxObject(eqv_hdf="dset")
elif entry.endswith("-attribute") is True:
self.tmp[entry[0:len(entry)-len("-attribute")]] = NxObject(eqv_hdf="attr")
else:
self.tmp[entry[0:len(entry)-len("-group")]] = NxObject(eqv_hdf="grp")
61 changes: 61 additions & 0 deletions pynxtools/dataconverter/readers/em/concepts/nxs_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""NXobject (element of a labelled property graph) to store instance data."""

# pylint: disable=no-member,too-few-public-methods

from typing import Dict


class NxObject:
"""An object in a graph e.g. an attribute, dataset, or group in NeXus."""

def __init__(self,
name: str = None,
unit: str = None,
dtype=str,
value=None,
**kwargs):
if (name is not None) and (name == ""):
raise ValueError(f"Value for argument name needs to be a non-empty string !")
if (unit is not None) and (unit == ""):
raise ValueError(f"Value for argument unit needs to be a non-empty string !")
if (dtype is not None) and isinstance(dtype, type) is False:
raise ValueError(f"Value of argument dtype must not be None " \
f" and a valid, ideally a numpy datatype !")
# self.doc = None # docstring
self.name = name # name of the field
self.unit = unit # not unit category but actual unit
# use special values "unitless" for NX_UNITLESS (e.g. 1) and
# "dimensionless" for NX_DIMENSIONLESS (e.g. 1m / 1m)
self.dtype = dtype # use np.dtype if possible
if value is None or dtype is str:
self.unit = "unitless"
if value is not None:
self.value = value
# value should be a numpy scalar, tensor, or string if possible
self.eqv_hdf = None
if "eqv_hdf" in kwargs:
if kwargs["eqv_hdf"] in ["group", "dataset", "attribute"]:
self.eqv_hdf = kwargs["eqv_hdf"]
else:
raise ValueError(f"Value of keyword argument eqv_hdf needs to be one of grp, dset, attr !")

def __repr__(self):
"""Report values."""
return f"Name: {self.name}, unit: {self.unit}, dtype: {self.dtype}, eqv_hdf: {self.eqv_hdf}"
2 changes: 1 addition & 1 deletion pynxtools/dataconverter/readers/em/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from typing import Tuple, Any

from pynxtools.dataconverter.readers.base.reader import BaseReader
from pynxtools.dataconverter.readers.em.concepts.nexus_concepts import NxEmAppDef
from pynxtools.pynxtools.dataconverter.readers.em.concepts.nxs_concepts import NxEmAppDef
# from pynxtools.dataconverter.readers.em.subparsers.nxs_mtex import NxEmNxsMTexSubParser
# from pynxtools.dataconverter.readers.em.subparsers.nxs_pyxem import NxEmNxsPyxemSubParser
from pynxtools.dataconverter.readers.em.subparsers.nxs_imgs import NxEmImagesSubParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ def get_fei_childs(concept: str) -> List:
"IGNORE": {"fun": "load_from", "terms": "EBeam/VFW"},
"/ENTRY[entry*]/measurement/em_lab/OPTICAL_SYSTEM_EM[optical_system_em]/working_distance": {"fun": "load_from", "terms": "EBeam/WD"},
"/ENTRY[entry*]/measurement/em_lab/OPTICAL_SYSTEM_EM[optical_system_em]/working_distance/@units": "m",
"IGNORE": {"fun": "load_from", "terms": "EBeam/BeamCurrent"},
"/ENTRY[entry*]/measurement/em_lab/OPTICAL_SYSTEM_EM[optical_system_em]/beam_current": {"fun": "load_from", "terms": "EBeam/WD"},
"/ENTRY[entry*]/measurement/em_lab/OPTICAL_SYSTEM_EM[optical_system_em]/beam_current/@units": "A",
"IGNORE": {"fun": "load_from", "terms": "EBeam/TiltCorrectionIsOn"},
"IGNORE": {"fun": "load_from", "terms": "EBeam/DynamicFocusIsOn"},
"IGNORE": {"fun": "load_from", "terms": "EBeam/DynamicWDIsOn"},
Expand Down
47 changes: 47 additions & 0 deletions pynxtools/dataconverter/readers/em/subparsers/rsciio_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Base class to inherit sub-parser from when interacting with rosettasciio."""

# this subparser is currently implemented such that it represents the first
# and the second step of a parsing and mapping workflow whereby concepts and
# instance data within the representation realm of a tech partner is mapped
# onto the realm of NeXus e.g. to offer normalized content to e.g. NOMAD OASIS

# the first step is the reading of information (all code relevant to enable
# information extraction from a specific file of a tech partner
# the second step is normalization of the information
# the third step is (currently performed) with the nxs_hyperspy.py parser
# which finally processes the already normalized information into the
# template object that is thereafter consumed by the convert.py and writer.py
# functionalities to create a serialized NeXus data artifact

from typing import Dict


class RsciioBaseParser:
def __init__(self, file_path: str = ""):
# self.supported_version = VERSION_MANAGEMENT
# self.version = VERSION_MANAGEMENT
# tech_partner the company which designed this format
# schema_name the specific name of the family of schemas supported by this reader
# schema_version the specific version(s) supported by this reader
# writer_name the specific name of the tech_partner's (typically proprietary) software
self.prfx = None
self.tmp: Dict = {}
if file_path is not None and file_path != "":
self.file_path = file_path
Loading

0 comments on commit 49fb0a3

Please sign in to comment.