Skip to main content

A thin client library to use the API of the ISIMIP repository using Python.

Project description

isimip-client

Latest release Python Version License DOI

A thin client library to use the API of the ISIMIP repository using Python.

Setup

The library is written in Python (> 3.8) uses only dependencies, which can be installed without administrator priviledges. The installation of Python (and its developing packages), however differs from operating system to operating system. The installation of Python 3 for different plattforms is documented here.

The library can be installed via pip. Usually you want to create a virtual environment first, but this is optional:

# setup venv on Linux/macOS/Windows WSL
python3 -m venv env
source env/bin/activate

# setup venv on Windows cmd
python -m venv env
call env\Scripts\activate.bat

The library can conveniently installed using pip:

pip install isimip-client

Usage

The package provides a the Python class ISIMIPClient which can be used in scripts or notebooks in the following way:

from isimip_client.client import ISIMIPClient

client = ISIMIPClient()

The methods of this client object can then be used to perform queries to the ISIMIP Repository, e.g. to seach for datasets

# search the ISIMIP repository using a search string
response = client.datasets(query='gfdl-esm4 ssp370 pr')

# search the ISIMIP repository for a specific subtree
response = client.datasets(path='ISIMIP3b/InputData/climate/atmosphere/bias-adjusted/global/daily/ssp370/GFDL-ESM4/')

# search the ISIMIP repository using specifiers
response = client.datasets(simulation_round='ISIMIP3b',
                           product='InputData',
                           climate_forcing='gfdl-esm4',
                           climate_scenario='ssp370',
                           climate_variable='pr')

The response object is a dictionary of the form

{
    "count": 1001,
    "next": "https://data.isimip.org/api/v1/datasets/?page=2&...",
    "previous": null,
    "results": [
        ...
    ]
}

where each result contains the information for one dataset matching the provided search criteria. By default, only 10 datasets are returned and you can access the next 10 by providing page=2 to the datasets method. You can also use page_size=N to increase the number of returned results per page.

Similar searches can be performed on the files endpoint, e.g.:

response = client.files(...)

The ISIMIP Repository proviedes a "Configure download" feature, which can be used to perform operations on a set of files before downloading them. A common use case it the cut-out of a specific region. Technical details about this Files API can be found here. The client can be used to perform the same operations which are available on the webpage:

response = client.select_bbox(paths, west, east, south, north, poll=poll)

response = client.select_point(paths, lat, lon, poll=poll)

response = client.mask_bbox(paths, west, east, south, north, poll=poll)

response = client.mask_country(paths, country, poll=poll)

response = client.mask_landonly(paths, poll=poll)

response = client.mask_mask(paths, mask, var, poll=poll)

response = client.mask_shape(paths, shapefile, layer, poll=poll)

response = client.mask_shape(paths, geojson, layer, poll=poll)

response = client.cutout_bbox(paths, west, east, south, north, poll=poll)

response = client.cutout_point(paths, lat, lon, poll=poll)

# in order to download the created zip file, download method can be used
client.download(response['file_url'], path='downloads')

In addition, the client allows to use the API with a custom list of operations. In order to first cut out a rectangular area from the CHELSA high resolution data and then cut out a shape from a shapefile, you can use:

# Admin 0 - Countries from https://www.naturalearthdata.com
ne_shape = Path('~/data/isimip/shapes/ne_10m_admin_0_sovereignty.zip')
ne_mask = ne_shape.with_suffix('.nc')

# ISIMIP3a high resolution precipitation input data
paths = [
    'ISIMIP3a/InputData/climate/atmosphere/obsclim/global/daily/historical/CHELSA-W5E5/chelsa-w5e5_obsclim_pr_30arcsec_global_daily_201612.nc',
    ...
]

# chain of operations
operations = [
    {
        'operation': 'cutout_bbox',
        'bbox': [
             5.800,  # west
            10.600,  # east
            45.800,  # south
            47.900   # north
        ]
    },
    {
        'operation': 'create_mask',
        'shape': ne_shape.name,
        'mask': ne_mask.name,
    },
    {
        'operation': 'mask_mask',
        'mask': ne_mask.name,
        'var': 'm_91'  # switzerland layer 91 in the shapefile
    }
]

# list of uploaded files, referenced in the operations list
uploads = [ne_shape]

# sumbit the prepared job to the API and poll every 4 seconds for it's status
response = client.submit_job(paths, operations, uploads, poll=4)

Before 2025, the File API was only available in its first version, which can still be used:

client = ISIMIPClient(files_api_url='https://files.isimip.org/api/v1', files_api_version='v1')

client.select(paths, bbox=[south, north, west, east])
client.select(paths, point=(lat, lon))
client.select(paths, country=country)

client.mask(paths, bbox=[south, north, west, east])
client.mask(paths, country=country)
client.mask(paths, landonly=True)

client.cutout(paths, bbox=[south, north, west, east])

More examples can be found in the notebooks directory.

Command line client

Most features of the client can also be used on the command line using the isimip-client command, e.g.:

isimip-client select_bbox   [PATHS]... --west=-20 --east=20 --south=-10 --north=10

isimip-client select_point  [PATHS]... --lat=6.25 --lon=18.17

isimip-client mask_bbox     [PATHS]... --west=-20 --east=20 --south=-10 --north=10

isimip-client mask_country  [PATHS]... --country=bra

isimip-client mask_landonly [PATHS]...

isimip-client mask_mask     [PATHS]... --mask=~/data/isimip/api/countrymasks.nc --var=m_AUS

isimip-client mask_shape    [PATHS]... --shape=~/data/isimip/shapes/World_Continents.zip --layer=3

isimip-client mask_shape    [PATHS]... --shape=~/data/isimip/shapes/World_Continents.geojson --layer=4

isimip-client cutout_bbox   [PATHS]... --west=-20 --east=20 --south=-10 --north=10

isimip-client cutout_point  [PATHS]... --lat=6.25 --lon=18.17

where [PATHS]... denotes the list of ISIMIP file path to process, seperated by spaces.

Jupyter notebooks

I you want to run the included jupyter notebooks, you can install the additional packages using:

pip install isimip-client[jupyter]

Then Jupyter lab can be started using:

jupyter lab

The example notebooks are in the notebooks directory.

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

isimip_client-2.0.2.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

isimip_client-2.0.2-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file isimip_client-2.0.2.tar.gz.

File metadata

  • Download URL: isimip_client-2.0.2.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for isimip_client-2.0.2.tar.gz
Algorithm Hash digest
SHA256 fb3cb35ef2506a0b8908fd60ab98002b9143457a2d463a0a1b2f4a4bc354b5e3
MD5 ed8ae5f54118ad8e6c8c3b2e06417bb8
BLAKE2b-256 1f6c3f25874b37d9c71547e50e33f49618574804bffefd421eeecfc8a89fb453

See more details on using hashes here.

Provenance

The following attestation bundles were made for isimip_client-2.0.2.tar.gz:

Publisher: ci.yml on ISI-MIP/isimip-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file isimip_client-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: isimip_client-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for isimip_client-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bba7c65329af62af04f163256f6cb12a5fb393d7d3c24a816de81b54532ac68b
MD5 771a5aa6b96a0ca0afc5de05eb4ec909
BLAKE2b-256 49d1abc416f88190d6b795dd418fdf3a2cedc48027e41b88f13f333aee2b4b7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for isimip_client-2.0.2-py3-none-any.whl:

Publisher: ci.yml on ISI-MIP/isimip-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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