Skip to content

Commit

Permalink
moving changes to NeXusMeasurement which is not anymore using normali…
Browse files Browse the repository at this point in the history
…sation from Measurement and Activity
  • Loading branch information
sanbrock committed Dec 18, 2024
1 parent 3c9c2b5 commit 9f0b992
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions src/pynxtools/nomad/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
"NXsample": [CompositeSystem],
"NXsample_component": [Component],
"NXidentifier": [EntityReference],
"NXentry": [ActivityStep, Task],
"NXprocess": [ActivityStep, Task],
"NXentry": [ActivityStep], # , Task],
"NXprocess": [ActivityStep], # , Task],
"NXdata": [ActivityResult],
# "object": BaseSection,
}
Expand Down Expand Up @@ -140,7 +140,44 @@ def normalize(self, archive, logger):
self.method = self.m_def.name + " Experiment"
except (AttributeError, TypeError):
pass
super(NexusMeasurement, self).normalize(archive, logger)
super(Activity, self).normalize(archive, logger)

if archive.results.eln.methods is None:
archive.results.eln.methods = []
if self.method:
archive.results.eln.methods.append(self.method)
else:
archive.results.eln.methods.append(self.m_def.name)
if archive.workflow2 is None:
archive.workflow2 = Workflow(name=self.name)
# steps to tasks
act_array = archive.workflow2.tasks
existing_items = {(task.name, task.section) for task in act_array}
new_items = [
item.to_task()
for item in self.steps
if (item.name, item) not in existing_items
]
act_array.extend(new_items)
# samples to inputs
act_array = archive.workflow2.inputs
existing_items = {(link.name, link.section) for link in act_array}
new_items = [
Link(name=item.name, section=item.reference)
for item in self.samples
if (item.name, item.reference) not in existing_items
]
act_array.extend(new_items)

# results to outputs
act_array = archive.workflow2.outputs
existing_items = {(link.name, link.section) for link in act_array}
new_items = [
Link(name=item.name, section=item)
for item in self.results
if (item.name, item) not in existing_items
]
act_array.extend(new_items)


VALIDATE = False
Expand Down Expand Up @@ -971,9 +1008,10 @@ def normalize_entry(self, archive, logger):
super(current_cls, self).normalize(archive, logger)


def to_task_itself(self):
"""takes advantage if an object itself is also a Task"""
return self
# def to_task_itself(self):
# """takes advantage if an object itself is also a Task"""
# self.section=self
# return self


def normalize_process(self, archive, logger):
Expand Down Expand Up @@ -1004,7 +1042,7 @@ def create_Entity(lab_id, archive, f_name):
data=entitySec,
m_context=archive.m_context,
metadata=EntryMetadata(
entry_type="identifier", domain="nexus"
entry_type="identifier", domain="nexus", readonly=True
), # upload_id=archive.m_context.upload_id,
)
with archive.m_context.raw_file(f_name, "w") as f_obj:
Expand Down Expand Up @@ -1047,11 +1085,11 @@ def get_entry_reference(archive, f_name):
__rename_nx_for_nomad("NXidentifier"): normalize_identifier,
__rename_nx_for_nomad("NXentry"): {
"normalize": normalize_entry,
"to_task": to_task_itself,
# "to_task": to_task_itself,
},
__rename_nx_for_nomad("NXprocess"): {
"normalize": normalize_process,
"to_task": to_task_itself,
# "to_task": to_task_itself,
},
__rename_nx_for_nomad("NXdata"): normalize_data,
}
Expand Down

0 comments on commit 9f0b992

Please sign in to comment.