From fb5b683f2b7a5283ca5d9c390a6a26813aee5118 Mon Sep 17 00:00:00 2001 From: Chiara Monforte <75482817+MOchiara@users.noreply.github.com> Date: Mon, 1 Jul 2024 10:28:18 +0200 Subject: [PATCH 1/7] Added pytest to requirements-dev.txt --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index 43168aa..930987f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,3 +3,4 @@ matplotlib netcdf4 pooch xarray +pytest From faefce15520bfe6fb16eae8a4e9e3804cc94b144 Mon Sep 17 00:00:00 2001 From: ChiaraMonforte Date: Mon, 1 Jul 2024 11:25:17 +0200 Subject: [PATCH 2/7] Removed test from fuction name and demo --- glidertest/tools.py | 2 +- notebooks/demo.ipynb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/glidertest/tools.py b/glidertest/tools.py index 538d393..f0dcc3d 100644 --- a/glidertest/tools.py +++ b/glidertest/tools.py @@ -26,7 +26,7 @@ def grid2d(x, y, v, xi=1, yi=1): return grid, XI, YI -def test_updown_bias(ds, axis, var='PSAL', v_res=0, return_val=False): +def updown_bias(ds, axis, var='PSAL', v_res=0, return_val=False): p = 1 # Horizontal resolution z = v_res # Vertical resolution varG, profG, depthG = grid2d(ds.PROFILE_NUMBER, ds.DEPTH, ds[var], p, z) diff --git a/notebooks/demo.ipynb b/notebooks/demo.ipynb index ca660c5..160ec2b 100644 --- a/notebooks/demo.ipynb +++ b/notebooks/demo.ipynb @@ -79,10 +79,10 @@ "outputs": [], "source": [ "fig, ax = plt.subplots(1,4,figsize=(15, 5))\n", - "tools.test_updown_bias(ds, ax[0],var='PSAL',v_res=0.1)\n", - "tools.test_updown_bias(ds,ax[1], var='CHLA',v_res=0.1)\n", - "tools.test_updown_bias(ds, ax[2], var='TEMP',v_res=0.1)\n", - "tools.test_updown_bias(ds, ax[3], var='DOXY',v_res=0.1)" + "tools.updown_bias(ds, ax[0],var='PSAL',v_res=0.1)\n", + "tools.updown_bias(ds,ax[1], var='CHLA',v_res=0.1)\n", + "tools.updown_bias(ds, ax[2], var='TEMP',v_res=0.1)\n", + "tools.updown_bias(ds, ax[3], var='DOXY',v_res=0.1)" ] }, { From df48590ce782c5f374ffeb3ce9d7bd8192b46e10 Mon Sep 17 00:00:00 2001 From: ChiaraMonforte Date: Mon, 1 Jul 2024 11:34:40 +0200 Subject: [PATCH 3/7] Add all other packages --- notebooks/demo.ipynb | 2 +- pyproject.toml | 4 +++- requirements-dev.txt | 13 ++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/notebooks/demo.ipynb b/notebooks/demo.ipynb index 160ec2b..2906ea7 100644 --- a/notebooks/demo.ipynb +++ b/notebooks/demo.ipynb @@ -171,7 +171,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/pyproject.toml b/pyproject.toml index 507f4be..7113847 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,9 +14,11 @@ license = { file = "LICENSE" } maintainers = [ { name = "Callum Rollo", email = "c.rollo@outlook.com" }, ] -requires-python = ">=3.10" +requires-python = ">=3.8" classifiers = [ "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", diff --git a/requirements-dev.txt b/requirements-dev.txt index 930987f..0648586 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,13 @@ -jupyterlab -matplotlib netcdf4 pooch xarray -pytest +numpy +matplotlib +pandas +seaborn +scipy +cmocean +skyfield +tqdm +jupyterlab +pytest \ No newline at end of file From 5b8943585ad2ac77cc78d80458f79fea8825ac14 Mon Sep 17 00:00:00 2001 From: ChiaraMonforte Date: Mon, 1 Jul 2024 14:02:18 +0200 Subject: [PATCH 4/7] Moved set index TIME into the function --- glidertest/tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glidertest/tools.py b/glidertest/tools.py index f0dcc3d..b4bde13 100644 --- a/glidertest/tools.py +++ b/glidertest/tools.py @@ -313,8 +313,8 @@ def check_npq(ds, offset=np.timedelta64(1, "h"), start_time='2024-04-18', end_ti Two plots: a chlorphyll section and a comparison of day and night average chlorphyll over depth for the selcted day """ - - + if not "TIME" in ds.indexes.keys(): + ds = ds.set_xindex('TIME') ds_sel = ds.sel(TIME=slice(start_time, end_time)) sunrise, sunset = sunset_sunrise(ds_sel.TIME, ds_sel.LATITUDE, ds_sel.LONGITUDE) From 8bb1bad98736012a50d108896b84d5834d54c5ee Mon Sep 17 00:00:00 2001 From: ChiaraMonforte Date: Mon, 1 Jul 2024 14:04:52 +0200 Subject: [PATCH 5/7] Added test functions --- tests/test_fetchers.py | 6 ++++++ tests/test_tools.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/test_fetchers.py create mode 100644 tests/test_tools.py diff --git a/tests/test_fetchers.py b/tests/test_fetchers.py new file mode 100644 index 0000000..71d37d8 --- /dev/null +++ b/tests/test_fetchers.py @@ -0,0 +1,6 @@ +from glidertest import fetchers + + +def test_demo_datasets(): + for remote_ds_name in fetchers.data_source_og.registry.keys(): + ds = fetchers.load_sample_dataset(dataset_name=remote_ds_name) \ No newline at end of file diff --git a/tests/test_tools.py b/tests/test_tools.py new file mode 100644 index 0000000..3bde88d --- /dev/null +++ b/tests/test_tools.py @@ -0,0 +1,25 @@ +from glidertest import fetchers, tools +import matplotlib.pyplot as plt + + +def test_plots(): + ds = fetchers.load_sample_dataset() + tools.plot_basic_vars(ds, end_prof=int(ds.PROFILE_NUMBER.max())) + + +def test_up_down_bias(): + ds = fetchers.load_sample_dataset() + fig, ax = plt.subplots() + tools.updown_bias(ds, ax, var='PSAL', v_res=0.1) + + +def test_chl(): + ds = fetchers.load_sample_dataset() + tools.chl_first_check(ds) + + +def test_quench(): + ds = fetchers.load_sample_dataset() + if not "TIME" in ds.indexes.keys(): + ds = ds.set_xindex('TIME') + tools.check_npq(ds, start_time='2023-09-06', end_time='2023-09-08', sel_day=0) \ No newline at end of file From 695bff22ce711a40f0d18ebcc0a51a398b205231 Mon Sep 17 00:00:00 2001 From: ChiaraMonforte Date: Mon, 1 Jul 2024 14:44:28 +0200 Subject: [PATCH 6/7] Added workflow --- .github/workflows/tests.yml | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..d3d0b1c --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,39 @@ +name: Tests + +on: + pull_request: + push: + branches: [main] + +jobs: + run: + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: ["3.8", "3.10", "3.12"] + os: [windows-latest, ubuntu-latest, macos-latest] + fail-fast: true + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Micromamba + uses: mamba-org/setup-micromamba@v1 + + - name: Python ${{ matrix.python-version }} + shell: bash -l {0} + run: > + micromamba create --name TEST python=${{ matrix.python-version }} pytest --file requirements-dev.txt --channel conda-forge + && micromamba activate TEST + - name: Install glidertest + shell: bash -l {0} + run: > + micromamba activate TEST + && python -m pip install -e . --no-deps --force-reinstall + - name: Tests + shell: bash -l {0} + run: > + micromamba activate TEST + && python -m pytest -rxs tests/ \ No newline at end of file From d83b9256356e45714d241f2a6b5433e14c91fd13 Mon Sep 17 00:00:00 2001 From: ChiaraMonforte Date: Mon, 1 Jul 2024 15:40:06 +0200 Subject: [PATCH 7/7] Updated tools - removed plt.show which is bothering the tests --- glidertest/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glidertest/tools.py b/glidertest/tools.py index b4bde13..992c61d 100644 --- a/glidertest/tools.py +++ b/glidertest/tools.py @@ -156,7 +156,7 @@ def chl_first_check(ds): ax.set(ylim=(np.nanpercentile(bottom_chl_data, 0.1), np.nanpercentile(bottom_chl_data, 99.9)), xlabel='Measurements', ylabel='Chla') - plt.show() + if slope >= 0.00001: print( 'Data from the deepest 10% of data has been analysed and data does not seem stable. An alternative solution for dark counts has to be considered. \nMoreover, it is recommended to check the sensor has this may suggest issues with the sensor (i.e water inside the sensor, temporal drift etc)')