Skip to content

Commit

Permalink
Update Include the X and Y axis in NXdata.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubelMozumder committed Nov 21, 2024
1 parent 52dc425 commit a085c39
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/pynxtools_stm/configs/nanonis_sxm_generic_afm.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@
"@units": "/DATA/INFO/Excitation/Unit",
},
"@title": "Excitation Plot of AFM Experiment (Backward Direction)",
"grp_name": "excitation _backward",
"grp_name": "excitation_backward",
},
{
"data": {
Expand Down
2 changes: 1 addition & 1 deletion src/pynxtools_stm/configs/nanonis_sxm_generic_stm.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@
"raw_path": "/Z/forward",
"@units": "@default:m",
},
# If axis will be provided use the following structure
# Syntax Note: If axis will be provided use the following structure
# "0": {
# "name": "Bias Voltage",
# "raw_path": [
Expand Down
19 changes: 14 additions & 5 deletions src/pynxtools_stm/nxformatters/base_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@ def _get_eln_dict(self, eln_file: str):
return eln_dict

def work_though_config_nested_dict(self, config_dict: Dict, parent_path: str):
# This concept is just note where the group will be
# handeld or somthing like that.
if "#note" in config_dict:
return
for key, val in config_dict.items():
if val is None or val == "":
continue
# Special case, will be handled in a specific function registerd in
# self._grp_to_func
# Special case, will be handled in a specific function registerd
# in self._grp_to_func
if key in self._grp_to_func:
# First fill the default values
self.work_though_config_nested_dict(
Expand All @@ -146,11 +148,18 @@ def work_though_config_nested_dict(self, config_dict: Dict, parent_path: str):
if other_attrs:
for k, v in other_attrs.items():
self.template[f"{parent_path}/{key}/@{k}"] = v
# Handle to construct nxdata group that comes alon as a dict
elif ("@title" in val or "grp_name" in val) and "data" in val:
_ = self._NXdata_grp_from_conf_description(
partial_conf_dict=val,
parent_path=parent_path,
group_name=key,
)
# variadic fields that would have several values according to the dimentions
elif isinstance(val, list) and isinstance(val[0], dict):
for item in val:
# Handle to construct nxdata group
if "@title" in item or "grp_name" in item and "data" in item:
if ("@title" in item or "grp_name" in item) and "data" in item:
_ = self._NXdata_grp_from_conf_description(
partial_conf_dict=item,
parent_path=parent_path,
Expand Down Expand Up @@ -195,9 +204,9 @@ def rearrange_data_according_to_axes(self, data):
np.flip(data)
elif self.NXScanControl.fast_axis == "-y":
if self.NXScanControl.slow_axis == "x":
return np.flipud(data)
return np.transpose(np.flipud(data))
elif self.NXScanControl.slow_axis == "-x":
return np.flip(data)
return np.transpose(data)
elif self.NXScanControl.fast_axis == "y":
if self.NXScanControl.slow_axis == "-x":
return np.fliplr(data)
Expand Down
40 changes: 39 additions & 1 deletion src/pynxtools_stm/nxformatters/nanonis_sxm_stm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import copy
from pynxtools_stm.nxformatters.base_formatter import SPMformatter
from typing import Dict, Optional, Union
from pathlib import Path
Expand Down Expand Up @@ -275,7 +276,7 @@ def construct_scan_data_grps(
data_dict=self.raw_data,
end_dict=partial_conf_dict,
)
# Example of data des and info and each column is separated by tab
## Example of data des and info and each column is separated by tab
# Channel Name Unit Direction Calibration Offset
# 14 Z m both 9.000E-9 0.000E+0
# 0 Current A both 1.000E-9 -1.132E-13
Expand Down Expand Up @@ -403,3 +404,40 @@ def _construct_nxscan_controllers(
parent_path=f"{parent_path}/{group_name}",
group_name=scan_pattern_grp,
)

def _NXdata_grp_from_conf_description(
self, partial_conf_dict, parent_path, group_name, group_index=0
):
"""Specialization of the generic funciton to create NXdata group or plots."""
store_partial_dict = copy.deepcopy(partial_conf_dict)
super()._NXdata_grp_from_conf_description(
partial_conf_dict, parent_path, group_name, group_index
)
print(" ################### ", partial_conf_dict)
nxdata_group_nm = store_partial_dict["grp_name"]
axis_x = "x"
axis_y = "y"
print(" ######################### ", group_name)
self.template[f"{parent_path}/{nxdata_group_nm}/@axes"] = [
axis_x,
axis_y,
]
self.template[f"{parent_path}/{nxdata_group_nm}/@{axis_x}_indices"] = 0
self.template[f"{parent_path}/{nxdata_group_nm}/{axis_x}"] = np.linspace(
self.NXScanControl.x_start,
self.NXScanControl.x_end,
int(self.NXScanControl.x_points),
)
self.template[f"{parent_path}/{nxdata_group_nm}/{axis_x}/@units"] = (
self.NXScanControl.x_start_unit
)

self.template[f"{parent_path}/{nxdata_group_nm}/@{axis_y}_indices"] = 1
self.template[f"{parent_path}/{nxdata_group_nm}/{axis_y}"] = np.linspace(
self.NXScanControl.y_start,
self.NXScanControl.y_end,
int(self.NXScanControl.y_points),
)
self.template[f"{parent_path}/{nxdata_group_nm}/{axis_y}/@units"] = (
self.NXScanControl.y_start_unit
)
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@
"@units": "/DATA/INFO/Excitation/Unit"
},
"@title": "Excitation Plot of AFM Experiment (Backward Direction)",
"grp_name": "excitation _backward"
"grp_name": "excitation_backward"
},
{
"data": {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions update_example_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
!#/local/bin/bash

# STS Nanonis
echo " !!! Converting Nanonis STS data !!! "
find tests/data/nanonis/sts/version_gen_5e_default_config -type f ! -name '*.nxs' | xargs dataconverter --nxdl NXspm --reader spm --output sts_5e_default_config.nxs
find tests/data/nanonis/sts/version_gen_5e_default_config -type f -name '*.nxs' | xargs mv sts_5e_default_config.nxs

find tests/data/nanonis/sts/version_gen_5e_with_described_nxdata -type f ! -name '*.nxs' | xargs dataconverter --nxdl NXspm --reader spm --output sts_5e_with_described_nxdata.nxs
find tests/data/nanonis/sts/version_gen_5e_with_described_nxdata -type f -name '*.nxs' | xargs mv sts_5e_with_described_nxdata.nxs

# AFM Nanonis
echo " !!! Converting Nanonis AFM data !!! "
find tests/data/nanonis/afm/version_gen_4_default_config -type f ! -name '*.nxs' | xargs dataconverter --nxdl NXafm --reader spm --output afm_4_with_default_config.nxs
find tests/data/nanonis/afm/version_gen_4_default_config -type f -name '*.nxs' | xargs mv afm_4_with_default_config.nxs

find tests/data/nanonis/afm/version_gen_4_with_described_nxdata -type f ! -name '*.nxs' | xargs dataconverter --nxdl NXafm --reader spm --output afm_4_with_described_nxdata.nxs
find tests/data/nanonis/afm/version_gen_4_with_described_nxdata -type f -name '*.nxs' | xargs mv afm_4_with_described_nxdata.nxs

# STM Nanonis
echo " !!! Converting Nanonis STM data !!! "
find tests/data/nanonis/stm/version_gen_4_5_default_config -type f ! -name '*.nxs' | xargs dataconverter --nxdl NXstm --reader spm --output stm_4_5_default_config.nxs
find tests/data/nanonis/stm/version_gen_4_5_default_config -type f -name '*.nxs' | xargs mv stm_4_5_default_config.nxs

find tests/data/nanonis/stm/version_gen_4_5_with_described_nxdata -type f ! -name '*.nxs' | xargs dataconverter --nxdl NXstm --reader spm --output stm_4_5_with_described_nxdata.nxs
find tests/data/nanonis/stm/version_gen_4_5_with_described_nxdata -type f -name '*.nxs' | xargs mv stm_4_5_with_described_nxdata.nxs

0 comments on commit a085c39

Please sign in to comment.