Compare commits

..

2 Commits

Author SHA256 Message Date
4e224d3e29 completes Entrypoint class for now
also adds a few comments to Layers class
and changes debug mode to test Entrypoint
2026-01-28 16:03:14 +01:00
f74d8efea8 keyerrors handled on all attributes of classes Layers and Entrypoint 2026-01-28 15:45:36 +01:00

View File

@@ -3,11 +3,14 @@ from getpass import getpass
from classes import Header
class Layers:
'''
Layers(layer_data) - where layer_data is a Python dictionary.
eLabFTW experiments contain most of the data required by the NeXus file - although every layer is on a different eLab entry; unfortunately, some data like the target's chemical formula must be retrieved through additional HTTP requests. Attributes 'target_elabid', 'rheed_system_elabid' and 'laser_system_elabid' contain elabid's for these resources, which are all items.
'''
def __init__(self, layer_data):
try:
self.extra = layer_data["metadata_decoded"]["extra_fields"]
except KeyError as k:
raise KeyError(f"The provided dictionary lacks a \"{k}\" key.")
self.target_elabid = self.extra["Target"]["value"]
self.start_time = layer_data.get("created_at")
self.operator = layer_data.get("fullname")
@@ -15,8 +18,11 @@ class Layers:
self.deposition_time = self.extra["Duration"]["value"]
self.repetition_rate = self.extra["Repetition rate"]["value"]
self.number_of_pulses = float(self.deposition_time) * float(self.repetition_rate)
# TO-DO: remove trailing space on eLabFTW's template for deposition layers
self.temperature = self.extra["Heater temperature "]["value"]
self.heating_method = self.extra["Heating Method"]["value"]
except KeyError as k:
raise KeyError(f"The provided dictionary lacks a \"{k}\" key.")
class Entrypoint:
'''
@@ -25,19 +31,14 @@ class Entrypoint:
The entrypoint is the starting point of the process of resolving the data chain. The entrypoint must be a dictionary containing the data of a sample, created directly from the JSON of the item endpoint on eLabFTW - which can be done through the function get_entry_from_elabid.
'''
def __init__(self, sample_data):
'''
Attributes:
- self.linked_experiments is a sub-dictionary which only includes links to related experiments.
- self.linked_items is a sub-dictionary which only includes links to related items.
- self.batch_elabid is an integer (or NoneType if there's an error) containing the elabid of the associated substrate batch entry.
'''
try:
self.extra = sample_data["metadata_decoded"]["extra_fields"]
self.linked_items = sample_data["items_links"]
self.batch_elabid = self.extra["Substrate batch"]["value"]
self.linked_experiments = sample_data["related_experiments_links"]
self.linked_experiments_elabid = [ i["entityid"] for i in self.linked_experiments ]
except KeyError as k:
raise KeyError(f"The provided dictionary lacks a \"{k}\" key.")
self.linked_experiments = sample_data.get("related_experiments_links") or None
self.linked_items = sample_data.get("items_links") or None
self.batch_elabid = self.extra["Substrate batch"]["value"]
def get_entry_from_elabid(elabid, entryType="items"):
@@ -74,7 +75,14 @@ if __name__=="__main__":
data = get_entry_from_elabid(elabid, entryType)
if entryType == "experiments":
layer = Layers(data)
print(layer.__dict__)
result = layer.__dict__
result.pop("extra")
print(result)
elif entryType == "items":
sample = Entrypoint(data)
result = sample.__dict__
result.pop("extra")
print(result)
# print(json.dumps(chain.sample_data))
# print(json.dumps(chain.linked_experiments))
# print(chain.batch_elabid)