Skip to content

Commit

Permalink
Results are now saved in the result folder + Add example_plot_results
Browse files Browse the repository at this point in the history
  • Loading branch information
mballaro committed Sep 21, 2020
1 parent cad8bf1 commit a9b81c2
Show file tree
Hide file tree
Showing 4 changed files with 343 additions and 32 deletions.
13 changes: 0 additions & 13 deletions notebooks/baseline_oi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
"source": [
"import xarray as xr\n",
"import numpy\n",
"import pyinterp\n",
"import dask\n",
"import warnings\n",
"import logging\n",
"import sys\n",
Expand All @@ -63,17 +61,6 @@
"logger.setLevel(logging.INFO)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cluster = dask.distributed.LocalCluster()\n",
"client = dask.distributed.Client(cluster)\n",
"client"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
48 changes: 31 additions & 17 deletions notebooks/example_data_eval.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@
"source": [
"import xarray as xr\n",
"import numpy\n",
"import hvplot.xarray\n",
"import pyinterp\n",
"import dask\n",
"import warnings\n",
"import xrft\n",
"import logging\n",
Expand All @@ -78,17 +75,6 @@
"logger.setLevel(logging.INFO)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cluster = dask.distributed.LocalCluster()\n",
"client = dask.distributed.Client(cluster)\n",
"client"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -198,6 +184,36 @@
"psd_oi1, leaderboard_psds_score, leaderboard_psdt_score = psd_based_scores(ds_oi1_regrid, dc_ref_sample)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Define outputs\n",
"output_directory = '../results/'\n",
"if not os.path.exists(output_directory):\n",
" os.mkdir(output_directory)\n",
"filename_rmse_t = output_directory + 'rmse_t_ssh_reconstruction_2012-10-22-2012-12-02_jason1.nc'\n",
"filename_rmse_xy = output_directory + 'rmse_xy_ssh_reconstruction_2012-10-22-2012-12-02_jason1.nc'\n",
"filename_psd = output_directory + 'psd_ssh_reconstruction_2012-10-22-2012-12-02_jason1.nc'\n",
"filename_dc_ref_sample = output_directory + 'dc_ref_2012-10-22-2012-12-02_sample.nc'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Save results\n",
"rmse_t_oi1.to_netcdf(filename_rmse_t)\n",
"rmse_xy_oi1.to_netcdf(filename_rmse_xy)\n",
"psd_oi1.name = 'psd_score'\n",
"psd_oi1.to_netcdf(filename_psd)\n",
"dc_ref_sample.to_netcdf(filename_dc_ref_sample)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -252,9 +268,7 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# TODO : Add the plot (serie temporelle nrmse, psd score, spatial pattern rmse ????)"
]
"source": []
}
],
"metadata": {
Expand Down
263 changes: 263 additions & 0 deletions notebooks/example_plot_results.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# IV- Demo. plot results"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"An example of data evaluation metrics have been produced in the \"demo_data_eval.ipynb\" notebook. Here, we illustrate the results. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import hvplot.xarray\n",
"import numpy\n",
"import sys"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sys.path.append('..')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from src.mod_plot import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load the reference SSH field"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filename_ssh_reference = '../results/dc_ref_2012-10-22-2012-12-02_sample.nc'\n",
"dc_ref_sample = xr.open_dataset(filename_ssh_reference)\n",
"dc_ref_sample"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load the reconstructed SSH field"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filename_ssh_reconstruction_regridded = '../results/ssh_reconstruction_regridded_2012-10-22-2012-12-02_jason1.nc'\n",
"dc_reconstruction_regridded = xr.open_dataset(filename_ssh_reconstruction_regridded)\n",
"dc_reconstruction_regridded"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filename_ssh_reconstruction = '../results/ssh_reconstruction_2012-10-22-2012-12-02_jason1.nc'\n",
"dc_reconstruction = xr.open_dataset(filename_ssh_reconstruction)\n",
"dc_reconstruction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Display the reference & reconstructed SSH fields"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds_concat = xr.concat((dc_ref_sample, dc_reconstruction_regridded), dim='field')\n",
"ds_concat['field'] = [\"Nature Run\", \"OI Reconstruction\"]\n",
"ds_concat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds_concat.hvplot.image(x='lon', y='lat', cmap='gist_stern', by='field', width=500, height=400, widget_location='bottom', clabel='SSH [m]', subplots=True, clim=(-0.5, 1))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Display the difference SSH_reconstruction minus SSH_reference"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(dc_reconstruction_regridded - dc_ref_sample).hvplot.image(x='lon', y='lat', cmap='coolwarm', width=500, height=400, widget_location='bottom', clabel='dSSH[m]')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Display spatially averaged daily RMSE score (normalized RMSE)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Shows the temporal stability of the reconstuction. A score of 1 means a perfect reconstruction, a zero score means strong incoherency between the reconstruction & reference fields "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filename_rmse_t = '../results/rmse_t_ssh_reconstruction_2012-10-22-2012-12-02_jason1.nc'\n",
"ds = xr.open_dataset(filename_rmse_t)\n",
"ds.rmse_t.hvplot(yaxis='left', title='Spatially averaged daily RMSE', ylim=(0, 1), ylabel='RMSE score')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dc_reconstruction.nobs.hvplot.area(color='grey', title='# obs in OI')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Display temporally averaged RMSE"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Highlight the regions of large/low mean reconstruction errors"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filename_rmse_xy = '../results/rmse_xy_ssh_reconstruction_2012-10-22-2012-12-02_jason1.nc'\n",
"ds = xr.open_dataset(filename_rmse_xy)\n",
"ds.rmse_xy.hvplot(x='lon', y='lat', cmap='Reds', width=500, height=400, clabel='RMSE[m]', title='Temporally averaged RMSE')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Display PSD score"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Highlight the average space-time scales that are resolved in the reconstruction. The boundary is delimited by the iso-contour 0.5 (green area in the figure)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"filename_psd = '../results/psd_ssh_reconstruction_2012-10-22-2012-12-02_jason1.nc'\n",
"ds = xr.open_dataset(filename_psd)\n",
"plot_psd_score(ds)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ds['freq_time'] = 1./ds['freq_time']\n",
"ds['freq_lon'] = 1./ds['freq_lon']\n",
"ds.hvplot.quadmesh(x='freq_lon', y='freq_time', z='psd_score', cmap='RdYlGn',\n",
" clim=(0, 1), logx=False, logy=False, title='PSD-score', width=500, height=400, \n",
" clabel='PSD score', xlabel='wavelenght (degree)', ylabel='wavelenght (days)')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit a9b81c2

Please sign in to comment.