Skip to content

Commit

Permalink
Added citations for 176case study and fixed NX_CLASS decoration bug f…
Browse files Browse the repository at this point in the history
…or charge_state_model
  • Loading branch information
atomprobe-tc committed Jan 10, 2024
1 parent 9c362c8 commit d784ecd
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 28 deletions.
59 changes: 59 additions & 0 deletions apm.dev.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "6da1aea0-545b-446b-a3d1-1574af72f6c6",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import numpy as np\n",
"from jupyterlab_h5web import H5Web"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3889c47f-11c4-4bf3-97de-04fc52f0798d",
"metadata": {},
"outputs": [],
"source": [
"src = f\"{os.getcwd()}\"\n",
"print(src)\n",
"fnm = [\"debug.nor_trondheim_hatzeglou_0.nxs\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aec5b20a-20ed-4fe3-8097-a53bcc9dded0",
"metadata": {},
"outputs": [],
"source": [
"H5Web(f\"{src}/debug/{fnm[0]}\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
6 changes: 5 additions & 1 deletion debug/apm.oasis.specific.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
operation_mode: apt
citation:
- doi: https://doi.org/repo
description: DOI to the respective entry in a data repository.
- doi: https://doi.org/paper
description: DOI to the respective publication.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
"""Dict mapping values for a specifically configured NOMAD OASIS."""

# pylint: disable=no-member,line-too-long
# pylint: disable=line-too-long

# currently by virtue of design NOMAD OASIS specific examples show how different tools and
# services can be specifically coupled and implemented so that they work together
Expand All @@ -43,15 +43,16 @@
import datetime as dt

from pynxtools.dataconverter.readers.apm.utils.apm_versioning \
import NX_APM_ADEF_NAME, NX_APM_ADEF_VERSION, NX_APM_EXEC_NAME, NX_APM_EXEC_VERSION
import NX_APM_ADEF_NAME, NX_APM_ADEF_VERSION


APM_OASIS_TO_NEXUS_CFG \
= [("/ENTRY[entry*]/@version", f"{NX_APM_ADEF_VERSION}"),
("/ENTRY[entry*]/definition", f"{NX_APM_ADEF_NAME}"),
("/ENTRY[entry*]/operation_mode", "load_from", "operation_mode"),
("/ENTRY[entry*]/operation_mode", "ignore", "operation_mode"),
("/ENTRY[entry*]/start_time", f"{dt.datetime.now(dt.timezone.utc).isoformat().replace('+00:00', 'Z')}")]

# ("/ENTRY[entry*]/PROGRAM[program1]/program", f"{NX_APM_EXEC_NAME}"),
# ("/ENTRY[entry*]/PROGRAM[program1]/program/@version", f"{NX_APM_EXEC_VERSION}"),
# ("/ENTRY[entry*]/atom_probe/location", "load_from", "location")]

APM_PARAPROBE_EXAMPLE_TO_NEXUS_CFG \
= [("/ENTRY[entry*]/CITE[cite*]/doi", "load_from", "doi"),
("/ENTRY[entry*]/CITE[cite*]/description", "load_from", "description")]
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import yaml

from pynxtools.dataconverter.readers.apm.map_concepts.apm_oasis_cfg_to_nx_map \
import APM_OASIS_TO_NEXUS_CFG
import APM_OASIS_TO_NEXUS_CFG, APM_PARAPROBE_EXAMPLE_TO_NEXUS_CFG
from pynxtools.dataconverter.readers.shared.map_concepts.mapping_functors \
import apply_modifier, variadic_path_to_specific_path
import variadic_path_to_specific_path


class NxApmNomadOasisConfigurationParser: # pylint: disable=too-few-public-methods
Expand All @@ -49,22 +49,38 @@ def __init__(self, file_path: str, entry_id: int, verbose: bool = False):

def report(self, template: dict) -> dict:
"""Copy data from configuration applying mapping functors."""
identifier = [self.entry_id]
for tpl in APM_OASIS_TO_NEXUS_CFG:
identifier = [self.entry_id]
if isinstance(tpl, tuple) and len(tpl) >= 2:
if tpl[0] not in ("IGNORE", "UNCLEAR"):
if tpl[1] != "ignore":
trg = variadic_path_to_specific_path(tpl[0], identifier)
# print(f"processing tpl {tpl} ... trg {trg}")
if len(tpl) == 2:
# nxpath, value to use directly
template[trg] = tpl[1]
if len(tpl) == 3:
# nxpath, modifier, value, modifier (function) evaluates value to use
if tpl[1] == "load_from":
if tpl[2] in self.yml.keys():
template[trg] = self.yml[tpl[2]]
else:
raise ValueError(f"tpl2 {tpl[2]} not in self.yml.keys()!")
else:
raise ValueError(f"tpl1 {tpl[1]} is not load_from!")
if (tpl[1] == "load_from") and (tpl[2] in self.yml):
template[trg] = self.yml[tpl[2]]

# related to joint paper https://arxiv.org/abs/2205.13510 and NOMAD OASIS
src = "citation"
if src in self.yml:
if isinstance(self.yml[src], list):
if all(isinstance(entry, dict) for entry in self.yml[src]) is True:
ref_id = 1
# custom schema delivers a list of dictionaries...
for cite_dict in self.yml[src]:
if cite_dict == {}:
continue
identifier = [self.entry_id, ref_id]
for key in cite_dict:
for tpl in APM_PARAPROBE_EXAMPLE_TO_NEXUS_CFG:
if isinstance(tpl, tuple) and (len(tpl) == 3):
if (tpl[1] == "load_from") and (key == tpl[2]):
trg = variadic_path_to_specific_path(
tpl[0], identifier)
# res = apply_modifier(modifier, user_dict)
# res is not None
template[trg] = cite_dict[tpl[2]]
ref_id += 1
return template
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,8 @@ def parse_user(self, template: dict) -> dict:
identifier = [self.entry_id, user_id]
for key in user_dict:
for tpl in APM_EXAMPLE_USER_TO_NEXUS:
# this currently N_user * M_nxpaths complexity implementation should
# be replaced with a faster ideally N_user * log(M_nxpaths)
# implementation also because the mapping table is defined
# trg <- modifier, src, instead of src, modifier -> trg
# but the first formulation is easier to read as typically
# the nxpath is longer than the src path
if isinstance(tpl, tuple) and (len(tpl) == 3):
if (tpl[1] == "load_from") and (tpl[2] == key):
if (tpl[1] == "load_from") and (key == tpl[2]):
trg = variadic_path_to_specific_path(
tpl[0], identifier)
# res = apply_modifier(modifier, user_dict)
Expand All @@ -146,7 +140,7 @@ def parse_pulser_source(self, template: dict) -> dict:
# custom schema delivers a list of dictionaries...
for ldct in self.yml[src]:
trg_sta = f"/ENTRY[entry{self.entry_id}]/measurement/" \
f"pulser/SOURCE[source{laser_id}]"
f"instrument/pulser/SOURCE[source{laser_id}]"
if "name" in ldct:
template[f"{trg_sta}/name"] = ldct["name"]
quantities = ["wavelength"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def add_standardize_molecular_ions(ion_lst: list, template: dict, entry_id: int)
template[f"{path}name"] = ion.name.values

if ion.charge_state_model["n_cand"] > 0:
path = f"{trg}ION[ion{ion_id}]/charge_state_model/"
path = f"{trg}ION[ion{ion_id}]/charge_state_analysis/"
template[f"{path}min_abundance"] \
= np.float64(ion.charge_state_model["min_abundance"])
template[f"{path}min_abundance_product"] \
Expand Down

0 comments on commit d784ecd

Please sign in to comment.