File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ import numpy as np
2+ import xarray as xr
3+
4+ from xarray_regrid .utils import format_lat
5+
6+
7+ def test_format_lat ():
8+ lat_vals = np .arange (- 89.5 , 89.5 + 1 , 1 )
9+ lon_vals = np .arange (- 179.5 , 179.5 + 1 , 1 )
10+ x_vals = np .broadcast_to (lat_vals , (len (lon_vals ), len (lat_vals )))
11+ ds = xr .Dataset (
12+ data_vars = {"x" : (("lon" , "lat" ), x_vals )},
13+ coords = {"lat" : lat_vals , "lon" : lon_vals },
14+ attrs = {"foo" : "bar" },
15+ )
16+ ds .lat .attrs ["is" ] = "coord"
17+ ds .x .attrs ["is" ] = "data"
18+
19+ formatted = format_lat (ds , ds , {"lat" : "lat" , "lon" : "lon" })
20+ # Check that lat has been extended to include poles
21+ assert formatted .lat .values [0 ] == - 90
22+ assert formatted .lat .values [- 1 ] == 90
23+ # Check that data has been extrapolated to include poles
24+ assert (formatted .x .isel (lat = 0 ) == - 89.5 ).all ()
25+ assert (formatted .x .isel (lat = - 1 ) == 89.5 ).all ()
26+ # Check that attrs have been preserved
27+ assert formatted .attrs ["foo" ] == "bar"
28+ assert formatted .lat .attrs ["is" ] == "coord"
29+ assert formatted .x .attrs ["is" ] == "data"
You can’t perform that action at this time.
0 commit comments