import re
import os
import glob
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import netCDF4 as nc
import seaborn as sns
import xarray as xr
import functools
from IPython.display import clear_output
import datetime as dt
import random
import itertools
from mpl_toolkits.basemap import Basemap
from salishsea_tools import geo_tools, geo_tools, tidetools, data_tools
%matplotlib inline
plt.rcParams['image.cmap'] = 'jet'
# converts lons/lats like this "124° 01.400" to decimal format
def strLonLatToDec(lstr):
if type(lstr) is not str:
return(np.NaN)
lstr = lstr.replace(u'°',' ')
lstr = lstr.split()
return (int(lstr[0])+float(lstr[1])/60.0)
# Grab tracer data
# '/ocean/rich/home/metro/venus_adcp/PSF/bottle/PSF_2015bottle_RPedit.xls'
tracer_df = pd.read_excel('/ocean/rich/home/metro/venus_adcp/PSF/bottle/PSF_2015bottle_RPeditfinal.xls')
tracer_df = tracer_df[~pd.isnull(tracer_df["Date"])]
#tracer_df["Date"] = pd.to_datetime(tracer_df["Date"])
tracer_df = tracer_df.sort_values("Date")
tracer_df["DECIMAL_LON"] = (tracer_df["Longitude"].apply(strLonLatToDec))*(-1)
tracer_df["DECIMAL_LAT"] = (tracer_df["Latitude"].apply(strLonLatToDec))
tracer_df["STATION_LAT"] = tracer_df.groupby("Station ID")["DECIMAL_LAT"].transform(np.median)
tracer_df["STATION_LON"] = tracer_df.groupby("Station ID")["DECIMAL_LON"].transform(np.median)
# Create smaller dataframe with location of stations
station_lon_lat = tracer_df[["Station ID", "STATION_LON", "STATION_LAT"]].drop_duplicates()
station_lon_lat.columns = ["STATION", "LON", "LAT"]
# Add corresponding model points to station data frame
grid_B = nc.Dataset('/data/nsoontie/MEOPAR/NEMO-forcing/grid/bathy_meter_SalishSea2.nc')
bathy, X, Y = tidetools.get_bathy_data(grid_B)
def closest_model_point_wrapper(lon, lat):
try:
model_point = geo_tools.find_closest_model_point(lon, lat, model_lons = X, model_lats = Y, grid = 'NEMO', land_mask = bathy.mask)
return(model_point)
except:
print("ERROR" + str(lon) + " " + str(lat))
return(np.nan)
station_lon_lat["MODEL_POINT"] = station_lon_lat.apply(lambda row: closest_model_point_wrapper(row[1], row[2]) , axis = 1)
station_lon_lat["MODEL_J"] = station_lon_lat["MODEL_POINT"].apply(lambda x: x[0])
station_lon_lat["MODEL_I"] = station_lon_lat["MODEL_POINT"].apply(lambda x: x[1])
import numpy as np
from scipy.io import loadmat # this is the SciPy module that loads mat-files
import matplotlib.pyplot as plt
from datetime import datetime, date, time
import pandas as pd
mat = loadmat('/ocean/jylam/Final/2015/PSF_CWBstn.mat') # load mat-file
mdata = mat['PSFc'] # variable in mat file
ndata = {n: mdata[n][0, 0] for n in mdata.dtype.names}
for key in ndata.keys():
if ndata[key].shape == (400, 2054):
ndata[key] = ndata[key].ravel()
elif ndata[key].shape == (1, 2054):
ndata[key] = np.tile(ndata[key],400).ravel()
else:
print("what")
all_ts_df = pd.DataFrame(ndata)
patrol_num_name = {1 : "LD", 2 : "PR", 3 : "IS", 4 : "BS", 5 : "NQ", 6 : "CR", 8 : "SV", 9 : "VC", 10 : "CWB"}
def get_station_name(patrol_num, station_num):
station_name = None
patrol_name = patrol_num_name[patrol_num]
if patrol_name == "CWB":
if station_num == 5:
station_name = "CBW2"
elif station_num ==7:
station_name = "CBC1"
elif station_num ==8:
station_name = "CBC2"
elif station_num ==9:
station_name = "CBC3"
elif station_num ==11:
station_name = "CBE2"
else:
station_name = patrol_name + str(station_num)
return(station_name)
all_ts_df["STATION_NAME"] = all_ts_df.apply(lambda row: get_station_name(int(row["patrol"]), int(row["stnN"])), axis = 1)
all_ts_df = all_ts_df[~pd.isnull(all_ts_df["mtimes"])]
all_ts_df["DATE"] = all_ts_df.mtimes.apply(lambda mt: dt.datetime.fromordinal(int(mt)) + dt.timedelta(days=mt%1) - dt.timedelta(days = 366))
ts_df = all_ts_df[["STATION_NAME", "DATE","long", "lat", "depth", "sal", "temp"]]
ts_df.columns = ["STATION", "DATE", "LON", "LAT", "DEPTH", "SAL", "TEMP"]
ts_df["DATA_TYPE"] = "Measured"
ts_df["DAY_OF_YEAR"] = ts_df["DATE"].apply(lambda x: x.dayofyear)
/home/jpetrie/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:3: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy app.launch_new_instance() /home/jpetrie/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
# Choose which values to add to nowcast dataframe
tracers = ["votemper", "vosaline"]
months = ["feb", "mar", "apr", "may", "jun", "jul", "aug", "sep"]
hours = np.array([12])
max_depth = 60
result_depths = xr.open_dataset('/data/nsoontie/MEOPAR/NEMO-forcing/grid/deptht_428m.nc').deptht.values
depth_indices = np.where(result_depths < max_depth)[0]
station_points = station_lon_lat["MODEL_POINT"]
station_names = station_lon_lat["STATION"]
stations = dict(zip(station_names, station_points))
nowcast_df = pd.read_pickle("/ocean/jpetrie/MEOPAR/analysis-james/nowcast_green_subset/station_ts_feb-sep.pkl")
#nowcast_df["DATE"] = pd.to_datetime(nowcast_df["DATE"], infer_datetime_format=True)
#nowcast_df = data_tools.load_nowcast_station_tracers(tracers, stations, months, hours, depth_indices, file_ending = "grid_T.nc", save_path = "/ocean/jpetrie/MEOPAR/analysis-james/nowcast_green_subset/station_ts_feb-sep.pkl")
nowcast_df["SALINITY"] = nowcast_df["vosaline"]
nowcast_df["TEMPERATURE"] = nowcast_df["votemper"]
ts_df["SALINITY"] = ts_df["SAL"]
ts_df["TEMPERATURE"] = ts_df["TEMP"]
/home/jpetrie/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:3: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy app.launch_new_instance() /home/jpetrie/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
nowcast_df["DAY_OF_YEAR"] = nowcast_df["DATE"].apply(lambda x: x.dayofyear)
nowcast_df["DATA_TYPE"] = "Nowcast"
combined = pd.concat([ts_df.query("(DEPTH - 0.75)**2 < 0.0001 | (DEPTH - 19.75)**2 < 0.0001"), nowcast_df.query("(DEPTH - 0.500011)**2 < 0.0001 | (DEPTH - 19.481785)**2 < 0.0001")])
combined["IDENTIFIER"] = combined["DATA_TYPE"] + ", Depth = " + combined["DEPTH"].apply(str)
combined.STATION = combined.STATION.apply(lambda x: x.strip() if x is not None else x)
combined = combined.sort_values(["STATION", "DATE"])
# Temperature
colors = ["red","burnt orange", "dark grey blue", "cerulean",]
cmap = sns.xkcd_palette(colors)
sns.set(font_scale = 3)
fg = sns.FacetGrid(data = combined[(combined["DAY_OF_YEAR"] <= max(nowcast_df["DAY_OF_YEAR"]))], col = "STATION", col_wrap=3, hue = "IDENTIFIER", size =8, sharex = False, sharey = True, palette= cmap)
fg.map(plt.plot,"DAY_OF_YEAR", "TEMPERATURE").add_legend()
#plt.xticks(rotation=45)
plt.subplots_adjust(top=0.9)
combined_all_depths = pd.concat([ts_df, nowcast_df])
combined_all_depths["DATE_STR"] = combined_all_depths["DATE"].apply(lambda x: x.strftime('%Y-%m-%d'))
combined_all_depths["IDENTIFIER"] = combined_all_depths["DATA_TYPE"] + ", Date = " + combined_all_depths["DATE_STR"]
combined_all_depths.STATION = combined_all_depths.STATION.apply(lambda x: x.strip() if x is not None else x)
combined_all_depths = combined_all_depths.sort_values(["STATION", "DATE"])
combined_all_depths
DATA_TYPE | DATE | DAY_OF_YEAR | DEPTH | HOUR | LAT | LON | MONTH | SAL | SALINITY | STATION | TEMP | TEMPERATURE | vosaline | votemper | DATE_STR | IDENTIFIER | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
847 | Measured | 2015-02-18 23:08:10.346147 | 49 | 0.75 | NaN | 49.603911 | -124.866963 | NaN | 20.899147 | 20.899147 | BS1 | 7.820374 | 7.820374 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
2901 | Measured | 2015-02-18 23:08:12.000010 | 49 | 1.25 | NaN | 49.603911 | -124.866963 | NaN | 22.786068 | 22.786068 | BS1 | 8.351978 | 8.351978 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
4955 | Measured | 2015-02-18 23:08:12.916662 | 49 | 1.75 | NaN | 49.603911 | -124.866963 | NaN | 24.504444 | 24.504444 | BS1 | 8.882751 | 8.882751 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
7009 | Measured | 2015-02-18 23:08:13.916667 | 49 | 2.25 | NaN | 49.603911 | -124.866963 | NaN | 25.395384 | 25.395384 | BS1 | 8.933599 | 8.933599 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
9063 | Measured | 2015-02-18 23:08:14.999994 | 49 | 2.75 | NaN | 49.603911 | -124.866963 | NaN | 25.777566 | 25.777566 | BS1 | 8.712089 | 8.712089 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
11117 | Measured | 2015-02-18 23:08:16.083331 | 49 | 3.25 | NaN | 49.603911 | -124.866963 | NaN | 26.078511 | 26.078511 | BS1 | 8.509384 | 8.509384 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
13171 | Measured | 2015-02-18 23:08:17.166719 | 49 | 3.75 | NaN | 49.603911 | -124.866963 | NaN | 26.347331 | 26.347331 | BS1 | 8.520700 | 8.520700 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
15225 | Measured | 2015-02-18 23:08:18.250007 | 49 | 4.25 | NaN | 49.603911 | -124.866963 | NaN | 26.392752 | 26.392752 | BS1 | 8.637238 | 8.637238 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
17279 | Measured | 2015-02-18 23:08:19.416637 | 49 | 4.75 | NaN | 49.603911 | -124.866963 | NaN | 26.421414 | 26.421414 | BS1 | 8.646931 | 8.646931 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
19333 | Measured | 2015-02-18 23:08:20.583337 | 49 | 5.25 | NaN | 49.603911 | -124.866963 | NaN | 26.464781 | 26.464781 | BS1 | 8.653310 | 8.653310 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
21387 | Measured | 2015-02-18 23:08:21.583332 | 49 | 5.75 | NaN | 49.603911 | -124.866963 | NaN | 26.629902 | 26.629902 | BS1 | 8.602621 | 8.602621 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
23441 | Measured | 2015-02-18 23:08:22.666720 | 49 | 6.25 | NaN | 49.603911 | -124.866963 | NaN | 26.810574 | 26.810574 | BS1 | 8.599683 | 8.599683 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
25495 | Measured | 2015-02-18 23:08:23.666604 | 49 | 6.75 | NaN | 49.603911 | -124.866963 | NaN | 26.892777 | 26.892777 | BS1 | 8.611249 | 8.611249 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
27549 | Measured | 2015-02-18 23:08:24.583326 | 49 | 7.25 | NaN | 49.603911 | -124.866963 | NaN | 26.955538 | 26.955538 | BS1 | 8.620763 | 8.620763 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
29603 | Measured | 2015-02-18 23:08:25.583340 | 49 | 7.75 | NaN | 49.603911 | -124.866963 | NaN | 27.081465 | 27.081465 | BS1 | 8.638128 | 8.638128 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
31657 | Measured | 2015-02-18 23:08:26.500002 | 49 | 8.25 | NaN | 49.603911 | -124.866963 | NaN | 27.154465 | 27.154465 | BS1 | 8.659161 | 8.659161 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
33711 | Measured | 2015-02-18 23:08:27.416664 | 49 | 8.75 | NaN | 49.603911 | -124.866963 | NaN | 27.214740 | 27.214740 | BS1 | 8.665700 | 8.665700 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
35765 | Measured | 2015-02-18 23:08:28.333406 | 49 | 9.25 | NaN | 49.603911 | -124.866963 | NaN | 27.251835 | 27.251835 | BS1 | 8.660571 | 8.660571 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
37819 | Measured | 2015-02-18 23:08:29.166604 | 49 | 9.75 | NaN | 49.603911 | -124.866963 | NaN | 27.275418 | 27.275418 | BS1 | 8.651324 | 8.651324 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
39873 | Measured | 2015-02-18 23:08:30.083336 | 49 | 10.25 | NaN | 49.603911 | -124.866963 | NaN | 27.334683 | 27.334683 | BS1 | 8.663172 | 8.663172 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
41927 | Measured | 2015-02-18 23:08:31.083331 | 49 | 10.75 | NaN | 49.603911 | -124.866963 | NaN | 27.384781 | 27.384781 | BS1 | 8.721049 | 8.721049 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
43981 | Measured | 2015-02-18 23:08:31.999992 | 49 | 11.25 | NaN | 49.603911 | -124.866963 | NaN | 27.418795 | 27.418795 | BS1 | 8.717194 | 8.717194 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
46035 | Measured | 2015-02-18 23:08:32.916674 | 49 | 11.75 | NaN | 49.603911 | -124.866963 | NaN | 27.457859 | 27.457859 | BS1 | 8.685674 | 8.685674 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
48089 | Measured | 2015-02-18 23:08:33.916669 | 49 | 12.25 | NaN | 49.603911 | -124.866963 | NaN | 27.478476 | 27.478476 | BS1 | 8.691889 | 8.691889 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
50143 | Measured | 2015-02-18 23:08:34.916663 | 49 | 12.75 | NaN | 49.603911 | -124.866963 | NaN | 27.528251 | 27.528251 | BS1 | 8.715495 | 8.715495 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
52197 | Measured | 2015-02-18 23:08:35.900001 | 49 | 13.25 | NaN | 49.603911 | -124.866963 | NaN | 27.546023 | 27.546023 | BS1 | 8.726788 | 8.726788 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
54251 | Measured | 2015-02-18 23:08:37.000005 | 49 | 13.75 | NaN | 49.603911 | -124.866963 | NaN | 27.588944 | 27.588944 | BS1 | 8.734693 | 8.734693 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
56305 | Measured | 2015-02-18 23:08:38.000000 | 49 | 14.25 | NaN | 49.603911 | -124.866963 | NaN | 27.639568 | 27.639568 | BS1 | 8.758014 | 8.758014 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
58359 | Measured | 2015-02-18 23:08:38.916662 | 49 | 14.75 | NaN | 49.603911 | -124.866963 | NaN | 27.718939 | 27.718939 | BS1 | 8.753535 | 8.753535 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
60413 | Measured | 2015-02-18 23:08:39.999999 | 49 | 15.25 | NaN | 49.603911 | -124.866963 | NaN | 27.759589 | 27.759589 | BS1 | 8.745819 | 8.745819 | NaN | NaN | 2015-02-18 | Measured, Date = 2015-02-18 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
133505 | Measured | 2015-09-16 17:40:04.666602 | 259 | 32.75 | NaN | 48.758301 | -123.612100 | NaN | 30.270028 | 30.270028 | None | 12.565387 | 12.565387 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
2052 | Measured | 2015-09-16 17:58:23.966604 | 259 | 0.75 | NaN | 48.743460 | -123.619609 | NaN | 28.967557 | 28.967557 | None | NaN | NaN | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
4106 | Measured | 2015-09-16 17:58:24.833407 | 259 | 1.25 | NaN | 48.743460 | -123.619609 | NaN | 28.981912 | 28.981912 | None | NaN | NaN | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
6160 | Measured | 2015-09-16 17:58:25.750008 | 259 | 1.75 | NaN | 48.743460 | -123.619609 | NaN | 29.326570 | 29.326570 | None | 13.859797 | 13.859797 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
8214 | Measured | 2015-09-16 17:58:26.750013 | 259 | 2.25 | NaN | 48.743460 | -123.619609 | NaN | 29.465701 | 29.465701 | None | 13.687612 | 13.687612 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
10268 | Measured | 2015-09-16 17:58:27.833280 | 259 | 2.75 | NaN | 48.743460 | -123.619609 | NaN | 29.514180 | 29.514180 | None | 13.575631 | 13.575631 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
12322 | Measured | 2015-09-16 17:58:29.083374 | 259 | 3.25 | NaN | 48.743460 | -123.619609 | NaN | 29.600878 | 29.600878 | None | 13.439892 | 13.439892 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
14376 | Measured | 2015-09-16 17:58:30.333287 | 259 | 3.75 | NaN | 48.743460 | -123.619609 | NaN | 29.646946 | 29.646946 | None | 13.374717 | 13.374717 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
16430 | Measured | 2015-09-16 17:58:31.416684 | 259 | 4.25 | NaN | 48.743460 | -123.619609 | NaN | 29.720990 | 29.720990 | None | 13.316528 | 13.316528 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
18484 | Measured | 2015-09-16 17:58:32.500002 | 259 | 4.75 | NaN | 48.743460 | -123.619609 | NaN | 29.754040 | 29.754040 | None | 13.311711 | 13.311711 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
20538 | Measured | 2015-09-16 17:58:33.750005 | 259 | 5.25 | NaN | 48.743460 | -123.619609 | NaN | 29.768002 | 29.768002 | None | 13.288517 | 13.288517 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
22592 | Measured | 2015-09-16 17:58:34.916665 | 259 | 5.75 | NaN | 48.743460 | -123.619609 | NaN | 29.771582 | 29.771582 | None | 13.261205 | 13.261205 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
24646 | Measured | 2015-09-16 17:58:35.916680 | 259 | 6.25 | NaN | 48.743460 | -123.619609 | NaN | 29.779080 | 29.779080 | None | 13.248764 | 13.248764 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
26700 | Measured | 2015-09-16 17:58:36.916655 | 259 | 6.75 | NaN | 48.743460 | -123.619609 | NaN | 29.800551 | 29.800551 | None | 13.241933 | 13.241933 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
28754 | Measured | 2015-09-16 17:58:37.916669 | 259 | 7.25 | NaN | 48.743460 | -123.619609 | NaN | 29.816046 | 29.816046 | None | 13.250432 | 13.250432 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
30808 | Measured | 2015-09-16 17:58:38.916664 | 259 | 7.75 | NaN | 48.743460 | -123.619609 | NaN | 29.831163 | 29.831163 | None | 13.268839 | 13.268839 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
32862 | Measured | 2015-09-16 17:58:40.000001 | 259 | 8.25 | NaN | 48.743460 | -123.619609 | NaN | 29.850709 | 29.850709 | None | 13.290985 | 13.290985 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
34916 | Measured | 2015-09-16 17:58:40.999996 | 259 | 8.75 | NaN | 48.743460 | -123.619609 | NaN | 29.866048 | 29.866048 | None | 13.304816 | 13.304816 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
36970 | Measured | 2015-09-16 17:58:41.916668 | 259 | 9.25 | NaN | 48.743460 | -123.619609 | NaN | 29.862750 | 29.862750 | None | 13.291326 | 13.291326 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
39024 | Measured | 2015-09-16 17:58:43.000005 | 259 | 9.75 | NaN | 48.743460 | -123.619609 | NaN | 29.882857 | 29.882857 | None | 13.284066 | 13.284066 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
41078 | Measured | 2015-09-16 17:58:43.999990 | 259 | 10.25 | NaN | 48.743460 | -123.619609 | NaN | 29.897541 | 29.897541 | None | 13.281927 | 13.281927 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
43132 | Measured | 2015-09-16 17:58:44.833409 | 259 | 10.75 | NaN | 48.743460 | -123.619609 | NaN | 29.911305 | 29.911305 | None | 13.256116 | 13.256116 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
45186 | Measured | 2015-09-16 17:58:45.749990 | 259 | 11.25 | NaN | 48.743460 | -123.619609 | NaN | 29.931156 | 29.931156 | None | 13.250865 | 13.250865 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
47240 | Measured | 2015-09-16 17:58:46.749995 | 259 | 11.75 | NaN | 48.743460 | -123.619609 | NaN | 29.934665 | 29.934665 | None | 13.240814 | 13.240814 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
49294 | Measured | 2015-09-16 17:58:47.666596 | 259 | 12.25 | NaN | 48.743460 | -123.619609 | NaN | 29.951175 | 29.951175 | None | 13.216913 | 13.216913 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
51348 | Measured | 2015-09-16 17:58:48.583338 | 259 | 12.75 | NaN | 48.743460 | -123.619609 | NaN | 29.973865 | 29.973865 | None | 13.194102 | 13.194102 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
53402 | Measured | 2015-09-16 17:58:49.583333 | 259 | 13.25 | NaN | 48.743460 | -123.619609 | NaN | 29.982148 | 29.982148 | None | 13.179606 | 13.179606 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
55456 | Measured | 2015-09-16 17:58:50.583328 | 259 | 13.75 | NaN | 48.743460 | -123.619609 | NaN | 29.985696 | 29.985696 | None | 13.173528 | 13.173528 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
57510 | Measured | 2015-09-16 17:58:51.499999 | 259 | 14.25 | NaN | 48.743460 | -123.619609 | NaN | 29.987815 | 29.987815 | None | 13.166534 | 13.166534 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
59564 | Measured | 2015-09-16 17:58:51.999997 | 259 | 14.75 | NaN | 48.743460 | -123.619609 | NaN | 29.996910 | 29.996910 | None | 13.150818 | 13.150818 | NaN | NaN | 2015-09-16 | Measured, Date = 2015-09-16 |
597991 rows × 17 columns
# Temperature depth profiles
sns.set(font_scale = 3)
fg = sns.FacetGrid(data = combined_all_depths[(combined_all_depths["DAY_OF_YEAR"] <= max(nowcast_df["DAY_OF_YEAR"])) &
( (combined_all_depths["DAY_OF_YEAR"]%20 == 0)) & #(combined_all_depths["DATA_TYPE"] == "Measured") |
(combined_all_depths["DEPTH"] < 50)
],
col = "STATION", col_wrap=3, hue = "IDENTIFIER", size =8, sharex = False, sharey = True)
fg.map(plt.plot,"SALINITY", "DEPTH").add_legend()
#plt.xticks(rotation=45)
plt.subplots_adjust(top=0.9)
plt.gca().invert_yaxis()
#Salinity
colors = ["red","burnt orange", "dark grey blue", "cerulean",]
cmap = sns.xkcd_palette(colors)
sns.set(font_scale = 3)
fg = sns.FacetGrid(data = combined[(combined["DAY_OF_YEAR"] <= max(nowcast_df["DAY_OF_YEAR"]))], col = "STATION", col_wrap=3, hue = "IDENTIFIER", size =8, sharex = False, sharey = True, palette= cmap)
fg.map(plt.plot,"DAY_OF_YEAR", "SALINITY").add_legend()
#plt.xticks(rotation=45)
plt.subplots_adjust(top=0.9)
# get unique stations and map them
# map:
width = 225000; lon_0 = -124.0; lat_0 = 49.25
plt.figure(figsize=(14,14))
m = Basemap(width=width,height=width,projection='aeqd', resolution='h',
lat_0=lat_0,lon_0=lon_0)
# fill background.
m.drawmapboundary()
# draw coasts and fill continents.
m.drawcoastlines(linewidth=0.5)
m.drawrivers()
#m.shadedrelief()
# 20 degree graticule.
m.drawparallels(np.arange(40,60,2))
m.drawmeridians(np.arange(-130,-110,2))
plt.title('Stations')
cb_count = 0
# map stations:
for index, row in station_lon_lat.iterrows():
name = row["STATION"]
lon = row["LON"]
lat = row["LAT"]
xpt, ypt = m(lon, lat)
xpt2, ypt2 = m(lon+.05, lat)
if re.search('CB',name):
xpt2, ypt2 = m(lon+np.cos(cb_count*2.0*np.pi/5.0)*.12 - 0.04, lat+np.sin(cb_count*2.0*np.pi/5.0)*0.08)
cb_count = cb_count + 1
m.plot([xpt],[ypt],'bo')
plt.text(xpt2,ypt2,name,fontsize=10,fontweight='bold',
ha='left',va='center',color='k')