8000 Refix reference by RubelMozumder · Pull Request #604 · FAIRmat-NFDI/pynxtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refix reference #604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions src/pynxtools/nomad/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,45 +176,55 @@ def get_entry_reference(archive, f_name):


class NexusIdentifiers(ArchiveSection):
NeXus_identifiers = SubSection(
Nexus_identifiers = SubSection(
section_def=AnchoredReference,
repeats=True,
description="These are the NOMAD references correspond to NeXus identifierNAME fields.",
)

def normalize(self, archive, logger):
# Consider multiple identifiers exists in the same group/section
def generate_anchored_reference_and_normalize(value, idname):
def generate_anchored_reference_and_normalize(
attr_obj, id_value, idname, is_full_storage=False
):
"""Generate anchored reference, connect to m quantities, and normalize."""
field_n = idname.split("__field")[0]
logger.info(f"Lab id {value} to be created")
nx_id = AnchoredReference(lab_id=value, name=field_n)
nx_id.m_set_section_attribute(
"m_nx_data_path",
self.m_get_quantity_attribute(idname, "m_nx_data_path"),
)
nx_id.m_set_section_attribute(
"m_nx_data_file",
self.m_get_quantity_attribute(idname, "m_nx_data_file"),
)
logger.info(f"Lab id {id_value} to be created")
nx_id = AnchoredReference(lab_id=id_value, name=field_n)
if not is_full_storage:
nx_data_path = attr_obj.m_get_quantity_attribute(
idname, "m_nx_data_path"
)
nx_data_file = attr_obj.m_get_quantity_attribute(
idname, "m_nx_data_file"
)
else:
nx_data_path = attr_obj.attributes.get("m_nx_data_path")
nx_data_file = attr_obj.attributes.get("m_nx_data_file")

nx_id.m_set_section_attribute("m_nx_data_path", nx_data_path)
nx_id.m_set_section_attribute("m_nx_data_file", nx_data_file)

self.Nexus_identifiers.append(nx_id)
nx_id.normalize(archive, logger)
self.NeXus_identifiers.append(nx_id)

identifiers = [
key
for key in self.__dict__.keys()
if key.startswith("identifier") and key.endswith("__field")
]
if identifiers:
self.NeXus_identifiers = []
self.Nexus_identifiers = []
for identifier in identifiers:
if not (val := getattr(self, identifier)):
continue
if isinstance(val, dict):
for idname, idobj in val.items():
generate_anchored_reference_and_normalize(idobj.value, idname)
generate_anchored_reference_and_normalize(
idobj, idobj.value, idname, True
)
else:
generate_anchored_reference_and_normalize(val, identifier)
generate_anchored_reference_and_normalize(self, val, identifier)
super().normalize(archive, logger)


Expand Down
Loading
0