Precipitation Uncertainty

Create a template run directory

In [1]:
%%bash
# Make a new directory for our baseline simulation
mkdir -p ~/wrf-hydro-training/output/free_lesson_precip/run_template

# Copy our model files to the simulation directory
cp ~/wrf-hydro-training/wrf_hydro_nwm_public/trunk/NDHMS/Run/*.TBL \
~/wrf-hydro-training/output/free_lesson_precip/run_template
cp ~/wrf-hydro-training/wrf_hydro_nwm_public/trunk/NDHMS/Run/wrf_hydro.exe \
~/wrf-hydro-training/output/free_lesson_precip/run_template

# Copy the forcing files so we can modify them
cp -r $HOME/wrf-hydro-training/example_case/FORCING \
~/wrf-hydro-training/output/free_lesson_precip/run_template

# Copy the domain/parameter files so we can modify them
cp -r $HOME/wrf-hydro-training/example_case/Gridded_no_lakes/DOMAIN \
~/wrf-hydro-training/output/free_lesson_precip/run_template
cp -r $HOME/wrf-hydro-training/example_case/Gridded_no_lakes/RESTART \
~/wrf-hydro-training/output/free_lesson_precip/run_template

# Copy namelist files
cp ~/wrf-hydro-training/example_case/Gridded_no_lakes/namelist.hrldas \
~/wrf-hydro-training/output/free_lesson_precip/run_template
cp ~/wrf-hydro-training/example_case/Gridded_no_lakes/hydro.namelist \
~/wrf-hydro-training/output/free_lesson_precip/run_template

Review the current precipitation values

Examine the forcing files:

In [2]:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_template/FORCING
ncdump -v RAINRATE 2011082700.LDASIN_DOMAIN1 | tail -n 20
data:

 RAINRATE =
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;
}
In [3]:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_template/FORCING
ncdump -v RAINRATE 2011082812.LDASIN_DOMAIN1 | tail -n 20
    0.003599961, 0.003575217, 0.003547333, 0.003519389,
  0.003687089, 0.00367106, 0.003666807, 0.0036616, 0.003655352, 0.003648069, 
    0.003639755, 0.00363046, 0.003620161, 0.003608777, 0.003596449, 
    0.003582248, 0.00355479, 0.003527194, 0.003499388,
  0.003645457, 0.003639691, 0.003637013, 0.003633342, 0.003628631, 
    0.00362292, 0.003616141, 0.003608417, 0.003599602, 0.003589833, 
    0.003579013, 0.003561741, 0.003534491, 0.003507103, 0.003479589,
  0.0036095, 0.003609371, 0.003608254, 0.003606093, 0.003602938, 0.003598721, 
    0.003593564, 0.003587349, 0.003580137, 0.003571869, 0.003562627, 
    0.003541372, 0.003514335, 0.003487164, 0.003459844,
  0.00357863, 0.003580063, 0.003580475, 0.003579866, 0.003578255, 
    0.003575637, 0.003571977, 0.003567337, 0.003561644, 0.003554937, 
    0.003547236, 0.003521232, 0.003494326, 0.003467353, 0.003440241,
  0.003548772, 0.003551746, 0.00355373, 0.003554672, 0.003554594, 
    0.003553513, 0.003551438, 0.003548309, 0.003544202, 0.003539035, 
    0.003527619, 0.003501152, 0.003474521, 0.003447675, 0.00342078,
  0.003519944, 0.003524443, 0.003527978, 0.003530491, 0.003531981, 
    0.003532442, 0.003531882, 0.003530317, 0.003527737, 0.003524132, 
    0.003507545, 0.00348119, 0.003454777, 0.003428144, 0.003401466 ;
}
In [4]:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_template/FORCING
ncdump -v RAINRATE 2011082900.LDASIN_DOMAIN1 | tail -n 20
    1.358192e-05, 1.61564e-05, 1.911441e-05, 2.219118e-05,
  0, 4.628337e-07, 1.321959e-06, 2.257915e-06, 3.272189e-06, 4.36787e-06, 
    5.542051e-06, 6.792232e-06, 8.121661e-06, 9.530568e-06, 1.101749e-05, 
    1.264398e-05, 1.528074e-05, 1.804257e-05, 2.093713e-05,
  0, 5.839819e-07, 1.323051e-06, 2.139062e-06, 3.035893e-06, 4.009194e-06, 
    5.062525e-06, 6.193894e-06, 7.404165e-06, 8.692227e-06, 1.006195e-05, 
    1.183136e-05, 1.427818e-05, 1.685004e-05, 1.954953e-05,
  8.673664e-08, 6.26828e-07, 1.24595e-06, 1.94366e-06, 2.718365e-06, 
    3.572666e-06, 4.50552e-06, 5.518694e-06, 6.60812e-06, 7.777621e-06, 
    9.02445e-06, 1.089317e-05, 1.315079e-05, 1.553442e-05, 1.80415e-05,
  1.712463e-07, 5.912723e-07, 1.090057e-06, 1.667546e-06, 2.32419e-06, 
    3.057913e-06, 3.871623e-06, 4.763141e-06, 5.734486e-06, 6.784969e-06, 
    7.911587e-06, 9.82752e-06, 1.18994e-05, 1.409166e-05, 1.640881e-05,
  1.779577e-07, 4.771131e-07, 8.560017e-07, 1.313378e-06, 1.849388e-06, 
    2.464629e-06, 3.157808e-06, 3.930013e-06, 4.780835e-06, 5.710113e-06, 
    6.886172e-06, 8.640917e-06, 1.051744e-05, 1.252247e-05, 1.465155e-05,
  1.053409e-07, 2.84952e-07, 5.438178e-07, 8.80796e-07, 1.297245e-06, 
    1.792141e-06, 2.365657e-06, 3.018652e-06, 3.748303e-06, 4.558507e-06, 
    5.761025e-06, 7.325963e-06, 9.014046e-06, 1.082951e-05, 1.277081e-05 ;
}

Modify the precipitation to be 25% higher

Copy the template directory:

In [5]:
%%bash
cp -r ~/wrf-hydro-training/output/free_lesson_precip/run_template \
~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_1.25

Use a simple bash "for loop" to loop through all of the LDASIN files and multiply the values by 1.25:

In [6]:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_1.25/FORCING
for i in `ls 20*.LDASIN_DOMAIN1`; do
  ncap2 -O -s "RAINRATE=RAINRATE*1.25" ${i} ${i}
done
In [7]:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_1.25/FORCING
ncdump -v RAINRATE 2011082812.LDASIN_DOMAIN1 | tail -n 20
    0.004499951, 0.004469022, 0.004434166, 0.004399236,
  0.004608861, 0.004588825, 0.004583509, 0.004577001, 0.004569191, 
    0.004560086, 0.004549693, 0.004538075, 0.004525202, 0.004510972, 
    0.004495561, 0.00447781, 0.004443488, 0.004408992, 0.004374234,
  0.004556821, 0.004549614, 0.004546267, 0.004541678, 0.004535789, 
    0.00452865, 0.004520176, 0.004510521, 0.004499502, 0.004487291, 
    0.004473766, 0.004452176, 0.004418114, 0.004383879, 0.004349486,
  0.004511875, 0.004511714, 0.004510317, 0.004507616, 0.004503672, 
    0.004498401, 0.004491956, 0.004484186, 0.004475171, 0.004464836, 
    0.004453284, 0.004426715, 0.004392919, 0.004358955, 0.004324805,
  0.004473287, 0.004475079, 0.004475594, 0.004474833, 0.004472819, 
    0.004469546, 0.004464971, 0.004459171, 0.004452055, 0.004443672, 
    0.004434044, 0.00440154, 0.004367907, 0.004334191, 0.004300301,
  0.004435965, 0.004439682, 0.004442163, 0.00444334, 0.004443243, 
    0.004441891, 0.004439298, 0.004435386, 0.004430253, 0.004423794, 
    0.004409524, 0.004376439, 0.004343152, 0.004309594, 0.004275976,
  0.00439993, 0.004405554, 0.004409972, 0.004413114, 0.004414977, 
    0.004415552, 0.004414853, 0.004412896, 0.004409671, 0.004405165, 
    0.004384431, 0.004351488, 0.004318472, 0.00428518, 0.004251833 ;
}

Run the model:

In [8]:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_1.25
mpirun -np 2 ./wrf_hydro.exe >> run.log 2>&1

Modify the precipitation to be 25% lower

Copy the template directory:

In [9]:
%%bash
cp -r ~/wrf-hydro-training/output/free_lesson_precip/run_template \
~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_0.75

Use a simple bash "for loop" to loop through all of the LDASIN files and multiply the values by 0.75:

In [10]:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_0.75/FORCING
for i in `ls 20*.LDASIN_DOMAIN1`; do
  ncap2 -O -s "RAINRATE=RAINRATE*0.75" ${i} ${i}
done
In [11]:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_0.75/FORCING
ncdump -v RAINRATE 2011082812.LDASIN_DOMAIN1 | tail -n 20
    0.002699971, 0.002681413, 0.002660499, 0.002639542,
  0.002765317, 0.002753295, 0.002750105, 0.0027462, 0.002741514, 0.002736052, 
    0.002729816, 0.002722845, 0.002715121, 0.002706583, 0.002697337, 
    0.002686686, 0.002666093, 0.002645395, 0.002624541,
  0.002734093, 0.002729768, 0.00272776, 0.002725007, 0.002721473, 0.00271719, 
    0.002712105, 0.002706313, 0.002699702, 0.002692375, 0.00268426, 
    0.002671306, 0.002650869, 0.002630327, 0.002609692,
  0.002707125, 0.002707028, 0.002706191, 0.00270457, 0.002702204, 
    0.002699041, 0.002695173, 0.002690512, 0.002685103, 0.002678902, 
    0.002671971, 0.002656029, 0.002635751, 0.002615373, 0.002594883,
  0.002683972, 0.002685047, 0.002685356, 0.0026849, 0.002683692, 0.002681728, 
    0.002678982, 0.002675503, 0.002671233, 0.002666203, 0.002660427, 
    0.002640924, 0.002620744, 0.002600515, 0.002580181,
  0.002661579, 0.002663809, 0.002665298, 0.002666004, 0.002665946, 
    0.002665135, 0.002663579, 0.002661232, 0.002658152, 0.002654277, 
    0.002645714, 0.002625864, 0.002605891, 0.002585756, 0.002565585,
  0.002639958, 0.002643333, 0.002645983, 0.002647868, 0.002648986, 
    0.002649331, 0.002648911, 0.002647738, 0.002645802, 0.002643099, 
    0.002630658, 0.002610893, 0.002591083, 0.002571108, 0.0025511 ;
}

Run the model:

In [12]:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_0.75
mpirun -np 2 ./wrf_hydro.exe >> run.log 2>&1

Plot the resulting hydrographs

In [13]:
# Load the xarray package
%matplotlib inline
import xarray as xr
import matplotlib.pyplot as plt
import pandas as pd
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()

chanobs_baseline = xr.open_mfdataset('/home/docker/wrf-hydro-training/output/lesson5/run_gridded_baseline/*CHANOBS*',
                            combine='by_coords')
chanobs_prec125 = xr.open_mfdataset('/home/docker/wrf-hydro-training/output/free_lesson_precip/run_precip_x_1.25/*CHANOBS*',
                            combine='by_coords')
chanobs_prec075 = xr.open_mfdataset('/home/docker/wrf-hydro-training/output/free_lesson_precip/run_precip_x_0.75/*CHANOBS*',
                            combine='by_coords')
In [14]:
fig, axes = plt.subplots(ncols=1,figsize=(12, 6))
plt.suptitle('Hydrographs for precipitation sensitivity',fontsize=24)
chanobs_baseline.sel(feature_id = 2).streamflow.plot(label='Baseline Precipitation',
                                                        color='black',
                                                        linestyle='--')
chanobs_prec125.sel(feature_id = 2).streamflow.plot(label='Precipitation+25%',
                                                        color='blue',
                                                        linestyle='-')
chanobs_prec075.sel(feature_id = 2).streamflow.plot(label='Precipitation-25%',
                                                        color='red',
                                                        linestyle='-')


plt.ylim(0,100)
plt.legend()
plt.show()

Plot evapotranspiration differences

We want to calculate average latent heat flux over the simulation.

In [15]:
# Load the time series
ldasout_base = xr.open_mfdataset('/home/docker/wrf-hydro-training/output/lesson5/run_gridded_baseline/*.LDASOUT*',
                            combine='by_coords')
ldasout_high = xr.open_mfdataset('/home/docker/wrf-hydro-training/output/free_lesson_precip/run_precip_x_1.25/*.LDASOUT*',
                            combine='by_coords')
ldasout_low = xr.open_mfdataset('/home/docker/wrf-hydro-training/output/free_lesson_precip/run_precip_x_0.75/*.LDASOUT*',
                            combine='by_coords')
In [16]:
# Calculate the mean latent heat flux across the domain
et_base = ldasout_base.LH.mean(dim=('y','x'), skipna=True)
et_high = ldasout_high.LH.mean(dim=('y','x'), skipna=True)
et_low = ldasout_low.LH.mean(dim=('y','x'), skipna=True)

# Plot the soil moisture time series
fig, axes = plt.subplots(ncols=1,figsize=(12, 6))
plt.suptitle('Average Latent Heat Flux',fontsize=24)
et_base.plot(label='Baseline Precipitation', color='black', linestyle='--')
et_high.plot(label='Precipitation+25%', color='blue', linestyle='-')
et_low.plot(label='Precipitation-25%', color='red', linestyle='-')
plt.legend()
plt.show()
/home/docker/miniconda3/lib/python3.7/site-packages/dask/array/numpy_compat.py:40: RuntimeWarning: invalid value encountered in true_divide
  x = np.divide(x1, x2, out)
/home/docker/miniconda3/lib/python3.7/site-packages/dask/array/numpy_compat.py:40: RuntimeWarning: invalid value encountered in true_divide
  x = np.divide(x1, x2, out)
/home/docker/miniconda3/lib/python3.7/site-packages/dask/array/numpy_compat.py:40: RuntimeWarning: invalid value encountered in true_divide
  x = np.divide(x1, x2, out)

Plot soil moisture storage differences

In [17]:
# Calculate the mean top-layer soil moisture across the domain
smois_base_avg = ldasout_base.SOIL_M.sel(soil_layers_stag = 0).mean(dim=('y','x'))
smois_high_avg = ldasout_high.SOIL_M.sel(soil_layers_stag = 0).mean(dim=('y','x'))
smois_low_avg = ldasout_low.SOIL_M.sel(soil_layers_stag = 0).mean(dim=('y','x')) 

# Plot the soil moisture time series
fig, axes = plt.subplots(ncols=1,figsize=(12, 6))
plt.suptitle('Average Soil Moisture: Top Layer',fontsize=24)
smois_base_avg.plot(label='Baseline Precipitation', color='black', linestyle='--')
smois_high_avg.plot(label='Precipitation+25%', color='blue', linestyle='-')
smois_low_avg.plot(label='Precipitation-25%', color='red', linestyle='-')
plt.ylim(0.28,0.43)
plt.legend()
plt.show()
In [18]:
# Calculate the mean top-layer soil moisture across the domain
smois_base_avg = ldasout_base.SOIL_M.sel(soil_layers_stag = 3).mean(dim=('y','x'))
smois_high_avg = ldasout_high.SOIL_M.sel(soil_layers_stag = 3).mean(dim=('y','x'))
smois_low_avg = ldasout_low.SOIL_M.sel(soil_layers_stag = 3).mean(dim=('y','x')) 

# Plot the soil moisture time series
fig, axes = plt.subplots(ncols=1,figsize=(12, 6))
plt.suptitle('Average Soil Moisture: Bottom Layer',fontsize=24)
smois_base_avg.plot(label='Baseline Precipitation', color='black', linestyle='--')
smois_high_avg.plot(label='Precipitation+25%', color='blue', linestyle='-')
smois_low_avg.plot(label='Precipitation-25%', color='red', linestyle='-')
plt.ylim(0.28,0.43)
plt.legend()
plt.show()

Plot groundwater storage differences

In [19]:
# Load the time series
gwbucket_base = xr.open_mfdataset('/home/docker/wrf-hydro-training/output/lesson5/run_gridded_baseline/*GWOUT*',
                            combine='by_coords')
gwbucket_high = xr.open_mfdataset('/home/docker/wrf-hydro-training/output/free_lesson_precip/run_precip_x_1.25/*GWOUT*',
                            combine='by_coords')
gwbucket_low = xr.open_mfdataset('/home/docker/wrf-hydro-training/output/free_lesson_precip/run_precip_x_0.75/*GWOUT*',
                            combine='by_coords')
In [20]:
# Calculate the mean bucket level across the domain
gwlevel_base_avg = gwbucket_base.depth.mean(dim=('feature_id'))
gwlevel_high_avg = gwbucket_high.depth.mean(dim=('feature_id')) 
gwlevel_low_avg = gwbucket_low.depth.mean(dim=('feature_id')) 

# Plot the bucket level time series
fig, axes = plt.subplots(ncols=1,figsize=(12, 6))
plt.suptitle('Average Groundwater Bucket Level',fontsize=24)
gwlevel_base_avg.plot(label='Baseline Precipitation', color='black', linestyle='--')
gwlevel_high_avg.plot(label='Precipitation+25%', color='blue', linestyle='-')
gwlevel_low_avg.plot(label='Precipitation-25%', color='red', linestyle='-')
plt.legend()
plt.show()
In [ ]: