<jupyter_start><jupyter_text>A notebook to generate a river forcing. Constant Fraser river outflow 2000m^3/s.Based on /data/nsoontie/MEOPAR/NEMO-forcing/rivers/Fraser_only_cnst.ncUses a runoff temperaure of 14 deg to avoid runaway temperatures.<jupyter_code>import netCDF4 as nc
import numpy as np

from salishsea_tools import nc_tools

import matplotlib.pyplot as plt

%matplotlib inline<jupyter_output><empty_output><jupyter_text>3D constant forcing First look at the constant Fraser river forcing file.<jupyter_code>river = nc.Dataset('/data/nsoontie/MEOPAR/NEMO-forcing/rivers/rivers_Fraser_only_cnst.nc')
nc_tools.show_variables(river)
run_off_3D = river.variables['rorunoff'][0,:,:]
depth_3D =river.variables['rodepth'][:]
inds = np.where(run_off_3D != 0.0)
run_off_3D[inds]
total_run_off_3D = np.sum(run_off_3D[inds])
print(total_run_off_3D)
np.max(depth_3D)<jupyter_output><empty_output><jupyter_text>Dishcharge distrubuted across three different points.Plan: add these up and distrubute across right end of my domain.  Towards 2D files Load bathymetry<jupyter_code>fB=nc.Dataset('/data/nsoontie/MEOPAR/2Ddomain/grid/bathy2D_36.nc')<jupyter_output><empty_output><jupyter_text>Iniitialize run off arrays<jupyter_code>d = fB.variables['Bathymetry'][:]
X = fB.variables['x'][:]
Y=fB.variables['y'][:]
ymax, xmax = d.shape
runoff = np.zeros((ymax, xmax))
run_depth = -np.ones((ymax, xmax)) 
run_temp = -999*np.ones((ymax, xmax)) # -999 means missing data and will use surface temp

TEMP = 14<jupyter_output><empty_output><jupyter_text>Set up parameters<jupyter_code>run_off_depth = 3 # fresh water will be added over three metres<jupyter_output><empty_output><jupyter_text>Add river to second to last grid cell. Divide discgarge in spanwise, but exlude first and last.<jupyter_code>#depth at last grid cell?
print(d[2,-2])
js=1; je=ymax-2

runoff[js:je+2,xmax-2] = total_run_off_3D/(je-js)
run_depth[js:je+2,xmax-2]= run_off_depth
run_temp[js:je+2,xmax-2]= TEMP
plt.plot(runoff[1,:])
plt.plot(run_depth[1,:])
plt.plot(run_temp[1,:])<jupyter_output><empty_output><jupyter_text>Create netcdf file<jupyter_code>nemo = nc.Dataset('../rivers/river_cnst.nc', 'w')
nemo.description = 'Constant Yearly Average, One River' 
# dimensions
nemo.createDimension('x', xmax)
nemo.createDimension('y', ymax)
nemo.createDimension('time_counter', None)
    
# variables
y = nemo.createVariable('y','float32',('y','x'),zlib=True)
y = Y
x = nemo.createVariable('x','float32',('y','x'),zlib=True)
x = X
    # time
time_counter = nemo.createVariable('time_counter', 'float32', ('time_counter'),zlib=True)
time_counter.units = 'non-dim'
time_counter[0] = 1
# runoff
rorunoff = nemo.createVariable('rorunoff', 'float32', ('time_counter','y','x'), zlib=True)
rorunoff._Fillvalue = 0.
rorunoff._missing_value = 0.
rorunoff._units = 'kg m-2 s-1'
rorunoff[0,:] = runoff
# depth
rodepth = nemo.createVariable('rodepth','float32',('y','x'),zlib=True)
rodepth._Fillvalue = -1.
rodepth.missing_value = -1.
rodepth.units = 'm'
rodepth[:] = run_depth
# temp
rotemper = nemo.createVariable('rotemper','float32',('y','x'),zlib=True)
rotemper._Fillvalue = -999.
rotemper.missing_value = -999.
rotemper.units = 'deg C'
rotemper[:] = run_temp
nemo.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14984615384615385, 'fraction_numerical': 0.023076923076923078, 'mean_word_length': 7.1275, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '107483', 'license': 'Apache-2.0', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1290, 'n_words': 235, 'path': 'notebooks/Generate_rivers_forcing.ipynb', 'repo_name': 'SalishSeaCast/2d-domain', 'size': '3250'}