Skip to content

Commit

Permalink
Test clip models
Browse files Browse the repository at this point in the history
  • Loading branch information
robbibt authored Nov 8, 2024
1 parent 5e9bcfa commit 4c58bac
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 60 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ test-stats: ## Test stats module with pytest

.PHONY: test-utils
test-utils: ## Test utils module with pytest
@echo "🚀 Testing utils module: Running pytest"
@tar --skip-old-files -xzf ./tests/data/tide_models.tar.gz -C ./tests/data
@export EO_TIDES_TIDE_MODELS=./tests/data/tide_models && \
uv run python -m pytest tests/test_utils.py --verbose
Expand Down
13 changes: 12 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import pathlib
import tempfile
from datetime import datetime

import numpy as np
import pandas as pd
import pytest

from eo_tides.utils import _standardise_time, idw, list_models
from eo_tides.utils import _standardise_time, clip_models, idw, list_models


def test_clip_models():
with tempfile.TemporaryDirectory() as tmpdirname:
clip_models(
input_directory="tests/data/tide_models", output_directory=tmpdirname, bbox=(122.27, -18.07, 122.29, -18.05)
)

output_files = [i.stem for i in pathlib.Path(tmpdirname).iterdir()]
assert output_files == ["GOT5", "EOT20", "hamtide"]


