@@ -70,7 +70,7 @@ def resize3DField(var, data, coordsAndSizesTuple, method, mute):
70
70
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.RegularGridInterpolator.html
71
71
# for details)
72
72
gridInterpolator = RegularGridInterpolator (
73
- (xCoordOld , yCoordOld , zCoordOld ), data , method
73
+ (xCoordOld , yCoordOld , zCoordOld ), data , method , bounds_error = False , fill_value = None
74
74
)
75
75
76
76
# Need to fill with one exrta z plane (will only contain zeros)
@@ -184,19 +184,28 @@ def is_pow2(x):
184
184
break
185
185
186
186
nx , ny , nz = data .shape
187
+ dx , dy , dz = old ['dx' ].flat [0 ], old ['dy' ].flat [0 ], old ['dz' ].flat [0 ]
188
+ # shift grid if CELL-CENTRED
189
+ xshift = 0.0 if old .attributes (var )['cell_location' ] == 'CELL_XLOW' else 0.5
190
+ yshift = 0.0 if old .attributes (var )['cell_location' ] == 'CELL_YLOW' else 0.5
191
+ zshift = 0.0 if old .attributes (var )['cell_location' ] == 'CELL_ZLOW' else 0.5
192
+
187
193
# Make coordinates
188
194
# NOTE: The max min of the coordinates are irrelevant when
189
195
# interpolating (as long as old and new coordinates
190
196
# are consistent), so we just choose all variable to
191
- # be between 0 and 1 Calculate the old coordinates
192
- xCoordOld = np .linspace (0 , 1 , nx )
193
- yCoordOld = np .linspace (0 , 1 , ny )
194
- zCoordOld = np .linspace (0 , 1 , nz )
195
-
197
+ # be between 0 and 1 Calculate the old coordinates
198
+ xCoordOld = (np .arange (nx ) - mxg + xshift )* dx
199
+ yCoordOld = (np .arange (ny ) - myg + yshift )* dy
200
+ zCoordOld = (np .arange (nz ) + zshift )* dz
201
+ # Calculate the new spacing
202
+ newDx = dx * ((nx - 2 * mxg ) / (newNx - 2 * mxg ) )
203
+ newDy = dy * ((ny - 2 * myg ) / (newNy - 2 * myg ) )
204
+ newDz = dz * (nz / newNz )
196
205
# Calculate the new coordinates
197
- xCoordNew = np .linspace ( xCoordOld [ 0 ], xCoordOld [ - 1 ], newNx )
198
- yCoordNew = np .linspace ( yCoordOld [ 0 ], yCoordOld [ - 1 ], newNy )
199
- zCoordNew = np .linspace ( zCoordOld [ 0 ], zCoordOld [ - 1 ], newNz )
206
+ xCoordNew = ( np .arange ( newNx ) - mxg + xshift ) * newDx
207
+ yCoordNew = ( np .arange ( newNy ) - myg + yshift ) * newDy
208
+ zCoordNew = ( np .arange ( newNz ) + zshift ) * newDz
200
209
201
210
# Make a pool of workers
202
211
pool = multiprocessing .Pool (maxProc )
@@ -240,7 +249,7 @@ def is_pow2(x):
240
249
else :
241
250
if not (mute ):
242
251
print (" Copying " + var )
243
- newData = data .copy ()
252
+ newData = data .copy ()
244
253
if not (mute ):
245
254
print ("Writing " + var )
246
255
new .write (var , newData )
0 commit comments