Skip to content

Nearest / KDTree resampling fails if numcodecs>=0.16 #3340

@needham-michael

Description

@needham-michael

Describe the bug
Calling scene.resample(...) fails with KeyError: "Resampler 'kd_tree' not available" when user's numcodecs>=0.16, which seems to be related to zarr-developers/numcodecs#721. The example below resamples as expected when run with numcodecs=0.15.1 but fails when run with numcodecs=0.16.5.

I dug into this a bit and it appears that the problem stems from _get_resampler_classes_from_module within satpy.resample.base..py. It seems that the with suppress(ImportError) statement within _get_resampler_classes_from_module suppresses the ImportError which would have been raised from import zarr within satpy.resample.kdtree.py. In that case _get_resampler_classes_from_module returns no resampler classes from satpy.resample.kdtree.py, which then gives the user the error listed above.

To Reproduce

# Script downloads a VIIRS L2 cloud mask granule from NASA earthacces 
# as an example to demonstrate the resample error behavior. But can likely 
# reproduce with a different file supplied to granule_files
import earthaccess
import numcodecs
from pyresample import create_area_def
from satpy.scene import Scene

earthaccess.login()

bounding_box = (-97.75, 35.75, -95.25, 39.75)
granule_files = None

if granule_files is None:
    
    local_path = ./'

    granule_search_results_cldmask = earthaccess.search_data(
        short_name="CLDMSK_L2_VIIRS_SNPP",
        bounding_box=bounding_box,
        temporal=('2025-04-06', '2025-04-06'),
        day_night_flag='day',
        instrument='VIIRS',
        platform='SUOMI-NPP'  
    )
    
    granule_files = earthaccess.download(
        granule_search_results_cldmask,
        local_path = local_path
    )

area_def = create_area_def(
    "area_name",
    {'proj': 'lcc', 'lon_0': -95, 'lat_0': 25, 'lat_1': 35},
    width=500,
    height=1000,
    area_extent=bounding_box,
    units='degrees'
)

print(f"{numcodecs.__version__ = }")

scene = Scene(granule_files,reader='viirs_l2')
scene.load(scene.available_dataset_names())
scene_resampled = scene.resample(area_def) # <- Fails here if numcodecs>=0.16
scene_resampled.load(scene.available_dataset_names())

  

Environment Info:

  • OS: Windows 11 Enterprise
  • Satpy Version: 0.59.0
  • PyResample Version: 1.35.0
