Metadata-Version: 2.4
Name: calicropyield
Version: 0.3.0
Summary: A multi-modal data downloader and processing library for California crop yield benchmarking
Author-email: Hamid Kamangir <hamid.kamangir@gmail.com>
License-Expression: BSD-3-Clause
Project-URL: Homepage, https://github.com/plant-ai-biophysics-lab/calicropyield-dev
Project-URL: Repository, https://github.com/plant-ai-biophysics-lab/calicropyield-dev
Project-URL: Bug Tracker, https://github.com/plant-ai-biophysics-lab/calicropyield-dev/issues
Keywords: california,crop yield,benchmark,remote sensing,agriculture
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pandas>=1.3
Requires-Dist: xarray>=0.19
Requires-Dist: netCDF4>=1.6
Requires-Dist: rasterio>=1.2
Requires-Dist: geopandas>=0.10
Requires-Dist: shapely>=1.8
Requires-Dist: numpy>=1.21
Requires-Dist: google-cloud-storage>=2.10
Requires-Dist: google-auth>=2.0
Requires-Dist: gcsfs>=2023.1
Requires-Dist: zarr<3.2,>=3.0.8
Provides-Extra: dev
Requires-Dist: setuptools-scm>=8.0; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == "test"
Requires-Dist: pytest-cov>=4.0; extra == "test"
Dynamic: license-file

# calicropyield

Python client library for downloading and preparing county-level data used in the California Crop Yield Benchmark.

## What this package does

`calicropyield` provides a single client to retrieve benchmark-ready files from a versioned Google Drive dataset release:

- ET (OpenET monthly GeoTIFF)
- Landsat monthly GeoTIFF
- DayMet climate annual NetCDF
- Soil NetCDF
- CDL annual GeoTIFF
- USDA crop yield CSV

The package supports optional geometry-based cropping and lightweight filtering for CDL/USDA outputs.

## Installation

### From source (this repository)

```bash
git clone https://github.com/plant-ai-biophysics-lab/calicropyield-dev.git
cd calicropyield-dev
pip install .
```

### Development install (recommended)

```bash
uv sync --extra dev --extra test
```

## Authentication setup

This package accesses protected Google Drive data via a service account key.

Credential resolution order:

1. `CALICROPYIELD_CREDENTIALS` environment variable
2. `~/.calicropyield/service_account.json`

Example:

```bash
export CALICROPYIELD_CREDENTIALS=/absolute/path/to/service_account.json
```

If no credential file is found, the client raises `FileNotFoundError` with setup instructions.

## Quickstart

```python
from calicropyield import CalCropYieldClient

client = CalCropYieldClient(
    cache_dir="~/data/calicropyield",
    dataset_version="v1",   # optional; defaults to latest
    overwrite=False,
)

print(client.list_datasets())
print(client.list_years())

# Download 2021 Landsat files for two counties
paths = client.download_landsat(["Yolo", "Fresno"], years=[2021])
print(f"Downloaded {len(paths)} files")
```

## Public API

Main exports:

- `CalCropYieldClient`
- `DatasetCatalog`
- `DataDownloader` (backward-compatible alias of `CalCropYieldClient`)

### Download methods

All download methods return `List[pathlib.Path]`:

- `download_et(county_names, years=None, geometry=None)`
- `download_landsat(county_names, years=None, geometry=None)`
- `download_climate(county_names, years=None, geometry=None, variables=None)`
- `download_soil(county_names, geometry=None, variables=None)`
- `download_cdl(county_names, years=None, geometry=None, crop_types=None)`
- `download_yield(county_names, years=None, crop_types=None)`

### Introspection helpers

- `list_datasets()`
- `list_years(dataset="landsat")`
- `list_counties()`

## Dataset catalog and versioning

Dataset layout is defined in a versioned manifest file: `calicropyield/catalog.json`.

- Current latest dataset version: `v1`
- Years in `v1`: 2008, 2009, 2010, 2011, 2013-2022
- Available dataset keys: `et`, `landsat`, `climate`, `soil`, `cdl`, `usda`

You can inspect catalog metadata via:

```python
from calicropyield import DatasetCatalog

catalog = DatasetCatalog()  # latest
print(catalog.version)
print(catalog.available_datasets)
print(catalog.available_years)
```

## Output structure

Downloaded files are stored under:

```text
<cache_dir>/counties/<County>/data/<dataset_type>/<year>/...
```

For non-yearly datasets (for example `soil`), year subfolders are omitted.

## Development workflow

This project uses:

- `uv` for environment and lockfile management
- `ruff` for linting
- `pytest` for tests
- `setuptools-scm` for dynamic package versioning from git tags

Common commands:

```bash
uv sync --extra dev --extra test
uv run ruff check calicropyield/
uv run pytest
uv lock
```

## Releases

Package version is derived from git tags (for example `v0.2.0`).

Typical release flow:

```bash
git tag vX.Y.Z
git push origin vX.Y.Z
```

On tag push, GitHub Actions builds wheel and sdist artifacts and validates them with `twine check`.

## Repository layout

- `calicropyield/`: installable Python package
- `dataset/`: internal dataset generation scripts/notebooks
- `.github/workflows/ci.yml`: lint/test/build CI

## Related project

End-user tutorial notebooks and benchmark usage examples live in the companion repository:

- https://github.com/plant-ai-biophysics-lab/california-crop-yield-benchmark

## License

BSD 3-Clause License. See `LICENSE`.
