Metadata-Version: 2.4
Name: xarray-subset-grid
Version: 0.1.0
Summary: Subset Xarray datasets in time and space
Author-email: Matthew Iannucci <matt.iannucci@tetratech.com>, "Christopher H. Barker" <chris.barker@noaa.gov>
License: BSD 3-Clause License
        
        Copyright (c) 2024, Applied Science Associates
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://github.com/asascience-open/xarray-subset-grid
Keywords: xarray
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cf-xarray
Requires-Dist: cftime
Requires-Dist: dask
Requires-Dist: netcdf4
Requires-Dist: numpy
Requires-Dist: xarray>=2024.6
Provides-Extra: dev
Requires-Dist: pre-commit; extra == "dev"
Requires-Dist: pyright; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: sphinx; extra == "dev"
Requires-Dist: sphinx-rtd-theme; extra == "dev"
Provides-Extra: examples
Requires-Dist: fsspec; extra == "examples"
Requires-Dist: h5netcdf; extra == "examples"
Requires-Dist: matplotlib; extra == "examples"
Requires-Dist: s3fs; extra == "examples"
Requires-Dist: zarr<3; extra == "examples"
Dynamic: license-file

# xarray-subset-grid

Subset Xarray datasets in space while retaining the original grid for complex grid systems.

## Installation

### `pip compatible`

This package is not yet released on pypi, for now install using git:

```
pip install xarray_subset_grid@git+https://github.com/asascience-open/xarray-subset-grid.git
```

Or clone the project from git and build / install it from there.

## Usage

This package is designed to be used in conjunction with [`xarray`](https://xarray.dev/). Given a [CF Compliant](https://cfconventions.org/) `xarray` dataset named `ds`, this package can be accessed using the `xsg` accessor:

```python
# Get the interprested grid class
grid = ds.xsg

# subset to only include temperature
ds_temp = ds.xsg.subset_vars(['temp'])

# subset by bounding box
ds_subset_bbox = ds.xsg.subset_bbox([-72, 32, -70, 35])

# or by polygon
poly = np.array([
    [-72, 32],
    [-72, 33],
    [-73, 33],
    [-73, 31],
    [-72, 32],
])
ds_subset_poly = ds.xsg.subset_polygon(poly)
```

For full usage, see the [example notebooks](./examples/)

## Development

### `pip compatible`

First, create a new `virtualenv` and activate it:

```bash
python -m venv venv
source venv/bin.activate
```

Then install the project in local edit mode:

```bash
pip install -e .
```

Once installed, the tests can be run:

```bash
python -m pytest
```

Or alternatively run the notebooks in the same `virtualenv`

### `pixi`


Learn about `pixi` here: https://prefix.dev/

See the pixi docs for details, but for this setup:

There are three "environments" set up for pixi:

- `default`
- `dev`
- `examples`

And three "tasks":

- `lint`
- `test` : run most of the tests
- `test_all` : run the tests that access AWS -- i.e. download data directly.

To run the tests in an isolated environment:

```bash
pixi run -e dev test
```

Or with a specific python version:
```bash
pixi run -e test312 test
```

Options are: `test310` `test311` `test312` `test313`


To run a shell to do dev work:

```bash
pixi shell -e dev
```

To run a shell in which you can run the examples (notebooks and al that):

```bash
pixi shell -e examples
```

To run a shell with everything (dev and example deps:

```bash
pixi shell -e all
```

Finally, to when the `pyproject.toml` is updated, be sure to update the `pixi` lockfile:

```bash
pixi install
```

### `conda`

If you are using (or want to use) conda, you can install the dependencies with:

```
conda install --file conda_requirements.txt
```

That will get you the full set, including what you need to run the examples, etc.

If you need the development tools, you can also install:

```
conda install --file conda_requirements_dev.txt
```

(requirements should all be on the conda-forge channel)
