%%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
Examine the forcing files:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_template/FORCING
ncdump -v RAINRATE 2011082700.LDASIN_DOMAIN1 | tail -n 20
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_template/FORCING
ncdump -v RAINRATE 2011082812.LDASIN_DOMAIN1 | tail -n 20
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_template/FORCING
ncdump -v RAINRATE 2011082900.LDASIN_DOMAIN1 | tail -n 20
Copy the template directory:
%%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:
%%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
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_1.25/FORCING
ncdump -v RAINRATE 2011082812.LDASIN_DOMAIN1 | tail -n 20
Run the model:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_1.25
mpirun -np 2 ./wrf_hydro.exe >> run.log 2>&1
Copy the template directory:
%%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:
%%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
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_0.75/FORCING
ncdump -v RAINRATE 2011082812.LDASIN_DOMAIN1 | tail -n 20
Run the model:
%%bash
cd ~/wrf-hydro-training/output/free_lesson_precip/run_precip_x_0.75
mpirun -np 2 ./wrf_hydro.exe >> run.log 2>&1
# 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')
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()
We want to calculate average latent heat flux over the simulation.
# 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')
# 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()
# 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()
# 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()
# 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')
# 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()