Helper function for accessing the `xarray.DataArray` of a `MultiscaleSpatialImage`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 394
- Forks
- 95
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 7
Description
FYI @giovp
As explained here https://github.com/scverse/spatialdata/issues/115, we assume that for each level of a MultiscaleSpatialImage we have only one variable. So, it would be handy to have a convenience function to get directly the xarray.DataArray for a particular multiscale level.
This could be a method of MultiscaleSpatialImage that we could propose to add upstream in the multiscale-spatial-image library, or a convenience function like the following, to define in our repo.
def get_scale(multiscale_image: MultiscaleSpatialImage, level: int) -> xarray.DataArray:
# code is explained in the examples below
d = dict(multiscale_image[f'scale{level}'])
assert len(d) == 1
return d.values().__iter__().__next__()
At the moment I am using repeatedly the following code (for instance to iterate over the various levels of the pyramid):
multiscale_image # a MultiscaleSpatialImage object
for level in multiscale_image.keys():
node = multiscale_image[level]
d = dict(node)
assert len(d) == 1
xarray_data = d.values().__iter__().__next__()
an alternative approach is the following (but it is also verbose):
multiscale_image # a MultiscaleSpatialImage object
for level in multiscale_image.keys():
node = multiscale_image[level]
variables = node.variables
assert len(variables) == 1
xarray_data = d[variables[0]]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the MultiscaleSpatialImage usage and the helper examples in this issue, then inspect the repository for existing multiscale image utilities. Decide whether the convenience function belongs in this repository or upstream. Done means a callable helper or method returns the single xarray.DataArray for a requested multiscale level, with coverage for the expected one-variable assumption.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100