Output from uv pip list:
Package                   Version     Editable project location
------------------------- ----------- --------------------------------------------------------------------------------------------------
affine                    2.4.0
aggdraw                   1.4.1
aiobotocore               3.1.3
aiohappyeyeballs          2.6.1
aiohttp                   3.13.3
aioitertools              0.13.0
aiosignal                 1.4.0
anyio                     4.12.1
argon2-cffi               25.1.0
argon2-cffi-bindings      25.1.0
arrow                     1.4.0
asciitree                 0.3.3
asttokens                 3.0.1
async-lru                 2.1.0
attrs                     25.4.0
babel                     2.18.0
beautifulsoup4            4.14.3
bleach                    6.3.0
bokeh                     3.8.2
botocore                  1.42.49
bottleneck                1.6.0
bounded-pool-executor     0.0.3
cartopy                   0.25.0
certifi                   2026.1.4
cffi                      2.0.0
cftime                    1.6.5
charset-normalizer        3.4.4
click                     8.3.1
cligj                     0.7.2
cloudpickle               3.1.2
colorama                  0.4.6
colorcet                  3.1.0
comm                      0.2.3
configobj                 5.0.9
contourpy                 1.3.3
cycler                    0.12.1
dask                      2026.1.2
debugpy                   1.8.20
decorator                 5.2.1
defusedxml                0.7.1
deprecated                1.3.1
donfig                    0.8.1.post1
earthaccess               0.16.0
executing                 2.2.1
fasteners                 0.20
fastjsonschema            2.21.2
fonttools                 4.61.1
fqdn                      1.5.1
frozenlist                1.8.0
fsspec                    2026.2.0
geopandas                 1.1.2
geotiff                   0.2.10
geoviews                  1.15.1
h11                       0.16.0
h5netcdf                  1.8.1
h5py                      3.15.1
holoviews                 1.22.1
httpcore                  1.0.9
httpx                     0.28.1
hvplot                    0.12.2
idna                      3.11
importlib-resources       6.5.2
ipykernel                 7.2.0
ipython                   9.10.0
ipython-pygments-lexers   1.1.1
ipywidgets                8.1.8
isoduration               20.11.0
jedi                      0.19.2
jinja2                    3.1.6
jmespath                  1.1.0
joblib                    1.5.3
json5                     0.13.0
jsonpointer               3.0.0
jsonschema                4.26.0
jsonschema-specifications 2025.9.1
jupyter-client            8.8.0
jupyter-core              5.9.1
jupyter-events            0.12.0
jupyter-lsp               2.3.0
jupyter-server            2.17.0
jupyter-server-terminals  0.5.4
jupyterlab                4.5.4
jupyterlab-pygments       0.3.0
jupyterlab-server         2.28.0
jupyterlab-widgets        3.0.16
kiwisolver                1.4.9
lark                      1.3.1
linkify-it-py             2.0.3
locket                    1.0.0
markdown                  3.10.2
markdown-it-py            4.0.0
markupsafe                3.0.3
matplotlib                3.10.8
matplotlib-inline         0.2.1
mdit-py-plugins           0.5.0
mdurl                     0.1.2
mistune                   3.2.0
multidict                 6.7.1
multimethod               2.0.2
narwhals                  2.16.0
nbclient                  0.10.4
nbconvert                 7.17.0
nbformat                  5.10.4
nest-asyncio              1.6.0
netcdf4                   1.7.4
notebook-shim             0.2.4
numcodecs                 0.16.5
numpy                     2.4.2
packaging                 26.0
pandas                    3.0.1
pandocfilters             1.5.1
panel                     1.8.7
param                     2.3.2
parso                     0.8.6
partd                     1.4.2
pathlib-abc               0.5.2
pillow                    12.1.1
platformdirs              4.9.2
pooch                     1.9.0
pqdm                      0.2.0
prometheus-client         0.24.1
prompt-toolkit            3.0.52
propcache                 0.4.1
psutil                    7.2.2
pure-eval                 0.2.3
pyarrow                   23.0.1
pycoast                   1.8.0
pycparser                 3.0
pydecorate                0.5.0
pygments                  2.19.2
pykdtree                  1.4.3
pyogrio                   0.12.1
pyorbital                 1.12.0
pyparsing                 3.3.2
pyproj                    3.7.2
pyresample                1.35.0
pyshp                     3.0.3
pyspectral                0.14.1
python-cmr                0.13.0
python-dateutil           2.9.0.post0
python-geotiepoints       1.9.0
python-json-logger        4.0.0
pyviz-comms               3.0.6
pywinpty                  3.0.3
pyyaml                    6.0.3
pyzmq                     27.1.0
rasterio                  1.5.0
referencing               0.37.0
requests                  2.32.5
rfc3339-validator         0.1.4
rfc3986-validator         0.1.1
rfc3987-syntax            1.1.0
rioxarray                 0.21.0
rpds-py                   0.30.0
ruff                      0.15.1
s3fs                      2026.2.0
satpy                     0.59.0
scikit-learn              1.8.0
scipy                     1.17.0
send2trash                2.1.0
setuptools                82.0.0
shapely                   2.1.2
six                       1.17.0
soupsieve                 2.8.3
stack-data                0.6.3
tenacity                  9.1.4
terminado                 0.18.1
threadpoolctl             3.6.0
tifffile                  2026.2.16
tinycss2                  1.4.0
tinynetrc                 1.3.1
toolz                     1.1.0
tornado                   6.5.4
tqdm                      4.67.3
traitlets                 5.14.3
trollimage                1.28.0
trollsift                 1.0.0
typing-extensions         4.15.0
tzdata                    2025.3
uc-micro-py               1.0.3
universal-pathlib         0.3.9
uri-template              1.3.0
urllib3                   2.6.3
wcwidth                   0.6.0
webcolors                 25.10.0
webencodings              0.5.1
websocket-client          1.9.0
widgetsnbextension        4.0.15
wrapt                     2.1.1
xarray                    2025.11.0
xyzservices               2025.11.0
yarl                      1.22.0
zarr                      2.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions