Skip to content

Commit

Permalink
feat: added function to calculate a tidal time series (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutterley authored Dec 27, 2021
1 parent eed51e9 commit 0df213a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/user_guide/compute_tide_corrections.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tide = compute_tide_corrections(x, y, delta_time, DIRECTORY=DIRECTORY,
* `None`: determined from input variable dimensions
* `'drift'`: drift buoys or satellite/airborne altimetry (time per data point)
* `'grid'`: spatial grids or images (single time per image)
* `'time series'`: time series at a single point (multiple times)
- `TIME`: input time standard or input type
* `'GPS'`: leap seconds needed
* `'TAI'`: leap seconds needed (TAI = GPS + 19 seconds)
Expand Down
19 changes: 18 additions & 1 deletion pyTMD/compute_tide_corrections.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
u"""
compute_tide_corrections.py
Written by Tyler Sutterley (09/2021)
Written by Tyler Sutterley (12/2021)
Calculates tidal elevations for correcting elevation or imagery data
Uses OTIS format tidal solutions provided by Ohio State University and ESR
Expand All @@ -28,6 +28,7 @@
None: determined from input variable dimensions
drift: drift buoys or satellite/airborne altimetry (time per data point)
grid: spatial grids or images (single time for all data points)
time series: time series at a single point (multiple times)
TIME: input time standard or input type
GPS: leap seconds needed
TAI: leap seconds needed (TAI = GPS + 19 seconds)
Expand Down Expand Up @@ -67,6 +68,7 @@
load_constituent.py: loads parameters for a given tidal constituent
load_nodal_corrections.py: load the nodal corrections for tidal constituents
predict_tide.py: predict tides at single times using harmonic constants
predict_tidal_ts.py: predict tidal time series using harmonic constants
predict_tide_drift.py: predict tidal elevations using harmonic constants
read_tide_model.py: extract tidal harmonic constants from OTIS tide models
read_netcdf_model.py: extract tidal harmonic constants from netcdf models
Expand All @@ -76,6 +78,7 @@
nearest_extrap.py: nearest-neighbor extrapolation of data to coordinates
UPDATE HISTORY:
Updated 12/2021: added function to calculate a tidal time series
Updated 09/2021: refactor to use model class for files and attributes
Updated 07/2021: can use numpy datetime arrays as input time variable
added function for determining the input spatial variable type
Expand Down Expand Up @@ -108,6 +111,7 @@
from pyTMD.calc_delta_time import calc_delta_time
from pyTMD.infer_minor_corrections import infer_minor_corrections
from pyTMD.predict_tide import predict_tide
from pyTMD.predict_tidal_ts import predict_tidal_ts
from pyTMD.predict_tide_drift import predict_tide_drift
from pyTMD.read_tide_model import extract_tidal_constants
from pyTMD.read_netcdf_model import extract_netcdf_constants
Expand Down Expand Up @@ -141,6 +145,7 @@ def compute_tide_corrections(x, y, delta_time, DIRECTORY=None, MODEL=None,
None: determined from input variable dimensions
drift: drift buoys or satellite/airborne altimetry (time per data point)
grid: spatial grids or images (single time per image)
time series: time series at a single point (multiple times)
TIME: time type if need to compute leap seconds to convert to UTC
GPS: leap seconds needed
TAI: leap seconds needed (TAI = GPS + 19 seconds)
Expand Down Expand Up @@ -181,6 +186,9 @@ def compute_tide_corrections(x, y, delta_time, DIRECTORY=None, MODEL=None,
#-- reform coordinate dimensions for input grids
if (TYPE.lower() == 'grid') and (np.size(x) != np.size(y)):
x,y = np.meshgrid(np.copy(x),np.copy(y))
elif (TYPE.lower() == 'time series'):
x = np.atleast_1d(x)
y = np.atleast_1d(y)

#-- converting x,y from EPSG to latitude/longitude
try:
Expand Down Expand Up @@ -285,6 +293,15 @@ def compute_tide_corrections(x, y, delta_time, DIRECTORY=None, MODEL=None,
minor = infer_minor_corrections(t, hc, c,
DELTAT=deltat, CORRECTIONS=model.format)
tide.data[:] += minor.data[:]
elif (TYPE.lower() == 'time series'):
npts = len(t)
tide = np.ma.zeros((npts), fill_value=FILL_VALUE)
tide.mask = np.any(hc.mask,axis=1)
tide.data[:] = predict_tidal_ts(t, hc, c,
DELTAT=deltat, CORRECTIONS=model.format)
minor = infer_minor_corrections(t, hc, c,
DELTAT=deltat, CORRECTIONS=model.format)
tide.data[:] += minor.data[:]
#-- replace invalid values with fill value
tide.data[tide.mask] = tide.fill_value

Expand Down
7 changes: 6 additions & 1 deletion pyTMD/spatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@
import logging
import netCDF4
import datetime
import warnings
import numpy as np
import osgeo.gdal, osgeo.osr
try:
import osgeo.gdal, osgeo.osr
except ModuleNotFoundError:
warnings.filterwarnings("always")
warnings.warn("GDAL not available")

def case_insensitive_filename(filename):
"""
Expand Down

0 comments on commit 0df213a

Please sign in to comment.