{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## DFO Nutrient Comparison" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sqlalchemy\n", "from sqlalchemy import (create_engine, Column, String, Integer, Float, MetaData, \n", " Table, type_coerce, ForeignKey, case)\n", "from sqlalchemy.orm import mapper, create_session, relationship, aliased, Session\n", "from sqlalchemy.ext.declarative import declarative_base\n", "from sqlalchemy import case\n", "import numpy as np\n", "from sqlalchemy.ext.automap import automap_base\n", "import matplotlib.pyplot as plt\n", "import sqlalchemy.types as types\n", "from sqlalchemy.sql import and_, or_, not_, func\n", "from sqlalchemy.sql import select\n", "import os\n", "from os.path import isfile\n", "import pandas as pd\n", "import netCDF4 as nc\n", "import datetime as dt\n", "from salishsea_tools import evaltools as et, viz_tools\n", "import datetime\n", "import glob\n", "import gsw\n", "import matplotlib.gridspec as gridspec\n", "import matplotlib as mpl\n", "import matplotlib.dates as mdates\n", "\n", "mpl.rc('xtick', labelsize=16)\n", "mpl.rc('ytick', labelsize=16)\n", "mpl.rc('legend', fontsize=12)\n", "mpl.rc('axes', titlesize=16)\n", "mpl.rc('axes', labelsize=16)\n", "mpl.rc('figure', titlesize=16)\n", "mpl.rc('font', size=16)\n", "\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\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", " \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", " \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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
YearMonthDayHourLatLonPressureDepthAmmoniumAmmonium_unitsChlorophyll_ExtractedChlorophyll_Extracted_unitsNSiSilicate_unitsAbsSalTT_unitsZdtUTC
02015.02.011.011.06861148.300833-124.0003331.9NaNNoneNoneNaNmg/m^315.3132.14umol/L29.2275079.7647'deg_C_(ITS90)'1.8839982015-02-11 11:04:07
12015.02.011.011.06861148.300833-124.0003336.6NaNNoneNone2.57mg/m^317.1333.90umol/L29.4843419.6880'deg_C_(ITS90)'6.5443402015-02-11 11:04:07
22015.02.011.011.06861148.300833-124.0003336.7NaNNoneNoneNaNmg/m^3NaNNaNumol/L29.4848399.6828'deg_C_(ITS90)'6.6434952015-02-11 11:04:07
32015.02.011.011.06861148.300833-124.00033311.0NaNNoneNoneNaNmg/m^3NaNNaNumol/L30.1445499.3646'deg_C_(ITS90)'10.9071172015-02-11 11:04:07
42015.02.011.011.06861148.300833-124.00033311.0NaNNoneNoneNaNmg/m^320.6237.65umol/L30.1579139.3586'deg_C_(ITS90)'10.9071172015-02-11 11:04:07
\n", "
" ], "text/plain": [ " Year Month Day Hour Lat Lon Pressure Depth \\\n", "0 2015.0 2.0 11.0 11.068611 48.300833 -124.000333 1.9 NaN \n", "1 2015.0 2.0 11.0 11.068611 48.300833 -124.000333 6.6 NaN \n", "2 2015.0 2.0 11.0 11.068611 48.300833 -124.000333 6.7 NaN \n", "3 2015.0 2.0 11.0 11.068611 48.300833 -124.000333 11.0 NaN \n", "4 2015.0 2.0 11.0 11.068611 48.300833 -124.000333 11.0 NaN \n", "\n", " Ammonium Ammonium_units Chlorophyll_Extracted Chlorophyll_Extracted_units \\\n", "0 None None NaN mg/m^3 \n", "1 None None 2.57 mg/m^3 \n", "2 None None NaN mg/m^3 \n", "3 None None NaN mg/m^3 \n", "4 None None NaN mg/m^3 \n", "\n", " N Si Silicate_units AbsSal T T_units Z \\\n", "0 15.31 32.14 umol/L 29.227507 9.7647 'deg_C_(ITS90)' 1.883998 \n", "1 17.13 33.90 umol/L 29.484341 9.6880 'deg_C_(ITS90)' 6.544340 \n", "2 NaN NaN umol/L 29.484839 9.6828 'deg_C_(ITS90)' 6.643495 \n", "3 NaN NaN umol/L 30.144549 9.3646 'deg_C_(ITS90)' 10.907117 \n", "4 20.62 37.65 umol/L 30.157913 9.3586 'deg_C_(ITS90)' 10.907117 \n", "\n", " dtUTC \n", "0 2015-02-11 11:04:07 \n", "1 2015-02-11 11:04:07 \n", "2 2015-02-11 11:04:07 \n", "3 2015-02-11 11:04:07 \n", "4 2015-02-11 11:04:07 " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "PATH= '/results2/SalishSea/hindcast/'\n", "start_date = datetime.datetime(2015,1,1)\n", "end_date = datetime.datetime(2018,1,1)\n", "flen=1\n", "namfmt='nowcast'\n", "#varmap={'N':'nitrate','Si':'silicon','Ammonium':'ammonium'}\n", "filemap={'nitrate':'ptrc_T','silicon':'ptrc_T','ammonium':'ptrc_T','diatoms':'ptrc_T','ciliates':'ptrc_T','flagellates':'ptrc_T','vosaline':'grid_T','votemper':'grid_T'}\n", "#gridmap={'nitrate':'tmask','silicon':'tmask','ammonium':'tmask'}\n", "fdict={'ptrc_T':1,'grid_T':1}\n", "\n", "df1=et.loadDFO()\n", "df1.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "data=et.matchData(df1,filemap, fdict, start_date, end_date, namfmt, PATH, flen)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig, ax = plt.subplots(figsize = (6,6))\n", "viz_tools.set_aspect(ax, coords = 'map')\n", "ax.plot(data['Lon'], data['Lat'], 'ro',label='data')\n", "ax.plot(data.loc[(data.Lon < -123.5) & (data.Lat < 48.6),['Lon']], \n", " data.loc[(data.Lon < -123.5) & (data.Lat < 48.6),['Lat']], \n", " 'bo', label = 'Juan de Fuca')\n", "\n", "ax.plot(data.loc[data.Si>75,['Lon']],data.loc[data.Si>75,['Lat']],'*',color='y',label='high Si')\n", "grid = nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/bathymetry_201702.nc')\n", "viz_tools.plot_coastline(ax, grid, coords = 'map')\n", "ax.set_ylim(48, 50.5)\n", "ax.legend()\n", "ax.set_xlim(-125.7, -122.5);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2015" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# 2015\n", "data2015=data.loc[(data.dtUTC>=dt.datetime(2015,1,1))&(data.dtUTC=0)|(idata.Si>=0)]\n", "ax3.plot(datanut['Lon'], datanut['Lat'], '.',color='darkorange',label='data',markersize=6)\n", "grid = nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/bathymetry_201702.nc')\n", "viz_tools.plot_coastline(ax3, grid, coords = 'map')\n", "ax3.set_ylim(48, 50.7)\n", "#ax3.legend()\n", "ax3.set_xlim(-125.8, -122.4);\n", "ax3.axis('off')\n", "test=ax3.get_position()\n", "ax3.set_position(mpl.transforms.Bbox(points=[[.7,.2],[.97,.99]]))\n", "\n", "axb.plot(datanut.dtUTC,np.ones(np.shape(datanut.dtUTC)),'.',color='darkorange',markersize=6)\n", "axb.set_yticks(());\n", "yearsFmt = mdates.DateFormatter('%d %b %Y')\n", "axb.xaxis.set_major_formatter(yearsFmt)\n", "axb.xaxis.set_ticks([dt.datetime(int(yy),1,1), dt.datetime(int(yy),4,1),dt.datetime(int(yy),7,1),dt.datetime(int(yy),10,1),dt.datetime(int(yy)+1,1,1)])\n", "#axb.autofmt_xdate(bottom=0.2, rotation=15, ha='right')\n", "#axb.set_title('Sampling Dates')\n", "#plt.setp(plt.xticks()[1], rotation=10, ha='right')\n", "axb.set_title('Sample Dates')\n", "#fig.savefig('/home/eolson/pyCode/notebooks/figs/EvalDFO2015.png',dpi=200,transparent=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2016" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# 2016\n", "data2016=data.loc[(data.dtUTC>=dt.datetime(2016,1,1))&(data.dtUTC=0)|(idata.Si>=0)]\n", "ax3.plot(datanut['Lon'], datanut['Lat'], '.',color='darkorange',label='data',markersize=6)\n", "grid = nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/bathymetry_201702.nc')\n", "viz_tools.plot_coastline(ax3, grid, coords = 'map')\n", "ax3.set_ylim(48, 50.7)\n", "#ax3.legend()\n", "ax3.set_xlim(-125.8, -122.4);\n", "ax3.axis('off')\n", "test=ax3.get_position()\n", "ax3.set_position(mpl.transforms.Bbox(points=[[.7,.2],[.97,.99]]))\n", "\n", "axb.plot(datanut.dtUTC,np.ones(np.shape(datanut.dtUTC)),'.',color='darkorange',markersize=6)\n", "axb.set_yticks(());\n", "yearsFmt = mdates.DateFormatter('%d %b %Y')\n", "axb.xaxis.set_major_formatter(yearsFmt)\n", "axb.xaxis.set_ticks([dt.datetime(int(yy),1,1), dt.datetime(int(yy),4,1),dt.datetime(int(yy),7,1),dt.datetime(int(yy),10,1),dt.datetime(int(yy)+1,1,1)])\n", "#axb.autofmt_xdate(bottom=0.2, rotation=15, ha='right')\n", "#axb.set_title('Sampling Dates')\n", "#plt.setp(plt.xticks()[1], rotation=10, ha='right')\n", "axb.set_title('Sample Dates')\n", "#fig.savefig('/home/eolson/pyCode/notebooks/figs/EvalDFO2016.png',dpi=200,transparent=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 2017" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# 2017\n", "data2016=data.loc[(data.dtUTC>=dt.datetime(2016,1,1))&(data.dtUTC=0)|(idata.Si>=0)]\n", "ax3.plot(datanut['Lon'], datanut['Lat'], '.',color='darkorange',label='data',markersize=6)\n", "grid = nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/bathymetry_201702.nc')\n", "viz_tools.plot_coastline(ax3, grid, coords = 'map')\n", "ax3.set_ylim(48, 50.7)\n", "#ax3.legend()\n", "ax3.set_xlim(-125.8, -122.4);\n", "ax3.axis('off')\n", "test=ax3.get_position()\n", "ax3.set_position(mpl.transforms.Bbox(points=[[.7,.2],[.97,.99]]))\n", "\n", "axb.plot(datanut.dtUTC,np.ones(np.shape(datanut.dtUTC)),'.',color='darkorange',markersize=6)\n", "axb.set_yticks(());\n", "yearsFmt = mdates.DateFormatter('%d %b %Y')\n", "axb.xaxis.set_major_formatter(yearsFmt)\n", "axb.xaxis.set_ticks([dt.datetime(int(yy),1,1), dt.datetime(int(yy),4,1),dt.datetime(int(yy),7,1),dt.datetime(int(yy),10,1),dt.datetime(int(yy)+1,1,1)])\n", "#axb.autofmt_xdate(bottom=0.2, rotation=15, ha='right')\n", "#axb.set_title('Sampling Dates')\n", "#plt.setp(plt.xticks()[1], rotation=10, ha='right')\n", "axb.set_title('Sample Dates')\n", "#fig.savefig('/home/eolson/pyCode/notebooks/figs/EvalDFO2016.png',dpi=200,transparent=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Chl" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "data['l10_obsChl']=np.log10(data['Chlorophyll_Extracted']+0.01)\n", "data['l10_modChl']=np.log10(2*(data['mod_diatoms']+data['mod_ciliates']+data['mod_flagellates'])+0.01)\n", "data['mod_Chl']=2*(data['mod_diatoms']+data['mod_ciliates']+data['mod_flagellates'])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig = plt.figure(figsize = (12,4.5))\n", "gs1 = gridspec.GridSpec(1,3,left=.1,right=.96,wspace=.5,bottom=.15,top=.85,width_ratios=[4,4,1])\n", "ax1 = fig.add_subplot(gs1[0])\n", "ax2 = fig.add_subplot(gs1[1])\n", "chtick=np.arange(-2,2.1,1)\n", "chtickl=[str(i) for i in chtick]\n", "\n", "data2015=data.loc[(data.dtUTC>=dt.datetime(2015,1,1))&(data.dtUTC=dt.datetime(2016,1,1))&(data.dtUTC