Skip to content

Automatically initialize regridders with loaded weights in the Regridder class#2700

Open
mnurisso wants to merge 2 commits intomainfrom
regridder-alone-fix
Open

Automatically initialize regridders with loaded weights in the Regridder class#2700
mnurisso wants to merge 2 commits intomainfrom
regridder-alone-fix

Conversation

@mnurisso
Copy link
Collaborator

@mnurisso mnurisso commented Feb 18, 2026

PR description:

I tested a Regridder alone workflow such as:

regridder = Regridder(cfg_regrid, data=data, loglevel=args.loglevel, src_grid_name=src_grid_name)
regridder.weights(tgt_grid_name=resolution, regrid_method="con", reader_kwargs=reader_kwargs)
data_r = regridder.regrid(data)

In the current implementation it gives error:

2026-02-18 16:23:22 :: Regridder :: ERROR    -> Regridder for vertical coordinate 2d not found.
2026-02-18 16:23:22 :: Regridder :: ERROR    -> Cannot regrid variable tprate

This because the self.initialize method is not used. I can add it manually in my code but this is exactly the example from the documentation so I think a fix should be inserted in the code and this is what I am proposing

People involved:

@oloapinivad

  • Changelog is updated.

@mnurisso mnurisso self-assigned this Feb 18, 2026
@mnurisso mnurisso added the run tests Set this up to let test run label Feb 18, 2026
@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.01%. Comparing base (8a08c15) to head (a98dfb6).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2700   +/-   ##
=======================================
  Coverage   74.01%   74.01%           
=======================================
  Files          80       80           
  Lines        7680     7681    +1     
  Branches     1494     1494           
=======================================
+ Hits         5684     5685    +1     
  Misses       1486     1486           
  Partials      510      510           
Flag Coverage Δ
unittests 74.01% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@mnurisso
Copy link
Collaborator Author

Hi @jhardenberg could you check if you find any problem in this additional step?
I had problem running a script in which the Regridder class alone had to generate weights and immediately use them because they were not initialized. I think in the Reader the initialization is handled somewhere else so I'm not sure if I'm adding an overhead.

@mnurisso mnurisso added the fix This is a minor fix of existing functionality label Feb 26, 2026
@jhardenberg
Copy link
Collaborator

jhardenberg commented Feb 27, 2026

The reason why the initialization of the regridders was delayed in the initialize() method is to allow the application of the datamodel and of the fixers on the weights, see lines 322-326 of the reader. So in the reader the weights generation is called, the weights are fixed and only then the initialization of the regridders occurs.
As you notice, this breaks the usage of the Regridder class alone.

The example should be fixed anyway, because regridder.weights() norw actually returns the weights.

We could either just change the docs saying that one needs to call initialize after computing the weights (but I admit that for a user this looks complicated) or introduce a 'double' behaviour of the weights() method by adding a initialize key as an argument which will be True by default and which will be used with False by the reader instead.
This way we could preserve the behaviour described in the docs and at the meantime leave the reader the opportunity to apply the fixer/datamodel .....

@mnurisso
Copy link
Collaborator Author

The reason why the initialization of theregridders was delayed in the initialize() method is to allow the application of the datamodel and of the fixers on the weights, see lines 322-326 of the reader. So in the reader the weights generation is called, the weights are fixed and only then the initialization of the regridders occurs. As you notice, this breaks the usage of the Regridder class alone.

The example should be fixed anyway, because regridder.weights() norw actually returns the weights.

We could either just change the docs saying that one needs to call initialize after computing the weights (but I admit that for a user this looks complicated) or introduce a 'double' behaviour of the weights() method by adding a initialize key as an argument which will be True by default and which will be used with False by the reader instead. This way we could preserve the behaviour described in the docs and at the meantime leave the reader the opportunity to apply the fixer/datamodel .....

Maybe this can be discussed on monday if there is extra time, I have no problem in calling explicitly the initialize method but indeed I'm not a beginner user and the documentation was wrong about this specific case.

@mnurisso
Copy link
Collaborator Author

mnurisso commented Mar 2, 2026

Add initialize=True by default for Regridder call alone and initialize=False to be added in the Reader to shut down the automatic call of the initialize method

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

Labels

fix This is a minor fix of existing functionality run tests Set this up to let test run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants