Skip to main content

EPA region definitions and representations in

Project description

epa-regions-python

EPA regions with GeoPandas / regionmask.

Version on PyPI

regions

Code
python -m epa_regions -r 50m --states-only --save

Installation

conda activate ...
conda install -c conda-forge geopandas regionmask pooch pyogrio
pip install epa-regions

Usage

import epa_regions

# GeoPandas GeoDataFrame
epa = epa_regions.get(resolution="50m")

# Convert to regionmask Regions for use with gridded data
epa = epa_regions.to_regionmask(epa)

Point data

points

Code
import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np

import epa_regions

rng = np.random.default_rng(seed=123)

epa = epa_regions.get(resolution="50m")

# CONUS
lonmin, lonmax = -125, -66
latmin, latmax = 24, 50
n = 250
lon = rng.uniform(lonmin, lonmax, n)
lat = rng.uniform(latmin, latmax, n)
points = gpd.GeoDataFrame(
    geometry=gpd.points_from_xy(lon, lat, crs="EPSG:4326")
)

fig, ax = plt.subplots(constrained_layout=True, figsize=(4, 2.5))

epa.plot(column="number", ax=ax, alpha=0.6)
points.sjoin(epa, predicate="within").plot(column="number", ax=ax, ec="0.3", lw=1)

ax.set(xlim=(lonmin, lonmax), ylim=(latmin, latmax))
ax.axis("off")

fig.savefig("points.png", dpi="figure", bbox_inches="tight")

Gridded data

gridded

Code
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import xarray as xr

import epa_regions

epa = epa_regions.to_regionmask(epa_regions.get(resolution="50m"))

# CONUS
lonmin, lonmax = -125, -66
latmin, latmax = 24, 50

ds = (
    xr.tutorial.open_dataset("air_temperature")
    .sel(lon=slice(lonmin + 360, lonmax + 360), lat=slice(latmax, latmin))
)
mask = epa.mask(ds.isel(time=0))

proj = ccrs.LambertConformal(central_longitude=-100)
tran = ccrs.PlateCarree()

fig = plt.figure(figsize=(6, 6), constrained_layout=True)

ax = fig.add_subplot(3, 1, (1, 2), projection=proj)

mask.plot.pcolormesh(
    levels=np.arange(mask.min() - 0.5, mask.max() + 1),
    ax=ax,
    transform=ccrs.PlateCarree(),
    cmap="tab10",
    cbar_kwargs=dict(
        orientation="horizontal",
        fraction=0.075,
        pad=0.05,
        ticks=np.arange(mask.min(), mask.max() + 1),
        format="R{x:.0f}",
        label="EPA Region",
    ),
)

ax.add_feature(cfeature.STATES, linewidth=0.7, edgecolor="0.3")
ax.coastlines()
ax.set_extent([lonmin, lonmax - 2, latmin, latmax], crs=tran)
ax.set_title("")

ax = fig.add_subplot(3, 1, 3)

(dt,) = np.unique(ds.time.diff("time"))

window = pd.Timedelta("30D")
(
    ds["air"].groupby(mask)
    .mean()
    .rolling(time=int(window / dt), center=True)
    .mean()
    .plot(
        hue="mask",
        ax=ax,
        add_legend=False,
    )
)

ax.set_xlabel("")
ax.text(
    0.01,
    0.97,
    f"{window.total_seconds() / 86400:g}-day rolling mean",
    ha="left",
    va="top",
    transform=ax.transAxes,
    fontsize=11,
)

fig.savefig("gridded.png", dpi="figure", bbox_inches="tight")

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

epa_regions-0.0.3.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

epa_regions-0.0.3-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file epa_regions-0.0.3.tar.gz.

File metadata

  • Download URL: epa_regions-0.0.3.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for epa_regions-0.0.3.tar.gz
Algorithm Hash digest
SHA256 97c98fab0cc19cfd85b30f07f2a85144fc9d716bbee6146cf1c5d6264f089d25
MD5 cfaa60fa6efd5e6cb5db6a42bbe4cbcb
BLAKE2b-256 9b1a453c5d4731ff67230b7f3418220367e76275fc8c2f240c0ef32905978aa4

See more details on using hashes here.

File details

Details for the file epa_regions-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for epa_regions-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 21b73e4b64c754504e36732c16cc399bb65af8484b8ce3100cf6f7650c6ba8cf
MD5 c8b7685b6c6a80408cc49b7de4e2a195
BLAKE2b-256 db4a6e6c78c8543956b843a78d3efd32cd065ee39ddfcd67778c1bd732dcdf73

See more details on using hashes here.

Supported by

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