openPMD / openPMD/openPMD-api

Using Maps/Dictionaries for attributes corresponding to `axisLabels`

Open
#1,447 1 comment 2 reactions 1 assignee Claimed by @franzpoeschel View on GitHub
feature request
Dominant language
C++
Stars
161
Forks
59
Avg merge
2d 22h
Merged PRs (30d)
7

Description

Regarding the [openPMD-standard](https://github.com/openPMD/openPMD-standard/blob/latest/STANDARD.md#mesh-based-records) attributes corresponding to specific axes (e.g. `gridSpacing`, `globalGridOffset`) of a mesh should be ordered in the same way as the `axisLabels` in their array. Currently this is just a suggestion to implementors which totally makes sense.

Guaranteeing that `axisLabels` match axis specific attributes is possible by storing these attributes e.g. in a C++ `std::map`. That makes it impossible to mess up axis specific attributes and axis labels.

Currently the implementor has to make sure that the order is correct which does not guarantee the correct order such that the following implementation mistakes are possible
```C++
openPMD::Mesh mesh{};

std::vector axisLabels = {"x","y","z"};
mesh.setAxisLabels(axisLabels);
std::vector gridSpacing = {dx,dz,dy};
mesh.setGridSpacing(gridSpacing);
```

A safer way would be
```C++
openPMD::Mesh mesh{};

std::vector axisLabels = {"x","z","y"};
mesh.setAxisLabels(axisLabels);
std::map gridSpacing = {{"x",dx},{"y",dy},{"z",dz}};
mesh.setGridSpacing(gridSpacing);
```
In this implementation additional safeguards could be added within openPMD such that attributes can only be added for axes that are already stored in axisLabels.

Possible Problem:
I am not sure how well a python `dictionary` interacts with a C++ `std::map`. This might be an issue in the python API of openPMD.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.