<jupyter_start><jupyter_text>Comparison of output from coupled surface- and soil- bmis and PRMS6.PRMS6 is decoupled into 4 bmis including Surface, Soil, Groundwater and Streamflow.  The purpose of this notebook is to compare the output from a coupled surface-soil model with PRMS6.  An example of the Fortran code for this coupling is below and the full code can be found here [ifr_ex](https://github.com/nhm-usgs/bmi-prms6-soil/blob/master/examples/irf_ex.f90):``` fortran  use bmif_2_0, only: BMI_MAX_UNITS_NAME, BMI_SUCCESS, BMI_FAILURE  use bmiprmssurface  use bmiprmssoil  implicit none  type (bmi_prms_surface) :: m_surf  type (bmi_prms_soil) :: m_soil  integer :: s, i  double precision :: time, time0, time1  character (len=BMI_MAX_UNITS_NAME) :: time_units  character (len=*), parameter :: control_file = './pipestem/control.simple1'  character (len=*), parameter :: control_file1 = './pipestem_surface/control.simple1'  character (len=*), parameter :: control_file2 = './pipestem_soil/control.simple1'  double precision :: endtime  write (*,"(a)",advance="no") "Initializing..."  s = m_surf%initialize(control_file1)  s = m_soil%initialize(control_file2)    s = m_surf%get_end_time(endtime)    do i = 1,int(endtime)      s = m_surf%update()      s = surface2soil(m_surf, m_soil)      s = m_soil%update()      s = soil2surface(m_surf, m_soil)  enddo  write (*,*) "Done."  write (*,"(a)", advance="no") "Finalizing..."  s = m_surf%finalize()  s = m_soil%finalize()  write (*,*) "Done"```<jupyter_code># code for specific functions in this notebook. See repo Readme.md for install instructions
import prms6bmi
import geopandas as gpd
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
from pathlib import Path<jupyter_output><empty_output><jupyter_text>--- Set the paths to the summary_daily.nc (NetCDF) files and read into [xarray](http://xarray.pydata.org/en/stable/)---<jupyter_code>soil_file = Path('B:/gitbmi/bmi-prms6-soil/bmi_prms_soil/irf_ex/pipestem_soil/output/summary_daily.nc')
surf_file = Path('B:/gitbmi/bmi-prms6-soil/bmi_prms_soil/irf_ex/pipestem_surface/output/summary_daily.nc')
prms_file = Path('B:/gitbmi/prms/_build/prms/pipestem/output/summary_daily.nc')
clim_file = Path('B:/gitbmi/prms/_build/prms/pipestem/daymet.nc')
dsoil = xr.open_dataset(soil_file)
dprms = xr.open_dataset(prms_file)
dsurf = xr.open_dataset(surf_file)
clim = xr.open_dataset(clim_file)<jupyter_output><empty_output><jupyter_text>--- Print min/max dates of climate forcing data and then print some meta-data---<jupyter_code>clim_date_min = clim.time.min().values
clim_date_max = clim.time.max().values
print(clim_date_min, clim_date_max)
clim<jupyter_output>1980-01-01T00:00:00.000000000 2016-12-31T00:00:00.000000000<jupyter_text>--- Print min/max dates of of the bmi-soil simulation and then print some meta-data---<jupyter_code>sim_start_date = dsoil.time.min()
sim_end_date = dsoil.time.max()
dsoil<jupyter_output><empty_output><jupyter_text>--- surface-bmi meta-data---<jupyter_code>dsurf<jupyter_output><empty_output><jupyter_text>--- PRMS6 simulation metadata---<jupyter_code>print(dprms.nhm_id)
dprms
# the following results from a future-warning message so implemented below
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()<jupyter_output><empty_output><jupyter_text>--- Plot the climate data over the simulation period1. The hru to plot can be adjusted by setting t_hru. There are 14 hrus.---<jupyter_code>fig, ax = plt.subplots(ncols=3)
t_hru = 13
prms6bmi.plot_climate(clim, t_hru, 'prcp', sim_start_date, sim_end_date, ax[0])
prms6bmi.plot_climate(clim, t_hru, 'tmax', sim_start_date, sim_end_date, ax[1])
prms6bmi.plot_climate(clim, t_hru, 'tmin', sim_start_date, sim_end_date, ax[2])
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>--- Plot a comparison of the 4 variables that are passed between the surface and soil bmi's and check the residual compared to the regular PRMS6 run1. The hru to plot can be adjusted by setting t_hru. There are 14 hrus. Parameters passed from bmi-soil to bmi-surface From climateflow class1. soil_moist: Storage of capillary reservoir for each HRU2. soil_rechr: Storage for recharge zone (upper portion) of the capillary reservoir that is available for both evaporation and transpiration From runoff class3. infil: Infiltration to the capillary reservoir for each HRU4. sroff: Surface runoff to the stream network for each HRU---<jupyter_code>t_hru = 13

fig, ax = plt.subplots(ncols=2)
prms6bmi.bmi_prms6_value_plot(dsoil, t_hru, 'infil', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_value_plot(dprms, t_hru, 'infil', 'prms', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_residual_plot(dsoil, dprms, t_hru, 'infil', 'prms', sim_start_date, sim_end_date, ax[1])
plt.tight_layout()
plt.show()

fig, ax = plt.subplots(ncols=2)
prms6bmi.bmi_prms6_value_plot(dsoil, t_hru, 'sroff', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_value_plot(dprms, t_hru, 'sroff', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_residual_plot(dsoil, dprms, t_hru, 'sroff', 'prms', sim_start_date, sim_end_date, ax[1])
plt.tight_layout()
plt.show()

fig, ax = plt.subplots(ncols=2)
prms6bmi.bmi_prms6_value_plot(dsoil, t_hru, 'soil_moist', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_value_plot(dprms, t_hru, 'soil_moist', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_residual_plot(dsoil, dprms, t_hru, 'soil_moist', 'prms', sim_start_date, sim_end_date, ax[1])
plt.tight_layout()
plt.show()

fig, ax = plt.subplots(ncols=2)
prms6bmi.bmi_prms6_value_plot(dsoil, t_hru, 'soil_rechr', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_value_plot(dprms, t_hru, 'soil_rechr', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_residual_plot(dsoil, dprms, t_hru, 'soil_rechr', 'prms', sim_start_date, sim_end_date, ax[1])
plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>--- Plot a comparison some other variables in the surface and soil zones1. The hru to plot can be adjusted by setting t_hru. There are 14 hrus. Parameters passed from bmi-soil to bmi-surface From soil class1. soil_to_gw: Storage of capillary reservoir for each HRU2. ssr_to_gw: Portion of excess flow to the capillary reservoir that drains to the associated GWR for each HRU From Evapotranspiration class3. dprst_evap_hru: Evaporation from surface-depression storage for each HRU From the Surface Depression Storage Class4. dprst_seep_hru: Seepage from surface-depression storage to associated GWR for each HRU---<jupyter_code>fig, ax = plt.subplots(ncols=2)
prms6bmi.bmi_prms6_value_plot(dsoil, t_hru, 'soil_to_gw', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_value_plot(dprms, t_hru, 'soil_to_gw', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_residual_plot(dsoil, dprms, t_hru, 'soil_to_gw', 'prms', sim_start_date, sim_end_date, ax[1])
plt.tight_layout()
plt.show()

fig, ax = plt.subplots(ncols=2)
prms6bmi.bmi_prms6_value_plot(dsoil, t_hru, 'ssr_to_gw', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_value_plot(dprms, t_hru, 'ssr_to_gw', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_residual_plot(dsoil, dprms, t_hru, 'ssr_to_gw', 'prms', sim_start_date, sim_end_date, ax[1])
plt.tight_layout()
plt.show()

fig, ax = plt.subplots(ncols=2)
prms6bmi.bmi_prms6_value_plot(dsoil, t_hru, 'dprst_seep_hru', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_value_plot(dprms, t_hru, 'dprst_seep_hru', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_residual_plot(dsoil, dprms, t_hru, 'dprst_seep_hru', 'prms', sim_start_date, sim_end_date, ax[1])
plt.tight_layout()
plt.show()

fig, ax = plt.subplots(ncols=2)
prms6bmi.bmi_prms6_value_plot(dsoil, t_hru, 'dprst_evap_hru', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_value_plot(dprms, t_hru, 'dprst_evap_hru', 'soil-bmi', sim_start_date, sim_end_date, ax[0])
prms6bmi.bmi_prms6_residual_plot(dsoil, dprms, t_hru, 'dprst_evap_hru', 'prms', sim_start_date, sim_end_date, ax[1])
plt.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12258919961427193, 'fraction_numerical': 0.021817743490838957, 'mean_word_length': 6.761459307764266, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '358636', 'license': 'MIT', 'n_tokens_mistral': 3600, 'n_tokens_neox': 3465, 'n_words': 710, 'path': 'notebooks/01_Fortran_prms_and_bmi_compare_soil.ipynb', 'repo_name': 'nhm-usgs/bmi-test-projects', 'size': '8296'}