{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Ocean Color Classifications\n", "\n", "Here we apply simple & standard classifiers to `ocean color data` over a wide region. \n", "\n", "_Credit: sample data file was provided by T. Jackson from [Plymouth Marine Lab](https://www.pml.ac.uk)_\n", "\n", "\"Drawing\"" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### Activate packages for later use\n", "\n", "It is assumed that listed packages have aleary been installed using `julia`'s package manager (documentation available [here](https://docs.julialang.org/en/)). " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "using OceanColorData, Plots, NCDatasets" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### Observed wavebands\n", "\n", "Currently, the `OC-CCI` [satellite data set](https://esa-oceancolour-cci.org) provides remotely sensed reflectance at 6 wavelengths (`wv_cci` in `nm`)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "wv_cci=[412, 443, 490, 510, 555, 670];" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "### Optical classification using reflectances\n", "\n", "`Fuzzy logic` classifiers defined in [Moore et al 2009](https://doi.org/10.1016/j.rse.2009.07.016) and [Jackson et al 2017](http://dx.doi.org/10.1016/j.rse.2017.03.036) can be used to assign optical class memberships from an `Rrs` vector. While Moore et al define `n=8` classes using an in-situ database, Jackson et al instead define `n=14` classes using a satellite database. The latter benefits from better data coverage across all of the ecological provinces of the global ocean and is used in `OC-CCI`. \n", "\n", "In both cases the classifier is encoded in a mean reflectance spectra (`M[i][1:6]`) and a covariance matrix (`S[i][1:6,1:6]`) provided for each optical class (`i` in `1:n`). Class memberships are then derived by computing the squared Mahalanobis distance to each `M[i]` and passing the result to cumulative chi-squared distribution function (Equations 11 and 12 in [Moore et al 2011](https://doi.org/10.1109/36.942555))." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [], "source": [ "(M,Sinv)=Jackson2017();" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Read In Data Sample\n", "\n", "_Credit: sample data file was provided by T. Jackson from [Plymouth Marine Lab](https://www.pml.ac.uk)_" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "dir0=\"../samples/\"; \n", "fil=dir0*\"ESACCI-OC-RRS-sample-fv4.0.nc\"\n", "ds = Dataset(fil)\n", "\n", "Rrs_412=ds[\"Rrs_412\"]; Rrs_443=ds[\"Rrs_443\"]; Rrs_490=ds[\"Rrs_490\"]; \n", "Rrs_510=ds[\"Rrs_510\"]; Rrs_555=ds[\"Rrs_555\"]; Rrs_670=ds[\"Rrs_670\"];\n", "lon=ds[\"lon\"]; lat=ds[\"lat\"];" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "subslide" } }, "source": [ "Plot one of the wave bands as an example." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "-60\n", "\n", "\n", "-50\n", "\n", "\n", "-40\n", "\n", "\n", "-30\n", "\n", "\n", "-20\n", "\n", "\n", "-10\n", "\n", "\n", "30\n", "\n", "\n", "40\n", "\n", "\n", "50\n", "\n", "\n", "60\n", "\n", "\n", "Rrs at 490nm\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "0.0025\n", "\n", "\n", "0.0050\n", "\n", "\n", "0.0075\n", "\n", "\n", "0.0100\n", "\n", "\n", "0.0125\n", "\n", "\n", "0.0150\n", "\n", "\n", "0.0175\n", "\n", "\n", "0.0200\n", "\n", "\n", "\n" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c=transpose(reverse(ds[\"Rrs_490\"][:,:,1],dims=2))\n", "heatmap(lon,reverse(lat),c,title=\"Rrs at 490nm\")" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Compute memberships\n", "\n", "Apply Classification to our 2D data sample and plot out a map." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "lines_to_next_cell": 0 }, "outputs": [], "source": [ "#Find points that have a full set of input\n", "tmp=fill(false,size(Rrs_412))\n", "for ii in eachindex(Rrs_412)\n", " !ismissing(Rrs_412[ii]) ? tmp[ii]=!ismissing(Rrs_443[ii].*Rrs_490[ii].*Rrs_510[ii].*Rrs_555[ii].*Rrs_670[ii]) : nothing\n", "end\n", "ii=findall(tmp);\n", "\n", "#Apply classifier\n", "mbrshp=fill(NaN,(1440,960,14))\n", "for jj=1:length(ii); \n", " kk=ii[jj]\n", " Rrs_tmp=[Rrs_412[kk] Rrs_443[kk] Rrs_490[kk] Rrs_510[kk] Rrs_555[kk] Rrs_670[kk]]\n", " mbrshp[kk[1],kk[2],:]=FuzzyClassification(M,Sinv,vec(Rrs_tmp))\n", "end" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "slideshow": { "slide_type": "subslide" } }, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "-60\n", "\n", "\n", "-50\n", "\n", "\n", "-40\n", "\n", "\n", "-30\n", "\n", "\n", "-20\n", "\n", "\n", "-10\n", "\n", "\n", "30\n", "\n", "\n", "40\n", "\n", "\n", "50\n", "\n", "\n", "60\n", "\n", "\n", "Membership for class 10\n", "\n", "\n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "0\n", "\n", "\n", "0.1\n", "\n", "\n", "0.2\n", "\n", "\n", "0.3\n", "\n", "\n", "0.4\n", "\n", "\n", "0.5\n", "\n", "\n", "0.6\n", "\n", "\n", "0.7\n", "\n", "\n", "0.8\n", "\n", "\n", "0.9\n", "\n", "\n", "\n" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c=transpose(reverse(mbrshp[:,:,10],dims=2))\n", "heatmap(lon,reverse(lat),c,title=\"Membership for class 10\")" ] } ], "metadata": { "@webio": { "lastCommId": null, "lastKernelId": null }, "celltoolbar": "Slideshow", "jupytext": { "formats": "ipynb,jl:light" }, "kernelspec": { "display_name": "Julia 1.3.1", "language": "julia", "name": "julia-1.3" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.3.1" }, "rise": { "enable_chalkboard": true } }, "nbformat": 4, "nbformat_minor": 4 }