Skip to content

Commit

Permalink
fix: use case insensitive assertions of string argument values
Browse files Browse the repository at this point in the history
thanks @SmithB!
  • Loading branch information
tsutterley committed Sep 17, 2024
1 parent 0f6a07c commit 83c4dcf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
6 changes: 3 additions & 3 deletions doc/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ if "%SPHINXBUILD%" == "" (
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
Expand All @@ -21,10 +19,12 @@ if errorlevel 9009 (
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

Expand Down
47 changes: 24 additions & 23 deletions pyTMD/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
drop support for the ascii definition file format
use model class attributes for file format and corrections
add keyword argument to select nodal corrections type
fix to use case insensitive assertions of string argument values
Updated 08/2024: allow inferring only specific minor constituents
use prediction functions for pole tides in cartesian coordinates
use rotation matrix to convert from cartesian to spherical
Expand Down Expand Up @@ -207,7 +208,7 @@ def tide_elevations(
TIME: str = 'UTC',
METHOD: str = 'spline',
EXTRAPOLATE: bool = False,
CUTOFF: int | float=10.0,
CUTOFF: int | float = 10.0,
CORRECTIONS: str | None = None,
INFER_MINOR: bool = True,
MINOR_CONSTITUENTS: list | None = None,
Expand Down Expand Up @@ -297,8 +298,8 @@ def tide_elevations(
raise FileNotFoundError("Invalid tide directory")

# validate input arguments
assert TIME in ('GPS', 'LORAN', 'TAI', 'UTC', 'datetime')
assert METHOD in ('bilinear', 'spline', 'linear', 'nearest')
assert TIME.lower() in ('gps', 'loran', 'tai', 'utc', 'datetime')
assert METHOD.lower() in ('bilinear', 'spline', 'linear', 'nearest')

# get parameters for tide model
if DEFINITION_FILE is not None:
Expand Down Expand Up @@ -327,7 +328,7 @@ def tide_elevations(
transformer = pyproj.Transformer.from_crs(crs1, crs2, always_xy=True)
lon, lat = transformer.transform(x.flatten(), y.flatten())

# assert delta time is an array
# verify that delta time is an array
delta_time = np.atleast_1d(delta_time)
# convert delta times or datetimes objects to timescale
if (TIME.lower() == 'datetime'):
Expand Down Expand Up @@ -447,7 +448,7 @@ def tide_currents(
TIME: str = 'UTC',
METHOD: str = 'spline',
EXTRAPOLATE: bool = False,
CUTOFF: int | float=10.0,
CUTOFF: int | float = 10.0,
CORRECTIONS: str | None = None,
INFER_MINOR: bool = True,
MINOR_CONSTITUENTS: list | None = None,
Expand Down Expand Up @@ -532,8 +533,8 @@ def tide_currents(
raise FileNotFoundError("Invalid tide directory")

# validate input arguments
assert TIME in ('GPS', 'LORAN', 'TAI', 'UTC', 'datetime')
assert METHOD in ('bilinear', 'spline', 'linear', 'nearest')
assert TIME.lower() in ('gps', 'loran', 'tai', 'utc', 'datetime')
assert METHOD.lower() in ('bilinear', 'spline', 'linear', 'nearest')

# get parameters for tide model
if DEFINITION_FILE is not None:
Expand Down Expand Up @@ -562,7 +563,7 @@ def tide_currents(
transformer = pyproj.Transformer.from_crs(crs1, crs2, always_xy=True)
lon, lat = transformer.transform(x.flatten(), y.flatten())

# assert delta time is an array
# verify that delta time is an array
delta_time = np.atleast_1d(delta_time)
# convert delta times or datetimes objects to timescale
if (TIME.lower() == 'datetime'):
Expand Down Expand Up @@ -714,7 +715,7 @@ def LPET_elevations(
"""

# validate input arguments
assert TIME in ('GPS', 'LORAN', 'TAI', 'UTC', 'datetime')
assert TIME.lower() in ('gps', 'loran', 'tai', 'utc', 'datetime')
# determine input data type based on variable dimensions
if not TYPE:
TYPE = pyTMD.spatial.data_type(x, y, delta_time)
Expand All @@ -736,7 +737,7 @@ def LPET_elevations(
transformer = pyproj.Transformer.from_crs(crs1, crs2, always_xy=True)
lon, lat = transformer.transform(x.flatten(), y.flatten())

# assert delta time is an array
# verify that delta time is an array
delta_time = np.atleast_1d(delta_time)
# convert delta times or datetimes objects to timescale
if (TIME.lower() == 'datetime'):
Expand Down Expand Up @@ -832,9 +833,9 @@ def LPT_displacements(
"""

# validate input arguments
assert TIME in ('GPS', 'LORAN', 'TAI', 'UTC', 'datetime')
assert ELLIPSOID in pyTMD._ellipsoids
assert CONVENTION in timescale.eop._conventions
assert TIME.lower() in ('gps', 'loran', 'tai', 'utc', 'datetime')
assert ELLIPSOID.upper() in pyTMD._ellipsoids
assert CONVENTION.isdigit() and CONVENTION in timescale.eop._conventions
# determine input data type based on variable dimensions
if not TYPE:
TYPE = pyTMD.spatial.data_type(x, y, delta_time)
Expand All @@ -856,7 +857,7 @@ def LPT_displacements(
transformer = pyproj.Transformer.from_crs(crs1, crs2, always_xy=True)
lon,lat = transformer.transform(x.flatten(), y.flatten())

# assert delta time is an array
# verify that delta time is an array
delta_time = np.atleast_1d(delta_time)
# convert delta times or datetimes objects to timescale
if (TIME.lower() == 'datetime'):
Expand Down Expand Up @@ -1039,10 +1040,10 @@ def OPT_displacements(
"""

# validate input arguments
assert TIME in ('GPS', 'LORAN', 'TAI', 'UTC', 'datetime')
assert ELLIPSOID in pyTMD._ellipsoids
assert CONVENTION in timescale.eop._conventions
assert METHOD in ('bilinear', 'spline', 'linear', 'nearest')
assert TIME.lower() in ('gps', 'loran', 'tai', 'utc', 'datetime')
assert ELLIPSOID.upper() in pyTMD._ellipsoids
assert CONVENTION.isdigit() and CONVENTION in timescale.eop._conventions
assert METHOD.lower() in ('bilinear', 'spline', 'linear', 'nearest')
# determine input data type based on variable dimensions
if not TYPE:
TYPE = pyTMD.spatial.data_type(x, y, delta_time)
Expand All @@ -1064,7 +1065,7 @@ def OPT_displacements(
transformer = pyproj.Transformer.from_crs(crs1, crs2, always_xy=True)
lon,lat = transformer.transform(x.flatten(), y.flatten())

# assert delta time is an array
# verify that delta time is an array
delta_time = np.atleast_1d(delta_time)
# convert delta times or datetimes objects to timescale
if (TIME.lower() == 'datetime'):
Expand Down Expand Up @@ -1261,9 +1262,9 @@ def SET_displacements(
"""

# validate input arguments
assert TIME in ('GPS', 'LORAN', 'TAI', 'UTC', 'datetime')
assert TIDE_SYSTEM in ('mean_tide', 'tide_free')
assert EPHEMERIDES in ('approximate', 'JPL')
assert TIME.lower() in ('gps', 'loran', 'tai', 'utc', 'datetime')
assert TIDE_SYSTEM.lower() in ('mean_tide', 'tide_free')
assert EPHEMERIDES.lower() in ('approximate', 'JPL')
# determine input data type based on variable dimensions
if not TYPE:
TYPE = pyTMD.spatial.data_type(x, y, delta_time)
Expand All @@ -1285,7 +1286,7 @@ def SET_displacements(
transformer = pyproj.Transformer.from_crs(crs1, crs2, always_xy=True)
lon, lat = transformer.transform(x.flatten(), y.flatten())

# assert delta time is an array
# verify that delta time is an array
delta_time = np.atleast_1d(delta_time)
# convert delta times or datetimes objects to timescale
if (TIME.lower() == 'datetime'):
Expand Down
3 changes: 2 additions & 1 deletion pyTMD/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
UPDATE HISTORY:
Updated 09/2024: verify order of minor constituents to infer
fix to use case insensitive assertions of string argument values
Updated 08/2024: minor nodal angle corrections in radians to match arguments
include inference of eps2 and eta2 when predicting from GOT models
add keyword argument to allow inferring specific minor constituents
Expand Down Expand Up @@ -767,7 +768,7 @@ def solid_earth_tide(
kwargs.setdefault('mass_ratio_solar', 332946.0482)
kwargs.setdefault('mass_ratio_lunar', 0.0123000371)
# validate output tide system
assert tide_system in ('tide_free', 'mean_tide')
assert tide_system.lower() in ('tide_free', 'mean_tide')
# number of input coordinates
nt = len(np.atleast_1d(t))
# convert time to Modified Julian Days (MJD)
Expand Down

0 comments on commit 83c4dcf

Please sign in to comment.