<jupyter_start><jupyter_text>* To investigate the impact of each forcing, i.e., river flow, tides, winds and Coriolis force on the plume properties and stratification.<jupyter_code>import numpy as np
import netCDF4 as nc
from salishsea_tools import (
    nc_tools,
    viz_tools,
    stormtools,
    tidetools,
)
import datetime, os
from glob import glob
from IPython.core.display import Image,display
from nowcast import figures
import matplotlib.pyplot as plt
import pytz 
import wind
%matplotlib inline<jupyter_output><empty_output><jupyter_text>* First, take a look at the conditions of the selected simulations, which are Oct 2014 and May 2015, respectively.  River flow at Hope<jupyter_code>x = Image(filename='/ocean/jieliu/research/meopar/surface current/oct2014.png')
y = Image(filename='/ocean/jieliu/research/meopar/surface current/may2015.png')
display(x, y)<jupyter_output><empty_output><jupyter_text>Tides at PA<jupyter_code>Image(filename='/ocean/jieliu/research/meopar/surface current/tideneapsspringgraph.PNG')
## load t_tide
tfile = '/ocean/jieliu/research/meopar/tools/SalishSeaNowcast/tidal_predictions/\
Point Atkinson_t_tide_compare8_31-Dec-2013_02-Dec-2015.csv'
ttide, msl = stormtools.load_tidal_predictions(tfile)
def find_ind_tide(run_low, run_up, run_label1,run_label2):
    """To find index of ttide within a time range"""
    run_low = run_low.replace(tzinfo=pytz.utc) ## convert model datetime to tzinfo=<UTC>
    run_up = run_up.replace(tzinfo=pytz.utc) ## the time i want to label on the plot
    run_label1 = run_label1.replace(tzinfo=pytz.utc)
    run_label2 = run_label2.replace(tzinfo=pytz.utc)
    ttide_dt  = ttide.time.dt.to_pydatetime() ## convert ttide.time (pandas) to datetime
    for i in range(len(ttide_dt)):
        if ttide_dt[i]== run_low:
            low_ind = i
        if ttide_dt[i]== run_up:
            up_ind = i  
        if ttide_dt[i]== run_label1:
            lab_ind1 = i  
        if ttide_dt[i]== run_label2:
            lab_ind2 = i  
    return low_ind, up_ind, lab_ind1,lab_ind2
run_low = datetime.datetime(2014,9,1)
run_up = datetime.datetime(2014,10,31)
run_label1 = datetime.datetime(2014,9,24)
run_label2 = datetime.datetime(2014,10,1)
low_ind,up_ind,lab_ind1,lab_ind2 = find_ind_tide(run_low,run_up,run_label1,run_label2)
fig, ax = plt.subplots(1,1,figsize = (15,6))
ax.plot(ttide.time[low_ind:up_ind], ttide.pred_all[low_ind:up_ind])
ax.plot([ttide.time[lab_ind1],ttide.time[lab_ind1]],[-3.5,3.5],'y-',label = run_label1)
ax.plot([ttide.time[lab_ind2],ttide.time[lab_ind2]],[-3.5,3.5],'r-',label = run_label2)
ax.grid('on')
ax.legend()
ax.set_ylim(-3.5,3.5)<jupyter_output><empty_output><jupyter_text>* spin-up period is in Springs, but Spring-Neap cycle is not very significant in fall.<jupyter_code>run_low = datetime.datetime(2015,4,1)
run_up = datetime.datetime(2015,5,31)
run_label1 = datetime.datetime(2015,4,20)
run_label2 = datetime.datetime(2015,5,1)
low_ind,up_ind,lab_ind1,lab_ind2 = find_ind_tide(run_low,run_up,run_label1,run_label2)
fig, ax = plt.subplots(1,1,figsize = (15,6))
ax.plot(ttide.time[low_ind:up_ind], ttide.pred_all[low_ind:up_ind])
ax.plot([ttide.time[lab_ind1],ttide.time[lab_ind1]],[-3.5,3.5],'y-',label = run_label1)
ax.plot([ttide.time[lab_ind2],ttide.time[lab_ind2]],[-3.5,3.5],'r-',label = run_label2)
ax.grid('on')
ax.legend()
ax.set_ylim(-3.5,3.5)<jupyter_output><empty_output><jupyter_text>* spin-up period cross Spring-Neap tidal modulation period.  Winds at Sand Heads<jupyter_code>OP = nc.Dataset('/results/forcing/atmospheric/GEM2.5/operational/ops_y2014m10d01.nc')
OPlon =OP.variables['nav_lon'][:]-360
OPlat = OP.variables['nav_lat'][:]
import glob
filesOP = glob.glob('/results/forcing/atmospheric/GEM2.5/operational/ops_y2014m10d*.nc')
filesOP.sort(key=os.path.basename)
start = '31-Oct-2014'; end = '01-Nov-2014';
start2 = '01-Nov-2014'; end2 = '01-Nov-2014';
endd = '01-Nov-2014';
stations = ['Sandheads']; stationsOP =['Sandheads_OP'];
sax=datetime.datetime.strptime(start,'%d-%b-%Y')
eax=datetime.datetime.strptime(endd,'%d-%b-%Y')
t1= datetime.datetime(2014,10,31,12)
t2= datetime.datetime(2014,10,31,20)
time =wind.compare_winds_label(start, end, start2, end2,stations,stationsOP,OPlon,OPlat,filesOP,\
                       t1,t2,27,'Sandheads','Sandheads_OP',sax,eax,8, 16, 0)
import glob
filesOP = glob.glob('/results/forcing/atmospheric/GEM2.5/operational/ops_y2014m10d*.nc')
filesOP.sort(key=os.path.basename)
start = '1-Oct-2014'; end = '31-Oct-2014';
start2 = '31-Oct-2014'; end2 = '31-Oct-2014';
endd = '31-Oct-2014';
stations = ['Sandheads']; stationsOP =['Sandheads_OP'];
sax=datetime.datetime.strptime(start,'%d-%b-%Y')
eax=datetime.datetime.strptime(endd,'%d-%b-%Y')

ax =wind.compare_winds(start, end, start2, end2,stations,stationsOP,OPlon,OPlat,filesOP,\
                       27,'Sandheads','Sandheads_OP',sax,eax,8, 16, 0)
filesOP = glob.glob('/results/forcing/atmospheric/GEM2.5/operational/ops_y2015m05d*.nc')
filesOP.sort(key=os.path.basename)
start = '1-May-2015'; end = '31-May-2015';
start2 = '31-May-2015'; end2 = '31-May-2015';
endd = '31-May-2015';
stations = ['Sandheads']; stationsOP =['Sandheads_OP'];
sax=datetime.datetime.strptime(start,'%d-%b-%Y')
eax=datetime.datetime.strptime(endd,'%d-%b-%Y')

ax =wind.compare_winds(start, end, start2, end2,stations,stationsOP,OPlon,OPlat,filesOP,\
                       27,'Sandheads','Sandheads_OP',sax,eax,8, 16, 0)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15800110233327208, 'fraction_numerical': 0.061179496601139076, 'mean_word_length': 5.535414165666267, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '616194', 'license': 'Apache-2.0', 'n_tokens_mistral': 2387, 'n_tokens_neox': 2178, 'n_words': 337, 'path': 'jie/surface_current/ImpactOfEachForcing.ipynb', 'repo_name': 'SalishSeaCast/analysis', 'size': '5443'}