Skip to content

Commit

Permalink
Merge pull request #19 from MOchiara/chiara-patch-12
Browse files Browse the repository at this point in the history
Prepare for tests
  • Loading branch information
callumrollo authored Jul 1, 2024
2 parents 6a05b1e + d83b925 commit 55bb788
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 12 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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/
8 changes: 4 additions & 4 deletions glidertest/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)')
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions notebooks/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
},
{
Expand Down Expand Up @@ -171,7 +171,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ license = { file = "LICENSE" }
maintainers = [
{ name = "Callum Rollo", email = "[email protected]" },
]
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",
Expand Down
12 changes: 10 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
jupyterlab
matplotlib
netcdf4
pooch
xarray
numpy
matplotlib
pandas
seaborn
scipy
cmocean
skyfield
tqdm
jupyterlab
pytest
6 changes: 6 additions & 0 deletions tests/test_fetchers.py
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 25 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 55bb788

Please sign in to comment.