Skip to content

Commit

Permalink
transform and models (#52)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Isaac Virshup <[email protected]>
Co-authored-by: Macbook Marconato <[email protected]>
Co-authored-by: Luca Marconato <[email protected]>
Co-authored-by: Kevin Yamauchi <[email protected]>
  • Loading branch information
6 people authored Dec 12, 2022
1 parent 365982a commit ef9b92a
Show file tree
Hide file tree
Showing 43 changed files with 3,820 additions and 1,210 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
- name: Install test dependencies
run: |
python -m pip install --upgrade pip wheel
pip install pytest-cov
pip install codecov
- name: Install dependencies
run: |
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ __pycache__/
# data
spatialdata-sandbox
*.zarr/

# temp files
temp/

# rst generated from myst
docs/generated
26 changes: 20 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
rev: v3.0.0-alpha.4
hooks:
- id: prettier
- repo: https://github.com/asottile/blacken-docs
Expand All @@ -23,7 +23,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.982
rev: v0.991
hooks:
- id: mypy
additional_dependencies: [numpy==1.22.0, types-requests]
Expand All @@ -40,7 +40,7 @@ repos:
- flake8-bugbear
- flake8-blind-except
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: detect-private-key
- id: check-ast
Expand All @@ -49,8 +49,9 @@ repos:
args: [--fix=lf]
- id: trailing-whitespace
- id: check-case-conflict
- id: check-docstring-first
- repo: https://github.com/PyCQA/autoflake
rev: v1.7.1
rev: v2.0.0
hooks:
- id: autoflake
args:
Expand All @@ -59,7 +60,7 @@ repos:
- --remove-unused-variable
- --ignore-init-module-imports
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
Expand All @@ -70,7 +71,20 @@ repos:
- flake8-bugbear
- flake8-blind-except
- repo: https://github.com/asottile/pyupgrade
rev: v3.0.0
rev: v3.2.2
hooks:
- id: pyupgrade
args: [--py3-plus, --py38-plus, --keep-runtime-typing]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
hooks:
- id: python-no-eval
- id: python-use-type-annotations
- id: python-check-blanket-noqa
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
hooks:
- id: doc8
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[badge-tests]: https://img.shields.io/github/workflow/status/scverse/spatialdata/Test/main
[link-tests]: https://github.com/scverse/spatialdata.git/actions/workflows/test.yml

Up-to-date design doc [here](docs/design_doc.md#Abstract)
Up-to-date design doc [here](https://github.com/scverse/spatialdata/blob/main/docs/design_doc.md)

## Getting started

Expand Down
2 changes: 2 additions & 0 deletions docs/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Attributes
~~~~~~~~~~~

{% for item in attributes %}

{{ item }}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand All @@ -54,6 +55,7 @@ Methods

{% for item in methods %}
{%- if item != '__init__' %}

{{ item }}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
62 changes: 62 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1 +1,63 @@
# API

```{eval-rst}
.. module:: spatialdata
```

## SpatialData

The `SpatialData` class.

```{eval-rst}
.. autosummary::
:toctree: generated
SpatialData
```

## Models

The elements (building-blocks) that consitute `SpatialData`.

### Regions

#### Raster

```{eval-rst}
.. autosummary::
:toctree: generated
Image2DModel
Image3DModel
Labels2DModel
Labels2DModel
```

#### Polygons

#### Shapes

```{eval-rst}
.. autosummary::
:toctree: generated
ShapesModel
```

### Points

```{eval-rst}
.. autosummary::
:toctree: generated
PointsModel
```

### Table

```{eval-rst}
.. autosummary::
:toctree: generated
TableModel
```
15 changes: 14 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,26 @@
intersphinx_mapping = {
"anndata": ("https://anndata.readthedocs.io/en/stable/", None),
"numpy": ("https://numpy.org/doc/stable/", None),
"geopandas": ("https://geopandas.org/en/stable/", None),
"xarray": ("https://docs.xarray.dev/en/stable/", None),
}


# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "**.ipynb_checkpoints"]
exclude_patterns = [
"_build",
"Thumbs.db",
"**.ipynb_checkpoints",
"generated/spatialdata.PolygonsModel.rst",
]
# Ignore warnings.
nitpicky = False # TODO: solve upstream.
# nitpick_ignore = [
# ("py:class", "spatial_image.SpatialImage"),
# ("py:class", "multiscale_spatial_image.multiscale_spatial_image.MultiscaleSpatialImage"),
# ]


# -- Options for HTML output -------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions docs/design_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ Transforms map Elements between coordinate systems. Each `Transform` object must

Here is a short list of examples of the elements used to represent some spatial omics datasets. Real world will be available as notebooks [in this repository](https://github.com/scverse/spatialdata-notebooks), furthermore, some draft [implementations are available here](https://github.com/giovp/spatialdata-sandbox).

API

```python
import spatialdata as sd
from spatialdata import SpatialData

sdata = SpatialData(...)
points = sd.transform(sdata.points["image1"], tgt="tgt_space")
sdata = sd.transform(sdata, tgt="tgt_space")
```

The transfromation object should not have a method to apply itself to an element.
`SpatialData` can have a `transform` method, that can be applied to either a `SpatialData` object or an element.

#### Layout of a SpatialData object

The layout of some common datasets.
Expand Down
23 changes: 21 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,31 @@ version = "0.0.1.dev0"
requires-python = ">=3.8"
license = {file = "LICENSE"}
readme = "README.md"
dependencies = ["anndata","numpy","xarray","zarr","ome_zarr", "pyarrow"]
dependencies = [
"anndata",
"numpy",
"xarray",
"zarr",
"ome_zarr",
"spatial_image",
"multiscale_spatial_image",
"xarray-schema",
"pygeos",
"geopandas",
"shapely==2.0rc2",
"pyarrow",
"rich",
"tqdm",
"typing_extensions>=4.0.0",
]

[project.optional-dependencies]
dev = [
# dev version generation
"bump2version",
]
doc = [
"sphinx>=4",
"sphinx>=4.5",
"sphinx-book-theme>=0.3.3",
"myst-nb",
"sphinxcontrib-bibtex>=1.0.0",
Expand Down Expand Up @@ -91,3 +107,6 @@ exclude = '''

[tool.jupytext]
formats = "ipynb,md"

[tool.doc8]
ignore-path = "/docs/_templates/autosummary/*.rst"
52 changes: 50 additions & 2 deletions spatialdata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,53 @@

__version__ = version("spatialdata")

from spatialdata._core.spatialdata import SpatialData
from spatialdata._core.transform import Transform
__all__ = [
"SpatialData",
"Identity",
# "MapIndex",
"MapAxis",
"Translation",
"Scale",
"Affine",
"Rotation",
"Sequence",
# "Displacements",
# "Coordinates",
# "VectorField",
# "InverseOf",
# "Bijection",
# "ByDimension",
"Image3DModel",
"Image2DModel",
"Labels2DModel",
"Labels3DModel",
"PointsModel",
"PolygonsModel",
"ShapesModel",
"TableModel",
"SpatialElement",
"get_transform",
"set_transform",
]

from spatialdata._core._spatialdata import SpatialData
from spatialdata._core.core_utils import SpatialElement, get_transform, set_transform
from spatialdata._core.models import (
Image2DModel,
Image3DModel,
Labels2DModel,
Labels3DModel,
PointsModel,
PolygonsModel,
ShapesModel,
TableModel,
)
from spatialdata._core.transformations import ( # Bijection,; ByDimension,; Coordinates,; Displacements,; InverseOf,; MapIndex,; VectorField,
Affine,
Identity,
MapAxis,
Rotation,
Scale,
Sequence,
Translation,
)
15 changes: 15 additions & 0 deletions spatialdata/_constants/_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from enum import unique

from spatialdata._constants._enum import ModeEnum


@unique
class RasterType(ModeEnum):
IMAGE = "Image"
LABEL = "Label"


@unique
class ShapeType(ModeEnum):
CIRCLE = "Circle"
SQUARE = "Square"
2 changes: 1 addition & 1 deletion spatialdata/_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from spatialdata._core.spatialdata import SpatialData
from spatialdata._core._spatialdata import SpatialData
Loading

0 comments on commit ef9b92a

Please sign in to comment.