diff --git a/src/nomad_uibk_plugin/schema_packages/XRFreader.py b/src/nomad_uibk_plugin/filereader/XRFreader.py similarity index 100% rename from src/nomad_uibk_plugin/schema_packages/XRFreader.py rename to src/nomad_uibk_plugin/filereader/XRFreader.py diff --git a/src/nomad_uibk_plugin/filereader/sputterreader.py b/src/nomad_uibk_plugin/filereader/sputterreader.py new file mode 100644 index 0000000..a3c4f41 --- /dev/null +++ b/src/nomad_uibk_plugin/filereader/sputterreader.py @@ -0,0 +1,83 @@ +# +# Copyright The NOMAD Authors. +# +# This file is part of NOMAD. See https://nomad-lab.eu for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from typing import TYPE_CHECKING + +# import numpy as np +from nomad_uibk_plugin.schema_packages.sputtering import ( + SputterParameters, + UIBKSputterDeposition, +) + +if TYPE_CHECKING: + from structlog.stdlib import ( + BoundLogger, + ) + + +def read_sputter_csv( + file_path: str, logger: 'BoundLogger' = None +) -> UIBKSputterDeposition: + """ + Read the sputter deposition data from a .csv file and return an instance of + UIBKSputterDeposition. + """ + + # with open(file_path, 'r') as file: + # lines = file.readlines() + + # # Split sections + # in_metadata = True + # metadata = {} + # time_series_lines = [] + # for line in lines: + # # skip commented lines + # if line.startswith("%") or line.startswith("#"): + # continue + + # line = line.strip() + # # skip empty lines + # if not line: + # continue + # if line == "END_OF_PARAMETERS": + # in_metadata = False + # continue + + # # Split metadata and time series + # if in_metadata: + # key, *values = line.split(';') + # key = key.strip() + # values = [v.strip() for v in values if v.strip()] + # metadata[key] = values + # else: + # time_series_lines.append(line) + + deposition = UIBKSputterDeposition( + name='TESTTESTTEST', + ) + + # Parse metadata + # TODO: Implement metadata parsing + + # Parse time series + # TODO: Implement time series parsing + + deposition.parameters = SputterParameters(test='HUHU!') + deposition.samples = [] + + return deposition diff --git a/src/nomad_uibk_plugin/parsers/sputterparser.py b/src/nomad_uibk_plugin/parsers/sputterparser.py index d168f3a..5c40ba3 100644 --- a/src/nomad_uibk_plugin/parsers/sputterparser.py +++ b/src/nomad_uibk_plugin/parsers/sputterparser.py @@ -44,16 +44,17 @@ def parse( child_archives: dict[str, 'EntryArchive'] = None, ) -> None: logger.info('SputterParser.parse') - data_file = mainfile.split('/')[-1] - entry = UIBKSputterDeposition.m_from_dict( - UIBKSputterDeposition.m_def.a_template - ) - entry.data_file = data_file - file_name = f'{"".join(data_file.split(".")[:-1])}.archive.json' + filename = mainfile.split('/')[-1] + # entry = UIBKSputterDeposition.m_from_dict( + # UIBKSputterDeposition.m_def.a_template + # ) + entry = UIBKSputterDeposition() + entry.data_file = filename + archive_name = f'{"".join(filename.split(".")[:-1])}.archive.json' archive.data = RawFileSputterData( measurement=get_reference( archive.metadata.upload_id, - get_entry_id_from_file_name(file_name, archive), + get_entry_id_from_file_name(archive_name, archive), ) ) - create_archive(entry, archive, file_name) + create_archive(entry, archive, archive_name) diff --git a/src/nomad_uibk_plugin/schema_packages/XRFschema.py b/src/nomad_uibk_plugin/schema_packages/XRFschema.py index a78aee0..50f2315 100644 --- a/src/nomad_uibk_plugin/schema_packages/XRFschema.py +++ b/src/nomad_uibk_plugin/schema_packages/XRFschema.py @@ -20,6 +20,8 @@ TYPE_CHECKING, ) +from nomad_uibk_plugin.filereader import XRFreader + if TYPE_CHECKING: from nomad.datamodel.datamodel import ( EntryArchive, @@ -59,7 +61,7 @@ from nomad.metainfo import Datetime, Quantity, SchemaPackage, Section, SubSection from nomad_measurements.utils import merge_sections -from nomad_uibk_plugin.schema_packages import UIBKCategory, XRFreader +from nomad_uibk_plugin.schema_packages import UIBKCategory if TYPE_CHECKING: from structlog.stdlib import BoundLogger diff --git a/src/nomad_uibk_plugin/schema_packages/sputtering.py b/src/nomad_uibk_plugin/schema_packages/sputtering.py index 8052c31..0b8b1c9 100644 --- a/src/nomad_uibk_plugin/schema_packages/sputtering.py +++ b/src/nomad_uibk_plugin/schema_packages/sputtering.py @@ -1,3 +1,5 @@ +from typing import TYPE_CHECKING + from nomad.datamodel.data import ArchiveSection, EntryData from nomad.datamodel.metainfo.annotations import ELNAnnotation, ELNComponentEnum from nomad.datamodel.metainfo.basesections import ( @@ -27,6 +29,12 @@ from nomad_uibk_plugin.schema_packages import UIBKCategory from nomad_uibk_plugin.schema_packages.sample import UIBKSample +if TYPE_CHECKING: + from nomad.datamodel.datamodel import EntryArchive + from structlog.stdlib import BoundLogger + +from nomad_measurements.utils import merge_sections # create_archive + m_package = SchemaPackage() @@ -68,6 +76,7 @@ class Target(PVDSource, EntryData): """ m_def = Section() + internal_id = Quantity( type=int, description='The lab ID of the target.', @@ -225,11 +234,13 @@ class Substrate(EntryData): - """ + m_def = Section() + type = Quantity( type=MEnum(['c-Si die', 'glass', 'polyimide']), description='Type of substrate material', default='', - a_eln={'component': 'AutocompleteEditQuasntity'}, + a_eln={'component': 'AutocompleteEditQuantity'}, ) subtype = Quantity( type=str, @@ -251,25 +262,25 @@ class Substrate(EntryData): default='', a_eln={'component': 'RadioEnumEditQuantity'}, ) - m_def = Section() + size_x = Quantity( type=float, description='Radius or x-dimension of the sample.', a_eln={'component': 'NumberEditQuantity', 'defaultDisplayUnit': 'mm'}, - unit='mmm', + unit='meter', ) size_y = Quantity( type=float, description='Y-dimension of the sample.', a_eln={'component': 'NumberEditQuantity', 'defaultDisplayUnit': 'mm'}, - unit='mmm', + unit='meter', ) size_z = Quantity( type=float, description='Height of the sample.', a_eln={'component': 'NumberEditQuantity', 'defaultDisplayUnit': 'mm'}, - unit='mmm', + unit='meter', ) @@ -279,13 +290,12 @@ class SubstrateReference(SectionReference): class Operator(EntryData): author = Quantity( - # type = ? + type=str, ## < ? description='Authors/Operators', a_eln=ELNAnnotation( - component=ELNComponentEnum.AuthorEditQuantity, + component=ELNComponentEnum.StringEditQuantity, # AuthorEditQuantity? ), ) - # or `UserEditQuantity`:? class OperatorReference(SectionReference): @@ -316,6 +326,8 @@ class PSU(EntryData): - pulse reverse time """ + m_def = Section() + internal_id = Quantity( type=int, description='NOMAD ID of the PSU', @@ -385,7 +397,7 @@ class PSU(EntryData): component=ELNComponentEnum.BoolEditQuantity, ), ) - m_def = Section() + operating_hours = Quantity( type=int, description='NOMAD ID of the PSU', @@ -403,7 +415,7 @@ class PSU(EntryData): type=MEnum(['W', 'V', 'A']), description='', default='W', - a_eln={'component': 'RadioEnumEditQuantityty'}, + a_eln={'component': 'RadioEnumEditQuantity'}, ) setpoint_value = Quantity( type=float, @@ -551,7 +563,7 @@ class SputterParameters(ArchiveSection): - sample rotation speed """ - pass + test = Quantity(type=str) class UIBKSputterDeposition(SputterDeposition, EntryData): @@ -560,11 +572,32 @@ class UIBKSputterDeposition(SputterDeposition, EntryData): label='Sputter Deposition', ) + data_file = Quantity( + type=str, + description='Path to the data file', + a_eln=ELNAnnotation( + component=ELNComponentEnum.FileEditQuantity, + ), + ) + samples = SubSection(section_def=UIBKSample, repeats=True) target = SubSection(section_def=TargetReference, repeats=True) - # parameter = SubSection() + parameters = SubSection(section_def=SputterParameters) + + def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None: + """Update the data from the data file if it is not already set""" + + from nomad_uibk_plugin.filereader.sputterreader import read_sputter_csv + + # if self.data is None and self.data_file is not None: + if self.data_file is not None: + with archive.m_context.raw_file(self.data_file) as file: + sputter_entry = read_sputter_csv(file, logger) + merge_sections(self, sputter_entry, logger) + + super().normalize(archive, logger) m_package.__init_metainfo__()