Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes on docs, updated notebooks #523

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ and this project adheres to [Semantic Versioning][].

## [0.1.2] - 2024-xx-xx

### Minor

- Made `get_channels()` public.

## [0.1.1] - 2024-03-28

### Added

- Added method `update_annotated_regions_metadata() which updates the `region` value automatically from the `region_key` columns
- Added method `update_annotated_regions_metadata() which updates the `region`value automatically from the`region_key` columns

### Changed

Expand Down
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The elements (building-blocks) that consitute `SpatialData`.
get_spatial_axes
points_geopandas_to_dask_dataframe
points_dask_dataframe_to_geopandas
get_channels
```

## Transformations
Expand Down
30 changes: 0 additions & 30 deletions src/spatialdata/_io/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,36 +271,6 @@ def _get_backing_files(element: DaskArray | DaskDataFrame) -> list[str]:
return files


@singledispatch
def get_channels(data: Any) -> list[Any]:
"""Get channels from data.

Parameters
----------
data
data to get channels from

Returns
-------
List of channels
"""
raise ValueError(f"Cannot get channels from {type(data)}")


@get_channels.register
def _(data: SpatialImage) -> list[Any]:
return data.coords["c"].values.tolist() # type: ignore[no-any-return]


@get_channels.register
def _(data: MultiscaleSpatialImage) -> list[Any]:
name = list({list(data[i].data_vars.keys())[0] for i in data})[0]
channels = {tuple(data[i][name].coords["c"].values) for i in data}
if len(channels) > 1:
raise ValueError("TODO")
return list(next(iter(channels)))


def save_transformations(sdata: SpatialData) -> None:
"""
Save all the transformations of a SpatialData object to disk.
Expand Down
2 changes: 1 addition & 1 deletion src/spatialdata/_io/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from shapely import GeometryType
from spatial_image import SpatialImage

from spatialdata._io._utils import get_channels
from spatialdata.models import PointsModel, ShapesModel
from spatialdata.models._utils import get_channels

CoordinateTransform_t = list[dict[str, Any]]

Expand Down
2 changes: 2 additions & 0 deletions src/spatialdata/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Y,
Z,
get_axes_names,
get_channels,
get_spatial_axes,
points_dask_dataframe_to_geopandas,
points_geopandas_to_dask_dataframe,
Expand Down Expand Up @@ -48,4 +49,5 @@
"points_dask_dataframe_to_geopandas",
"check_target_region_column_symmetry",
"get_table_keys",
"get_channels",
]
30 changes: 30 additions & 0 deletions src/spatialdata/models/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,33 @@ def points_geopandas_to_dask_dataframe(gdf: GeoDataFrame, suppress_z_warning: bo
else:
ddf = PointsModel.parse(ddf, coordinates={"x": "x", "y": "y"})
return ddf


@singledispatch
def get_channels(data: Any) -> list[Any]:
"""Get channels from data.

Parameters
----------
data
data to get channels from

Returns
-------
List of channels
"""
raise ValueError(f"Cannot get channels from {type(data)}")


@get_channels.register
def _(data: SpatialImage) -> list[Any]:
return data.coords["c"].values.tolist() # type: ignore[no-any-return]


@get_channels.register
def _(data: MultiscaleSpatialImage) -> list[Any]:
name = list({list(data[i].data_vars.keys())[0] for i in data})[0]
channels = {tuple(data[i][name].coords["c"].values) for i in data}
if len(channels) > 1:
raise ValueError("TODO")
return list(next(iter(channels)))
4 changes: 4 additions & 0 deletions src/spatialdata/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def parse(
Method to use for multiscale.
chunks
Chunks to use for dask array.
kwargs
Additional arguments for :func:`to_spatial_image`. In particular the `c_coords` kwargs argument (an
iterable) can be used to set the channel coordinates for image data. `c_coords` is not available for labels
data as labels do not have channels.

Returns
-------
Expand Down
Loading