Skip to content

Commit 3504049

Browse files
authored
Disc (#54)
* remove max_discontinuity between vdatum and fes (coastline mask does this now) * better vdatum/fes blending; blend inland from final instead of vdatum only
1 parent 2984734 commit 3504049

2 files changed

Lines changed: 7 additions & 18 deletions

File tree

src/transformez/grid_engine.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ def smart_blend(in_grid, background_grid, blend_pixels=50):
190190
dist = ndimage.distance_transform_edt(mask)
191191
alpha = np.clip(dist / blend_pixels, 0.0, 1.0)
192192

193+
# --- Hermite Interpolation ---
194+
# This converts the linear gradient into a smooth S-curve
195+
alpha = alpha * alpha * (3.0 - 2.0 * alpha)
196+
193197
nearest_indices = ndimage.distance_transform_edt(
194198
mask, return_distances=False, return_indices=True
195199
)
@@ -210,26 +214,13 @@ def coastal_aware_composite(
210214
shapefiles=None,
211215
decay_pixels=100,
212216
buffer_pixels=10,
213-
max_discontinuity=0.5,
217+
blend_pixels=50,
214218
):
215219
"""Handles inland decay vs. offshore blending, while
216220
filtering out low-resolution global artifacts.
217221
"""
218222

219223
final_grid = vdatum_grid.copy()
220-
vdatum_mask = np.isnan(vdatum_grid)
221-
if not vdatum_mask.all():
222-
nearest_idx = ndimage.distance_transform_edt(
223-
vdatum_mask, return_distances=False, return_indices=True
224-
)
225-
nearest_vdatum_vals = vdatum_grid[tuple(nearest_idx)]
226-
227-
fes_anomaly_mask = (
228-
np.abs(global_grid - nearest_vdatum_vals) > max_discontinuity
229-
)
230-
231-
global_grid[fes_anomaly_mask] = np.nan
232-
233224
land_mask = None
234225
if shapefiles:
235226
land_mask = GridEngine.create_land_mask(region, nx, ny, shapefiles)
@@ -244,14 +235,13 @@ def coastal_aware_composite(
244235

245236
if is_offshore.any():
246237
blended_ocean = GridEngine.smart_blend(
247-
vdatum_grid, global_grid, blend_pixels=50
238+
vdatum_grid, global_grid, blend_pixels=blend_pixels
248239
)
249240
final_grid[is_offshore] = blended_ocean[is_offshore]
250241

251242
if is_inland.any():
252-
source_for_decay = vdatum_grid if is_vdatum.any() else final_grid
253243
decayed_inland = GridEngine.fill_nans(
254-
source_for_decay,
244+
final_grid,
255245
decay_pixels=decay_pixels,
256246
buffer_pixels=buffer_pixels,
257247
land_mask=land_mask,

src/transformez/transform.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ def _get_vdatum_chain(self, datum_name, geoid_name):
563563
shapefiles=coast_shapefiles,
564564
decay_pixels=self.decay_pixels,
565565
buffer_pixels=10,
566-
max_discontinuity=5,
567566
)
568567
desc.append(f"Blended w/ Global({proxy_name.upper()})")
569568
else:

0 commit comments

Comments
 (0)