@@ -55,36 +55,37 @@ def __init__(self, src_grid_cube, target_grid_cube, mdtol=1):
5555
5656 .. Note::
5757
58- Both sourge and target cubes must have an XY grid defined by
58+ Both source and target cubes must have an XY grid defined by
5959 separate X and Y dimensions with dimension coordinates.
6060 All of the XY dimension coordinates must also be bounded, and have
6161 the same cooordinate system.
6262
6363 """
64- # Snapshot the state of the cubes to ensure that the regridder is
65- # impervious to external changes to the original source cubes.
64+ # Snapshot the state of the source cube to ensure that the regridder is
65+ # impervious to external changes to the original cubes.
6666 self ._src_grid = snapshot_grid (src_grid_cube )
67- self . _target_grid = snapshot_grid ( target_grid_cube )
67+
6868 # Missing data tolerance.
6969 if not (0 <= mdtol <= 1 ):
7070 msg = 'Value for mdtol must be in range 0 - 1, got {}.'
7171 raise ValueError (msg .format (mdtol ))
7272 self ._mdtol = mdtol
7373
74- # The need for an actual Cube is an implementation quirk caused by the
75- # current usage of the experimental regrid function.
76- self ._target_grid_cube_cache = None
77-
78- @property
79- def _target_grid_cube (self ):
80- if self ._target_grid_cube_cache is None :
81- x , y = self ._target_grid
82- data = np .empty ((y .points .size , x .points .size ))
83- cube = iris .cube .Cube (data )
84- cube .add_dim_coord (y , 0 )
85- cube .add_dim_coord (x , 1 )
86- self ._target_grid_cube_cache = cube
87- return self ._target_grid_cube_cache
74+ # Store regridding information
75+ _regrid_info = eregrid ._regrid_area_weighted_rectilinear_src_and_grid__prepare (
76+ src_grid_cube , target_grid_cube
77+ )
78+ (
79+ src_x ,
80+ src_y ,
81+ src_x_dim ,
82+ src_y_dim ,
83+ self .grid_x ,
84+ self .grid_y ,
85+ self .meshgrid_x ,
86+ self .meshgrid_y ,
87+ self .weights_info ,
88+ ) = _regrid_info
8889
8990 def __call__ (self , cube ):
9091 """
@@ -106,8 +107,25 @@ def __call__(self, cube):
106107 area-weighted regridding.
107108
108109 """
109- if get_xy_dim_coords (cube ) != self ._src_grid :
110- raise ValueError ('The given cube is not defined on the same '
111- 'source grid as this regridder.' )
112- return eregrid .regrid_area_weighted_rectilinear_src_and_grid (
113- cube , self ._target_grid_cube , mdtol = self ._mdtol )
110+ src_x , src_y = get_xy_dim_coords (cube )
111+ if (src_x , src_y ) != self ._src_grid :
112+ raise ValueError (
113+ "The given cube is not defined on the same "
114+ "source grid as this regridder."
115+ )
116+ src_x_dim = cube .coord_dims (src_x )[0 ]
117+ src_y_dim = cube .coord_dims (src_y )[0 ]
118+ _regrid_info = (
119+ src_x ,
120+ src_y ,
121+ src_x_dim ,
122+ src_y_dim ,
123+ self .grid_x ,
124+ self .grid_y ,
125+ self .meshgrid_x ,
126+ self .meshgrid_y ,
127+ self .weights_info ,
128+ )
129+ return eregrid ._regrid_area_weighted_rectilinear_src_and_grid__perform (
130+ cube , _regrid_info , mdtol = self ._mdtol
131+ )
0 commit comments