Skip to content
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

regridding regular grids with similar coordinates #1567

Merged
merged 5 commits into from
Jun 3, 2022

Conversation

tomaslovato
Copy link
Contributor

@tomaslovato tomaslovato commented Apr 21, 2022

Description

Regridding regular grid needs to produce an exact matching of the source lat/lon coordinates with those of the target cube.

Closes #1551

Checklist

It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.


@tomaslovato tomaslovato requested a review from zklaus April 21, 2022 16:35
@tomaslovato tomaslovato self-assigned this Apr 21, 2022
@tomaslovato tomaslovato added the bug Something isn't working label Apr 21, 2022
@tomaslovato tomaslovato added this to the v2.6.0 milestone Apr 21, 2022
@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #1567 (a233fdd) into main (be6f654) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1567   +/-   ##
=======================================
  Coverage   90.99%   91.00%           
=======================================
  Files         201      201           
  Lines       10676    10679    +3     
=======================================
+ Hits         9715     9718    +3     
  Misses        961      961           
Impacted Files Coverage Δ
esmvalcore/preprocessor/_regrid.py 97.18% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update be6f654...a233fdd. Read the comment docs.

@zklaus
Copy link

zklaus commented Apr 22, 2022

Thanks, @tomaslovato. Perhaps we should add a test for this functionality?

@tomaslovato
Copy link
Contributor Author

@zklaus maybe something like this could do the job ...

diff --git a/tests/integration/preprocessor/_regrid/test_regrid.py b/tests/integration/preprocessor/_regrid/test_regrid.py
index 7a6b87e1a..a156bfb6f 100644
--- a/tests/integration/preprocessor/_regrid/test_regrid.py
+++ b/tests/integration/preprocessor/_regrid/test_regrid.py
@@ -92,6 +92,24 @@ class Test(tests.Test):
         expected = np.array([[[1.5]], [[5.5]], [[9.5]]])
         self.assert_array_equal(result.data, expected)

+    def test_regrid__regular_coordinates(self):
+        data = np.ones((1, 1))
+        lons = iris.coords.DimCoord([1.50000000000001],
+                                    standard_name='longitude',
+                                    bounds=[[1, 2]],
+                                    units='degrees_east',
+                                    coord_system=self.cs)
+        lats = iris.coords.DimCoord([1.50000000000001],
+                                    standard_name='latitude',
+                                    bounds=[[1, 2]],
+                                    units='degrees_north',
+                                    coord_system=self.cs)
+        coords_spec = [(lats, 0), (lons, 1)]
+        regular_grid = iris.cube.Cube(data, dim_coords_and_dims=coords_spec)
+        result = regrid(regular_grid, self.grid_for_linear, 'linear')
+        expected = np.array([[[1.5]], [[1.5]], [[1.]]])
+        self.assert_array_equal(result.data, expected)
+
     def test_regrid__linear_do_not_preserve_dtype(self):
         self.cube.data = self.cube.data.astype(int)
         result = regrid(self.cube, self.grid_for_linear, 'linear')

@tomaslovato
Copy link
Contributor Author

@zklaus I added the test for the regular grid coordinate ... let me know if it works for you!

Copy link
Contributor

@sloosvel sloosvel left a comment

Choose a reason for hiding this comment

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

I would say the changes are fine, but it would be good people from @ESMValGroup/esmvaltool-coreteam who have followed the issue closer double checked.

@sloosvel sloosvel merged commit ead491a into main Jun 3, 2022
@sloosvel sloosvel deleted the fix_regular_coord_regrid branch June 3, 2022 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regridding very similar grids may result in lat/lon coordinates that are not exactly identical
3 participants