Skip to content

Commit

Permalink
122 move the transmission code from areaa repo (#123)
Browse files Browse the repository at this point in the history
* Add parser and schema

* Add init file containing transmission entry points

* Add deps and entry points to pyproject

* Bugfix: name of the file reader

* Add transmission raw files

* Add parser test

* Reference any composite system in the sample reference

* Rename to path_length

* Copy latest changes from AreaA repo

* Integrate suggestions from AreaA TF: sample path lenght and orientation

* Rename to detector_gain, detector_integration_time

* Reordering settings sections

* Fix

* Rename attenuator settings class

* Plural names

* Use common utils

* Use composite system for sample reference

* Move transmission test file

* Refactor test file

* Add schema config

* Test normalized data for one file

* Regex for matching raw file content

* Review: from sourcery

* Review: from Hampus
  • Loading branch information
ka-sarthak authored Jan 8, 2025
1 parent 617fb72 commit 5d8cc94
Show file tree
Hide file tree
Showing 11 changed files with 5,729 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies = [
"nomad-lab>=1.3.6",
"xmltodict==0.13.0",
"fairmat-readers-xrd>=0.0.3",
"nomad-material-processing",
"fairmat-readers-transmission",
]
[project.urls]
"Homepage" = "https://github.com/FAIRmat-NFDI/nomad-measurements"
Expand Down Expand Up @@ -137,5 +139,7 @@ xrd_parser = "nomad_measurements.xrd:parser"
ppms_schema = "nomad_measurements.ppms:ppms_schema"
ppms_data_parser = "nomad_measurements.ppms:ppms_data_parser"
ppms_sequence_parser = "nomad_measurements.ppms:ppms_sequence_parser"
transmission_schema = "nomad_measurements.transmission:schema"
transmission_parser = "nomad_measurements.transmission:parser"

[tool.setuptools_scm]
59 changes: 59 additions & 0 deletions src/nomad_measurements/transmission/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# 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 nomad.config.models.plugins import ParserEntryPoint, SchemaPackageEntryPoint


class TransmissionSchemaEntryPoint(SchemaPackageEntryPoint):
"""
Entry point for lazy loading of the Transmission schemas.
"""

def load(self):
from nomad_measurements.transmission.schema import m_package

return m_package


class TransmissionParserEntryPoint(ParserEntryPoint):
"""
Entry point for lazy loading of the TransmissionParser.
"""

def load(self):
from nomad_measurements.transmission.parser import TransmissionParser

return TransmissionParser(**self.dict())


schema = TransmissionSchemaEntryPoint(
name='Transmission Schema',
description='Schema for data from Transmission Spectrophotometry.',
)


parser = TransmissionParserEntryPoint(
name='Transmission Parser',
description="""
Parser for data from Transmission Spectrophotometry measurements. Currently
supports `.asc` files generated by Perkin Elmer UV WinLab software.
""",
mainfile_mime_re=r'text/.*|application/zip',
mainfile_name_re=r'^.*\.asc$',
mainfile_contents_re=r'^PE UV',
)
52 changes: 52 additions & 0 deletions src/nomad_measurements/transmission/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# 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

from nomad.parsing import MatchingParser

from nomad_measurements.transmission.schema import (
ELNUVVisNirTransmission,
RawFileTransmissionData,
)
from nomad_measurements.utils import create_archive

if TYPE_CHECKING:
from nomad.datamodel.datamodel import (
EntryArchive,
)


class TransmissionParser(MatchingParser):
"""
Parser for matching files from Transmission Spectrophotometry and
creating instances of ELN.
"""

def parse(
self, mainfile: str, archive: 'EntryArchive', logger=None, child_archives=None
) -> None:
data_file = mainfile.split('/')[-1]
entry = ELNUVVisNirTransmission.m_from_dict(
ELNUVVisNirTransmission.m_def.a_template
)
entry.data_file = data_file
file_name = f'{".".join(data_file.split(".")[:-1])}.archive.json'
archive.data = RawFileTransmissionData(
measurement=create_archive(entry, archive, file_name)
)
archive.metadata.entry_name = f'{data_file} data file'
Loading

0 comments on commit 5d8cc94

Please sign in to comment.