Skip to content

Latest commit

 

History

History
73 lines (48 loc) · 2.19 KB

intake_regionmask.rst

File metadata and controls

73 lines (48 loc) · 2.19 KB

Using regionmask with intake

Regions from geopandas shapefiles can be pre-defined in a yaml file, which can be easily shared. This relies on intake_geopandas and accepts regionmask_kwargs, which are passed to regionmask.from_geopandas.

python

# Use defaults so we don't get gridlines in generated docs import matplotlib as mpl mpl.rcdefaults() mpl.use('Agg')

# cut border when saving (for maps) mpl.rcParams["savefig.bbox"] = "tight"

You need to install intake_geopandas, which combines geopandas and intake, see https://intake.readthedocs.io/en/latest/.

Let's explore the Marine Ecoregions Of the World (MEOW) data set, which is a biogeographic classification of the world's coasts and shelves.

python

import intake import intake_geopandas

# open a pre-defined remote or local catalog yaml file, containing the MEOW regions path = "../data/regions_remote_catalog.yaml" cat = intake.open_catalog(path)

# access data from remote source meow_regions = cat.MEOW.read() print(meow_regions)

@savefig plotting_MEOW.png width=100% meow_regions.plot(add_label=False)

Remote catalogs can also be used:

url = 'https://raw.githubusercontent.com/regionmask/regionmask/main/data/regions_remote_catalog.yaml'
cat = intake.open_catalog(path)

Because the catalog sets use_fsspec=True and uses simplecache:: in the url, the shapefile is cached locally:

python

import os import zipfile

file = "cache/MEOW-TNC/data"

assert os.path.exists(file) assert zipfile.is_zipfile(file)

Find more such pre-defined regions in remote_climate_data.

Build your own catalog

To create a catalog we use the syntax described in intake. Below we show the catalog used above, which contains two example datasets (the second is the MEOW regions):

../data/regions_remote_catalog.yaml