|
| 1 | +<img |
| 2 | + src='https://carbonplan-assets.s3.amazonaws.com/monogram/dark-small.png' |
| 3 | + height='48' |
| 4 | +/> |
| 5 | + |
1 | 6 | # xarray-schema
|
| 7 | + |
| 8 | +Schema validation for Xarray |
| 9 | + |
| 10 | +[](https://github.com/carbonplan/xarray-schema/actions/workflows/main.yaml) |
| 11 | + |
| 12 | + |
| 13 | +# installation |
| 14 | + |
| 15 | +This package is in the early stages of development. Install it from source: |
| 16 | + |
| 17 | +```shell |
| 18 | +pip install git+git://github.com/TomNicholas/datatree |
| 19 | +pip install git+git://github.com/carbonplan/xarray-schema |
| 20 | +``` |
| 21 | + |
| 22 | +# usage |
| 23 | + |
| 24 | +Xarray-schema's API is modeled after [Pandera](https://pandera.readthedocs.io/en/stable/). The `DataArraySchema` and `DatasetSchema` objects both have `.validate()` methods. |
| 25 | + |
| 26 | +The basic usage is as follows: |
| 27 | + |
| 28 | +```python |
| 29 | +import numpy as np |
| 30 | +import xarray as xr |
| 31 | +from xarray_schema import DataArraySchema, DatasetSchema |
| 32 | + |
| 33 | +da = xr.DataArray(np.ones(4, dtype='i4'), dims=['x'], name='foo') |
| 34 | + |
| 35 | +schema = DataArraySchema(dtype=np.integer, name='foo', shape=(4, ), dims=['x']) |
| 36 | + |
| 37 | +schema.validate(da) |
| 38 | +``` |
| 39 | + |
| 40 | +# roadmap |
| 41 | + |
| 42 | +This is a very early prototype of a library. Some key things are missing: |
| 43 | + |
| 44 | +1. Validation of `coords`, `chunks`, and `attrs`. None of these are implemented yet. |
| 45 | +1. Class-based schema's for parts of the Xarray data model. Most validations are currently made as direct comparisons (`da.name == self.name`) but a more robust approach is possible that leverages classes for each component of the data model. We're already handling some special cases using `None` as a sentinel value to allow for wildcard-like behavior in places (i.e. `dims` and `shape`) |
| 46 | +1. Exceptions: Pandera accumulates schema exceptions and reports them all at once. Currently, we are a eagerly raising `SchemaErrors` when the are found. |
| 47 | + |
| 48 | +## license |
| 49 | + |
| 50 | +All the code in this repository is [MIT](https://choosealicense.com/licenses/mit/) licensed, but we request that you please provide attribution if reusing any of our digital content (graphics, logo, articles, etc.). |
| 51 | + |
| 52 | +## about us |
| 53 | + |
| 54 | +CarbonPlan is a non-profit organization working on the science and data of carbon removal. We aim to improve the transparency and scientific integrity of carbon removal and climate solutions through open data and tools. Find out more at [carbonplan.org ](https://carbonplan.org/) or get in touch by [opening an issue ](https://github.com/carbonplan/xarray-schema/issues/new) or [sending us an email ](mailto:[email protected]). |
0 commit comments