@@ -253,8 +253,7 @@ def coastal_aware_composite(
253253 @staticmethod
254254 def fill_nans (data , decay_pixels = 0 , buffer_pixels = 10 , land_mask = None ):
255255 """Fills NaNs by extrapolating nearest valid coastal values.
256- If decay_pixels > 0, it will smoothly ramp the values to 0.0 inland.
257- If decay_pixels == 0, it extrapolates the coastal values infinitely inland.
256+ Melted Voronoi ridges ensure C1 continuity deep inland.
258257 """
259258
260259 mask = np .isnan (data )
@@ -264,20 +263,32 @@ def fill_nans(data, decay_pixels=0, buffer_pixels=10, land_mask=None):
264263 dist , indices = ndimage .distance_transform_edt (
265264 mask , return_distances = True , return_indices = True
266265 )
267- coast_values = data [tuple (indices )]
266+
267+ raw_extrapolation = data [tuple (indices )]
268+ # Blur the "Voronoi Ridges" deep inland
269+ blurred_extrapolation = ndimage .gaussian_filter (raw_extrapolation , sigma = 25 )
270+ # Crossfade! Beach = Raw Data, Inland = Blurred Data
271+ blur_blend = np .clip (dist / 50.0 , 0 , 1 )
272+ coast_values = (raw_extrapolation * (1.0 - blur_blend )) + (
273+ blurred_extrapolation * blur_blend
274+ )
275+
268276 out_data = data .copy ()
269277
270278 if decay_pixels and decay_pixels > 0 :
271279 # --- Inland Decay ---
272280 effective_dist = np .clip (dist - buffer_pixels , 0 , None )
273- decay_factor = np .clip ((decay_pixels - effective_dist ) / decay_pixels , 0 , 1 )
281+
282+ # Calculate the linear decay (1.0 down to 0.0)
283+ linear_decay = np .clip ((decay_pixels - effective_dist ) / decay_pixels , 0 , 1 )
284+
285+ # Apply Smoothstep (Hermite) easing to create the S-curve!
286+ decay_factor = linear_decay * linear_decay * (3.0 - 2.0 * linear_decay )
287+
274288 out_data [mask ] = coast_values [mask ] * decay_factor [mask ]
275289
276- if land_mask is not None :
277- # Force areas deep inland (and covered by the land mask) to exactly 0.0
278- out_data [mask & ~ land_mask ] = 0.0
279290 else :
280- # --- Infinite Nearest-Neighbor Extrapolation (Default) ---
291+ # --- Infinite Extrapolation (Default) ---
281292 out_data [mask ] = coast_values [mask ]
282293
283294 return out_data
0 commit comments