Skip to content

Commit

Permalink
Add and populate ElementalComposition and Datetime fields to XRFResul…
Browse files Browse the repository at this point in the history
…t schema
  • Loading branch information
fabianschoeppach committed Apr 11, 2024
1 parent 995fce2 commit d55387c
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions src/nomad_measurements/xrf/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
Quantity,
Section,
SubSection,
Datetime,
MEnum,
)
from nomad.datamodel.data import (
Expand All @@ -48,6 +49,7 @@
from nomad.datamodel.results import (
Results,
Properties,
ElementalComposition,
StructuralProperties,
DiffractionPattern,
Method,
Expand All @@ -62,15 +64,30 @@
m_package = Package(name='nomad_xrf')


class XRFResult(MeasurementResult, System):
class XRFResult(MeasurementResult):
"""
Section containing the result of an X-ray fluorescence measurement.
"""

elements = SubSection(section_def=ElementalComposition, repeats=True)

date = Quantity(
type=Datetime,
a_eln=ELNAnnotation(component=ELNComponentEnum.DateTimeEditQuantity),
description='Date of the measurement',
)

thickness = Quantity(
type=np.dtype(np.float64),
unit=('nm'),
a_eln=dict(component='NumberEditQuantity', defaultDisplayUnit='nm'),
description='Thickness of the sample',
)

position = Quantity(
type=str,
a_eln=dict(component='StringEditQuantity'),
description='Position of the measurement',
)


Expand Down Expand Up @@ -139,7 +156,7 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger'):
# archive.results.method = Method(
# method_name='XRF',
# measurement=MeasurementMethod(
# xrd=XRFMethod()
# xrf=XRFMethod()
# )
# )
super().normalize(archive, logger)
Expand Down Expand Up @@ -202,10 +219,38 @@ def write_xrf_data(

# write for each measurement in xrf_dict
for key in xrf_dict:
name = xrf_dict.get(key, {}).get('application', None)
date = xrf_dict.get(key, {}).get('date', None)
thickeness = xrf_dict.get(key, {}).get('film_thickness', None)
position = xrf_dict.get(key, {}).get('position', None)
list_of_elements = xrf_dict.get(key, {}).get('elements', {}).keys()
list_of_ElementalComposition = []
for element in list_of_elements:
mass_fraction = (
xrf_dict.get(key, {})
.get('elements', {})
.get(element, {})
.get('mass_fraction', None)
)
atomic_fraction = (
xrf_dict.get(key, {})
.get('elements', {})
.get(element, {})
.get('atomic_fraction', None)
)
list_of_ElementalComposition.append(
ElementalComposition(
element=element,
mass_fraction=mass_fraction,
atomic_fraction=atomic_fraction,
)
)
result = XRFResult(
name=xrf_dict.get(key, {}).get('application', None),
datetime=xrf_dict.get(key, {}).get('date', None),
thickness=xrf_dict.get(key, {}).get('film_thickness', None),
name=name,
date=date,
thickness=thickeness,
position=position,
elements=list_of_ElementalComposition,
)
result.normalize(archive, logger)

Expand Down Expand Up @@ -240,10 +285,9 @@ def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger'):
else:
with archive.m_context.raw_file(self.data_file) as file:
xrf_dict = read_function(file.name, logger)
# TODO: Implement population of other xrf_dict components
self.write_xrf_data(xrf_dict, archive, logger)
super().normalize(archive, logger)

# TODO: Structure of multiple measurements in one file
if not self.results:
return

Expand Down

0 comments on commit d55387c

Please sign in to comment.