#!/usr/bin/env python # coding: utf-8 # In[1]: import numpy as np import pandas as pd import matplotlib.pyplot as plt import datetime as dt from salishsea_tools import evaltools as et get_ipython().run_line_magic('matplotlib', 'inline') # In[2]: ls '/ocean/ksuchy/MOAD/observe/Data and Code files for KS 2020dec11/2020_05_21 1995-2011 SoG VNH.csv' # In[3]: df=pd.read_csv('/ocean/ksuchy/MOAD/observe/Data and Code files for KS 2020dec11/2020_05_21 2012-2015 SoG VNH.csv', encoding = "ISO-8859-1") # In[4]: df # In[5]: df.keys() # In[6]: df['Biomass(mg/m3)'] # In[7]: df['Date'][0],df['STN_TIME'][0] # In[8]: df['Date'][1000:1020] # In[9]: df['Date'][0].split('/') # In[10]: dateslist=list() # In[11]: for el in df['Date']: dateslist.append(el.split('/')) # In[12]: timeslist=list() for el in df['STN_TIME']: timeslist.append(el.split(':')) # In[13]: dts=list() for ii,jj in zip(dateslist,timeslist): dts.append(dt.datetime(int(ii[2]),int(ii[0]),int(ii[1]),int(jj[0]),int(jj[1]))) # In[14]: df.loc[df.Twilight=='Daylight']['STN_TIME'].unique() # In[15]: df['dtUTC']=et.pac_to_utc(dts) #convert from Pac time to UTC # In[16]: df['Order:'].unique() # In[17]: colList=('Amphipoda', 'Decapoda','Euphausiacea', 'Calanoida', 'Cyclopoida', 'Poecilostomatoida','Copelata','Harpacticoida',) # In[18]: df.keys() # In[19]: dtsutc=et.pac_to_utc(dts) # In[20]: df.loc[0] # In[21]: towIDlist=['Key', 'region_name', 'Station', 'lon', 'lat', 'dtUTC', 'Twilight', 'Net_Type', 'Mesh_Size(um)', 'DEPTH_STRT1', 'DEPTH_END1', 'Bottom Depth(m)'] # In[22]: towIDlist2=['Key', 'region_name', 'Station', 'lon', 'lat', 'dtUTC', 'Twilight', 'Net_Type', 'Mesh_Size(um)', 'DEPTH_STRT1', 'DEPTH_END1', 'Bottom Depth(m)','CTD'] # In[23]: len(df.groupby(towIDlist)),len(df.groupby(towIDlist2)),len(df.groupby(['Key'])) # In[24]: # Key is a unique identifier for each tow # do not group by CTD due to NaN values # In[25]: biomassDF=df.groupby(towIDlist,as_index=False).first()\ .loc[:,towIDlist].copy(deep=True) # In[26]: biomassDF # In[27]: def getbiomass(colname,key,origdf): biomassArray=df.loc[(origdf.Key==key)&(origdf['Order:']==colname), ['Biomass(mg/m3)']] biomass=np.nansum(biomassArray) return biomass # In[28]: for icol in colList: biomassDF[icol]=[getbiomass(icol,ikey,df) for ikey in biomassDF['Key']] # In[29]: biomassDF # In[30]: import netCDF4 as nc # In[31]: ftemp=nc.Dataset('/data/eolson/results/MEOPAR/NEMO-forcing-new/grid/mesh_mask201702.nc') # In[32]: ftemp.variables.keys() # In[33]: ftemp.variables['e3t_0'] # In[34]: ftemp.variables['e3t_1d'][:] # In[35]: fdict={'ptrc_T':1,'grid_T':1} start_date = dt.datetime(2015,6,1) end_date = dt.datetime(2015,6,30) flen=1 # number of days per model output file. always 1 for 201905 and 201812 model runs namfmt='nowcast' # for 201905 and 201812 model runs, this should always be 'nowcast' # filemap is dictionary of the form variableName: fileType, where variableName is the name # of the variable you want to extract and fileType designates the type of # model output file it can be found in (usually ptrc_T for biology, grid_T for temperature and # salinity) filemap={'microzooplankton':'ptrc_T','mesozooplankton':'ptrc_T'} # fdict is a dictionary mappy file type to its time resolution. Here, 1 means hourly output # (1h file) and 24 means daily output (1d file). In certain runs, multiple time resolutions # are available fdict={'ptrc_T':1,'grid_T':1} # In[36]: PATH= '/results2/SalishSea/nowcast-green.201905/' # In[37]: biomassDF.rename(columns={'lon':'Lon','lat':'Lat'},inplace=True) # In[38]: biomassDF.keys() # In[39]: biomassDF.rename(columns={'DEPTH_STRT1':'Z_lower','DEPTH_END1':'Z_upper','Bottom Depth (m)': 'Z'},inplace=True) # In[40]: data=et.matchData(biomassDF,filemap,fdict,start_date,end_date,'nowcast',PATH,1,quiet=False,method='vertNet'); # In[41]: data # In[ ]: