#!/usr/bin/env python # coding: utf-8 # # **Oxygen in the Strait of Georgia** # In[1]: import cmocean.cm as cm import datetime as dt import matplotlib.pyplot as plt from matplotlib.colors import LogNorm import numpy as np import pandas as pd # import statfieldodels.api as sm import xarray as xr from salishsea_tools import viz_tools import netCDF4 as nc # import glob # # North # In[2]: def read_pieces(pieces): temp1 = pd.read_csv(pieces[0]) for piece in pieces[1:]: nextpiece = pd.read_csv(piece) if 'ferry' in piece: nextpiece['k'] = 0 temp1 = pd.concat([temp1, nextpiece], ignore_index=True) return temp1 # In[9]: y = [2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019] # y = [2018, 2019] years = np.array(y) pieces = [] df = pd.DataFrame() for year in years: pieces.append( f'/data/sallen/results/MEOPAR/202111/ObsModel/ObsModel_202111_bot_{year}0101_{year}1231.csv') data_bot = read_pieces(pieces) #df = pd.concat([data_bot, df_csv_append], ignore_index=True) data_bot # In[8]: fig, ax = plt.subplots(1,1,figsize = (6,6)) with nc.Dataset('/data/vdo/MEOPAR/NEMO-forcing/grid/bathymetry_201702.nc') as grid: viz_tools.plot_coastline(ax, grid, coords = 'map',isobath=.1) ax, plt.plot(data_bot.Lon, data_bot.Lat,'.') #ax.set_ylim(48.5, 48.78) ax.legend(bbox_to_anchor=[1,.6,0,0]) #ax.set_xlim(-123.65, -123.44); ax.set_title('Observation Locations - Bot'); # In[ ]: # Concat all bot data # np.savetxt('/ocean/atall/MOAD/ObsModel/202111/bot/ObsModel_202111_bot_all_200201_20191231.csv', data_bot, fmt='%s') # In[ ]: # date_range=(dt.datetime(2015,1,1),dt.datetime(2017,12,31)) # In[ ]: # SMOOTH data DO = data_bot.Oxygen_Dissolved dtime = data_bot.dtUTC # dtime = data_bot.D def smooth(DO, box_pts): box = np.ones(box_pts)/box_pts DO_smooth = np.convolve(DO, box, mode='same') return DO_smooth plt.plot(dtime[:365], DO[:365], '.') plt.plot(dtime[:365], smooth(DO[:365],3), 'r-') #plot(x, smooth(y,3), 'r-', lw=2) #plot(x, smooth(y,19), 'g-', lw=2) DO.shape #