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

fix: use case insensitive assertions of string argument values #340

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
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
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
"""

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

Check warning on line 718 in pyTMD/compute.py

View check run for this annotation

Codecov / codecov/patch

pyTMD/compute.py#L718

Added line #L718 was not covered by tests
# 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 @@
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 @@
"""

# 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 @@
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 @@
"""

# 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 @@
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 @@
"""

# 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 @@
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
Loading