Skip to content

Commit

Permalink
First working parsing from log file
Browse files Browse the repository at this point in the history
- minor bugfixes
- sorted reader in /filereader/
- improved labelling in parser
  • Loading branch information
fabianschoeppach committed Dec 3, 2024
1 parent 082e7c7 commit d04c346
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 21 deletions.
83 changes: 83 additions & 0 deletions src/nomad_uibk_plugin/filereader/sputterreader.py
Original file line number Diff line number Diff line change
@@ -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
17 changes: 9 additions & 8 deletions src/nomad_uibk_plugin/parsers/sputterparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion src/nomad_uibk_plugin/schema_packages/XRFschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
TYPE_CHECKING,
)

from nomad_uibk_plugin.filereader import XRFreader

if TYPE_CHECKING:
from nomad.datamodel.datamodel import (
EntryArchive,
Expand Down Expand Up @@ -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
Expand Down
57 changes: 45 additions & 12 deletions src/nomad_uibk_plugin/schema_packages/sputtering.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -68,6 +76,7 @@ class Target(PVDSource, EntryData):
"""

m_def = Section()

internal_id = Quantity(
type=int,
description='The lab ID of the target.',
Expand Down Expand Up @@ -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,
Expand All @@ -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',
)


Expand All @@ -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):
Expand Down Expand Up @@ -316,6 +326,8 @@ class PSU(EntryData):
- pulse reverse time
"""

m_def = Section()

internal_id = Quantity(
type=int,
description='NOMAD ID of the PSU',
Expand Down Expand Up @@ -385,7 +397,7 @@ class PSU(EntryData):
component=ELNComponentEnum.BoolEditQuantity,
),
)
m_def = Section()

operating_hours = Quantity(
type=int,
description='NOMAD ID of the PSU',
Expand All @@ -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,
Expand Down Expand Up @@ -551,7 +563,7 @@ class SputterParameters(ArchiveSection):
- sample rotation speed
"""

pass
test = Quantity(type=str)


class UIBKSputterDeposition(SputterDeposition, EntryData):
Expand All @@ -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__()

0 comments on commit d04c346

Please sign in to comment.