casangi / xradio

Xarray Radio Astronomy Data IO
Other
9 stars 5 forks source link

Add schema support based on Xarray dataclasses #102

Closed scpmw closed 6 months ago

scpmw commented 7 months ago

This follows the general approach of https://pypi.org/project/xarray-dataclasses/, which is to define schemas using (semi-pseudo) dataclasses along the lines of

X = Literal["x"]
Y = Literal["y"]

@dataclass
class Image(AsDataArray):
    """2D image as DataArray."""

    data: Data[tuple[X, Y], float]
    x: Coord[X, int] = 0
    y: Coord[Y, int] = 0

We do not actually share any code with xarray-dataclasses, and instead re-define the type annotations ourselves. The reasoning is that we likely want to implement things substantially differently. For instance, this PR adds:

Down the line, we will also want custom code for checking schemas as well as generating schema-adhering xarray arrays and datasets.

CLAassistant commented 7 months ago

CLA assistant check
All committers have signed the CLA.

FedeMPouzols commented 6 months ago

Note that with this PR we drop support for Python 3.8:

  File "/home/fedemp/ws_xradio_pointing/venv_xradio_python_38/lib/python3.8/site-packages/xradio/schema/typing.py", line 11, in <module>
    from typing import (
ImportError: cannot import name 'Annotated' from 'typing' (/usr/lib/python3.8/typing.py)

>= 3.9 should be ok.