Skip to content

Commit

Permalink
Expand tests, attempt to fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
robbibt authored Dec 20, 2024
1 parent a0c88d5 commit a22f075
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 165 deletions.
3 changes: 2 additions & 1 deletion eo_tides/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def _stats_figure(
marker="o",
linewidth=0.0,
color="black" if point_col is None else point_col,
markersize=4,
markeredgecolor="black",
markeredgewidth=0.6,
label="Satellite observations",
)

Expand Down
30 changes: 30 additions & 0 deletions tests/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,36 @@ def test_tidal_stats_models(satellite_ds, models):
assert isinstance(tidal_stats_df, pd.Series)


# Test if plotting a custom variable runs without errors
def test_tide_stats_plotvar(satellite_ds):
# Test on custom coordinate
satellite_ds_withcoords = satellite_ds.assign_coords(coord=("time", [1, 1, 2, 2, 3, 4, 5]))
tide_stats(
satellite_ds_withcoords,
plot_var="coord",
)

# Test on custom data variable
satellite_ds_withvar = satellite_ds.assign(var=("time", [1, 1, 2, 2, 3, 4, 5]))
tide_stats(
satellite_ds_withvar,
plot_var="var",
)

# Test configuring color when plotting variable
tide_stats(
satellite_ds_withvar,
plot_var="var",
point_col="red",
)

# Test when not plotting variable
tide_stats(
satellite_ds_withvar,
point_col="red",
)


# Run test for multiple models and with resampling on and off
@pytest.mark.parametrize(
"models, resample",
Expand Down
199 changes: 35 additions & 164 deletions tests/testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -51,32 +51,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/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"
]
}
],
"source": [
"cd .."
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -152,6 +127,15 @@
"measured_tides_ds = load_measured_tides_ds()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cd .."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -198,7 +182,7 @@
},
{
"cell_type": "code",
"execution_count": 110,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -217,75 +201,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"mot -0.417000\n",
"mat 0.005000\n",
"hot 1.674000\n",
"hat 4.259000\n",
"lot -2.141000\n",
"lat -4.320000\n",
"otr 3.814000\n",
"tr 8.579000\n",
"spread 0.445000\n",
"offset_low 0.254000\n",
"offset_high 0.301000\n",
"x 122.218002\n",
"y -18.000999\n",
"dtype: float32"
]
},
"execution_count": 114,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
" # Calculate tidal stats\n",
" tidal_stats_df = tide_stats(\n",
" satellite_ds,\n",
" modelled_freq=modelled_freq,\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 134,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using tide modelling location: 122.22, -18.00\n",
"Modelling tides with EOT20, GOT5.5 in parallel (models: 2, splits: 1)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 2/2 [00:01<00:00, 1.97it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using tide modelling location: 122.22, -18.00\n",
"Modelling tides with EOT20, GOT5.5 in parallel (models: 2, splits: 1)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 2/2 [00:01<00:00, 1.38it/s]\n"
]
}
],
"outputs": [],
"source": [
"models = [\"EOT20\", \"GOT5.5\"]\n",
"\n",
Expand All @@ -301,49 +217,25 @@
},
{
"cell_type": "code",
"execution_count": 136,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Creating reduced resolution 5000 x 5000 metre tide modelling array\n",
"Modelling tides with EOT20, GOT5.5 in parallel (models: 2, splits: 1)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 2/2 [00:01<00:00, 1.02it/s]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Returning low resolution tide array\n",
"Creating reduced resolution 5000 x 5000 metre tide modelling array\n",
"Modelling tides with EOT20, GOT5.5 in parallel (models: 2, splits: 1)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 2/2 [00:04<00:00, 2.40s/it]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Returning low resolution tide array\n",
"Returning low resolution statistics array\n"
]
}
],
"execution_count": 143,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"satellite_ds"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stats_ds = pixel_stats(\n",
" satellite_ds,\n",
Expand All @@ -355,30 +247,9 @@
},
{
"cell_type": "code",
"execution_count": 140,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['mot',\n",
" 'mat',\n",
" 'hot',\n",
" 'hat',\n",
" 'lot',\n",
" 'lat',\n",
" 'otr',\n",
" 'tr',\n",
" 'spread',\n",
" 'offset_low',\n",
" 'offset_high']"
]
},
"execution_count": 140,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"list(stats_ds.data_vars)"
]
Expand Down

0 comments on commit a22f075

Please sign in to comment.