Skip to content

Commit

Permalink
Move dicts to mapping file
Browse files Browse the repository at this point in the history
  • Loading branch information
domna committed Feb 23, 2024
1 parent 24eaed6 commit f16d044
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 54 deletions.
55 changes: 55 additions & 0 deletions pynxtools_mpes/mappings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Mapping dictionaries for the MPES conversion.
"""

DEFAULT_UNITS = {
"X": "step",
"Y": "step",
"t": "step",
"tofVoltage": "V",
"extractorVoltage": "V",
"extractorCurrent": "A",
"cryoTemperature": "K",
"sampleTemperature": "K",
"dldTimeBinSize": "ns",
"delay": "ps",
"timeStamp": "s",
"energy": "eV",
"kx": "1/A",
"ky": "1/A",
}

CONVERT_DICT = {
"Instrument": "INSTRUMENT[instrument]",
"Analyzer": "ELECTRONANALYSER[electronanalyser]",
"Manipulator": "MANIPULATOR[manipulator]",
"Beam": "beam_TYPE[beam]",
"unit": "@units",
"Sample": "SAMPLE[sample]",
"Source": "source_TYPE[source]",
"User": "USER[user]",
"energy_resolution": "energy_resolution/resolution",
"momentum_resolution": "RESOLUTION[momentum_resolution]/resolution",
"temporal_resolution": "RESOLUTION[temporal_resolution]/resolution",
"spatial_resolution": "RESOLUTION[spatial_resolution]/resolution",
"sample_temperature": "temperature_sensor/value",
}

REPLACE_NESTED = {
"SAMPLE[sample]/chemical_formula": "SAMPLE[sample]/SUBSTANCE[substance]/molecular_formula_hill",
"source_TYPE[source]/Probe": "source_TYPE[source_probe]",
"source_TYPE[source]/Pump": "source_TYPE[source_pump]",
"beam_TYPE[beam]/Probe": "beam_TYPE[beam_probe]",
"beam_TYPE[beam]/Pump": "beam_TYPE[beam_pump]",
"sample_history": "sample_history/notes",
"ELECTRONANALYSER[electronanalyser]/RESOLUTION[momentum_resolution]": (
"ELECTRONANALYSER[electronanalyser]/momentum_resolution"
),
"ELECTRONANALYSER[electronanalyser]/RESOLUTION[spatial_resolution]": (
"ELECTRONANALYSER[electronanalyser]/spatial_resolution"
),
"SAMPLE[sample]/gas_pressure": "INSTRUMENT[instrument]/pressure_gauge/value",
"SAMPLE[sample]/temperature": (
"INSTRUMENT[instrument]/MANIPULATOR[manipulator]/temperature_sensor/value"
),
}
57 changes: 3 additions & 54 deletions pynxtools_mpes/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,7 @@
parse_flatten_json,
)

DEFAULT_UNITS = {
"X": "step",
"Y": "step",
"t": "step",
"tofVoltage": "V",
"extractorVoltage": "V",
"extractorCurrent": "A",
"cryoTemperature": "K",
"sampleTemperature": "K",
"dldTimeBinSize": "ns",
"delay": "ps",
"timeStamp": "s",
"energy": "eV",
"kx": "1/A",
"ky": "1/A",
}
from pynxtools_mpes.mappings import CONVERT_DICT, DEFAULT_UNITS, REPLACE_NESTED


def recursive_parse_metadata(
Expand Down Expand Up @@ -98,7 +83,7 @@ def h5_to_xarray(faddr: str, mode: str = "r") -> xr.DataArray:
data = np.asarray(h5_file["binned"]["BinnedData"])
except KeyError as exc:
raise ValueError(
f"Wrong Data Format, the BinnedData was not found.",
"Wrong Data Format, the BinnedData was not found.",
) from exc

# Reading the axes
Expand All @@ -111,7 +96,7 @@ def h5_to_xarray(faddr: str, mode: str = "r") -> xr.DataArray:
bin_names.append(h5_file["axes"][axis].attrs["name"])
except KeyError as exc:
raise ValueError(
f"Wrong Data Format, the axes were not found.",
"Wrong Data Format, the axes were not found.",
) from exc

# load metadata
Expand Down Expand Up @@ -168,42 +153,6 @@ def iterate_dictionary(dic, key_string):
return None


CONVERT_DICT = {
"Instrument": "INSTRUMENT[instrument]",
"Analyzer": "ELECTRONANALYSER[electronanalyser]",
"Manipulator": "MANIPULATOR[manipulator]",
"Beam": "beam_TYPE[beam]",
"unit": "@units",
"Sample": "SAMPLE[sample]",
"Source": "source_TYPE[source]",
"User": "USER[user]",
"energy_resolution": "energy_resolution/resolution",
"momentum_resolution": "RESOLUTION[momentum_resolution]/resolution",
"temporal_resolution": "RESOLUTION[temporal_resolution]/resolution",
"spatial_resolution": "RESOLUTION[spatial_resolution]/resolution",
"sample_temperature": "temperature_sensor/value",
}

REPLACE_NESTED = {
"SAMPLE[sample]/chemical_formula": "SAMPLE[sample]/SUBSTANCE[substance]/molecular_formula_hill",
"source_TYPE[source]/Probe": "source_TYPE[source_probe]",
"source_TYPE[source]/Pump": "source_TYPE[source_pump]",
"beam_TYPE[beam]/Probe": "beam_TYPE[beam_probe]",
"beam_TYPE[beam]/Pump": "beam_TYPE[beam_pump]",
"sample_history": "sample_history/notes",
"ELECTRONANALYSER[electronanalyser]/RESOLUTION[momentum_resolution]": (
"ELECTRONANALYSER[electronanalyser]/momentum_resolution"
),
"ELECTRONANALYSER[electronanalyser]/RESOLUTION[spatial_resolution]": (
"ELECTRONANALYSER[electronanalyser]/spatial_resolution"
),
"SAMPLE[sample]/gas_pressure": "INSTRUMENT[instrument]/pressure_gauge/value",
"SAMPLE[sample]/temperature": (
"INSTRUMENT[instrument]/MANIPULATOR[manipulator]/temperature_sensor/value"
),
}


def handle_h5_and_json_file(file_paths, objects):
"""Handle h5 or json input files."""
x_array_loaded = xr.DataArray()
Expand Down

0 comments on commit f16d044

Please sign in to comment.