Skip to content

Conversation

@b8raoult
Copy link
Collaborator

@b8raoult b8raoult commented Jun 23, 2025

Description

Create a mask with

 anemoi-transform \
      make-regrid-file global-on-lam-mask \
     --global-grid era5.grib \
     --lam-grid carra.grib \
     --output era-over-carra-mask.npz

Then use it in a dataset recipe

input:
    pipe:    
       mars:
           class: ea
           param: [z, t, u, v]
           levelist: [1000, 500]
      regrid:
           mask: /path/to/era-over-carra-mask.npz     

What problem does this change solve?

This is a feature that was requested to extract the grid points of. global grid (e.g. ERA5 on N320) over the area covered by a LAM (e.g the CARRA domain)

image001 1

What issue or task does this change relate to?

Additional notes

As a contributor to the Anemoi framework, please ensure that your changes include unit tests, updates to any affected dependencies and documentation, and have been tested in a parallel setting (i.e., with multiple GPUs). As a reviewer, you are also responsible for verifying these aspects and requesting changes if they are not adequately addressed. For guidelines about those please refer to https://anemoi.readthedocs.io/en/latest/


📚 Documentation preview 📚: https://anemoi-transform--108.org.readthedocs.build/en/108/

b8raoult and others added 30 commits May 12, 2025 12:53
@yoel-zerah
Copy link

in tests/test_regrid.py, in test_make_regrid_mask the size of the mask produced by global-on-lam-mask is check against a reference provided in "anemoi-transform/filters/regrid/ea-over-rr-mask.npz".
Unfortunately, this reference mask has the wrong shape: the mask tested is generated by cropping ERA5 to CERRA (under 38k grid points), but the reference mask contains all of the original 542k ERA5 grid points.

  • How can we change the provided mask with another file ?
  • How do we generate a new reference file ? At the moment the only way I can generate a mask is with this feature being tested...

@yoel-zerah
Copy link

yoel-zerah commented Nov 14, 2025

Loading a grid with src/anemoi/transform/filters/regrid.py:84: in as_griddata fails - when tests/test_regrid.py::test_regrid_ekd is run for instance:

def test_regrid_ekd(test_source):
    era5 = test_source("anemoi-transform/filters/regrid/2t-ea.grib")
>   regrid = filter_registry.create("regrid", in_grid="N320", out_grid=[0.25, 0.25])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.12/site-packages/anemoi/utils/registry.py:334: in create
    return factory(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
src/anemoi/transform/filters/regrid.py:122: in __init__
    self.interpolator = make_interpolator(
src/anemoi/transform/filters/regrid.py:448: in make_interpolator
    return globals()[interpolator](**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/anemoi/transform/filters/regrid.py:164: in __init__
    self.out_griddata = as_griddata(out_grid)
                        ^^^^^^^^^^^^^^^^^^^^^
src/anemoi/transform/filters/regrid.py:84: in as_griddata
    return lookup(grid)
           ^^^^^^^^^^^^
src/anemoi/transform/grids/named.py:114: in lookup
    npz = np.load(BytesIO(data))
          ^^^^^^^^^^^^^^^^^^^^^^
  
ValueError: This file contains pickled (object) data

The problem is that the anemoi.transform.grids.named.lookup function (or the equivalent deprecated anemoi.utils.grids.grids) called in anemoi.transform.filters.regrid fail at loading an npz file at e.g. url="https://sites.ecmwf.int/repository/anemoi/grids/grid-0p25.npz":

response = requests.get(url)
data = response.content
npz = np.load(BytesIO(data))

However, downloading manually the file and saving to path/to/grid-0p25.npz, and then loading with np.load("path/to/grid-0p25.npz") works.

Does anyone know how to fix this issue ?
**EDIT: This issue only occurs for some specific files, i.e. grid-0p25.npz, whereas it runs correctly for others grid-o96.npz **

@yoel-zerah
Copy link

I have finished reviewing all your comments, and I would like to request some help to finish closing this PR.
I am able to solve the merge conflicts by myself, but I don't have an answer for the currently unresolved conversations, could someone have a look ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ATS approved documentation Improvements or additions to documentation enhancement New feature or request tests

Projects

Status: Under Review

Development

Successfully merging this pull request may close these issues.

8 participants