Skip to content

Commit 1b98fd7

Browse files
authored
Add support for model cropping within tide modelling functions (#1249)
* Add support for model cropping within tide modelling functions * Replace accidental file
1 parent 1830161 commit 1b98fd7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Tools/dea_tools/coastal.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ def _model_tides(
238238
time,
239239
directory,
240240
crs,
241+
crop,
241242
method,
242243
extrapolate,
243244
cutoff,
@@ -278,6 +279,15 @@ def _model_tides(
278279
# Convert datetime
279280
timescale = pyTMD.time.timescale().from_datetime(time.flatten())
280281

282+
# Calculate bounds for cropping
283+
buffer = 1 # one degree on either side
284+
bounds = [
285+
lon.min() - buffer,
286+
lon.max() + buffer,
287+
lat.min() - buffer,
288+
lat.max() + buffer,
289+
]
290+
281291
# Read tidal constants and interpolate to grid points
282292
if pytmd_model.format in ("OTIS", "ATLAS", "TMD3"):
283293
amp, ph, D, c = pyTMD.io.OTIS.extract_constants(
@@ -287,6 +297,8 @@ def _model_tides(
287297
pytmd_model.model_file,
288298
pytmd_model.projection,
289299
type=pytmd_model.type,
300+
crop=crop,
301+
bounds=bounds,
290302
method=method,
291303
extrapolate=extrapolate,
292304
cutoff=cutoff,
@@ -303,6 +315,8 @@ def _model_tides(
303315
pytmd_model.grid_file,
304316
pytmd_model.model_file,
305317
type=pytmd_model.type,
318+
crop=crop,
319+
bounds=bounds,
306320
method=method,
307321
extrapolate=extrapolate,
308322
cutoff=cutoff,
@@ -318,6 +332,8 @@ def _model_tides(
318332
lon,
319333
lat,
320334
pytmd_model.model_file,
335+
crop=crop,
336+
bounds=bounds,
321337
method=method,
322338
extrapolate=extrapolate,
323339
cutoff=cutoff,
@@ -335,6 +351,8 @@ def _model_tides(
335351
pytmd_model.model_file,
336352
type=pytmd_model.type,
337353
version=pytmd_model.version,
354+
crop=crop,
355+
bounds=bounds,
338356
method=method,
339357
extrapolate=extrapolate,
340358
cutoff=cutoff,
@@ -584,6 +602,7 @@ def model_tides(
584602
model="FES2014",
585603
directory=None,
586604
crs="EPSG:4326",
605+
crop=True,
587606
method="spline",
588607
extrapolate=True,
589608
cutoff=None,
@@ -674,6 +693,10 @@ def model_tides(
674693
crs : str, optional
675694
Input coordinate reference system for x and y coordinates.
676695
Defaults to "EPSG:4326" (WGS84; degrees latitude, longitude).
696+
crop : bool optional
697+
Whether to crop tide model constituent files on-the-fly to
698+
improve performance. Cropping will be performed based on a
699+
1 degree buffer around all input points. Defaults to True.
677700
method : string, optional
678701
Method used to interpolate tidal constituents
679702
from model files. Options include:
@@ -831,6 +854,7 @@ def model_tides(
831854
_model_tides,
832855
directory=directory,
833856
crs=crs,
857+
crop=crop,
834858
method=method,
835859
extrapolate=extrapolate,
836860
cutoff=np.inf if cutoff is None else cutoff,

0 commit comments

Comments
 (0)