pyresample

raw JSON →
1.35.0 verified Fri May 01 auth: no python

Pyresample is a Python library for geospatial image resampling, supporting both area-to-area and swath-to-area resampling. It is part of the PyTroll ecosystem. Current version is 1.35.0, with regular releases approximately every 2-3 months.

pip install pyresample
error AttributeError: module 'pyresample' has no attribute 'resample_nearest'
cause Attempting to import resampling functions from the top-level pyresample module instead of the correct submodule.
fix
Use: from pyresample.kd_tree import resample_nearest
error KeyError: 'area_id'
cause Missing required keyword when creating AreaDefinition; area_id is mandatory.
fix
Include area_id='my_area' in AreaDefinition constructor.
error ValueError: radius_of_influence must be defined for kd_tree based resampling
cause In pyresample >=1.20.0, radius_of_influence is not set by default and must be provided.
fix
Add radius_of_influence=50000 (or appropriate value) to the call.
error TypeError: 'NoneType' object is not callable
cause Using deprecated import path for area functions (e.g., from pyresample.area_config import load_area) after internal refactoring.
fix
Use: from pyresample.area_config import load_area (still works in 1.35) but prefer: from pyresample import parse_area_file
breaking In pyresample v1.20.0, the function `resample_nearest` and others changed their `radius_of_influence` default from 5000 to None. You must specify it explicitly to avoid errors.
fix Always provide `radius_of_influence` in meters.
deprecated The module `pyresample.area_config` is partially deprecated. Direct usage of `load_area` and `get_area_def` from `pyresample.area_config` is being replaced by `pyresample.parse_area_file` and similar functions in `pyresample.geometry`.
fix Use `from pyresample import parse_area_file` instead of `load_area`.
gotcha SwathDefinition's `lons` and `lats` must be 2D arrays (even for single scan lines). Using 1D arrays will cause cryptic errors.
fix Ensure lon/lat arrays have shape (n_scans, n_pixels) for swath data.
gotcha AreaDefinition's `area_extent` expects (xmin, ymin, xmax, ymax) in the projection's coordinate system, not geographic lon/lat. Common mistake: passing lon/lat directly.
fix Transform your geographic extent to the projection coordinates using pyproj before defining AreaDefinition.

Basic swath-to-area resampling with nearest neighbor method.

import numpy as np
from pyresample import AreaDefinition, SwathDefinition
from pyresample.kd_tree import resample_nearest

# Define source swath (e.g., satellite granule)
lon = np.array([[-10, -9], [-10, -9]])
lat = np.array([[40, 40], [41, 41]])
swath_def = SwathDefinition(lons=lon, lats=lat)

# Define target area (regular grid)
area_def = AreaDefinition(
    area_id='test',
    description='Test area',
    proj_id='test',
    projection='+proj=eqc +lon_0=0 +lat_0=0',
    width=100,
    height=100,
    area_extent=[-20, 30, 10, 50]
)

# Source data (same shape as swath)
data = np.random.rand(2, 2)

# Resample using nearest neighbor
result = resample_nearest(swath_def, data, area_def, radius_of_influence=50000)
print(result.shape)  # (100, 100)