@@ -41,36 +41,37 @@ def __init__(self, src_grid_cube, target_grid_cube, mdtol=1):
41
41
42
42
.. Note::
43
43
44
- Both sourge and target cubes must have an XY grid defined by
44
+ Both source and target cubes must have an XY grid defined by
45
45
separate X and Y dimensions with dimension coordinates.
46
46
All of the XY dimension coordinates must also be bounded, and have
47
47
the same cooordinate system.
48
48
49
49
"""
50
- # Snapshot the state of the cubes to ensure that the regridder is
51
- # impervious to external changes to the original source cubes.
50
+ # Snapshot the state of the source cube to ensure that the regridder is
51
+ # impervious to external changes to the original cubes.
52
52
self ._src_grid = snapshot_grid (src_grid_cube )
53
- self . _target_grid = snapshot_grid ( target_grid_cube )
53
+
54
54
# Missing data tolerance.
55
55
if not (0 <= mdtol <= 1 ):
56
56
msg = "Value for mdtol must be in range 0 - 1, got {}."
57
57
raise ValueError (msg .format (mdtol ))
58
58
self ._mdtol = mdtol
59
59
60
- # The need for an actual Cube is an implementation quirk caused by the
61
- # current usage of the experimental regrid function.
62
- self ._target_grid_cube_cache = None
63
-
64
- @property
65
- def _target_grid_cube (self ):
66
- if self ._target_grid_cube_cache is None :
67
- x , y = self ._target_grid
68
- data = np .empty ((y .points .size , x .points .size ))
69
- cube = iris .cube .Cube (data )
70
- cube .add_dim_coord (y , 0 )
71
- cube .add_dim_coord (x , 1 )
72
- self ._target_grid_cube_cache = cube
73
- return self ._target_grid_cube_cache
60
+ # Store regridding information
61
+ _regrid_info = eregrid ._regrid_area_weighted_rectilinear_src_and_grid__prepare (
62
+ src_grid_cube , target_grid_cube
63
+ )
64
+ (
65
+ src_x ,
66
+ src_y ,
67
+ src_x_dim ,
68
+ src_y_dim ,
69
+ self .grid_x ,
70
+ self .grid_y ,
71
+ self .meshgrid_x ,
72
+ self .meshgrid_y ,
73
+ self .weights_info ,
74
+ ) = _regrid_info
74
75
75
76
def __call__ (self , cube ):
76
77
"""
@@ -92,11 +93,25 @@ def __call__(self, cube):
92
93
area-weighted regridding.
93
94
94
95
"""
95
- if get_xy_dim_coords (cube ) != self ._src_grid :
96
+ src_x , src_y = get_xy_dim_coords (cube )
97
+ if (src_x , src_y ) != self ._src_grid :
96
98
raise ValueError (
97
99
"The given cube is not defined on the same "
98
100
"source grid as this regridder."
99
101
)
100
- return eregrid .regrid_area_weighted_rectilinear_src_and_grid (
101
- cube , self ._target_grid_cube , mdtol = self ._mdtol
102
+ src_x_dim = cube .coord_dims (src_x )[0 ]
103
+ src_y_dim = cube .coord_dims (src_y )[0 ]
104
+ _regrid_info = (
105
+ src_x ,
106
+ src_y ,
107
+ src_x_dim ,
108
+ src_y_dim ,
109
+ self .grid_x ,
110
+ self .grid_y ,
111
+ self .meshgrid_x ,
112
+ self .meshgrid_y ,
113
+ self .weights_info ,
114
+ )
115
+ return eregrid ._regrid_area_weighted_rectilinear_src_and_grid__perform (
116
+ cube , _regrid_info , mdtol = self ._mdtol
102
117
)
0 commit comments