Skip to content

New Resampler interface design and discussion #381

@djhoese

Description

@djhoese

I'm beginning more serious work on Pyresample 2.0 in #379 and I'm running into some issues with the interface as I saw it after looking at the legacy nearest neighbor resampler and how it was used. Here's the general structure of a Resampler subclass:

class MyResampler(Resampler):

    def __init__(self, src_geom, dst_geom, cache=None):
        ...

    def precompute(self, **kwargs):
        ...

    def compute(self, data, **kwargs):
        return new_data

    def resample(self, data, **kwargs):
        self.precompute(**kwargs)
        return self.compute(data, **kwargs)

The idea is that users will use create_resampler like this:

resampler = create_resampler(src_geom, dst_geom, resampler="nearest", cache=some_cache)
resampler.precompute(...)  # optional to pre-seed any cache
new_data = resampler.resample(data, **kwargs)

The issues and questions I'm running into:

  1. Should custom keyword arguments go in __init__ or in the precompute? For example, the nearest neighbor resampler currently allows you to customize number of neighbors, radius of influence, and epsilon. Originally I liked the idea of all resamplers having the same __init__ interface. It was nice and clean and leaves the work up to 2 methods (precompute/compute). If settings like these are passed to precompute/compute and not __init__ then it lets a single resampler instance be used for all combinations of these parameters BUT it also means that the user has to specify these parameters to the methods every time they call them.
  2. What, if anything, should precompute return? Currently these classes are returning a cache_id that has to be passed to compute so it can get the proper item from the cache and use it. I think this ID can just be generated multiple times (assuming it is quick) and doesn't have to be returned. And if the cache id isn't returned, then should precompute return anything at all? No probably?

Thoughts? We might need a video call for this.

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions