Skip to content

Commit

Permalink
Fix ra2ll() function memory consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeyPechnikov committed Aug 10, 2023
1 parent 03d6a23 commit 3268d94
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pygmtsar/pygmtsar/SBAS_geocode.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def ra2ll(self, grid, trans=None, chunksize=None):
trans = self.get_trans_dat()

@dask.delayed
def intf_block(lats_block, lons_block, grid_ra):
def intf_block(lats_block, lons_block):
from scipy.interpolate import RegularGridInterpolator

trans_block = trans.sel(lat=lats_block, lon=lons_block)
Expand All @@ -242,9 +242,12 @@ def intf_block(lats_block, lons_block, grid_ra):
points = np.column_stack([y, x])

# get interferogram full grid
ys = grid_ra.y.values
xs = grid_ra.x.values
ys = block_grid.y.values
xs = block_grid.x.values

# this code spends additional time for the checks to exclude warnings
if np.all(np.isnan(y)):
return np.nan * np.zeros((lats_block.size, lons_block.size), dtype=np.float32)
# calculate trans grid subset extent
ymin, ymax = np.nanmin(y), np.nanmax(y)
xmin, xmax = np.nanmin(x), np.nanmax(x)
Expand All @@ -260,7 +263,7 @@ def intf_block(lats_block, lons_block, grid_ra):
if ys.size == 0 or xs.size == 0:
return np.nan * np.zeros((lats_block.size, lons_block.size), dtype=np.float32)

values = grid_ra.sel(y=ys, x=xs).values.astype(np.float64)
values = block_grid.sel(y=ys, x=xs).values.astype(np.float64)

# perform interpolation
interp = RegularGridInterpolator((ys, xs), values, method='nearest', bounds_error=False)
Expand Down Expand Up @@ -312,7 +315,7 @@ def intf_block(lats_block, lons_block, grid_ra):
for lats_block in lats_blocks:
blocks = []
for lons_block in lons_blocks:
block = dask.array.from_delayed(intf_block(lats_block, lons_block, block_grid),
block = dask.array.from_delayed(intf_block(lats_block, lons_block),
shape=(lats_block.size, lons_block.size), dtype=np.float32)
blocks.append(block)
del block
Expand Down Expand Up @@ -340,7 +343,7 @@ def intf_block(lats_block, lons_block, grid_ra):
if k not in ['y','x']:
out[k] = v
return out.rename(grid.name)

##########################################################################################
# ll2ra
##########################################################################################
Expand Down

0 comments on commit 3268d94

Please sign in to comment.