Metadata-Version: 2.4
Name: ise-py
Version: 1.0.0
Summary: ISE (Ice Sheet Emulator) — ISEFlow, a flow-based neural network emulator for sea level projections with uncertainty quantification.
Project-URL: Homepage, https://github.com/Brown-SciML/ise
Project-URL: Documentation, https://ise.readthedocs.io
Project-URL: Repository, https://github.com/Brown-SciML/ise
Project-URL: Bug Tracker, https://github.com/Brown-SciML/ise/issues
Project-URL: HuggingFace Hub, https://huggingface.co/pvankatwyk/ISEFlow
Author-email: Peter Van Katwyk <pvankatwyk@gmail.com>
License: MIT License
        
        Copyright (c) 2026 Peter Van Katwyk
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE.md
Keywords: ISMIP6,climate science,deep learning,ice sheet emulator,normalizing flow,sea level projections,uncertainty quantification
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
Requires-Python: >=3.11
Requires-Dist: cftime>=1.6
Requires-Dist: huggingface-hub>=0.20
Requires-Dist: matplotlib>=3.7
Requires-Dist: netcdf4>=1.6
Requires-Dist: nflows>=0.14
Requires-Dist: numpy>=1.24
Requires-Dist: pandas>=2.0
Requires-Dist: properscoring>=0.1
Requires-Dist: scikit-learn>=1.4
Requires-Dist: scipy>=1.10
Requires-Dist: shap>=0.44
Requires-Dist: torch>=2.0
Requires-Dist: tqdm>=4.60
Requires-Dist: wandb>=0.17
Requires-Dist: xarray>=2023.0
Provides-Extra: dev
Requires-Dist: ipykernel>=6.29; extra == 'dev'
Requires-Dist: mypy>=1.8; extra == 'dev'
Requires-Dist: nbformat>=5.10; extra == 'dev'
Requires-Dist: optuna>=3.6; extra == 'dev'
Requires-Dist: pre-commit>=3.7; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Requires-Dist: tensorboard>=2.16; extra == 'dev'
Provides-Extra: docs
Requires-Dist: sphinx-autobuild>=2024.0; extra == 'docs'
Requires-Dist: sphinx-rtd-theme>=3.0; extra == 'docs'
Requires-Dist: sphinx>=8.0; extra == 'docs'
Provides-Extra: gpu
Requires-Dist: nvidia-cublas-cu12; extra == 'gpu'
Requires-Dist: nvidia-cuda-cupti-cu12; extra == 'gpu'
Requires-Dist: nvidia-cuda-nvrtc-cu12; extra == 'gpu'
Requires-Dist: nvidia-cuda-runtime-cu12; extra == 'gpu'
Requires-Dist: nvidia-cudnn-cu12; extra == 'gpu'
Requires-Dist: nvidia-cufft-cu12; extra == 'gpu'
Requires-Dist: nvidia-curand-cu12; extra == 'gpu'
Requires-Dist: nvidia-cusolver-cu12; extra == 'gpu'
Requires-Dist: nvidia-cusparse-cu12; extra == 'gpu'
Requires-Dist: nvidia-nccl-cu12; extra == 'gpu'
Requires-Dist: nvidia-nvjitlink-cu12; extra == 'gpu'
Requires-Dist: nvidia-nvtx-cu12; extra == 'gpu'
Description-Content-Type: text/markdown

# Ice Sheet Emulator (ISE)

