#!/usr/bin/env python # coding: utf-8 # In[1]: import numpy as np import pandas as pd from matplotlib import pyplot as plt from salishsea_tools import geo_tools, viz_tools, evaltools as et import gsw import netCDF4 as nc import datetime as dt import cmocean import pickle import os import warnings warnings.filterwarnings("ignore") get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: obslat=50.117 obslon=-125.223 # In[3]: with nc.Dataset('/ocean/eolson/MEOPAR/NEMO-forcing/grid/mesh_mask201702_noLPE.nc') as mesh: tmask=np.copy(mesh.variables['tmask'][0,:,:,:]) navlat=np.copy(mesh.variables['nav_lat'][:,:]) navlon=np.copy(mesh.variables['nav_lon'][:,:]) e3t_0=np.copy(mesh.variables['e3t_0'][0,:,:,:]) print(mesh.variables.keys()) # In[4]: j,i=geo_tools.find_closest_model_point(obslon,obslat,navlon,navlat) fig,ax=plt.subplots(1,2,figsize=(10,5)) ax[0].contour(navlon,navlat,tmask[0,:,:],(0.5,)) ax[0].plot(navlon[j,i],navlat[j,i],'r*') ax[0].set_xlim(-125.4,-125) ax[0].set_ylim(50,50.4) viz_tools.set_aspect(ax[0],coords='map') ax[0].set_title('Geo coords') ax[1].contour(tmask[0,:,:],(.5,)) ax[1].plot(i,j,'r*') ax[1].set_xlim(100,180) ax[1].set_ylim(730,800) viz_tools.set_aspect(ax[1],coords='grid') ax[1].set_title('Grid coords') ks=np.sum(tmask[:,j,i]) print('depth is {0} grid points at site or roughly {1:3.1f} m'.format(ks,np.sum(e3t_0[:ks,j,i]))) # In[5]: print(j,i) # In[5]: df=pd.read_csv('/ocean/eolson/MEOPAR/obs/IzettCTD/Quadra_Hakai_BoL-data_201906-202004.txt',header=0,skiprows=(1,)) # In[6]: df.head() # In[7]: df['dtUTC']=[dt.datetime(2014,1,1)+dt.timedelta(days=ii) for ii in df['Days']] # In[8]: df['SA']=[gsw.SA_from_SP(isp,1.4,obslon,obslat) for isp in df['TSG_S']] # In[9]: df['CT']=[gsw.CT_from_t(isa,ist,1.4) for isa,ist in zip(df['SA'],df['TSG_T'])] # In[10]: df['Z']=1.4 df['Lat']=obslat df['Lon']=obslon # In[11]: df['k']=1 df['i']=i df['j']=j # In[12]: df.head() # In[13]: flen=1 namfmt='nowcast' filemap={'vosaline':'grid_T','votemper':'grid_T'} fdict={'grid_T':1,} PATH='/results2/SalishSea/nowcast-green.201905/' runID='HC201905' dstart=dt.datetime(2014,12,19) dend=dt.datetime(2020,6,20) # In[14]: len(df) # In[15]: # remove a day because it is currently missing from model output df.drop(df.loc[(df.dtUTC>=dt.datetime(2020,6,10))&(df.dtUTC