import numpy as np # this module handles arrays, but here we need it for its NaN value
import pandas as pd # this module contains a lot of tools for handling tabular data
from matplotlib import pyplot as plt
from salishsea_tools import evaltools as et
import datetime as dt
import os
import gsw
import pickle
import netCDF4 as nc
import cmocean
from scipy import stats as spst
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
%matplotlib inline
df=pd.read_csv('/data/eolson/results/MEOPAR/oldDBs/HPLCPhyto.csv')
df=pd.read_csv('/data/eolson/results/MEOPAR/oldDBs/HPLCPhyto.csv',dtype={'dtUTC':str})
# convert dtUTC back to datetime
df['dtUTC']=[dt.datetime.strptime(ii,'%Y-%m-%d %H:%M:%S') for ii in df['dtUTC']]
df.head()
dtUTC | Lat | Lon | Z | p | i | j | k | Sample_Number | Diatoms-1 | ... | Dictyochophytes | Raphidophytes | Cyanobacteria | TchlA (ug/L) | Chlorophyll:Extracted [mg/m^3] | Nitrate_plus_Nitrite [umol/L] | Silicate [umol/L] | Fluorescence:URU [mg/m^3] | SA | CT | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2015-04-01 23:42:17 | 48.65233 | -123.50183 | 1.487321 | 1.5 | 207 | 354 | 1 | 9.0 | 23.580 | ... | 0.000 | 0.163 | 0.000 | 26.162 | 29.36 | 4.63 | 19.43 | NaN | 27.295384 | 10.045218 |
1 | 2015-04-02 03:24:50 | 48.63017 | -123.24284 | 2.082250 | 2.1 | 242 | 331 | 2 | 23.0 | 0.272 | ... | 0.000 | 0.000 | 0.000 | 0.439 | 0.67 | 23.23 | 41.81 | NaN | 29.374328 | 9.201191 |
2 | 2015-04-02 15:23:46 | 48.49983 | -124.73317 | 1.586497 | 1.6 | 7 | 413 | 1 | 37.0 | 2.033 | ... | 0.005 | 0.023 | 0.004 | 3.129 | 3.43 | 5.70 | 9.85 | NaN | 29.643997 | 10.547005 |
3 | 2015-04-02 18:19:18 | 48.46900 | -124.54850 | 1.883969 | 1.9 | 31 | 394 | 1 | 51.0 | 2.722 | ... | 0.014 | 0.033 | 0.010 | 4.219 | 4.69 | 15.58 | 24.48 | NaN | 30.492932 | 9.644676 |
4 | 2015-04-02 23:03:35 | 48.30817 | -124.06650 | 1.685682 | 1.7 | 82 | 328 | 1 | 64.0 | 3.341 | ... | 0.002 | 0.022 | 0.000 | 6.385 | 7.15 | 1.17 | 3.43 | NaN | 29.434686 | 11.089943 |
5 rows × 25 columns
# path to model files:
PATH= '/results/SalishSea/nowcast-green.201812/'
# start and end dates for analysis:
start_date = dt.datetime(2015,4,1)
end_date = dt.datetime(2015,5,1)
# number of days per model file:
flen=1
# dictionary mapping desired model variables to the file types where they are found
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'}
# dictionary mapping model file types to their time resolution in hours (1 is hourly files, 24 is daily)
fdict={'ptrc_T':1,'grid_T':1}
# results format
# -- nowcast: files like 01jan15/SalishSea_1h_20150101_20150101_ptrc_T.nc
# -- long: files like SalishSea_1h_20150206_20150804_ptrc_T_20150427-20150506.nc, all in one directory
namfmt='nowcast'
data=et.matchData(df,filemap,fdict,start_date,end_date,namfmt,PATH,flen,preIndexed=True)
data
dtUTC | Lat | Lon | Z | p | i | j | k | Sample_Number | Diatoms-1 | ... | SA | CT | mod_nitrate | mod_silicon | mod_ammonium | mod_diatoms | mod_ciliates | mod_flagellates | mod_vosaline | mod_votemper | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2015-04-01 23:42:17 | 48.65233 | -123.50183 | 1.487321 | 1.5 | 207 | 354 | 1 | 9.0 | 23.580 | ... | 27.295384 | 10.045218 | 0.207268 | 18.074280 | 0.061200 | 9.364264 | 0.538119 | 1.354740 | 27.297085 | 10.330333 |
1 | 2015-04-02 03:24:50 | 48.63017 | -123.24284 | 2.082250 | 2.1 | 242 | 331 | 2 | 23.0 | 0.272 | ... | 29.374328 | 9.201191 | 16.684338 | 38.885910 | 1.431027 | 2.013328 | 0.262435 | 0.523047 | 29.845945 | 9.545719 |
2 | 2015-04-02 15:23:46 | 48.49983 | -124.73317 | 1.586497 | 1.6 | 7 | 413 | 1 | 37.0 | 2.033 | ... | 29.643997 | 10.547005 | 5.142227 | 13.671011 | 0.531737 | 0.624700 | 0.046742 | 0.196337 | 28.772097 | 11.000047 |
3 | 2015-04-02 18:19:18 | 48.46900 | -124.54850 | 1.883969 | 1.9 | 31 | 394 | 1 | 51.0 | 2.722 | ... | 30.492932 | 9.644676 | 7.909885 | 19.923824 | 0.697330 | 1.382296 | 0.200322 | 0.537118 | 29.407999 | 10.531830 |
4 | 2015-04-02 23:03:35 | 48.30817 | -124.06650 | 1.685682 | 1.7 | 82 | 328 | 1 | 64.0 | 3.341 | ... | 29.434686 | 11.089943 | 5.250195 | 17.457861 | 0.507802 | 4.250437 | 0.419683 | 0.868200 | 30.088562 | 10.704157 |
5 | 2015-04-03 02:09:56 | 48.26083 | -123.72017 | 1.685690 | 1.7 | 127 | 294 | 1 | 76.0 | 5.729 | ... | 30.092338 | 10.375860 | 16.168316 | 36.099716 | 1.318640 | 1.465542 | 0.312656 | 0.623337 | 30.610191 | 9.816114 |
6 | 2015-04-03 05:34:12 | 48.23283 | -123.30100 | 1.586536 | 1.6 | 185 | 259 | 1 | 86.0 | 4.217 | ... | 30.367032 | 10.207919 | 14.524487 | 35.114857 | 1.585027 | 1.287341 | 0.345707 | 0.630652 | 30.366905 | 9.777546 |
7 | 2015-04-03 08:46:05 | 48.26483 | -123.16300 | 1.784847 | 1.8 | 209 | 255 | 1 | 96.0 | 4.665 | ... | 30.455359 | 9.832826 | 12.663631 | 32.201111 | 1.489424 | 1.889705 | 0.363822 | 0.591890 | 30.294970 | 9.950639 |
8 | 2015-04-03 10:34:51 | 48.24317 | -122.97517 | 1.983166 | 2.0 | 234 | 238 | 1 | 109.0 | 1.254 | ... | 30.019539 | 9.968907 | 12.999703 | 32.490604 | 1.477581 | 1.741756 | 0.356779 | 0.576574 | 30.354095 | 9.955937 |
9 | 2015-04-03 11:55:44 | 48.38000 | -123.04350 | 1.983141 | 2.0 | 240 | 269 | 1 | 120.0 | 0.290 | ... | 30.199268 | 9.437491 | 16.255709 | 37.583473 | 1.669954 | 0.906741 | 0.279977 | 0.520383 | 30.367716 | 9.629019 |
10 | 2015-04-03 20:20:17 | 48.77283 | -123.02517 | 1.288998 | 1.3 | 292 | 344 | 1 | 134.0 | 1.083 | ... | 27.500889 | 9.363429 | 12.618896 | 35.647545 | 1.121006 | 3.437740 | 0.302830 | 0.546674 | 27.733738 | 9.499469 |
11 | 2015-04-04 01:32:54 | 48.85633 | -123.17867 | 1.487293 | 1.5 | 280 | 371 | 1 | 146.0 | 1.203 | ... | 27.525352 | 9.406337 | 3.922194 | 25.668491 | 0.422477 | 6.346560 | 0.490985 | 0.773030 | 24.969782 | 9.671115 |
12 | 2015-04-04 05:50:40 | 49.02967 | -123.43650 | 1.487269 | 1.5 | 263 | 422 | 1 | 162.0 | 3.894 | ... | 17.902988 | 9.677448 | 0.070761 | 23.455862 | 0.115147 | 2.689742 | 0.517753 | 0.672885 | 20.679708 | 9.750998 |
13 | 2015-04-04 11:04:25 | 49.16333 | -123.55150 | 1.685550 | 1.7 | 263 | 456 | 1 | 179.0 | 4.599 | ... | 21.776615 | 9.714082 | 0.084008 | 23.786867 | 0.271984 | 1.890162 | 0.501170 | 0.559731 | 20.482256 | 9.741808 |
14 | 2015-04-04 13:57:22 | 49.25017 | -123.74783 | 1.685537 | 1.7 | 245 | 487 | 1 | 180.0 | 1.599 | ... | 25.564654 | 9.738741 | 0.163428 | 19.074352 | 0.409709 | 1.346822 | 0.509341 | 0.476899 | 23.812494 | 9.903145 |
15 | 2015-04-04 15:59:53 | 49.31883 | -123.79967 | 1.883823 | 1.9 | 246 | 504 | 1 | 196.0 | 0.976 | ... | 26.443527 | 9.652525 | 0.709665 | 20.795488 | 0.493228 | 1.876149 | 0.518488 | 0.519973 | 23.402004 | 9.558413 |
16 | 2015-04-04 20:47:25 | 49.40183 | -124.15600 | 1.487219 | 1.5 | 204 | 546 | 1 | 211.0 | 11.126 | ... | 26.053971 | 9.889691 | 2.344581 | 20.855665 | 0.806753 | 2.458612 | 0.524008 | 0.520034 | 25.652012 | 9.579053 |
17 | 2015-04-05 00:46:55 | 49.44333 | -124.33717 | 1.982948 | 2.0 | 183 | 567 | 1 | 227.0 | 13.403 | ... | 25.976407 | 9.785377 | 5.473182 | 25.645149 | 1.332969 | 1.920953 | 0.517515 | 0.583442 | 26.172964 | 9.411976 |
18 | 2015-04-05 03:20:15 | 49.48283 | -124.76667 | 1.685501 | 1.7 | 125 | 605 | 1 | 235.0 | 0.390 | ... | 28.038871 | 9.490264 | 9.324271 | 31.554089 | 1.083078 | 5.225220 | 0.413992 | 0.703063 | 27.223244 | 9.276813 |
19 | 2015-04-05 05:55:23 | 49.50933 | -124.46250 | 1.586351 | 1.6 | 173 | 588 | 1 | 248.0 | 1.652 | ... | 27.046460 | 9.640587 | 3.276875 | 22.250242 | 0.815836 | 2.715950 | 0.550262 | 0.602871 | 25.833595 | 9.409250 |
20 | 2015-04-05 08:54:02 | 49.59167 | -124.63783 | 1.586339 | 1.6 | 157 | 617 | 1 | 260.0 | 0.086 | ... | 28.096878 | 9.509801 | 9.321479 | 30.869684 | 1.274880 | 3.663012 | 0.431131 | 0.666596 | 27.706947 | 9.273652 |
21 | 2015-04-05 11:29:15 | 49.72650 | -124.68034 | 1.883753 | 1.9 | 168 | 646 | 1 | 276.0 | 0.126 | ... | 27.270725 | 9.639571 | 0.903672 | 19.272499 | 0.481597 | 2.480967 | 0.518646 | 0.520741 | 25.002720 | 9.569352 |
22 | 2015-04-05 14:32:52 | 49.88250 | -124.99384 | 1.784583 | 1.8 | 141 | 699 | 1 | 290.0 | 0.039 | ... | 28.163343 | 9.428767 | 8.485549 | 29.222990 | 1.590368 | 2.589933 | 0.416396 | 0.537411 | 27.481588 | 9.300419 |
23 | 2015-04-05 16:37:05 | 49.96250 | -125.14716 | 1.982855 | 2.0 | 129 | 726 | 1 | 302.0 | 0.000 | ... | 28.097068 | 9.569295 | 12.668829 | 34.420380 | 1.563163 | 1.963740 | 0.372351 | 0.538484 | 28.210239 | 9.191626 |
24 | 2015-04-07 03:24:52 | 49.67117 | -124.27233 | 1.586327 | 1.6 | 221 | 607 | 1 | 303.0 | 8.831 | ... | 25.080445 | 10.573161 | 0.111911 | 18.244190 | 0.238867 | 1.085410 | 0.572490 | 0.547362 | 24.493746 | 10.559558 |
25 rows × 33 columns
test=et.loadDFOCTD()
test
Year | Month | Day | Hour | Lat | Lon | Z | SA | CT | Fluor | dtUTC | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | 2014.0 | 2.0 | 11.0 | 6.598056 | 48.618333 | -123.248333 | 0.991551 | 31.189609 | 7.327741 | 0.567 | 2014-02-11 06:35:53 |
1 | 2014.0 | 2.0 | 11.0 | 6.598056 | 48.618333 | -123.248333 | 1.983098 | 31.191168 | 7.327932 | 0.596 | 2014-02-11 06:35:53 |
2 | 2014.0 | 2.0 | 11.0 | 6.598056 | 48.618333 | -123.248333 | 2.974640 | 31.191120 | 7.327442 | 0.612 | 2014-02-11 06:35:53 |
3 | 2014.0 | 2.0 | 11.0 | 6.598056 | 48.618333 | -123.248333 | 3.966176 | 31.197000 | 7.329882 | 0.577 | 2014-02-11 06:35:53 |
4 | 2014.0 | 2.0 | 11.0 | 6.598056 | 48.618333 | -123.248333 | 4.957709 | 31.201373 | 7.331038 | 0.576 | 2014-02-11 06:35:53 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
819620 | 2019.0 | 12.0 | 12.0 | 15.786111 | 49.322600 | -124.001568 | 385.200000 | 31.512139 | 9.599687 | NaN | 2019-12-12 15:47:10 |
819621 | 2019.0 | 12.0 | 12.0 | 15.786111 | 49.322600 | -124.001568 | 386.100000 | 31.504219 | 9.570673 | NaN | 2019-12-12 15:47:10 |
819622 | 2019.0 | 12.0 | 12.0 | 15.786111 | 49.322600 | -124.001568 | 387.000000 | 31.503033 | 9.547747 | NaN | 2019-12-12 15:47:10 |
819623 | 2019.0 | 12.0 | 12.0 | 15.786111 | 49.322600 | -124.001568 | 388.100000 | 31.500741 | 9.519935 | NaN | 2019-12-12 15:47:10 |
819624 | 2019.0 | 12.0 | 12.0 | 15.786111 | 49.322600 | -124.001568 | 389.200000 | 31.498651 | 9.490817 | NaN | 2019-12-12 15:47:10 |
819625 rows × 11 columns
test=pd.csv_read()