[![Documentation Status](https://readthedocs.org/projects/ise/badge/?version=latest)](https://ise.readthedocs.io/en/latest/)
[![PyPI version](https://badge.fury.io/py/ise-py.svg)](https://pypi.org/project/ise-py/)
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://python.org)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.md)
[![CI](https://github.com/Brown-SciML/ise/actions/workflows/ci.yml/badge.svg)](https://github.com/Brown-SciML/ise/actions/workflows/ci.yml)

**ISE** is a Python package for training and analyzing **ice sheet emulators**, including **ISEFlow** — a hybrid flow-based neural network emulator for improved **sea level projections** and **uncertainty quantification**.

ISEFlow supports emulation for both the **Antarctic Ice Sheet (AIS)** and the **Greenland Ice Sheet (GrIS)**, producing projections of ice volume above flotation (IVAF) changes driven by ISMIP6 climate forcings. Uncertainty is decomposed into **epistemic** (model) and **aleatoric** (data) components.

This codebase has been used in peer-reviewed research, including:

- *"A Variational LSTM Emulator of Sea Level Contribution From the Antarctic Ice Sheet"*
- *"ISEFlow: A Flow-Based Neural Network Emulator for Improved Sea Level Projections and Uncertainty Quantification"*

For replication details see the [Releases](https://github.com/Brown-SciML/ise/releases) section.

**Documentation:** <https://ise.readthedocs.io/>

---

## Installation

Install from PyPI:

```sh
pip install ise-py
```

> **Pretrained weights** are hosted on [HuggingFace Hub](https://huggingface.co/pvankatwyk/ISEFlow)
> and downloaded automatically on first use. No manual download required.

For development (editable install):

```sh
git clone https://github.com/Brown-SciML/ise.git
cd ise
pip install -e ".[dev]"
```

Or with [uv](https://github.com/astral-sh/uv):

```sh
uv venv
uv pip install -e ".[dev]"
```

---

## Project Structure

```text
ise/
├── examples/                   Example scripts for using ISEFlow
├── ise/                        Main package
│   ├── data/                   Forcing/grid loading, feature engineering, dataset classes
│   │   ├── anomaly.py          AnomalyConverter: raw forcing → ISMIP6 anomalies
│   │   ├── dataclasses.py      EmulatorDataset, PyTorchDataset, TSDataset, ScenarioDataset
│   │   ├── feature_engineer.py FeatureEngineer: split, scale, lag, outliers
│   │   ├── forcings.py         ForcingFile: load/process climate NetCDF data
│   │   ├── grids.py            GridFile: sector boundary definitions
│   │   ├── inputs.py           ISEFlowAISInputs, ISEFlowGrISInputs
│   │   ├── process.py          ProjectionProcessor, DatasetMerger, sector helpers
│   │   ├── scaler.py           PyTorch StandardScaler, RobustScaler, LogScaler
│   │   └── utils.py            convert_and_subset_times()
│   ├── evaluation/             Metrics
│   │   └── metrics.py          Point, probabilistic, and distribution metrics
│   ├── models/                 Model architectures
│   │   ├── iseflow.py          ISEFlow, ISEFlow_AIS, ISEFlow_GrIS
│   │   ├── deep_ensemble.py    DeepEnsemble
│   │   ├── lstm.py             LSTM
│   │   ├── normalizing_flow.py NormalizingFlow
│   │   ├── training.py         CheckpointSaver, EarlyStoppingCheckpointer
│   │   ├── loss.py             WeightedGridLoss, WeightedMSELoss, and variants
│   │   ├── _experimental/      Legacy models from prior manuscripts (deprecated)
│   │   └── pretrained/         Pretrained weights (v1.0.0, v1.1.0)
│   └── utils/                  Data helpers and tensor utilities
│       ├── functions.py        get_X_y, get_data, to_tensor, unscale_output, …
│       └── io.py               check_type() runtime type validation
├── manuscripts/                Research paper scripts
├── tests/                      Unit tests
├── pyproject.toml
└── uv.lock
```

---

## Usage

### Loading and Running a Pretrained ISEFlow-AIS Model

```python
import numpy as np
from ise.models import ISEFlow_AIS
from ise.data.inputs import ISEFlowAISInputs

year = np.arange(2015, 2101)  # 86 annual timesteps

# Option A: use a known ISMIP6 ISM configuration shortcut
inputs = ISEFlowAISInputs(
    year=year,
    sector=np.ones(86, dtype=int),      # sector 1 of 18
    pr_anomaly=np.zeros(86),
    evspsbl_anomaly=np.zeros(86),
    smb_anomaly=np.zeros(86),
    ts_anomaly=np.zeros(86),
    ocean_thermal_forcing=np.zeros(86),
    ocean_salinity=np.zeros(86),
    ocean_temperature=np.zeros(86),
    model_configs="AWI_PISM1",          # loads all ISM config fields automatically
    ice_shelf_fracture=False,
    ocean_sensitivity="medium",
    ocean_forcing_type="standard",
    standard_melt_type="local",
)

# Option B: provide all ISM parameters individually
inputs = ISEFlowAISInputs(
    year=year,
    sector=np.ones(86, dtype=int),
    pr_anomaly=np.zeros(86),
    evspsbl_anomaly=np.zeros(86),
    smb_anomaly=np.zeros(86),
    ts_anomaly=np.zeros(86),
    ocean_thermal_forcing=np.zeros(86),
    ocean_salinity=np.zeros(86),
    ocean_temperature=np.zeros(86),
    initial_year=1980,
    numerics="fd",
    stress_balance="ho",
    resolution="16",
    init_method="da",
    melt_in_floating_cells="floating condition",
    icefront_migration="str",
    ocean_forcing_type="open",
    ocean_sensitivity="low",
    ice_shelf_fracture=False,
    open_melt_type="picop",
    standard_melt_type=None,
)

# Option C: if you have raw (non-anomaly) forcing values, use from_absolute_forcings()
inputs = ISEFlowAISInputs.from_absolute_forcings(
    year=year,
    sector=10,
    pr=pr_array,
    evspsbl=evspsbl_array,
    smb=smb_array,
    ts=ts_array,
    ocean_thermal_forcing=otf_array,
    ocean_salinity=sal_array,
    ocean_temperature=temp_array,
    aogcm="noresm1-m_rcp85",           # or custom_climatology={...}
    model_configs="AWI_PISM1",
    ice_shelf_fracture=False,
    ocean_sensitivity="medium",
    ocean_forcing_type="standard",
    standard_melt_type="local",
)

# Load the pretrained v1.1.0 model (weights auto-downloaded from HuggingFace Hub on first use)
model = ISEFlow_AIS(version="v1.1.0")
predictions, uncertainties = model.predict(inputs)

print(predictions.shape)           # (86, 1)  — SLE in mm, 2015-2100
print(uncertainties["epistemic"])  # epistemic uncertainty per timestep
print(uncertainties["aleatoric"])  # aleatoric uncertainty per timestep
print(uncertainties["total"])      # total uncertainty (epistemic + aleatoric)
```

### Running the Pretrained GrIS Emulator

```python
import numpy as np
from ise.models import ISEFlow_GrIS
from ise.data.inputs import ISEFlowGrISInputs

inputs = ISEFlowGrISInputs(
    year=np.arange(2015, 2101),
    sector=np.ones(86, dtype=int),      # basin 1 of 6
    aST=np.zeros(86),                   # surface temperature anomaly
    aSMB=np.zeros(86),                  # SMB anomaly
    ocean_thermal_forcing=np.zeros(86),
    basin_runoff=np.zeros(86),
    model_configs="AWI_ISSM1",
    ice_shelf_fracture=False,
    ocean_sensitivity="medium",
    standard_ocean_forcing=True,
)

model = ISEFlow_GrIS(version="v1.1.0")
predictions, uncertainties = model.predict(inputs)
```

### Training ISEFlow from Scratch

```python
from ise.models import ISEFlow, DeepEnsemble, NormalizingFlow

nf = NormalizingFlow(input_size=93, output_size=1, num_flow_transforms=5)
de = DeepEnsemble(input_size=93, num_ensemble_members=5, output_sequence_length=86)
model = ISEFlow(deep_ensemble=de, normalizing_flow=nf)

# X: (N, n_features), y: (N,) — pre-scaled ISMIP6 data
model.fit(
    X_train, y_train,
    nf_epochs=100,
    de_epochs=100,
    X_val=X_val,
    y_val=y_val,
    early_stopping=True,
    patience=15,
)

model.save("./ISEFlow/", input_features=list(X_train.columns))
```

### Evaluating Model Performance

```python
from ise.models import ISEFlow
from ise.evaluation import metrics as m
from ise.utils import functions as f

model = ISEFlow.load("./ISEFlow/")

predictions, uncertainties = model.predict(X_val)
y_val_unscaled = f.unscale_output(y_val.reshape(-1, 1), "./ISEFlow/scaler_y.pkl")

mse = m.mean_squared_error(y_val_unscaled, predictions)
print(f"MSE: {mse:.4f}")
```

---

## Contributing

We welcome contributions! To get started:

1. Fork the repository on GitHub.
2. Create a new branch for your feature or bugfix.
3. Submit a pull request (PR) for review.

Run tests before submitting:

```sh
pytest tests/
```

---

## Contact & Support

Developed by **Peter Van Katwyk** (Ph.D., Brown University).

- **Email:** [pvankatwyk@gmail.com](mailto:pvankatwyk@gmail.com)
- **GitHub Issues:** [Report a bug](https://github.com/Brown-SciML/ise/issues)

If you use ISE in research, please consider citing our work. See [CITATION.md](CITATION.md) for details.
