__init__.py 4.7 KB
Newer Older
Markus Kühbach's avatar
Markus Kühbach committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Copyright 2016-2019 Markus Scheidgen, Markus Kühbach
#   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

22
from nomad.parsing.parser import FairdiParser
23
24
25
26
27
from nomad.datamodel.metainfo.general_experimental import (
    section_experiment as SectionExperiment,
    section_data as SectionData,
    section_method as SectionMethod,
    section_sample as SectionSample)
Markus Kühbach's avatar
Markus Kühbach committed
28
29


30
class APTFIMParser(FairdiParser):
31
32
33
34
35
    def __init__(self):
        super().__init__(
            name='parsers/aptfim', code_name='mpes', code_homepage='https://github.com/mpes-kit/mpes',
            domain='ems', mainfile_mime_re=r'(application/json)|(text/.*)', mainfile_name_re=(r'.*.aptfim')
        )
Markus Kühbach's avatar
Markus Kühbach committed
36

37
    def parse(self, filepath, archive, logger=None):
Markus Kühbach's avatar
Markus Kühbach committed
38
39
40
        with open(filepath, 'rt') as f:
            data = json.load(f)

41
        section_experiment = archive.m_create(SectionExperiment)
Markus Kühbach's avatar
Markus Kühbach committed
42
43

        # Read general tool environment details
44
45
46
        section_experiment.experiment_location = data.get('experiment_location')
        section_experiment.experiment_facility_institution = data.get('experiment_facility_institution')
        section_experiment.experiment_summary = '%s of %s.' % (data.get('experiment_method').capitalize(), data.get('specimen_description'))
47
        try:
48
            section_experiment.experiment_time = int(datetime.strptime(data.get('experiment_date_global_start'), '%d.%m.%Y %M:%H:%S').timestamp())
49
50
51
        except ValueError:
            pass
        try:
52
            section_experiment.experiment_end_time = int(datetime.strptime(data.get('experiment_date_global_end'), '%d.%m.%Y %M:%H:%S').timestamp())
53
54
55
56
        except ValueError:
            pass

        # Read data parameters
57
        section_data = section_experiment.m_create(SectionData)
58
59
        section_data.data_repository_name = data.get('data_repository_name')
        section_data.data_preview_url = data.get('data_repository_url')
60
61
62
63
        preview_url = data.get('data_preview_url')
        # TODO: This a little hack to correct the preview url and should be removed
        # after urls are corrected
        preview_url = '%s/files/%s' % tuple(preview_url.rsplit('/', 1))
64
        section_data.data_preview_url = preview_url
65
66

        # Read parameters related to method
67
        section_method = section_experiment.m_create(SectionMethod)
68
69
70
        section_method.experiment_method_name = data.get('experiment_method')
        section_method.experiment_method_abbreviation = 'APT/FIM'
        section_method.probing_method = 'electric pulsing'
71
72
73
74
75
76
77
78
79
80
81
        # backend.addValue('experiment_tool_info', data.get('instrument_info')) ###test here the case that input.json keyword is different to output.json
        # measured_pulse_voltage for instance should be a conditional read
        # backend.addValue('measured_number_ions_evaporated', data.get('measured_number_ions_evaporated'))
        # backend.addValue('measured_detector_hit_pos', data.get('measured_detector_hit_pos'))
        # backend.addValue('measured_detector_hit_mult', data.get('measured_detector_hit_mult'))
        # backend.addValue('measured_detector_dead_pulses', data.get('measured_detector_dead_pulses'))
        # backend.addValue('measured_time_of_flight', data.get('measured_time_of_flight'))
        # backend.addValue('measured_standing_voltage', data.get('measured_standing_voltage'))
        # backend.addValue('measured_pulse_voltage', data.get('measured_pulse_voltage'))
        # backend.addValue('experiment_operation_method', data.get('experiment_operation_method'))
        # backend.addValue('experiment_imaging_method', data.get('experiment_imaging_method'))
Markus Kühbach's avatar
Markus Kühbach committed
82
83

        # Read parameters related to sample
84
        section_sample = section_experiment.m_create(SectionSample)
85
86
87
        section_sample.sample_description = data.get('specimen_description')
        section_sample.sample_microstructure = data.get('specimen_microstructure')
        section_sample.sample_constituents = data.get('specimen_constitution')
88
89
        atom_labels = data.get('specimen_chemistry')
        formula = ase.Atoms(atom_labels).get_chemical_formula()
90
91
        section_sample.sample_atom_labels = np.array(atom_labels)
        section_sample.sample_chemical_formula = formula