Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Add output check to the test #86

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 40 additions & 16 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,66 @@
import pytest
from glidertest import fetchers, tools
import matplotlib.pyplot as plt
import math
import numpy as np


def test_plots():
def test_plots(start_prof=0, end_prof=100):
ds = fetchers.load_sample_dataset()
tools.plot_basic_vars(ds, end_prof=int(ds.PROFILE_NUMBER.max()))
fig, ax = tools.plot_basic_vars(ds,start_prof=start_prof, end_prof=end_prof)
assert ax[0].get_ylabel() == 'Depth (m)'
assert ax[0].get_xlabel() == f'Average Temperature [C] \nbetween profile {start_prof} and {end_prof}'
return fig


def test_up_down_bias():
def test_up_down_bias(v_res=1, xlabel='Salinity'):
ds = fetchers.load_sample_dataset()
fig, ax = plt.subplots()
df = tools.updown_bias(ds, var='PSAL', v_res=1)
tools.plot_updown_bias(df, ax, xlabel='Salinity')
df = tools.updown_bias(ds, var='PSAL', v_res=v_res)
bins = np.unique(np.round(ds.DEPTH,0))
ncell = math.ceil(len(bins)/v_res)
assert len(df) == ncell
tools.plot_updown_bias(df, ax, xlabel=xlabel)
lims = np.abs(df.dc)
assert ax.get_xlim() == (-np.nanpercentile(lims, 99.5), np.nanpercentile(lims, 99.5))
assert ax.get_ylim() == (df.depth.max() + 1, -df.depth.max() / 30)
assert ax.get_xlabel() == xlabel



def test_chl():
def test_chl(var1='CHLA', var2='BBP700'):
ds = fetchers.load_sample_dataset()
tools.optics_first_check(ds, var='CHLA')
tools.optics_first_check(ds, var='BBP700')
ax = tools.optics_first_check(ds, var=var1)
assert ax.get_ylabel() == var1
ax = tools.optics_first_check(ds, var=var2)
assert ax.get_ylabel() == var2
with pytest.raises(KeyError) as e:
tools.optics_first_check(ds, var='nonexistent_variable')


def test_quench_sequence():
def test_quench_sequence(xlabel='Temperature [C]',ylim=45):
ds = fetchers.load_sample_dataset()
if not "TIME" in ds.indexes.keys():
ds = ds.set_xindex('TIME')
fig, ax = plt.subplots()
tools.plot_section_with_srss(ds, 'CHLA')
tools.plot_section_with_srss(ds, 'CHLA', ax,ylim=ylim)
assert ax.get_ylabel() == 'Depth [m]'
assert ax.get_ylim() == (ylim, -ylim / 30)

dayT, nightT = tools.day_night_avg(ds, sel_var='TEMP')
fig, ax = plt.subplots()
tools.plot_daynight_avg(dayT, nightT, ax, xlabel='Temperature [C]')
assert len(nightT.dat.dropna()) > 0
assert len(dayT.dat.dropna()) > 0

fig, ax = tools.plot_daynight_avg(dayT, nightT,xlabel=xlabel)
assert ax.get_ylabel() == 'Depth [m]'
assert ax.get_xlabel() == xlabel

def test_temporal_drift():
def test_temporal_drift(var='DOXY'):
ds = fetchers.load_sample_dataset()
fig, ax = plt.subplots(1, 2)
tools.check_temporal_drift(ds,'DOXY', ax)
tools.check_temporal_drift(ds,var, ax)
assert ax[1].get_ylabel() == 'Depth (m)'
assert ax[0].get_ylabel() == var
assert ax[1].get_xlim() == (np.nanpercentile(ds[var], 0.01), np.nanpercentile(ds[var], 99.99))
tools.check_temporal_drift(ds,'CHLA')

def test_profile_check():
Expand All @@ -50,4 +74,4 @@ def test_check_monotony():
temperature_monotony = tools.check_monotony(ds.TEMP)
assert profile_number_monotony
assert not temperature_monotony