Skip to content

Commit

Permalink
Merge pull request #220 from FAIRmat-NFDI/xps-fixes
Browse files Browse the repository at this point in the history
Hotfixes for XPS reader
  • Loading branch information
lukaspie authored Feb 19, 2024
2 parents ea64cbf + 2947e51 commit db40a6a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
24 changes: 12 additions & 12 deletions examples/xps/eln_data_sle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ user:
address: Lukas Pielsticker
orcid: 0000-0001-9361-8333
email: [email protected]
Instrument:
instrument:
device_information:
vendor: SPECS GmbH
model: Custom NAP-XPS instrument
Expand All @@ -36,19 +36,19 @@ Instrument:
distance:
value: 0.0
unit: mm
Electronanalyser:
analyser:
description: hemispherical
device_information:
vendor: SPECS GmbH
model: PHOIBOS 150 NAP
identifier: null
Collectioncolumn:
collectioncolumn:
scheme: angular dispersive
device_information:
vendor: SPECS GmbH
model: PHOIBOS 150 NAP
identifier: null
Energydispersion:
energydispersion:
scheme: hemispherical
diameter:
unit: mm
Expand All @@ -57,14 +57,14 @@ Instrument:
vendor: SPECS GmbH
model: PHOIBOS 150
identifier: null
Detector:
detector:
amplifier_type: channeltron
detector_type: Multi-anode
detector_type: Multi-anode
device_information:
vendor: Surface Concept GmbH
model: 1D-DLD detector
identifier: null
Manipulator:
manipulator:
device_information:
vendor: SPECS GmbH
model: 5-axis manipulator
Expand All @@ -84,15 +84,15 @@ Instrument:
heater_power:
value: 0.0
unit: W
Pid:
pid:
setpoint:
value: 298.0
unit: K
cryostat:
name: null
physical_quantity: null
type: null
Pid:
pid:
setpoint: null
drain_current_amperemeter:
name: Amperemeter 1.0
Expand All @@ -113,7 +113,7 @@ Instrument:
name: XPS sample potentiostat
physical_quantity: voltage
type: potentiostat
Pid:
pid:
setpoint:
value: 0.0
unit: V
Expand All @@ -139,13 +139,13 @@ Instrument:
value:
value: null
unit: null
Sample:
sample:
name: Polycristalline Au foil
sample_id: S718
atom_types: Au
physical_form: foil
situation: vacuum
Substance:
substance:
name: Au
molecular_mass:
value: 196.96657
Expand Down
35 changes: 19 additions & 16 deletions pynxtools/dataconverter/readers/xps/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_entries_and_detectors(config_dict, xps_data_dict):
# Iteration over scan
for data_var in data.data_vars:
if chan_count in data_var:
detector_num = data_var.split("_chan_")[-1]
detector_num = data_var.split(chan_count)[-1]
detector_nm = f"detector{detector_num}"
DETECTOR_SET.add(detector_nm)
except AttributeError:
Expand Down Expand Up @@ -144,9 +144,10 @@ def fill_data_group(key, key_part, entries_values, config_dict, template):
data_group_key = data_field_key.rsplit("/data", 1)[0]

if key_part == "energy":
energy_field_key = f"{data_group_key}/energy"
# Here, we need to take here if the data/entry is
# written directly in the future.
energy_field_key = data_group_key
energy = np.array(xr_data.coords["energy"].values)
print(energy)
template[energy_field_key] = energy

else:
Expand Down Expand Up @@ -208,7 +209,7 @@ def fill_detector_group(key, entries_values, config_dict, xps_data_dict, templat

for data_var in data_vars:
if chan_count in data_var:
detector_num = data_var.split("_chan_")[-1]
detector_num = data_var.split(chan_count)[-1]
detector_nm = f"detector{detector_num}"
detector_scans[detector_nm] += [xr_data[data_var].data]
cycle_scan_num = data_var.split(chan_count)[0]
Expand Down Expand Up @@ -244,19 +245,21 @@ def fill_template_with_value(key, value, template):
if value is None or str(value) == "None":
return

# Do for all entry names
for entry in ENTRY_SET:
atom_types: List = []
if "chemical_formula" in key:
atom_types = list(extract_atom_types(value))
atom_types: List = []
if "chemical_formula" in key:
atom_types = list(extract_atom_types(value))

if isinstance(value, datetime.datetime):
value = value.isoformat()
if isinstance(value, datetime.datetime):
value = value.isoformat()

elif isinstance(value, dict) and LINK_TOKEN in value:
link_text = value[LINK_TOKEN]
link_text = link_text.replace("entry", f"{entry}")
value = {LINK_TOKEN: link_text}
elif isinstance(value, dict) and LINK_TOKEN in value:
initial_link_text = value[LINK_TOKEN]

# Do for all entry names
for entry in ENTRY_SET:
if isinstance(value, dict) and LINK_TOKEN in value:
# Reset link to original
value[LINK_TOKEN] = initial_link_text.replace("entry", f"{entry}")

modified_key = key.replace("[entry]", f"[{entry}]")

Expand All @@ -273,8 +276,8 @@ def fill_template_with_value(key, value, template):
# link.
link_text = link_text.replace("detector", f"{detector}")
value = {LINK_TOKEN: link_text}

template[detr_key] = value

else:
template[modified_key] = value

Expand Down
2 changes: 1 addition & 1 deletion pynxtools/dataconverter/readers/xps/sle/sle_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _update_xps_dict_with_spectrum(self, spectrum, key_map):
channels = [key for key in spectrum["data"] if "cps_ch_" in key]
for channel in channels:
ch_no = channel.rsplit("_")[-1]
channel_key = f"{scan_key}_chan_{ch_no}"
channel_key = f"{scan_key}_chan{ch_no}"
detector_data_key = (
f"{path_map['detector']}/{detector_data_key_child}"
f"_channels_Channel_{ch_no}/counts"
Expand Down
2 changes: 1 addition & 1 deletion pynxtools/dataconverter/readers/xps/txt/txt_scienta.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _update_xps_dict_with_spectrum(self, spectrum, key_map):
)

# Write channel data to 'data'.
channel_key = f"{scan_key}_chan_0"
channel_key = f"{scan_key}_chan0"
self._xps_dict["data"][entry][channel_key] = xr.DataArray(
data=intensity, coords={"energy": energy}
)
Expand Down

0 comments on commit db40a6a

Please sign in to comment.