{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import os\n", "import pickle\n", "from collections import OrderedDict" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# note to self: 'Lateral Transport, Advection' and 'Lateral Transport, Mixing' are of NO3 only" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "sums=dict()\n", "sums[2015]=pickle.load( open( \"sums2015.pkl\", \"rb\" ) )\n", "sums[2016]=pickle.load( open( \"sums2016.pkl\", \"rb\" ) )\n", "sums[2017]=pickle.load( open( \"sums2017.pkl\", \"rb\" ) )" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "dict_keys(['Lateral Transport, Advection', 'Lateral Transport, Mixing', 'Rivers NO3', 'NO3-based Primary Production', 'NH4-based Primary Production', 'Nitrification', 'Net change', 'DIN (NH4+NO3) from Rivers', 'Haro Strait NO3', 'Haro Strait NH4', 'Haro Strait DIN', 'Haro Strait PON', 'Haro Strait DON', 'Haro Strait Living', 'Southern NO3', 'Southern NH4', 'Southern DIN', 'Southern PON', 'Southern DON', 'Southern Living', 'Northern NO3', 'Northern NH4', 'Northern DIN', 'Northern PON', 'Northern DON', 'Northern Living', 'PON&DON->NH4', 'To Refractory N', 'Bottom flux diatoms', 'Bottom flux PON', 'Deep Haro Strait NO3', 'Deep Haro Strait NH4', 'Deep Haro Strait DIN', 'Deep Haro Strait PON', 'Deep Haro Strait DON', 'Deep Haro Strait Living', 'Net change NO3'])\n", "Lateral Transport, Advection\n", "Lateral Transport, Mixing\n", "Rivers NO3\n", "NO3-based Primary Production\n", "NH4-based Primary Production\n", "Nitrification\n", "Net change\n", "DIN (NH4+NO3) from Rivers\n", "Haro Strait NO3\n", "Haro Strait NH4\n", "Haro Strait DIN\n", "Haro Strait PON\n", "Haro Strait DON\n", "Haro Strait Living\n", "Southern NO3\n", "Southern NH4\n", "Southern DIN\n", "Southern PON\n", "Southern DON\n", "Southern Living\n", "Northern NO3\n", "Northern NH4\n", "Northern DIN\n", "Northern PON\n", "Northern DON\n", "Northern Living\n", "PON&DON->NH4\n", "To Refractory N\n", "Bottom flux diatoms\n", "Bottom flux PON\n", "Deep Haro Strait NO3\n", "Deep Haro Strait NH4\n", "Deep Haro Strait DIN\n", "Deep Haro Strait PON\n", "Deep Haro Strait DON\n", "Deep Haro Strait Living\n", "Net change NO3\n" ] } ], "source": [ "print(sums[2015].keys())\n", "for el in sums[2015].keys():\n", " print(el)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(' '.strip())" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "def kmps(Gmolperday):\n", " # non leap years\n", " #convert Gmol/year to kmol/s\n", " # Gmol/yr* 1e6 kmol/Gmol * 1/(3600*24*365 s/yr)\n", " kmolpers=Gmolperday*1e6/(3600*24*365)\n", " return kmolpers\n", "def kmps16(Gmolperday):\n", " # 2016 was leap year\n", " #convert Gmol/year to kmol/s\n", " # Gmol/yr* 1e6 kmol/Gmol * 1/(3600*24*366 s/yr)\n", " kmolpers=Gmolperday*1e6/(3600*24*366)\n", " return kmolpers" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "class tblList:\n", " # Initializer / Instance Attributes\n", " def __init__(self, headings, fname):\n", " self.lines = list()\n", " self.lines.append(r' \\small'+'\\n')\n", " self.lines.append(r' \\centering'+'\\n')\n", " self.lines.append(r' \\begin{tabular}{lrcccccccc}\\toprule'+'\\n')\n", " self.lines.append(r' & & & \\multicolumn{3}{c}{ kmol N s$^{-1}$ } & & \\multicolumn{3}{c}{ Gmol N yr$^{-1}$ } \\\\'+'\\n')\n", " if len(headings[0].strip())>0:\n", " self.lines.append(f' \\multicolumn{{2}}{{l}}{{ {headings[0]} }} & \\phantom{{a}} & {headings[1]} & {headings[2]} & {headings[3]}& \\phantom{{a}} & {headings[1]} & {headings[2]} & {headings[3]} \\\\\\\\ \\midrule'+'\\n')\n", " else:\n", " self.lines.append(f' & & \\phantom{a} & {headings[1]} & {headings[2]} & {headings[3]} & \\phantom{a} & {headings[1]} & {headings[2]} & {headings[3]} \\\\\\\\ \\midrule'+'\\n')\n", " self.fname = fname\n", " \n", " def addlines(self,heading,val2015,val2016,val2017):\n", " if val2015>10:\n", " self.lines.append(f' \\multicolumn{{2}}{{l}}{{ {heading} }} & & {kmps(val2015):.2f} & {kmps16(val2016):.2f} & {kmps(val2017):.2f} & & {val2015:.1f} & {val2016:.1f} & {val2017:.1f} \\\\\\\\'+'\\n')\n", " else:\n", " self.lines.append(f' \\multicolumn{{2}}{{l}}{{ {heading} }} & & {kmps(val2015):.3f} & {kmps16(val2016):.3f} & {kmps(val2017):.3f} & & {val2015:.2f} & {val2016:.2f} & {val2017:.2f} \\\\\\\\'+'\\n')\n", "\n", " def addlinesSub(self,heading,val2015,val2016,val2017):\n", " if val2015>10:\n", " self.lines.append(f' & {heading} & & {kmps(val2015):.2f} & {kmps16(val2016):.2f} & {kmps(val2017):.2f} & & {val2015:.1f} & {val2016:.1f} & {val2017:.1f} \\\\\\\\'+'\\n')\n", " else:\n", " self.lines.append(f' & {heading} & & {kmps(val2015):.3f} & {kmps16(val2016):.3f} & {kmps(val2017):.3f} & & {val2015:.2f} & {val2016:.2f} & {val2017:.2f} \\\\\\\\'+'\\n')\n", " \n", " def finish(self):\n", " self.lines.append(r' \\midrule'+'\\n')\n", " self.lines.append(r' \\\\ \\\\')\n", " self.lines.append(r' \\end{tabular}'+'\\n')\n", " \n", " def write(self):\n", " f = open(self.fname, 'w')\n", " f.writelines(self.lines)\n", " f.close()" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "tbl=tblList(('Budget Component','2015','2016','2017'),'fluxesTBL.tex')\n", "tbl.addlines('Primary Production',\n", " -1*(sums[2015]['NO3-based Primary Production']+sums[2015]['NH4-based Primary Production']),\n", " -1*(sums[2016]['NO3-based Primary Production']+sums[2016]['NH4-based Primary Production']),\n", " -1*(sums[2017]['NO3-based Primary Production']+sums[2017]['NH4-based Primary Production']))\n", "tbl.addlinesSub(' NO$_3$-based',\n", " -1*sums[2015]['NO3-based Primary Production'],\n", " -1*sums[2016]['NO3-based Primary Production'],\n", " -1*sums[2017]['NO3-based Primary Production'])\n", "tbl.addlinesSub(' NH$_4$-based',\n", " -1*sums[2015]['NH4-based Primary Production'],\n", " -1*sums[2016]['NH4-based Primary Production'],\n", " -1*sums[2017]['NH4-based Primary Production'])\n", "tbl.addlines('Remineralization (to NH$_4$)',\n", " -1*sums[2015]['PON&DON->NH4'],\n", " -1*sums[2016]['PON&DON->NH4'],\n", " -1*sums[2017]['PON&DON->NH4'])\n", "tbl.addlines('Nitrification',\n", " sums[2015]['Nitrification'],\n", " sums[2016]['Nitrification'],\n", " sums[2017]['Nitrification'])\n", "#tbl.addlines('Remineralization (to NH$_4$)',\n", "# sums[2015]['PON&DON->NH4'],\n", "# sums[2016]['PON&DON->NH4'],\n", "# sums[2017]['PON&DON->NH4'])\n", "#tbl.addlines('Loss to Refractory Pool',\n", "# sums[2015]['To Refractory N'],\n", "# sums[2016]['To Refractory N'],\n", "# sums[2017]['To Refractory N'])\n", "tbl.addlines('Loss to Sediments',\n", " -1*(sums[2015]['Bottom flux diatoms']+sums[2015]['Bottom flux PON']),\n", " -1*(sums[2016]['Bottom flux diatoms']+sums[2016]['Bottom flux PON']),\n", " -1*(sums[2017]['Bottom flux diatoms']+sums[2017]['Bottom flux PON']))\n", "tbl.addlinesSub(' diatoms',\n", " -1*sums[2015]['Bottom flux diatoms'],\n", " -1*sums[2016]['Bottom flux diatoms'],\n", " -1*sums[2017]['Bottom flux diatoms'])\n", "tbl.addlinesSub(' detrital PON',\n", " -1*sums[2015]['Bottom flux PON'],\n", " -1*sums[2016]['Bottom flux PON'],\n", " -1*sums[2017]['Bottom flux PON'])\n", "tbl.addlines('Rivers (DIN)',\n", " sums[2015]['DIN (NH4+NO3) from Rivers'],\n", " sums[2016]['DIN (NH4+NO3) from Rivers'],\n", " sums[2017]['DIN (NH4+NO3) from Rivers'])\n", "tbl.addlinesSub('NO$_3$',\n", " sums[2015]['Rivers NO3'],\n", " sums[2016]['Rivers NO3'],\n", " sums[2017]['Rivers NO3'])\n", "tbl.addlinesSub('NH$_4$',\n", " sums[2015]['DIN (NH4+NO3) from Rivers']-sums[2015]['Rivers NO3'],\n", " sums[2016]['DIN (NH4+NO3) from Rivers']-sums[2016]['Rivers NO3'],\n", " sums[2017]['DIN (NH4+NO3) from Rivers']-sums[2017]['Rivers NO3'])\n", "tbl.addlines('Deep Transport, Haro Strait',\n", " sums[2015]['Deep Haro Strait NO3']+sums[2015]['Deep Haro Strait NH4']+\\\n", " sums[2015]['Deep Haro Strait PON']+sums[2015]['Deep Haro Strait DON']+sums[2015]['Deep Haro Strait Living'],\n", " sums[2016]['Deep Haro Strait NO3']+sums[2016]['Deep Haro Strait NH4']+\\\n", " sums[2016]['Deep Haro Strait PON']+sums[2016]['Deep Haro Strait DON']+sums[2016]['Deep Haro Strait Living'],\n", " sums[2017]['Deep Haro Strait NO3']+sums[2017]['Deep Haro Strait NH4']+\\\n", " sums[2017]['Deep Haro Strait PON']+sums[2017]['Deep Haro Strait DON']+sums[2017]['Deep Haro Strait Living'])\n", "tbl.addlinesSub('NO$_3$',\n", " sums[2015]['Deep Haro Strait NO3'],\n", " sums[2016]['Deep Haro Strait NO3'],\n", " sums[2017]['Deep Haro Strait NO3'])\n", "tbl.addlinesSub('NH$_4$',\n", " sums[2015]['Deep Haro Strait NH4'],\n", " sums[2016]['Deep Haro Strait NH4'],\n", " sums[2017]['Deep Haro Strait NH4'])\n", "tbl.addlinesSub('detrital PON',\n", " sums[2015]['Deep Haro Strait PON'],\n", " sums[2016]['Deep Haro Strait PON'],\n", " sums[2017]['Deep Haro Strait PON'])\n", "tbl.addlinesSub('DON',\n", " sums[2015]['Deep Haro Strait DON'],\n", " sums[2016]['Deep Haro Strait DON'],\n", " sums[2017]['Deep Haro Strait DON'])\n", "tbl.addlinesSub('Living',\n", " sums[2015]['Deep Haro Strait Living'],\n", " sums[2016]['Deep Haro Strait Living'],\n", " sums[2017]['Deep Haro Strait Living'])\n", "tbl.addlines('Total Transport, Haro Strait',\n", " sums[2015]['Haro Strait NO3']+sums[2015]['Haro Strait NH4']+\\\n", " sums[2015]['Haro Strait PON']+sums[2015]['Haro Strait DON']+sums[2015]['Haro Strait Living'],\n", " sums[2016]['Haro Strait NO3']+sums[2016]['Haro Strait NH4']+\\\n", " sums[2016]['Haro Strait PON']+sums[2016]['Haro Strait DON']+sums[2016]['Haro Strait Living'],\n", " sums[2017]['Haro Strait NO3']+sums[2017]['Haro Strait NH4']+\\\n", " sums[2017]['Haro Strait PON']+sums[2017]['Haro Strait DON']+sums[2017]['Haro Strait Living'])\n", "tbl.addlinesSub('NO$_3$',\n", " sums[2015]['Haro Strait NO3'],\n", " sums[2016]['Haro Strait NO3'],\n", " sums[2017]['Haro Strait NO3'])\n", "tbl.addlinesSub('NH$_4$',\n", " sums[2015]['Haro Strait NH4'],\n", " sums[2016]['Haro Strait NH4'],\n", " sums[2017]['Haro Strait NH4'])\n", "tbl.addlinesSub('detrital PON',\n", " sums[2015]['Haro Strait PON'],\n", " sums[2016]['Haro Strait PON'],\n", " sums[2017]['Haro Strait PON'])\n", "tbl.addlinesSub('DON',\n", " sums[2015]['Haro Strait DON'],\n", " sums[2016]['Haro Strait DON'],\n", " sums[2017]['Haro Strait DON'])\n", "tbl.addlinesSub('Living',\n", " sums[2015]['Haro Strait Living'],\n", " sums[2016]['Haro Strait Living'],\n", " sums[2017]['Haro Strait Living'])\n", "tbl.addlines('Total Transport, Southern Straits',\n", " sums[2015]['Southern NO3']+sums[2015]['Southern NH4']+\\\n", " sums[2015]['Southern PON']+sums[2015]['Southern DON']+sums[2015]['Southern Living'],\n", " sums[2016]['Southern NO3']+sums[2016]['Southern NH4']+\\\n", " sums[2016]['Southern PON']+sums[2016]['Southern DON']+sums[2016]['Southern Living'],\n", " sums[2017]['Southern NO3']+sums[2017]['Southern NH4']+\\\n", " sums[2017]['Southern PON']+sums[2017]['Southern DON']+sums[2017]['Southern Living'])\n", "tbl.addlinesSub('NO$_3$',\n", " sums[2015]['Southern NO3'],\n", " sums[2016]['Southern NO3'],\n", " sums[2017]['Southern NO3'])\n", "tbl.addlinesSub('NH$_4$',\n", " sums[2015]['Southern NH4'],\n", " sums[2016]['Southern NH4'],\n", " sums[2017]['Southern NH4'])\n", "tbl.addlinesSub('detrital PON',\n", " sums[2015]['Southern PON'],\n", " sums[2016]['Southern PON'],\n", " sums[2017]['Southern PON'])\n", "tbl.addlinesSub('DON',\n", " sums[2015]['Southern DON'],\n", " sums[2016]['Southern DON'],\n", " sums[2017]['Southern DON'])\n", "tbl.addlinesSub('Living',\n", " sums[2015]['Southern Living'],\n", " sums[2016]['Southern Living'],\n", " sums[2017]['Southern Living'])\n", "tbl.addlines('Total Transport, Northern Straits',\n", " sums[2015]['Northern NO3']+sums[2015]['Northern NH4']+\\\n", " sums[2015]['Northern PON']+sums[2015]['Northern DON']+sums[2015]['Northern Living'],\n", " sums[2016]['Northern NO3']+sums[2016]['Northern NH4']+\\\n", " sums[2016]['Northern PON']+sums[2016]['Northern DON']+sums[2016]['Northern Living'],\n", " sums[2017]['Northern NO3']+sums[2017]['Northern NH4']+\\\n", " sums[2017]['Northern PON']+sums[2017]['Northern DON']+sums[2017]['Northern Living'])\n", "tbl.addlinesSub('NO$_3$',\n", " sums[2015]['Northern NO3'],\n", " sums[2016]['Northern NO3'],\n", " sums[2017]['Northern NO3'])\n", "tbl.addlinesSub('NH$_4$',\n", " sums[2015]['Northern NH4'],\n", " sums[2016]['Northern NH4'],\n", " sums[2017]['Northern NH4'])\n", "tbl.addlinesSub('detrital PON',\n", " sums[2015]['Northern PON'],\n", " sums[2016]['Northern PON'],\n", " sums[2017]['Northern PON'])\n", "tbl.addlinesSub('DON',\n", " sums[2015]['Northern DON'],\n", " sums[2016]['Northern DON'],\n", " sums[2017]['Northern DON'])\n", "tbl.addlinesSub('Living',\n", " sums[2015]['Northern Living'],\n", " sums[2016]['Northern Living'],\n", " sums[2017]['Northern Living'])\n", "tbl.addlines('Net Change',\n", " sums[2015]['Net change'],\n", " sums[2016]['Net change'],\n", " sums[2017]['Net change'])\n", "tbl.finish()\n", "tbl.write()" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "sums[2015]['Northern NO3']=1\n", "sums[2015]['Northern NH4']=1\n", "sums[2015]['Northern PON']=1\n", "sums[2015]['Northern DON']=1\n", "sums[2015]['Northern Living']=1\n", "sums[2016]['Northern NO3']=1\n", "sums[2016]['Northern NH4']=1\n", "sums[2016]['Northern PON']=1\n", "sums[2016]['Northern DON']=1\n", "sums[2016]['Northern Living']=1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "raw", "metadata": {}, "source": [ "sums[2016].keys()" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "\n", "lines=list()\n", "lines.append(r' \\small'+'\\n')\n", "lines.append(r' \\centering'+'\\n')\n", "lines.append(r' \\begin{tabular}{lccc}\\toprule'+'\\n')\n", "lines.append(r' & 2015 & 2016 & 2017 \\\\ \\midrule'+'\\n')\n", "lines.append(r' {} & {} & {} & {} \\\\'.format('Primary Production',\n", " sums[2015]['NO3-based Primary Production']+sums[2015]['NH4-based Primary Production'],\n", " sums[2016]['NO3-based Primary Production']+sums[2016]['NH4-based Primary Production'],\n", " sums[2017]['NO3-based Primary Production']+sums[2017]['NH4-based Primary Production'])+'\\n')\n", "lines.append(r' ${}$ & {} & {} & {} \\\\'.format(' NO_3-based',\n", " sums[2015]['NO3-based Primary Production'],\n", " sums[2016]['NO3-based Primary Production'],\n", " sums[2017]['NO3-based Primary Production'])+'\\n')\n", "lines.append(r' ${}$ & {} & {} & {} \\\\'.format('NH_4-based',\n", " sums[2015]['NH4-based Primary Production'],\n", " sums[2016]['NH4-based Primary Production'],\n", " sums[2017]['NH4-based Primary Production'])+'\\n')\n", "lines.append(r' \\midrule'+'\\n')\n", "lines.append(r' \\\\ \\\\')\n", "lines.append(r' \\end{tabular}'+'\\n')\n", "\n", "f = open('fluxesTBL.tex', 'w')\n", "f.writelines(lines)\n", "f.close()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python (py38_ct)", "language": "python", "name": "py38_ct" }, "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.8.2" } }, "nbformat": 4, "nbformat_minor": 2 }