diff --git a/notebooks/3-Analysis/14-cpme-demo.ipynb b/notebooks/3-Analysis/14-cpme-demo.ipynb
index 0f5e029..c768fb8 100644
--- a/notebooks/3-Analysis/14-cpme-demo.ipynb
+++ b/notebooks/3-Analysis/14-cpme-demo.ipynb
@@ -155,13 +155,18 @@
{
"cell_type": "markdown",
"metadata": {
- "collapsed": true
+ "collapsed": true,
+ "jupyter": {
+ "outputs_hidden": true
+ }
},
"source": [
"### Analysis\n",
"Analysis parameters have been calibrated in the other notebook [13-processing-parameter-optimization example.ipynb](13-processing-parameter-optimization). \n",
"\n",
- "⚠ if the statistical parameters are incorrectly estimated, the error fields are meaningless and only provide an idea of data coverage.\n",
+ "
\n",
+ " ⚠ If the statistical parameters are incorrectly estimated, the error fields are meaningless and only provide an idea of data coverage.\n",
+ "
\n",
"\n",
"The analysis parameters are:"
]
@@ -173,7 +178,7 @@
"outputs": [],
"source": [
"len = 0.3\n",
- "epsilon2 = 1.0;"
+ "epsilon2 = 1.4;"
]
},
{
@@ -224,21 +229,11 @@
"source": [
"## Exact error and approximations\n",
"\n",
- "Details can be found in the publication:\n",
+ " \n",
+ "NOTE Details can be found in the publication mentioned at the beginning of the notebook.\n",
+ "
\n",
"\n",
- "> Approximate and Efficient Methods to Assess Error Fields in Spatial Gridding with Data Interpolating Variational Analysis (DIVA) \n",
- "Beckers, Jean-Marie; Barth, Alexander; Troupin, Charles, Alvera-Azcarate, A. *Journal of Atmospheric & Oceanic Technology* (2014), **31(2)**, 515-530 \n",
- "https://orbi.uliege.be/handle/2268/161069 \n",
- "https://journals.ametsoc.org/doi/abs/10.1175/JTECH-D-13-00130.1"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "In the 2D case you can try to calculate the exact error expression. This demands the computationally expensive evaluation of `diag(s.P)` accessible via the analysis returned structure `s`. This is only available with `DIVAndrun`.\n",
- "\n",
- "We define a function that will be run to plot the error field."
+ "First we define a utility function for plotting."
]
},
{
@@ -261,6 +256,15 @@
"end"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Exact error by hand\n",
+ "\n",
+ "In the 2D case you can try to calculate the exact error expression. This demands the computationally expensive evaluation of `diag(s.P)` accessible via the analysis returned structure `s`. The latter is only available with `DIVAndrun`."
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,
@@ -268,7 +272,7 @@
"outputs": [],
"source": [
"exerr, = statevector_unpack(s.sv,diag(s.P),NaN)\n",
- "ploterr(exerr, figtitle= \"Unscaled error\")"
+ "ploterr(exerr, figtitle= \"Error using P, scaled by global background variance\")"
]
},
{
@@ -306,7 +310,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Do you see any difference between the exact and clever poor man's error ? \n",
+ "Do you see any difference between the exact and clever poor man's error ? "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
"## Difference between error fields"
]
},
@@ -376,15 +386,12 @@
"source": [
"# Conclusion\n",
"In view of the uncertainties on statistical parameters (L, $\\epsilon^2$), the *clever poor man's error* is generally a sufficient approximation for the error fields. \n",
- "This is the one implemented in the `DIVAndgo` high-level analysis function. "
+ "This is the one implemented in the `DIVAndgo` high-level analysis function. \n",
+ "\n",
+ " \n",
+ "NOTE The next notebook will focus on another function, `DIVAnd_errormap` to evaluate the error field.\n",
+ "
"
]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
}
],
"metadata": {
@@ -419,5 +426,5 @@
}
},
"nbformat": 4,
- "nbformat_minor": 1
+ "nbformat_minor": 4
}
diff --git a/notebooks/3-Analysis/14b-errormaps-demo.ipynb b/notebooks/3-Analysis/14b-errormaps-demo.ipynb
index b933942..6cc2e1d 100644
--- a/notebooks/3-Analysis/14b-errormaps-demo.ipynb
+++ b/notebooks/3-Analysis/14b-errormaps-demo.ipynb
@@ -22,7 +22,9 @@
"outputs": [],
"source": [
"using DIVAnd\n",
- "using PyPlot\n",
+ "using Makie\n",
+ "using CairoMakie\n",
+ "using GeoMakie\n",
"using Dates\n",
"using Statistics\n",
"using LinearAlgebra\n",
@@ -103,14 +105,14 @@
"metadata": {},
"outputs": [],
"source": [
- "bx,by,b = load_bath(bathname,true,lonr,latr);"
+ "bx, by, b = load_bath(bathname,true,lonr,latr);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "Create a land-sea mask based on the bathymetry."
+ "Create a land-sea mask based on the bathymetry at 1 meter depth."
]
},
{
@@ -125,7 +127,9 @@
" for i = 1:size(b,1)\n",
" mask[i,j] = b[i,j] >=1.0\n",
" end\n",
- "end"
+ "end\n",
+ "\n",
+ "plot_mask(bx, by, mask)"
]
},
{
@@ -165,9 +169,11 @@
},
"source": [
"### Analysis\n",
- "Analysis parameters have been calibrated in the other notebook [13-processing-parameter-optimization example.ipynb](13-processing-parameter-optimization). \n",
+ "The parameters have been calibrated in the other notebook [13-processing-parameter-optimization example.ipynb](13-processing-parameter-optimization). \n",
"\n",
- "#### ⚠ if the statistical parameters are incorrectly estimated, the error fields are meaningless and only provide an idea of data coverage.\n",
+ " \n",
+ " ⚠ If the statistical parameters are incorrectly estimated, the error fields are meaningless and only provide an idea of data coverage.\n",
+ "
\n",
"\n",
"The analysis parameters are:"
]
@@ -179,7 +185,7 @@
"outputs": [],
"source": [
"len = 0.3\n",
- "epsilon2 = 1.4"
+ "epsilon2 = 1.4;"
]
},
{
@@ -204,7 +210,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Create a simple plot of the analysis"
+ "### Create a simple plot of the analysis"
]
},
{
@@ -213,11 +219,16 @@
"metadata": {},
"outputs": [],
"source": [
- "pcolor(xi,yi,fi.+mean(obsval),vmin=37,vmax=38.5,shading=\"nearest\");\n",
- "colorbar(orientation=\"horizontal\")\n",
- "contourf(bx,by,copy(b'), levels = [-1e5,0],colors = [[.5,.5,.5]])\n",
- "aspectratio = 1/cos(mean([ylim()...]) * pi/180)\n",
- "gca().set_aspect(aspectratio)"
+ "fig = Figure(size = (600, 350))\n",
+ "ga = GeoAxis(fig[1, 1]; dest = \"+proj=merc\", title = \"Analysis\", \n",
+ "xticks=2.:1.:14, yticks=42.:1.:45.)\n",
+ "heatmap!(ga, bx, by, mask, colormap=Reverse(:binary))\n",
+ "hm = heatmap!(ga, lonr, latr, fi .+ mean(obsval), interpolate = false, colorrange=[37., 38.5])\n",
+ "# sc = scatter!(obslon, obslat, color=obsval, markersize=7, colorrange=[37., 38.5])\n",
+ "xlims!(ga, (bx[1], bx[end]))\n",
+ "ylims!(ga, (by[1], by[end]))\n",
+ "Colorbar(fig[2, 1], hm, vertical = false, label = \"S\")\n",
+ "fig"
]
},
{
@@ -226,18 +237,11 @@
"source": [
"## Exact error and approximations\n",
"\n",
- "Details can be found in the publication:\n",
+ " \n",
+ "NOTE Details can be found in the publication mentioned at the beginning of the notebook.\n",
+ "
\n",
"\n",
- "Approximate and Efficient Methods to Assess Error Fields in Spatial Gridding with Data Interpolating Variational Analysis (DIVA) Beckers, Jean-Marie; Barth, Alexander; Troupin, Charles, Alvera-Azcarate, A. *Journal of Atmospheric & Oceanic Technology* (2014), **31(2)**, 515-530 \n",
- "https://orbi.uliege.be/handle/2268/161069 \n",
- "https://journals.ametsoc.org/doi/abs/10.1175/JTECH-D-13-00130.1"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "First we define a utility function for plotting"
+ "First we define a utility function for plotting."
]
},
{
@@ -246,14 +250,17 @@
"metadata": {},
"outputs": [],
"source": [
- "# plots the error field `exerr`\n",
- "function ploterr(exerr; vmin=0, vmax=1.5, cmap=\"hot_r\")\n",
- " pcolor(xi,yi,exerr,vmin=vmin, vmax=vmax, cmap=cmap,shading=\"nearest\");\n",
- " colorbar(orientation=\"horizontal\")\n",
- " contourf(bx,by,copy(b'), levels = [-1e5,0],colors = [[.5,.5,.5]])\n",
- " plot(obslon, obslat, \"k.\", markersize=.5)\n",
- " ylim(extrema(yi))\n",
- " gca().set_aspect(1/cos(mean([ylim()...]) * pi/180))\n",
+ "function ploterr(exerr; vmin=0, vmax=1.5, cmap=Reverse(:hot), figtitle=\"Error field\")\n",
+ " fig = Figure(size = (600, 350))\n",
+ " ga = GeoAxis(fig[1, 1]; dest = \"+proj=merc\", title = figtitle, \n",
+ " xticks=2.:1.:14, yticks=42.:1.:45.)\n",
+ " heatmap!(ga, bx, by, mask, colormap=Reverse(:binary))\n",
+ " hm = heatmap!(ga, lonr, latr, exerr, colormap=cmap, interpolate = false, colorrange=[vmin, vmax])\n",
+ " # sc = scatter!(obslon, obslat, color=obsval, markersize=7, colorrange=[37., 38.5])\n",
+ " xlims!(ga, (bx[1], bx[end]))\n",
+ " ylims!(ga, (by[1], by[end]))\n",
+ " Colorbar(fig[2, 1], hm, vertical = false)\n",
+ " fig\n",
"end"
]
},
@@ -302,21 +309,15 @@
"metadata": {},
"outputs": [],
"source": [
- "ploterr(aerrora)\n",
- "title(\"Error using errormap version $method\");"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Other options"
+ "ploterr(aerrora, figtitle=\"Error using errormap version $method\")"
]
},
{
+ "attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
+ "# Other options\n",
"## Precise version, actual method chosen will depend on data coverage"
]
},
@@ -330,8 +331,7 @@
" s;\n",
" method = :precise,\n",
" Bscale = false)\n",
- "ploterr(aerror)\n",
- "title(\"Error using automatic version $method\");"
+ "ploterr(aerror, figtitle=\"Error using automatic version $method\")"
]
},
{
@@ -348,33 +348,37 @@
"metadata": {},
"outputs": [],
"source": [
- "ploterr(aerror-exerr,vmin=-0.2, vmax=0.2, cmap=\"RdBu_r\")\n",
- "title(\"Error on error\");"
+ "ploterr(aerror-exerr,vmin=-0.2, vmax=0.2, cmap=Reverse(:RdYlBu), figtitle=\"Error on error\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "### Other options for method are `:auto`, `:cheap`, `:precise`, `:cpme`, `:scpme`, `:exact`, `:aexerr`, `:diagapp`\n",
- " \n",
- " \n",
- " `:cheap` will automatically chose between `:scpme` (for a lot of data) or `:cpme` (for a few isolated data points) \n",
- " `:precise` will automatically chose between the methods very close to the exact version."
+ "### Other options \n",
+ "The method offers other options:\n",
+ "- `:auto`, \n",
+ "- `:cheap` will automatically chose between `:scpme` (for a lot of data) or `:cpme` (for a few isolated data points) \n",
+ "- `:precise` will automatically chose between the methods very close to the exact version.\n",
+ "- `:cpme`,\n",
+ "- `:scpme`,\n",
+ "- `:exact`,\n",
+ "- `:aexerr`,\n",
+ "- `:diagapp`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "## How to plot standart deviations ?"
+ "## How to plot standard deviations ?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "Error fields shown above are error variance divided by a global background error variance $\\sigma^2$. The latter is difficult to assess but a simple practical way is to use data variance VAR and split it into background error variance $\\sigma^2$ and observational error variance $\\epsilon^2$, assuming the $epsilon2$ value is correct ($epsilon2$ is the parameter used in DIVAndrun and is the relative observational error variance). VAR is the total variance of your data.\n",
+ "Error fields shown above are error variance divided by a global background error variance $\\sigma^2$. The latter is difficult to assess but a simple practical way is to use data variance VAR and split it into background error variance $\\sigma^2$ and observational error variance $\\epsilon^2$, assuming the $epsilon2$ value is correct ($epsilon2$ is the parameter used in `DIVAndrun` and is the relative observational error variance). VAR is the total variance of your data.\n",
"\n",
"$epsilon2$ = ${ \\epsilon^2 \\over \\sigma^2 } $\n",
"\n",
@@ -386,8 +390,11 @@
"\n",
"$\\epsilon^2$= $ {epsilon2 \\over 1 + epsilon2 }$ VAR\n",
"\n",
+ "If you are not sure about the value of $epsilon2$ you might consider using `DIVAnd_adaptedeps2(s, fi)`. \n",
"\n",
- "If you are not sure about the value of $epsilon2$ you might consider using `DIVAnd_adaptedeps2(s, fi)` . Note that if you do this and see a completely different value of $epsilon2$, you should probably rerun the analysis and error calculation before trying to get the absolute errors."
+ " \n",
+ "NOTE If you do this and see a completely different value of $epsilon2$, you should probably rerun the analysis and error calculation before trying to get the absolute errors.\n",
+ "
"
]
},
{
@@ -410,8 +417,7 @@
"outputs": [],
"source": [
"myabserror=sqrt.(sig2.*aerror)\n",
- "ploterr(myabserror,vmin=0.0,vmax=2*sqrt(sig2))\n",
- "title(\"Standard deviation\");"
+ "ploterr(myabserror,vmin=0.0,vmax=2*sqrt(sig2), figtitle=\"Standard deviation\")"
]
},
{
@@ -455,13 +461,19 @@
"# That is the error variance of the mean, still scaled by the background error variance (no units)"
]
},
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Now scale by estimate of $\\sigma^2$ and take square root:"
+ ]
+ },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
- "# now scale by estimate of $\\sigma^2$ and take square root\n",
"myabserror=sqrt(sig2*erronmean)"
]
},
@@ -513,7 +525,10 @@
"source": [
"# Warning\n",
"\n",
- "Always keep in mind that all error estimates are heavily relying on statistical hypothesis and in particular the parameters of the analysis. Just try to rerun the notebook by changing the parameters and possibly deactivate the update of epsilon2"
+ " \n",
+ "⚠️ Always keep in mind that all error estimates are heavily relying on statistical hypothesis and in particular the parameters of the analysis.
\n",
+ "Just try to rerun the notebook by changing the parameters and possibly deactivate the update of epsilon2\n",
+ "
"
]
},
{
@@ -531,11 +546,16 @@
"metadata": {},
"outputs": [],
"source": [
- "pcolor(xi,yi,fij.+mean(obsval),vmin=37,vmax=38.5,shading=\"nearest\");\n",
- "colorbar(orientation=\"horizontal\")\n",
- "contourf(bx,by,copy(b'), levels = [-1e5,0],colors = [[.5,.5,.5]])\n",
- "aspectratio = 1/cos(mean([ylim()...]) * pi/180)\n",
- "gca().set_aspect(aspectratio)"
+ "fig = Figure(size = (600, 350))\n",
+ "ga = GeoAxis(fig[1, 1]; dest = \"+proj=merc\", title = \"Analysis\", \n",
+ "xticks=2.:1.:14, yticks=42.:1.:45.)\n",
+ "heatmap!(ga, bx, by, mask, colormap=Reverse(:binary))\n",
+ "hm = heatmap!(ga, lonr, latr, fij .+ mean(obsval), interpolate = false, colorrange=[37., 38.5])\n",
+ "# sc = scatter!(obslon, obslat, color=obsval, markersize=7, colorrange=[37., 38.5])\n",
+ "xlims!(ga, (bx[1], bx[end]))\n",
+ "ylims!(ga, (by[1], by[end]))\n",
+ "Colorbar(fig[2, 1], hm, vertical = false, label = \"S\")\n",
+ "fig"
]
}
],