diff --git a/Makefile b/Makefile index f17d8ba..cc63269 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/tests/test_utils.py b/tests/test_utils.py index d1ceac8..b2b1613 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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( diff --git a/tests/testing.ipynb b/tests/testing.ipynb index 72825b9..ef7323b 100644 --- a/tests/testing.ipynb +++ b/tests/testing.ipynb @@ -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", @@ -115,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -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" ] } ], @@ -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