@pytest.mark.parametrize(
Expand Down
184 changes: 126 additions & 58 deletions tests/testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,66 +28,18 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Obtaining file:///home/jovyan/Robbi/pyTMD\n",
" Installing build dependencies ... \u001b[?25ldone\n",
"\u001b[?25h Checking if build backend supports build_editable ... \u001b[?25ldone\n",
"\u001b[?25h Getting requirements to build editable ... \u001b[?25ldone\n",
"\u001b[?25h Preparing editable metadata (pyproject.toml) ... \u001b[?25ldone\n",
"\u001b[?25hRequirement already satisfied: lxml in /env/lib/python3.10/site-packages (from pyTMD==2.1.6.dev21+g2276154.d20241031) (5.3.0)\n",
"Requirement already satisfied: netCDF4 in /env/lib/python3.10/site-packages (from pyTMD==2.1.6.dev21+g2276154.d20241031) (1.7.1)\n",
"Requirement already satisfied: numpy in /env/lib/python3.10/site-packages (from pyTMD==2.1.6.dev21+g2276154.d20241031) (1.26.4)\n",
"Requirement already satisfied: pyproj in /env/lib/python3.10/site-packages (from pyTMD==2.1.6.dev21+g2276154.d20241031) (3.7.0)\n",
"Requirement already satisfied: python-dateutil in /env/lib/python3.10/site-packages (from pyTMD==2.1.6.dev21+g2276154.d20241031) (2.9.0)\n",
"Requirement already satisfied: scipy>=1.10.1 in /env/lib/python3.10/site-packages (from pyTMD==2.1.6.dev21+g2276154.d20241031) (1.14.1)\n",
"Requirement already satisfied: setuptools-scm in /env/lib/python3.10/site-packages (from pyTMD==2.1.6.dev21+g2276154.d20241031) (8.1.0)\n",
"Requirement already satisfied: timescale>=0.0.3 in /env/lib/python3.10/site-packages (from pyTMD==2.1.6.dev21+g2276154.d20241031) (0.0.5)\n",
"Requirement already satisfied: cftime in /env/lib/python3.10/site-packages (from netCDF4->pyTMD==2.1.6.dev21+g2276154.d20241031) (1.6.4)\n",
"Requirement already satisfied: certifi in /env/lib/python3.10/site-packages (from netCDF4->pyTMD==2.1.6.dev21+g2276154.d20241031) (2024.8.30)\n",
"Requirement already satisfied: six>=1.5 in /env/lib/python3.10/site-packages (from python-dateutil->pyTMD==2.1.6.dev21+g2276154.d20241031) (1.16.0)\n",
"Requirement already satisfied: packaging>=20 in /env/lib/python3.10/site-packages (from setuptools-scm->pyTMD==2.1.6.dev21+g2276154.d20241031) (24.1)\n",
"Requirement already satisfied: setuptools in /env/lib/python3.10/site-packages (from setuptools-scm->pyTMD==2.1.6.dev21+g2276154.d20241031) (75.1.0)\n",
"Requirement already satisfied: tomli>=1 in /env/lib/python3.10/site-packages (from setuptools-scm->pyTMD==2.1.6.dev21+g2276154.d20241031) (2.0.2)\n",
"Building wheels for collected packages: pyTMD\n",
" Building editable for pyTMD (pyproject.toml) ... \u001b[?25ldone\n",
"\u001b[?25h Created wheel for pyTMD: filename=pyTMD-2.1.6.dev21+g2276154.d20241031-0.editable-py3-none-any.whl size=71883 sha256=1c2816ed684e0afc4313fdbd8d6ed53e5eefdb66f36bff9d6a69d625f0385bec\n",
" Stored in directory: /tmp/pip-ephem-wheel-cache-idns2gu6/wheels/a3/3a/5c/fdad1371f5626a2592e27e7b3568ba9ca052f5adaf865f781e\n",
"Successfully built pyTMD\n",
"Installing collected packages: pyTMD\n",
" Attempting uninstall: pyTMD\n",
" Found existing installation: pyTMD 2.1.7\n",
" Uninstalling pyTMD-2.1.7:\n",
" Successfully uninstalled pyTMD-2.1.7\n",
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
"eo-tides 0.2.0 requires pyTMD==2.1.7, but you have pytmd 2.1.6.dev21+g2276154.d20241031 which is incompatible.\u001b[0m\u001b[31m\n",
"\u001b[0mSuccessfully installed pyTMD-2.1.6.dev21+g2276154.d20241031\n"
]
}
],
"outputs": [],
"source": [
"!pip install -e /home/jovyan/Robbi/pyTMD"
]
},
{
"cell_type": "code",
"execution_count": 55,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2\n",
Expand Down Expand Up @@ -115,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 56,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -198,14 +150,22 @@
},
{
"cell_type": "code",
"execution_count": 109,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/home/jovyan/Robbi/eo-tides\n"
"/workspaces/eo-tides\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/workspaces/eo-tides/.venv/lib/python3.12/site-packages/IPython/core/magics/osm.py:417: UserWarning: using dhist requires you to install the `pickleshare` library.\n",
" self.shell.db['dhist'] = compress_dhist(dhist)[-100:]\n"
]
}
],
Expand Down Expand Up @@ -390,13 +350,121 @@
"!export EO_TIDES_TIDE_MODELS=./tests/data/tide_models && pytest tests --verbose"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Test `clip_models`"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"from eo_tides import clip_models"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['README', 'hamtide', 'EOT20', 'GOT5']"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Preparing to clip suitable NetCDF models: ['EOT20', 'GOT5.5', 'HAMTIDE11']\n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Clipping EOT20: 0%| | 0/17 [00:00<?, ?it/s]"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Clipping EOT20: 100%|██████████| 17/17 [00:01<00:00, 14.61it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" ✅ Clipped model exported and verified\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Clipping GOT5.5: 100%|██████████| 16/16 [00:00<00:00, 29.51it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" ✅ Clipped model exported and verified\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Clipping HAMTIDE11: 100%|██████████| 9/9 [00:00<00:00, 21.21it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" ✅ Clipped model exported and verified\n",
"\n",
"Outputs exported to /tmp/tmp65uqk8w4\n",
"────────────────────────────────────────────────────────────────────────────────\n",
" 󠀠🌊 | Model | Expected path \n",
"────────────────────────────────────────────────────────────────────────────────\n",
" ✅ │ EOT20 │ /tmp/tmp65uqk8w4/EOT20/ocean_tides \n",
" ✅ │ GOT5.5 │ /tmp/tmp65uqk8w4/GOT5.5/ocean_tides \n",
" ✅ │ HAMTIDE11 │ /tmp/tmp65uqk8w4/hamtide \n",
"────────────────────────────────────────────────────────────────────────────────\n",
"\n",
"Summary:\n",
"Available models: 3/51\n",
"['GOT5', 'EOT20', 'hamtide']\n"
]
}
],
"source": [
"\n",
" \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -8368,7 +8436,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -8382,7 +8450,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.15"
"version": "3.12.0"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 4c58bac

Please sign in to comment.