#!/usr/bin/env python # coding: utf-8 # Comparisons between nowcast, spinup, and observed salinity in the Strait of Juan de Fuca # In[1]: import pandas as pd import seaborn as sns import matplotlib.pyplot as plt import ACTDR import netCDF4 as nc from salishsea_tools import viz_tools import numpy as np import datetime from salishsea_tools import tidetools import comparisons get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: sns.set_style('darkgrid') # In[3]: grid_B = nc.Dataset('/data/nsoontie/MEOPAR/NEMO-forcing/grid/bathy_meter_SalishSea2.nc') # # Load observations # In[4]: ACTDR.load_dat('SOG_2000.dat') # In[5]: data = pd.DataFrame(ACTDR.CTD_DAT) lon_min=-124.6; lat_min=48; lon_max=-123.6; lat_max=48.6; data_region = comparisons.isolate_region(data, lon_min, lon_max, lat_min, lat_max) # In[6]: fig,axm = plt.subplots(1,figsize=(8,5)) data_region.plot(x='Longitude',y='Latitude',kind='scatter', marker='o',ax=axm) viz_tools.plot_coastline(axm,grid_B,coords='map') axm.set_xlim([lon_min,lon_max]) axm.set_ylim([lat_min, lat_max]) # In[7]: data_region.hist('Month',bins=np.arange(0.5,13.5)) # In[8]: data_region.hist('Year', bins= np.arange(data_region['Year'].min()-0.5, data_region['Year'].max() +1.5 )) ax=plt.gca() ax.get_xaxis().get_major_formatter().set_useOffset(False) # #Data model comparisons # * Compare model salinity profiles with observed in this region. Apply to both spinup and nowcasts. # * Focus on all depths # In[9]: paths = {'nowcast': '/data/dlatorne/MEOPAR/SalishSea/nowcast/', 'spinup': '/ocean/dlatorne/MEOPAR/SalishSea/results/spin-up/'} zmax= 250 # November # In[10]: month=11 fig=comparisons.compare_model_obs(month,2003,'Salinity',data_region,paths['spinup'],zmax=zmax,vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) fig=comparisons.compare_model_obs(month,2014,'Salinity',data_region,paths['nowcast'],zmax=zmax, vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) data_month=data_region[data_region['Month']==month] data_month.hist('Year',bins = np.arange(data_month['Year'].min()-0.5,data_month['Year'].max()+1.5 )) ax=plt.gca() ax.get_xaxis().get_major_formatter().set_useOffset(False) # December - no data # January - no data # February # In[11]: month=2 fig=comparisons.compare_model_obs(month,2003,'Salinity',data_region,paths['spinup'],zmax=zmax,vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) fig=comparisons.compare_model_obs(month,2015,'Salinity',data_region,paths['nowcast'],zmax=zmax, vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) data_month=data_region[data_region['Month']==month] data_month.hist('Year',bins = np.arange(data_month['Year'].min()-0.5,data_month['Year'].max()+1.5 )) ax=plt.gca() ax.get_xaxis().get_major_formatter().set_useOffset(False) # March # In[12]: month=3 fig=comparisons.compare_model_obs(month,2003,'Salinity',data_region,paths['spinup'],zmax=zmax,vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) fig=comparisons.compare_model_obs(month,2015,'Salinity',data_region,paths['nowcast'],zmax=zmax, vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) data_month=data_region[data_region['Month']==month] data_month.hist('Year',bins = np.arange(data_month['Year'].min()-0.5,data_month['Year'].max()+1.5 )) ax=plt.gca() ax.get_xaxis().get_major_formatter().set_useOffset(False) # April # In[13]: month=4 fig=comparisons.compare_model_obs(month,2003,'Salinity',data_region,paths['spinup'],zmax=zmax,vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) fig=comparisons.compare_model_obs(month,2015,'Salinity',data_region,paths['nowcast'],zmax=zmax, vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) data_month=data_region[data_region['Month']==month] data_month.hist('Year',bins = np.arange(data_month['Year'].min()-0.5,data_month['Year'].max()+1.5 )) ax=plt.gca() ax.get_xaxis().get_major_formatter().set_useOffset(False) # May - no data # June # In[14]: month=6 fig=comparisons.compare_model_obs(month,2003,'Salinity',data_region,paths['spinup'],zmax=zmax,vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) fig=comparisons.compare_model_obs(month,2015,'Salinity',data_region,paths['nowcast'],zmax=zmax, vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) data_month=data_region[data_region['Month']==month] data_month.hist('Year',bins = np.arange(data_month['Year'].min()-0.5,data_month['Year'].max()+1.5 )) ax=plt.gca() ax.get_xaxis().get_major_formatter().set_useOffset(False) # July # In[15]: month=7 fig=comparisons.compare_model_obs(month,2003,'Salinity',data_region,paths['spinup'],zmax=zmax,vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) fig=comparisons.compare_model_obs(month,2015,'Salinity',data_region,paths['nowcast'],zmax=zmax, vmin=25,vmax=34, xmin=lon_min,xmax=lon_max,ymin=lat_min,ymax=lat_max) data_month=data_region[data_region['Month']==month] data_month.hist('Year',bins = np.arange(data_month['Year'].min()-0.5,data_month['Year'].max()+1.5 )) ax=plt.gca() ax.get_xaxis().get_major_formatter().set_useOffset(False) # Consider comparing locations individually. # # 2014 # In[16]: data_2014 = data_region[data_region['Year']==2014] data_2014.hist('Month') # Unfortunately, no overlapping data with nowcasts # In[ ]: