pytroll / pytroll/pyresample

New Resampler interface design and discussion

Open
#381 1 comment 0 reactions 4 assignees View on GitHub

@pnuu is already working on this.

Since Sep 28, 2021.

enhancement
Dominant language
Python
Stars
385
Forks
102
Avg merge
4d 2h
Merged PRs (30d)
9

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.