Skip to content

Commit

Permalink
Add available tides
Browse files Browse the repository at this point in the history
  • Loading branch information
robbibt committed Oct 2, 2024
1 parent 914ce37 commit 97b9e63
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 31 deletions.
98 changes: 68 additions & 30 deletions docs/notebooks/Model_tides.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,61 @@
"\n",
"We will pass this path to `eo-tides` functions using the `directory` parameter.\n",
"\n",
"<div class=\"alert alert-info\">\n",
" \n",
"**Note:** Update the `directory` path below to point to the location of your own tide model directory.\n",
"\n",
"</div>\n",
"\n",
"<!-- For local installation:\n",
"pip install -e ../../. -->"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"directory = \"../../tests/data/tide_models_tests\""
"directory = \"../../tests/data/tide_models_tests/\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can use the `eo_tides.model.available_models` function to verify that we have some tide model data available in this directory:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tide models available in `../../tests/data/tide_models_tests`:\n",
" ✅ FES2014\n",
" ✅ HAMTIDE11\n"
]
}
],
"source": [
"from eo_tides.model import available_models\n",
"\n",
"available_models(directory, show_supported=False);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-info\">\n",
" \n",
"**Note:** The directory above contains demo data only. \n",
"Update the `directory` path to point to the location of your own tide model directory.\n",
"\n",
"</div>"
]
},
{
Expand All @@ -43,7 +81,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {
"tags": []
},
Expand Down Expand Up @@ -139,7 +177,7 @@
"2018-01-01 04:00:00 122.2186 -18.0008 FES2014 1.126837"
]
},
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -171,7 +209,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {
"tags": []
},
Expand Down Expand Up @@ -213,7 +251,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {
"tags": []
},
Expand All @@ -229,7 +267,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 2/2 [00:01<00:00, 1.41it/s]\n"
"100%|██████████| 2/2 [00:01<00:00, 1.46it/s]\n"
]
},
{
Expand Down Expand Up @@ -323,7 +361,7 @@
"2018-01-01 04:00:00 122.2186 -18.0008 1.126837 1.034931"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -351,7 +389,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {
"tags": []
},
Expand All @@ -362,7 +400,7 @@
"<Axes: xlabel='time'>"
]
},
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
},
Expand Down Expand Up @@ -399,7 +437,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {
"tags": []
},
Expand All @@ -415,7 +453,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 2/2 [00:01<00:00, 1.35it/s]\n"
"100%|██████████| 2/2 [00:01<00:00, 1.47it/s]\n"
]
},
{
Expand Down Expand Up @@ -494,7 +532,7 @@
"2018-01-20 122.22 -18.21 FES2014 -2.916972"
]
},
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -524,7 +562,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {
"tags": []
},
Expand Down Expand Up @@ -578,7 +616,7 @@
"1 2018-01-20 122.22 -18.21"
]
},
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -603,7 +641,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {
"tags": []
},
Expand All @@ -619,7 +657,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 2/2 [00:01<00:00, 1.35it/s]\n"
"100%|██████████| 2/2 [00:01<00:00, 1.47it/s]\n"
]
},
{
Expand Down Expand Up @@ -674,7 +712,7 @@
"1 2018-01-20 122.22 -18.21 -2.916972"
]
},
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -703,7 +741,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {
"tags": []
},
Expand All @@ -719,7 +757,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 4/4 [00:01<00:00, 2.77it/s]\n"
"100%|██████████| 4/4 [00:01<00:00, 2.95it/s]\n"
]
},
{
Expand Down Expand Up @@ -830,7 +868,7 @@
"2018-01-20 122.22 -18.21 HAMTIDE11 -2.662284"
]
},
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -857,7 +895,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {
"tags": []
},
Expand All @@ -873,7 +911,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 4/4 [00:01<00:00, 2.76it/s]\n"
"100%|██████████| 4/4 [00:01<00:00, 2.92it/s]\n"
]
},
{
Expand Down Expand Up @@ -957,7 +995,7 @@
" 122.22 -18.21 -2.916972 -2.662284"
]
},
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
62 changes: 62 additions & 0 deletions eo_tides/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,73 @@
import pandas as pd
import pyproj
import pyTMD
from pyTMD.io.model import load_database, model
from tqdm import tqdm

from eo_tides.utils import idw


def available_models(directory=None, show_supported=True):
"""
Prints a list of all tide models available for tide
modelling using `eo-tides`.
This function scans the specified tide model directory
for tide models supported by the `pyTMD` package, and
prints a list of models that are available in the
directory as well as the full list of supported models.
For instructions on setting up tide models, see:
<https://geoscienceaustralia.github.io/eo-tides/setup/>
Parameters
----------
directory : str
Path to the directory containing tide model files.
Returns
-------
available_m : list
A list of all available tide models within
`directory`.
"""
# TODO: Pull directory code into re-usable function

# Set tide modelling files directory. If no custom path is provided,
# first try global environmental var, then "/var/share/tide_models"
if directory is None:
if "EO_TIDES_TIDE_MODELS" in os.environ:
directory = os.environ["EO_TIDES_TIDE_MODELS"]
else:
directory = "/var/share/tide_models"

# Verify path exists
directory = pathlib.Path(directory).expanduser()
if not directory.exists():
raise FileNotFoundError("Invalid tide directory")

# Get full list of supported models from the database
supported_models = load_database()["elevation"].keys()

# Print list of supported models, marking available and
# unavailable models and appending available to list
print(f"Tide models available in `{directory}`:")
available_m = []
for m in supported_models:
try:
model(directory=directory).elevation(m=m)
# Mark available models with a green tick
print(f" ✅ {m}")
available_m.append(m)
except:
if show_supported:
# Mark unavailable models with a red cross
print(f" ❌ {m}")

# Return list of available models
return available_m


def _model_tides(
model,
x,
Expand Down
8 changes: 7 additions & 1 deletion tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
import xarray as xr

from eo_tides.model import model_tides, pixel_tides
from eo_tides.model import available_models, model_tides, pixel_tides
from eo_tides.validation import eval_metrics

GAUGE_X = 122.2183
Expand Down Expand Up @@ -90,6 +90,12 @@ def satellite_ds(request):
return ds


# Test available tide models
def test_available_models():
available_m = available_models()
assert available_m == ["FES2014", "HAMTIDE11"]


# Run test for multiple input coordinates, CRSs and interpolation methods
@pytest.mark.parametrize(
"x, y, crs, method",
Expand Down

0 comments on commit 97b9e63

Please sign in to comment.