<jupyter_start><jupyter_text>Hydrograph Development Notebooks  Methodology Overview: Reproduce [Grand Rapids Michigan Test Cast](documentation\ProofofConceptHydrologyStudies.pdf)<jupyter_code>import os
from glob import glob
import numpy as np
import pandas as pd
from scipy.integrate import trapz, cumtrapz, simps

from importlib import reload
import utils; reload(utils)
from utils import *

%matplotlib inline
import ny_clean_nb; reload(ny_clean_nb)
from ny_clean_nb import *
df = initialize_testcase()
testcase = df[['04119000_00060_iv']].interpolate().copy()
storm1 = testcase['1997-02-17 18:00':'1997-03-10'].values
storm2 = testcase['2000-05-12':'2000-06-09'].values
storm3 = testcase['2004-05-17':'2004-06-11'].values
f, ax = plt.subplots()
ax.plot(np.arange(0, len(storm1)),storm1 ,color = 'blue', label = 'Feb 1997')
ax.plot(np.arange(0, len(storm2)),storm2 ,color = 'black',label = 'May 2000')
ax.plot(np.arange(0, len(storm3)),storm3 ,color = 'green',label = 'May 2004')
ax.grid()
ax.legend()
ax.set_xlim(-250, 2000)
f.set_size_inches(10,4)
testcase = df[['04119000_00060_iv']].interpolate().copy()
storm3 = testcase['2004-05-15 00:00 ':'2004-06-10'].copy()
storm3['2004-05-15 00:00':'2004-05-22 00:00'] = np.nan
len(storm3['2004-05-15 00:00':'2004-05-22 00:00'])
idx =storm3.index[-337:]
storm3['2004-05-15 00:00':'2004-05-15 00:00'] = 5000
storm3['2004-05-16 00:00':'2004-05-16 00:00'] = 6000
storm3['2004-05-17 00:00':'2004-05-17 00:00'] = 7000
storm3['2004-05-18 00:00':'2004-05-18 00:00'] = 8000
storm3['2004-05-19 00:00':'2004-05-19 00:00'] = 9500

smooth_storm = storm3.interpolate(how = 'spline', order=3) 

f, ax = plt.subplots()
ax.plot(smooth_storm,color = 'green',label = 'May 2004')
ax.grid()
ax.legend()

f.set_size_inches(6,4)
f.autofmt_xdate()
peak = float(storm3.max())
pct_1 = 50000
pct_02 = 65200

stretch_1pct = pct_1/peak 
stretch_02pct = pct_02/peak 

smooth_storm_resample = smooth_storm.resample('30T').mean()

smooth_storm_1pct = smooth_storm_resample*stretch_1pct
smooth_storm_02pct = smooth_storm_resample*stretch_02pct

print('Factors: \n','\t1 Percent\t{}'.format(stretch_1pct), '\n\t0.2 Percent\t{}'.format(stretch_02pct))
storm01 = smooth_storm_1pct.values
storm02 = smooth_storm_02pct.values
idx = np.arange(0, len(storm01))
f, ax = plt.subplots()
ax.plot(idx,storm01 ,color = 'blue', label = '1-percent chance hydrograph')
ax.plot(idx,storm02 ,color = 'green', label = '0.2-percent chance hydrograph')

ax.grid()
ax.legend(loc=0)
my_xticks = np.multiply(idx,100)
ax.set_xticklabels(my_xticks)
ax.set_xlim(0,1350)
f.set_size_inches(8,6)
#--Calculate Volume to Verify Procedure
printbold('Volume Check')

may_volume = IntegrateHydrograph(smooth_storm, 4900.)
print('May Event\t',may_volume, 'inches' )
pct_1_volume = IntegrateHydrograph(smooth_storm_1pct, 4900.)
print('1 Percent\t', pct_1_volume, 'inches')
pct_02_volume = IntegrateHydrograph(smooth_storm_02pct, 4900.)
print('0.2 Percent\t',pct_02_volume, 'inches')<jupyter_output><empty_output><jupyter_text>Concept Checker Complete, Procedure Verified Next Steps: Compare stretching via factor to peak only interpolation<jupyter_code># Method #1
pct_1_peak, inst_peak  = Stretched_Daily_100yr(df, plot = False)
peak =  14209.0
pct_1 = 20960.0
stretch_1pct = pct_1/peak 
smooth_storm_resample = inst_peak.resample('30T').mean()
smooth_storm_1pct = smooth_storm_resample*stretch_1pct
print('Factor: \n','\t1 Percent\t{}'.format(stretch_1pct))
# APPLY TO NY DATA
storm01 = smooth_storm_resample.values
storm02 = smooth_storm_1pct.values
idx = np.arange(0, len(storm01))
f, ax = plt.subplots()
ax.plot(idx,storm01 ,color = 'blue', label = 'Base Storm hydrograph')
ax.plot(idx,storm02 ,color = 'green', label = '0.1-percent chance hydrograph')

ax.grid()
ax.legend(loc=0)
ax.set_xlim(0,175)
f.set_size_inches(8,6)
pct_1_peak, inst_peak  = Stretched_Daily_100yr(df, plot = False)
storm0 = pd.DataFrame(pct_1_peak).resample('30T').mean().values
storm01 = smooth_storm_resample.values
storm02 = smooth_storm_1pct.values
idx = np.arange(0, len(storm01))
f, ax = plt.subplots()

ax.plot(idx,storm0 ,color = 'black', label = 'Method 1:Stretch Daily Means')
ax.plot(idx,storm02 ,color = 'green', label = 'Method 2: Apply Factor')
ax.plot(idx,storm01 ,color = 'blue', label = 'Base Storm hydrograph')

ax.grid()
ax.legend(loc=0)
ax.set_xlim(-20,175)
f.set_size_inches(8,6)

#--Calculate Volume to Verify Procedure
printbold('Volume Check')
raw  = IntegrateHydrograph(smooth_storm_resample, 490.)
print('Base Hydrograph\t', pct_1_volume, 'inches')

stretched = IntegrateHydrograph(pct_1_peak, 490.)
print('Stretch Method\t',may_volume, 'inches' )

factored = IntegrateHydrograph(smooth_storm_1pct, 490.)
print('Factor Method',pct_02_volume, 'inches')<jupyter_output>
{'fraction_non_alphanumeric': 0.15690817186183656, 'fraction_numerical': 0.10909856781802864, 'mean_word_length': 6.709415584415584, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '46405', 'license': 'MIT', 'n_tokens_mistral': 2243, 'n_tokens_neox': 1867, 'n_words': 350, 'path': 'dev/MethodologyOverview_dev.ipynb', 'repo_name': 'slawler/HydrologyTools', 'size': '4748'}