completes Entrypoint class for now
also adds a few comments to Layers class and changes debug mode to test Entrypoint
This commit is contained in:
@@ -3,6 +3,11 @@ from getpass import getpass
|
|||||||
from classes import Header
|
from classes import Header
|
||||||
|
|
||||||
class Layers:
|
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):
|
def __init__(self, layer_data):
|
||||||
try:
|
try:
|
||||||
self.extra = layer_data["metadata_decoded"]["extra_fields"]
|
self.extra = layer_data["metadata_decoded"]["extra_fields"]
|
||||||
@@ -13,6 +18,7 @@ class Layers:
|
|||||||
self.deposition_time = self.extra["Duration"]["value"]
|
self.deposition_time = self.extra["Duration"]["value"]
|
||||||
self.repetition_rate = self.extra["Repetition rate"]["value"]
|
self.repetition_rate = self.extra["Repetition rate"]["value"]
|
||||||
self.number_of_pulses = float(self.deposition_time) * float(self.repetition_rate)
|
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.temperature = self.extra["Heater temperature "]["value"]
|
||||||
self.heating_method = self.extra["Heating Method"]["value"]
|
self.heating_method = self.extra["Heating Method"]["value"]
|
||||||
except KeyError as k:
|
except KeyError as k:
|
||||||
@@ -25,17 +31,12 @@ 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.
|
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):
|
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:
|
try:
|
||||||
self.extra = sample_data["metadata_decoded"]["extra_fields"]
|
self.extra = sample_data["metadata_decoded"]["extra_fields"]
|
||||||
self.linked_experiments = sample_data.get("related_experiments_links") or None
|
self.linked_items = sample_data["items_links"]
|
||||||
self.linked_items = sample_data.get("items_links") or None
|
|
||||||
self.batch_elabid = self.extra["Substrate batch"]["value"]
|
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:
|
except KeyError as k:
|
||||||
raise KeyError(f"The provided dictionary lacks a \"{k}\" key.")
|
raise KeyError(f"The provided dictionary lacks a \"{k}\" key.")
|
||||||
|
|
||||||
@@ -74,7 +75,14 @@ if __name__=="__main__":
|
|||||||
data = get_entry_from_elabid(elabid, entryType)
|
data = get_entry_from_elabid(elabid, entryType)
|
||||||
if entryType == "experiments":
|
if entryType == "experiments":
|
||||||
layer = Layers(data)
|
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.sample_data))
|
||||||
# print(json.dumps(chain.linked_experiments))
|
# print(json.dumps(chain.linked_experiments))
|
||||||
# print(chain.batch_elabid)
|
# print(chain.batch_elabid)
|
||||||
Reference in New Issue
Block a user