Commit ae403871 authored by RealPolitiX's avatar RealPolitiX
Browse files

Update with mpes-parser content

parent 6744335e
# Copyright 2016-2018 Markus Scheidgen
# 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.
import sys
import os.path
import json
import ase
import re
import numpy as np
from datetime import datetime
from nomadcore.simple_parser import SimpleMatcher
from nomadcore.baseclasses import ParserInterface, AbstractBaseParser
from nomad.parsing import LocalBackend
class MPESParserInterface(ParserInterface):
def get_metainfo_filename(self):
"""
The parser specific metainfo. To include other metadata definitions, use
the 'dependencies' key to refer to other local nomadmetainfo.json files or
to nomadmetainfo.json files that are part of the general nomad-meta-info
submodule (i.e. ``dependencies/nomad-meta-info``).
"""
return os.path.join(os.path.dirname(__file__), 'mpes.nomadmetainfo.json')
def get_parser_info(self):
""" Basic info about parser used in archive data and logs. """
return {
'name': 'mpes-parser',
'version': '1.0.0'
}
def setup_version(self):
""" Can be used to call :func:`setup_main_parser` differently for different code versions. """
self.setup_main_parser(None)
def setup_main_parser(self, _):
""" Setup the actual parser (behind this interface) """
self.main_parser = MPESParser(self.parser_context)
class MPESParser(AbstractBaseParser):
def parse(self, filepath):
backend = self.parser_context.super_backend
with open(filepath, 'rt') as f:
data = json.load(f)
# print(data)
# # You need to open sections before you can add values or sub sections to it.
# # The returned 'gid' can be used to reference a specific section if multiple
# # sections of the same type are opened.
root_gid = backend.openSection('section_experiment')
# # Values do not necessarely have to be read from the parsed file.
# # The backend will check the type of the given value agains the metadata definition.
# backend.addValue('experiment_time', int(datetime.strptime(data.get('date'), '%d.%M.%Y').timestamp()))
#
# # Read data .
# data_gid = backend.openSection('section_data')
# backend.addValue('data_repository_name', 'zenodo.org')
# backend.addValue('data_repository_url', 'https://zenodo.org/path/to/mydata')
# backend.addValue('data_preview_url', 'https://www.physicsforums.com/insights/wp-content/uploads/2015/09/fem.jpg')
# backend.closeSection('section_data', data_gid)
# Read general experimental parameters
# general_gid = backend.openSection('section_experiment_general_parameters')
backend.addValue('general_experiment_method', data.get('experiment_method'))
backend.addValue('general_experiment_method_abbreviation', data.get('experiment_method_abbrv'))
backend.addArrayValues('general_experiment_location', np.array(re.findall(r"[\w']+", data.get('experiment_location'))))
backend.addValue('general_experiment_date', data.get('experiment_date'))
backend.addValue('general_experiment_summary', data.get('experiment_summary'))
backend.addValue('general_experiment_facility_institution', data.get('facility_institution'))
backend.addValue('general_experiment_facility_name', data.get('facility_name'))
backend.addValue('general_beamline', data.get('beamline'))
backend.addValue('general_source_pump', data.get('source_pump'))
backend.addValue('general_source_probe', data.get('source_probe'))
backend.addValue('general_equipment_description', data.get('equipment_description'))
backend.addValue('general_sample_description', data.get('sample_description'))
backend.addArrayValues('general_measurement_axis', np.array(re.findall(r"[\w']+", data.get('measurement_axis'))))
backend.addArrayValues('general_physical_axis', np.array(re.findall(r"[\w']+", data.get('physical_axis'))))
# Read parameters related to experimental source
# source_gid = backend.openSection('section_experiment_source_parameters')
backend.addValue('source_pump_repetition_rate', data.get('pump_rep_rate'))
backend.addValue('source_pump_pulse_duration', data.get('pump_pulse_duration'))
backend.addValue('source_pump_wavelength', data.get('pump_wavelength'))
backend.addArrayValues('source_pump_spectrum', np.array(data.get('pump_spectrum')))
backend.addValue('source_pump_photon_energy', data.get('pump_photon_energy'))
backend.addArrayValues('source_pump_size', np.array(data.get('pump_size')))
backend.addArrayValues('source_pump_fluence', np.array(data.get('pump_fluence')))
backend.addValue('source_pump_polarization', data.get('pump_polarization'))
backend.addValue('source_pump_bunch', data.get('pump_bunch'))
backend.addValue('source_probe_repetition_rate', data.get('probe_rep_rate'))
backend.addValue('source_probe_pulse_duration', data.get('probe_pulse_duration'))
backend.addValue('source_probe_wavelength', data.get('probe_wavelength'))
backend.addArrayValues('source_probe_spectrum', np.array(data.get('probe_spectrum')))
backend.addValue('source_probe_photon_energy', data.get('probe_photon_energy'))
backend.addArrayValues('source_probe_size', np.array(data.get('probe_size')))
backend.addArrayValues('source_probe_fluence', np.array(data.get('probe_fluence')))
backend.addValue('source_probe_polarization', data.get('probe_polarization'))
backend.addValue('source_probe_bunch', data.get('probe_bunch'))
backend.addValue('source_temporal_resolution', data.get('temporal_resolution'))
# Read parameters related to detector
# detector_gid = backend.openSection('section_experiment_detector_parameters')
backend.addValue('detector_extractor_voltage', data.get('extractor_voltage'))
backend.addValue('detector_work_distance', data.get('work_distance'))
backend.addArrayValues('detector_lens_names', np.array(re.findall(r"[\w']+", data.get('lens_names'))))
backend.addArrayValues('detector_lens_voltages', np.array(data.get('lens_voltages')))
backend.addValue('detector_tof_distance', data.get('tof_distance'))
backend.addArrayValues('detector_tof_voltages', np.array(data.get('tof_voltages')))
backend.addValue('detector_sample_bias', data.get('sample_bias'))
backend.addValue('detector_magnification', data.get('magnification'))
backend.addArrayValues('detector_voltages', np.array(data.get('detector_voltages')))
backend.addValue('detector_type', data.get('detector_type'))
backend.addArrayValues('detector_sensor_size', np.array(data.get('sensor_size')))
backend.addValue('detector_sensor_count', data.get('sensor_count'))
backend.addArrayValues('detector_sensor_pixel_size', np.array(data.get('sensor_pixel_size')))
backend.addArrayValues('detector_calibration_x_to_momentum', np.array(data.get('calibration_x_to_momentum')))
backend.addArrayValues('detector_calibration_y_to_momentum', np.array(data.get('calibration_y_to_momentum')))
backend.addArrayValues('detector_calibration_tof_to_energy', np.array(data.get('calibration_tof_to_energy')))
backend.addArrayValues('detector_calibration_stage_to_delay', np.array(data.get('calibration_stage_to_delay')))
backend.addArrayValues('detector_calibration_other_converts', np.array(data.get('calibration_other_converts')))
backend.addArrayValues('detector_momentum_resolution', np.array(data.get('momentum_resolution')))
backend.addArrayValues('detector_spatial_resolution', np.array(data.get('spatial_resolution')))
backend.addArrayValues('detector_energy_resolution', np.array(data.get('energy_resolution')))
# Read parameters related to sample
# sample_gid = backend.openSection('section_experiment_sample_parameters')
backend.addValue('sample_id', data.get('sample_id'))
backend.addValue('sample_state_of_matter', data.get('sample_state'))
backend.addValue('sample_purity', data.get('sample_purity'))
backend.addValue('sample_surface_termination', data.get('sample_surface_termination'))
backend.addValue('sample_layers', data.get('sample_layers'))
backend.addValue('sample_stacking_order', data.get('sample_stacking_order'))
backend.addValue('sample_space_group', data.get('sample_space_group'))
backend.addValue('sample_chemical_name', data.get('chemical_name'))
backend.addValue('sample_chemical_formula', data.get('chemical_formula'))
# backend.addArrayValues('sample_chemical_elements', np.array(re.findall(r"[\w']+", data.get('chemical_elements'))))
atoms = set(ase.Atoms(data.get('chemical_formula')).get_chemical_symbols())
backend.addArrayValues('sample_atom_labels', np.array(list(atoms)))
backend.addValue('sample_chemical_id_cas', data.get('chemical_id_cas'))
backend.addValue('sample_temperature', data.get('sample_temperature'))
backend.addValue('sample_pressure', data.get('sample_pressure'))
backend.addValue('sample_growth_method', data.get('growth_method'))
backend.addValue('sample_preparation_method', data.get('preparation_method'))
backend.addValue('sample_vendor', data.get('sample_vendor'))
backend.addValue('sample_substrate_material', data.get('substrate_material'))
backend.addValue('sample_substrate_state_of_matter', data.get('substrate_state'))
backend.addValue('sample_substrate_vendor', data.get('substrate_vendor'))
# To add arrays (vectors, matrices, etc.) use addArrayValues and provide a
# numpy array. The shape of the numpy array must match the shape defined in
# the respective metadata definition.
# Close sections in the reverse order
# backend.closeSection('section_data', data_gid)
backend.closeSection('section_experiment', root_gid)
# backend.closeSection('section_experiment_general_parameters', general_gid)
# backend.closeSection('section_experiment_source_parameters', source_gid)
# backend.closeSection('section_experiment_detector_parameters', detector_gid)
# backend.closeSection('section_experiment_sample_parameters', sample_gid)
......@@ -14,11 +14,11 @@
import sys
from nomad.parsing import LocalBackend
from skeletonparser import SkeletonParserInterface
from mpesparser import MPESParserInterface
if __name__ == "__main__":
# instantiate the parser via its interface with a LocalBackend
parser = SkeletonParserInterface(backend=LocalBackend)
parser = MPESParserInterface(backend=LocalBackend)
# call the actual parsing with the given mainfile
parser.parse(sys.argv[1])
# print the results stored in the LocalBackend
......
This diff is collapsed.
......@@ -16,14 +16,14 @@ from setuptools import setup, find_packages
def main():
setup(
name='skeletonparser', # replace with new name for parser's python package
name='mpesparser',
version='0.1',
description='A skeleton NOMAD parser implementation.', # change accordingly
author='', # add your names
description='NOMAD parser implementation for multidimensional photoemission spectroscopy data.',
author='R. Patrick Xian',
license='APACHE 2.0',
packages=find_packages(),
package_data={
'skeletonparser': ['*.json']
'mpesparser': ['*.json']
},
install_requires=[
'nomadcore'
......
# Copyright 2016-2018 Markus Scheidgen
# 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.
import sys
import os.path
import json
import ase
import numpy as np
from datetime import datetime
from nomadcore.simple_parser import SimpleMatcher
from nomadcore.baseclasses import ParserInterface, AbstractBaseParser
from nomad.parsing import LocalBackend
class SkeletonParserInterface(ParserInterface):
def get_metainfo_filename(self):
"""
The parser specific metainfo. To include other metadata definitions, use
the 'dependencies' key to refer to other local nomadmetainfo.json files or
to nomadmetainfo.json files that are part of the general nomad-meta-info
submodule (i.e. ``dependencies/nomad-meta-info``).
"""
return os.path.join(os.path.dirname(__file__), 'skeleton.nomadmetainfo.json')
def get_parser_info(self):
""" Basic info about parser used in archive data and logs. """
return {
'name': 'you parser name',
'version': '1.0.0'
}
def setup_version(self):
""" Can be used to call :func:`setup_main_parser` differently for different code versions. """
self.setup_main_parser(None)
def setup_main_parser(self, _):
""" Setup the actual parser (behind this interface) """
self.main_parser = SkeletonParser(self.parser_context)
class SkeletonParser(AbstractBaseParser):
def parse(self, filepath):
backend = self.parser_context.super_backend
with open(filepath, 'rt') as f:
data = json.load(f)
# You need to open sections before you can add values or sub sections to it.
# The returned 'gid' can be used to reference a specific section if multiple
# sections of the same type are opened.
root_gid = backend.openSection('section_experiment')
# Values are added to the open section of the given metadata definitions. In
# the following case 'experiment_location' is a quantity of 'section_experiment'.
# When multiple sections of the same type (e.g. 'section_experiment') are open,
# you can use the 'gid' as an additional argument.
backend.addValue('experiment_location', data.get('location'))
# Values do not necessarely have to be read from the parsed file.
backend.addValue('experiment_method_name', data.get('method', 'Bare eyes'))
# The backend will check the type of the given value agains the metadata definition.
backend.addValue('experiment_time', int(datetime.strptime(data.get('date'), '%d.%M.%Y').timestamp()))
# Subsections work like before. The parent section must still be open.
data_gid = backend.openSection('section_data')
backend.addValue('data_repository_name', 'zenedo.org')
backend.addValue('data_repository_url', 'https://zenedo.org/path/to/mydata')
backend.addValue('data_preview_url', 'https://www.physicsforums.com/insights/wp-content/uploads/2015/09/fem.jpg')
backend.closeSection('section_data', data_gid)
# Subsections work like before. The parent section must still be open.
sample_gid = backend.openSection('section_sample')
backend.addValue('sample_chemical_name', data.get('sample_chemical'))
backend.addValue('sample_chemical_formula', data.get('sample_formula'))
backend.addValue('sample_temperature', data.get('sample_temp'))
atoms = set(ase.Atoms(data.get('sample_formula')).get_chemical_symbols())
# To add arrays (vectors, matrices, etc.) use addArrayValues and provide a
# numpy array. The shape of the numpy array must match the shape defined in
# the respective metadata definition.
backend.addArrayValues('sample_atom_labels', np.array(list(atoms)))
# Close sections in the reverse order.
backend.closeSection('section_sample', sample_gid)
backend.closeSection('section_experiment', root_gid)
{
"type": "nomad_meta_info_1_0",
"description": "Parser specific metadata definitions.",
"dependencies":[
{
"metainfoPath":"general.nomadmetainfo.json"
},
{
"metainfoPath":"general.experimental.nomadmetainfo.json"
}
],
"metaInfos": [
{
"description": "Contains information relating to an archive.",
"name": "experiment_location",
"dtypeStr": "C",
"superNames": ["section_experiment"]
}
]
}
{
"type":"skeleton experimental metadata format 1.0",
"date":"24.12.2018",
"location":"Northpole",
"sample_formula":"H2O",
"sample_chemical":"Ice",
"sample_state":"Frozen",
"result":"https://bitcoinist.com/wp-content/uploads/2018/08/shutterstock_764225425.jpg",
"sample_temp":384
}
\ No newline at end of file
{"GeneralParameters":
{"experiment_location": "Hamburg, Germany",
"experiment_date": "04.2018 - 05.2018",
"experiment_summary": "Characterization of excited-state circular dichroism of WSe2",
"institution": "DESY",
"facility": "FLASH",
"beamline": "PG-2",
"source_pump": "Free electron laser",
"source_probe": "Femtosecond laser",
"equipment": "HEXTOF detector",
"sample": "Bulk tungsten diselenide",
"measurement_axis": ["X", "Y", "t", "ADC"],
"physical_axis": ["kx", "ky", "E", "tpp"]},
"SourceParameters":
{"pump_rep_rate": 1000,
"pump_pulse_duration": 100,
"pump_wavelength": 800,
"pump_spectrum": [],
"pump_photon_energy": 1.55,
"pump_size": "",
"pump_fluence": 1.5,
"pump_polarization": "linear",
"pump_bunch": 400,
"probe_rep_rate": 1000,
"probe_pulse_duration": 100,
"probe_wavelength": 800,
"probe_spectrum": [],
"probe_photon_energy": 109,
"probe_size": "",
"probe_fluence": "",
"probe_polarization": "circular",
"probe_bunch": 400,
"temporal_resolution": 100},
"DetectorParameters":
{"extractor_voltage": 6000,
"work_distance": 4,
"lens_names": ["A", "B", "C", "D", "E", "F", "G", "H"],
"lens_voltages": [],
"tof_distance": 0.9,
"tof_voltages": 30,
"sample_bias": 15,
"magnification": [],
"detector_voltage": [],
"detector_type": "MCP",
"sensor_size": [],
"sensor_count": 4,
"sensor_pixel_size": [],
"x_to_momentum": [],
"y_to_momentum": [],
"tof_to_energy": [],
"stage_to_delay": [],
"other_converts": [],
"momentum_resolution": 0.01,
"spatial_resolution": "",
"energy_resolution": ""},
"SampleParameters":
{"sample_id": "000",
"sample_state": "solid",
"sample_purity": 0.99,
"sample_surface_term": "",
"sample_layer": "bulk",
"sample_stacking": "2H",
"sample_space_group": 194,
"chem_formula": "WSe2",
"chem_elements": ["W", "Se"],
"chem_name": "tungsten diselenide",
"chem_id_cas": "12067-46-8",
"sample_temp": 300,
"sample_pressure": 1e-11,
"growth_method": "chemical vaport transport",
"preparation_method": "in-vacuum cleaving",
"sample_vendor": "HQ Graphene",
"substrate_material": "copper",
"substrate_state": "solid",
"substrate_vendor": "custom"
}
}
{
"experiment_method": "multidimensional photoemission spectroscopy",
"experiment_method_abbrv": "MPES",
"experiment_location": "Hamburg, Germany",
"experiment_date": "04.2018 05.2018",
"experiment_summary": "Characterization of excited-state circular dichroism of WSe2",
"facility_institution": "DESY",
"facility_name": "FLASH",
"beamline": "PG-2",
"source_pump": "Free electron laser",
"source_probe": "Femtosecond laser",
"equipment_description": "HEXTOF detector",
"sample_description": "Bulk tungsten diselenide",
"measurement_axis": "X, Y, TOF, ADC",
"physical_axis": "kx, ky, E, tpp",
"pump_rep_rate": 1000,
"pump_pulse_duration": 100,
"pump_wavelength": 800,
"pump_spectrum": [],
"pump_photon_energy": 1.55,
"pump_size": [],
"pump_fluence": [],
"pump_polarization": "linear",
"pump_bunch": 400,
"probe_rep_rate": 1000,
"probe_pulse_duration": 100,
"probe_wavelength": 800,
"probe_spectrum": [],
"probe_photon_energy": 36.4970,
"probe_size": [],
"probe_fluence": [],
"probe_polarization": "circular",
"probe_bunch": 400,
"temporal_resolution": 100,
"extractor_voltage": 6030,
"work_distance": 4,
"lens_names": "A, B, C, D, E, F, G, H, I",
"lens_voltages": [],
"tof_distance": 0.9,
"tof_voltages": [20],
"sample_bias": 29,
"magnification": [-1.5],
"detector_voltages": [],
"detector_type": "MCP",
"sensor_size": [],
"sensor_count": 4,
"sensor_pixel_size": [],
"calibration_x_to_momentum": [],
"calibration_y_to_momentum": [],
"calibration_tof_to_energy": [],
"calibration_stage_to_delay": [],
"calibration_other_converts": [],
"momentum_resolution": [0.01],
"spatial_resolution": [],
"energy_resolution": [],
"sample_id": "000",
"sample_state": "solid",
"sample_purity": 0.99,
"sample_surface_termination": "0001",
"sample_layers": "bulk",
"sample_stacking_order": "2H",
"sample_space_group": 194,
"chemical_name": "tungsten diselenide",
"chemical_formula": "WSe2",
"chemical_id_cas": "12067-46-8",
"sample_temperature": 300,
"sample_pressure": 3.85e-10,
"growth_method": "chemical vaport transport",
"preparation_method": "in-vacuum cleaving",
"sample_vendor": "HQ Graphene",
"substrate_material": "copper",
"substrate_state": "solid",
"substrate_vendor": "custom"
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment