Skip to main content

Minimalist Python + xarray-based climate impact projection framework for researchers with little time.

Project description

isku

python-test codecov Documentation

Minimalist Python + Xarray-based climate impact projection framework for researchers with little time.

[!WARNING] This package is in early development. It is likely to change in breaking ways.

Features

  • Define and apply three-step models to project climate effects, impacts, and damages.

  • Extract regionalized variables from regularly gridded data, such as downscaled general circulation model output.

  • Minimalist.

  • Loosely coupled components and protocols for quick scripts with functions or gnarly OOP-heavy applications.

  • Designed around Xarray to work with larger-than-memory datasets and distributed computing (dask!), GPUs, TPUs, streaming datasets.

  • Great for weird ad hoc projects and researchers that love rechunking big data!

Example

Projection

Projecting data with a model in isku is similar to the preprocess/predict/postprocess workflow you might already be familar with.

In isku, we could do a linear model with pre/post-processing like:

import isku

import numpy as np
import xarray as xr

# Some toy input data to work with.
input_data = xr.Dataset(
    {
        "coef": (["region"], [0, 0, 0]),
        "tas": (["region"], [1, 2, 3]),
    }
)

# Define a basic workflow for the projection model, pre/post-processing steps.
def _preprocess(ds):
    my_coef = ds["coef"] + 1
    my_tas = ds["tas"]
    return xr.Dataset({"coef": my_coef, "tas": my_tas})


def _linear_impact_model(ds):
    y = ds["coef"] * 2 + ds["tas"]
    return xr.Dataset({"impact": y})


def _postprocess(ds):
    return ds[["impact"]] + 10


test_impact_model = isku.build_projection_template(
    pre=_preprocess,
    project=_linear_impact_model,
    post=_postprocess,
)

# Put it together and run the projection.
projected = isku.project(input_data, model=test_impact_model)

This example uses pure functions to define workflow, or template, steps. This can be useful for quick analysis but isku also accepts custom objects adhering to the select protocols. The intent is that components can be quickly used, ignored, extended or replaced as needed by a project.

Extracting regions

The relationship between data transformations and region extraction can be complex in impact and damage research.

Say you have temperature data on a regular latitude-longitude grid. You need to extract regions from this grid, e.g. political boundaries, but you need to weight each temperature grid point by the proportion of the region's population exposed to temperature within each region. To make matters more complex you likely need to be specific about additional processing and transformation before and after regionalization. This is a niche case but a common headache.

We can handle this type of transformation in isku like:

import isku

import numpy as np
import xarray as xr


# Define some toy data to transform and regionalize.
gridded_data = xr.DataArray(
    np.arange(25).reshape([5, 5]),
    dims=("lon", "lat"),
    coords={
        "lon": np.arange(5),
        "lat": np.arange(5),
    },
    name="variable1",
).to_dataset()

# Refine regions and how they weight each grid point in the gridded data.
# This is usually read from file, but we're making up a quick example dataset.
my_regions = isku.GridWeightingRegions(
    xr.Dataset(
        {
            "region": (["idx"], ["a", "a", "a", "b"]),
            "weight": (["idx"], [0.3, 0.3, 0.3, 1.0]),
            "lon": (["idx"], [2, 3, 4, 1]),
            "lat": (["idx"], [0, 0, 0, 2]),
        },
    )
)

# Define workflow with pre/post regionalization transformations.
def _add_one(ds):
    return ds[["variable1"]] + 1


def _add_ten(ds):
    return ds[["variable1"]] + 10


my_extraction_workflow = isku.build_extraction_template(
    pre=_add_one,  # Before regionalization.
    post=_add_ten,  # After regionalization.
)


# Put it all together to extract regions from gridded data.
transformed = isku.extract_regions(
    gridded_data,
    template=my_extraction_workflow,
    regions=my_regions,
)

Installation

isku is a Python package available for download from PyPI.

Using pip you can install this package with

pip install isku

best practice suggest installing the package into a virtual environment.

For a uv project this is

uv add isku

Install the unreleased and unstable bleeding-edge version of the package with:

pip install git+https://github.com/climateimpactlab/isku

using pip or with a project in uv, do

uv add git+https://github.com/climateimpactlab/isku

Is this any good?

Yes.

Support

isku is open-source software made available under the terms of either the MIT License or the Apache License 2.0, at your option.

See CONTRIBUTING.md if you would like to contribute.

Changes for each release are summarized in CHANGELOG.md.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

isku-0.3.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

isku-0.3.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file isku-0.3.0.tar.gz.

File metadata

  • Download URL: isku-0.3.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for isku-0.3.0.tar.gz
Algorithm Hash digest
SHA256 527bbf33c3b02a82aec8a6319be2413b50721f9e455ed12b060d01f7139c0983
MD5 36d1e68b85966c03b641a4a65faf44ac
BLAKE2b-256 913526b9372a6e6823fa3465fb6da120520fd105ebb2ef8d916568a08c34ab8a

See more details on using hashes here.

File details

Details for the file isku-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: isku-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for isku-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f9cc1e19bc8898b520f00d535b105c0725751f935b7b51cd92d2dda520e914b
MD5 7f91da6f59ed9befe9a1ac7ca6110628
BLAKE2b-256 52d00899923f9d0d8de11bddda50edd95b0095bf265dd0a6109eb89c0c62af1e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page