would it be possible to decompose this logic into a private or local method? eg 

```python
obs_idx = get_ids(h5grp['observation/ids'], observations)
samp_idx = get_ids(h5grp['sample/ids'], samples)
```