openPMD / openPMD/openPMD-api

Particles: Default for `positionOffset`

Open
#321 5 comments 0 reactions 1 assignee Claimed by @anokfireball View on GitHub
discussion frontend: C++17 frontend: Python3
Dominant language
C++
Stars
161
Forks
59
Avg merge
2d 22h
Merged PRs (30d)
7

Description

**Is your feature request related to a problem? If so, please describe.**
When writing particle data, we should define the default of `positionOffset` to a *constant record (component)* with default `0` (zero) offset.

This makes it easier for users to write position data if they do not care about fine-vs-coarse precision that `position` + `positionOffset` offer.

Python:
```python
import openPMD

num_cereals = 3

# cereal positions in my breakfast bowl
x = np.arange(num_cereals, dtype=np.double)
y = np.arange(num_cereals, dtype=np.double)

# open file for writing
series = openPMD.Series(
"cereals.h5",
openPMD.Access_Type.create
)

cereals = series.iterations[1].particles["cereals"]

datatype = openPMD.Datatype.DOUBLE
extent = [num_cereals]
dataset = openPMD.Dataset(datatype, extent)

cereals["position"]["x"].reset_dataset(dataset)
cereals["position"]["y"].reset_dataset(dataset)

offset = [0]
cereals["position"]["x"].store_chunk(offset, extent, x)
cereals["position"]["y"].store_chunk(offset, extent, y)

# terminate called after throwing an instance of 'std::runtime_error'
# what(): A Record can not be written without any contained RecordComponents: positionOffset
```

**Describe the solution you'd like**

Unless the user sets it explicitly, we should implicitly default in the above example to:
```python
cereals["positionOffset"]["x"].make_constant(0.0)
cereals["positionOffset"]["y"].make_constant(0.0)
```

**Additional context**

Also, this would solve a small bug: if I execute the above example and add the lines
```python
# cereals["positionOffset"]["x"].make_constant(0.0)
cereals["positionOffset"]["y"].make_constant(0.0)
```
the check `A Record can not be written without any contained RecordComponents: positionOffset` does *not throw* anymore, although not every `position` component has a `positionOffset` component counterpart:

```bash
$ h5ls -r cereals.h5
/ Group
/data Group
/data/1 Group
/data/1/particles Group
/data/1/particles/cereals Group
/data/1/particles/cereals/position Group
/data/1/particles/cereals/position/x Dataset {3}
/data/1/particles/cereals/position/y Dataset {3}
/data/1/particles/cereals/positionOffset Group
/data/1/particles/cereals/positionOffset/y Group
```

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.