Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rui Xian
parser-mpes
Compare Revisions
aa701e8f2780419e7911972c8e2a16d188008902...d4083cdadd4b34b9d99cbeed579c56c09aa7606b
Commits (1)
Switched to FairdiParser with archive not backend.
· d4083cda
Markus Scheidgen
authored
Jul 30, 2020
d4083cda
Show whitespace changes
Inline
Side-by-side
mpesparser/__init__.py
View file @
d4083cda
...
...
@@ -19,16 +19,14 @@ import re
import
numpy
as
np
from
datetime
import
datetime
from
.metainfo
import
m_env
from
.metainfo
import
mpes
as
mmpes
from
nomad.parsing.parser
import
MatchingParser
from
nomad.datamodel.metainfo.general_experimental
import
section_experiment
as
msection_experiment
from
nomad.datamodel.metainfo.general_experimental
import
section_data
as
msection_data
from
nomad.datamodel.metainfo.general_experimental_method
import
section_method
as
msection_method
from
nomad.datamodel.metainfo.general_experimental_sample
import
section_sample
as
msection_sample
from
nomad.parsing.parser
import
FairdiParser
from
nomad.datamodel.metainfo.general_experimental
import
section_experiment
as
SectionExperiment
from
nomad.datamodel.metainfo.general_experimental
import
section_data
as
SectionData
from
nomad.datamodel.metainfo.general_experimental_method
import
section_method
as
SectionMethod
from
nomad.datamodel.metainfo.general_experimental_sample
import
section_sample
as
SectionSample
class
MPESParser
(
Matching
Parser
):
class
MPESParser
(
Fairdi
Parser
):
def
__init__
(
self
):
super
().
__init__
(
name
=
'parsers/mpes'
,
code_name
=
'mpes'
,
code_homepage
=
'https://github.com/mpes-kit/mpes'
,
...
...
@@ -36,13 +34,11 @@ class MPESParser(MatchingParser):
mainfile_contents_re
=
(
r
'"data_repository_name": "zenodo.org"'
)
)
def
run
(
self
,
filepath
,
logger
=
None
):
self
.
_metainfo_env
=
m_env
def
parse
(
self
,
filepath
,
archive
,
logger
=
None
):
with
open
(
filepath
,
'rt'
)
as
f
:
data
=
json
.
load
(
f
)
section_experiment
=
ms
ection
_e
xperiment
(
)
section_experiment
=
archive
.
m_create
(
S
ection
E
xperiment
)
# Read general experimental parameters
# section_experiment.experiment_location = ', '.join(reversed(re.findall(r"[\w']+", data.get('experiment_location'))))
...
...
@@ -61,13 +57,13 @@ class MPESParser(MatchingParser):
section_experiment
.
experiment_facility_name
=
data
.
get
(
'facility_name'
)
# Read data parameters
section_data
=
section_experiment
.
m_create
(
ms
ection
_d
ata
)
section_data
=
section_experiment
.
m_create
(
S
ection
D
ata
)
section_data
.
data_repository_name
=
data
.
get
(
'data_repository_name'
)
section_data
.
data_repository_url
=
data
.
get
(
'data_repository_url'
)
section_data
.
data_preview_url
=
'preview.png'
# Read method parameters
section_method
=
section_experiment
.
m_create
(
ms
ection
_m
ethod
)
section_method
=
section_experiment
.
m_create
(
S
ection
M
ethod
)
section_method
.
experiment_method_name
=
data
.
get
(
'experiment_method'
)
section_method
.
experiment_method_abbreviation
=
data
.
get
(
'experiment_method_abbrv'
)
section_method
.
equipment_description
=
data
.
get
(
'equipment_description'
)
...
...
@@ -125,7 +121,7 @@ class MPESParser(MatchingParser):
section_method
.
detector_energy_resolution
=
np
.
array
(
data
.
get
(
'energy_resolution'
))
# Read parameters related to sample
section_sample
=
section_experiment
.
m_create
(
ms
ection
_s
ample
)
section_sample
=
section_experiment
.
m_create
(
S
ection
S
ample
)
section_sample
.
sample_description
=
data
.
get
(
'sample_description'
)
section_sample
.
sample_id
=
data
.
get
(
'sample_id'
)
section_sample
.
sample_state_of_matter
=
data
.
get
(
'sample_state'
)
...
...
@@ -152,5 +148,3 @@ class MPESParser(MatchingParser):
# TODO sample classification
section_sample
.
sample_microstructure
=
'bulk sample, polycrystalline'
section_sample
.
sample_constituents
=
'multi phase'
return
section_experiment
mpesparser/__main__.py
View file @
d4083cda
...
...
@@ -12,15 +12,10 @@
# limitations under the License.
import
sys
import
json
from
nomad.parsing
import
LocalBackend
from
mpesparser
import
MPESParserInterface
from
mpesparser
import
MPESParser
if
__name__
==
"__main__"
:
# instantiate the parser via its interface with a 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
parser
.
parser_context
.
super_backend
.
write_json
(
sys
.
stdout
,
pretty
=
True
,
root_sections
=
[
'section_experiment'
])
archive
=
MPESParser
.
main
(
sys
.
argv
[
1
])
json
.
dump
(
archive
.
m_to_dict
(),
sys
.
stdout
,
indent
=
2
)