Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for model cropping within tide modelling functions #1249

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Tools/dea_tools/coastal.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def _model_tides(
time,
directory,
crs,
crop,
method,
extrapolate,
cutoff,
Expand Down Expand Up @@ -278,6 +279,15 @@ def _model_tides(
# Convert datetime
timescale = pyTMD.time.timescale().from_datetime(time.flatten())

# Calculate bounds for cropping
buffer = 1 # one degree on either side
bounds = [
lon.min() - buffer,
lon.max() + buffer,
lat.min() - buffer,
lat.max() + buffer,
]

# Read tidal constants and interpolate to grid points
if pytmd_model.format in ("OTIS", "ATLAS", "TMD3"):
amp, ph, D, c = pyTMD.io.OTIS.extract_constants(
Expand All @@ -287,6 +297,8 @@ def _model_tides(
pytmd_model.model_file,
pytmd_model.projection,
type=pytmd_model.type,
crop=crop,
bounds=bounds,
method=method,
extrapolate=extrapolate,
cutoff=cutoff,
Expand All @@ -303,6 +315,8 @@ def _model_tides(
pytmd_model.grid_file,
pytmd_model.model_file,
type=pytmd_model.type,
crop=crop,
bounds=bounds,
method=method,
extrapolate=extrapolate,
cutoff=cutoff,
Expand All @@ -318,6 +332,8 @@ def _model_tides(
lon,
lat,
pytmd_model.model_file,
crop=crop,
bounds=bounds,
method=method,
extrapolate=extrapolate,
cutoff=cutoff,
Expand All @@ -335,6 +351,8 @@ def _model_tides(
pytmd_model.model_file,
type=pytmd_model.type,
version=pytmd_model.version,
crop=crop,
bounds=bounds,
method=method,
extrapolate=extrapolate,
cutoff=cutoff,
Expand Down Expand Up @@ -584,6 +602,7 @@ def model_tides(
model="FES2014",
directory=None,
crs="EPSG:4326",
crop=True,
method="spline",
extrapolate=True,
cutoff=None,
Expand Down Expand Up @@ -674,6 +693,10 @@ def model_tides(
crs : str, optional
Input coordinate reference system for x and y coordinates.
Defaults to "EPSG:4326" (WGS84; degrees latitude, longitude).
crop : bool optional
Whether to crop tide model constituent files on-the-fly to
improve performance. Cropping will be performed based on a
1 degree buffer around all input points. Defaults to True.
method : string, optional
Method used to interpolate tidal constituents
from model files. Options include:
Expand Down Expand Up @@ -831,6 +854,7 @@ def model_tides(
_model_tides,
directory=directory,
crs=crs,
crop=crop,
method=method,
extrapolate=extrapolate,
cutoff=np.inf if cutoff is None else cutoff,
Expand Down
Loading