Skip to content

Add interpolator backends and MIR interface #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 6, 2025
Merged

Conversation

sandorkertesz
Copy link
Collaborator

@sandorkertesz sandorkertesz commented Feb 3, 2025

This PR adds the following changes:

Backends

A Backend is an object implementing the interpolate() method. There are built-in backends:

"local-matrix": use a local matrix inventory from a user defined path. One object will be created per path. Paths can be added via the local-matrix-directories config option (set to None by default).
"remote-matrix": use a remote matrix inventory from a user defined url. One object will be created per url. Urls can be added via the remote-matrix-directories config option (set to None by default).
"system-matrix": the official remote matrix inventory with a hardcoded path
"mir": a MIR based interpolation. NOTE: this is not yet working!!!

Plugins

A backend can be implemented as a plugin.

Lazy object creation

An actual backend object is created lazily on first call of interpolate() on it.

Backend order config

When calling earthkit.regrid.interpolate() it tries all the available backends in a user specified order until one is able to perform the interpolation. The order is defined by the backends config option. By default it is set to None meaning that the following hardcoded default order is used:

DEFAULT_ORDER = ["local-matrix", "plugins", "remote-matrix", "system-matrix", "mir"]

E.g.

backends=None
backends="system-matrix"
backends="mir"
backends="system-matrix,mir"
backends=["system-matrix" ,"mir"]

Explicit backend order

The backend order can be directly passed to interpolate(). In this case the backends config option is ignored. E.g.

interpolate(vals, gs_in, gs_out, backends="system-matrix")
interpolate(vals, gs_in, gs_out, backends="mir")
interpolate(vals, gs_in, gs_out, backends="system-matrix,mir")
interpolate(vals, gs_in, gs_out, backends=["system-matrix", "mir"])

Breaking changes

The matrix_source keyword was removed from interpolate().

@codecov-commenter
Copy link

codecov-commenter commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.35%. Comparing base (389301b) to head (f0f3597).
Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
tests/test_memcache.py 83.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           develop      #60       +/-   ##
============================================
+ Coverage    52.55%   94.35%   +41.79%     
============================================
  Files           10       12        +2     
  Lines          588      885      +297     
  Branches        16       32       +16     
============================================
+ Hits           309      835      +526     
+ Misses         276       39      -237     
- Partials         3       11        +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sandorkertesz sandorkertesz changed the title Add interpolators and MIR interface. Add interpolators and MIR interface Feb 3, 2025

def interpolate(self, values, in_grid, out_grid, method, **kwargs):
try:
import mir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this mir-python? Or is this "from . import mir"?

@@ -1,7 +1,7 @@
Interpolation
==============

.. py:function:: interpolate(values, in_grid=None, out_grid=None, matrix_source=None, method='linear')
.. py:function:: interpolate(values, in_grid=None, out_grid=None, matrix_source=None, method='linear', backend=None, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "backend" is now "interpolator"

:param matrix_source: (experimental) the location of a user specified pre-generated matrix inventory. When it is None the default matrix inventory hosted on an ECMWF download server is used.
:type matrix_source: str, None
:backend: the backend to use for the interpolation. When it is None, the backends specified by the ``backend-order`` :ref:`config <configs>` option tried in the given order.
:type backend: str, list of str, None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "backend" is now "interpolator"

@pmaciel
Copy link
Member

pmaciel commented Feb 3, 2025

I believe you've generalised the "method" into an "interpolator" which can be local or remote and so on, and interprets arbitrary arguments instead of specifically passing down directly options to mir. That's perfect! (Although, I cannot follow all of it)

In any case I think somewhere you have "import mir" which is a little confusing as theres a "mir.py" in the same directory, I think that should import the mir-python module in, but here it does a "local" mir.py import? Just a clarification

@sandorkertesz
Copy link
Collaborator Author

@pmaciel, thank you for the comments.

  • Documentation has not been updated/written. Will be done when the "interpolator" concept is accepted
  • The MirInterpolator will call MIR python whenever it will be available. The code and import there is just a placeholder and will be adjusted when the concrete MIR python method to call will be available.

@sandorkertesz
Copy link
Collaborator Author

method remained the same (e.g. "linear" etc.). Interpolator is something that executes the interpolation with the given options.

@pmaciel
Copy link
Member

pmaciel commented Feb 3, 2025

Ok thanks! So in my case that I'm using mir-python in my own branch, I should for the moment stay away from this one right? :-) (it's work on starting from gridspec)

@sandorkertesz
Copy link
Collaborator Author

Ok thanks! So in my case that I'm using mir-python in my own branch, I should for the moment stay away from this one right? :-) (it's work on starting from gridspec)

Yes! I have just changed the code in mir.py to better reflect what it should do in the future.

@sandorkertesz sandorkertesz changed the title Add interpolators and MIR interface Add interpolator backends and MIR interface Feb 6, 2025
@sandorkertesz sandorkertesz merged commit 00a09fb into develop Feb 6, 2025
108 checks passed
@sandorkertesz sandorkertesz deleted the feature/mir branch February 6, 2025 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants