<jupyter_start><jupyter_text>Exploring hydrologic signatures of precipitation and daily runoff data**Author:** <NAME>**Date:** Sept. 7, 2021- Climate: the precipitation data from a weather station within or near Oviedo- Streamflow: the daily runoff data for Little Econlockhatchee River  Import libraries<jupyter_code>import pandas as pd
import numpy as np

# visualization
import seaborn as sns
import matplotlib.pyplot as plt
import plotly 
from plotly import graph_objects as go
import plotly.express as px
import plotly.io as pio
%matplotlib inline
plt.rcParams['figure.figsize'] = (15, 10)

# system
import os
import glob

# hide warnings
import warnings
warnings.filterwarnings('ignore')<jupyter_output><empty_output><jupyter_text>Load and check the data<jupyter_code># precipitation data
precip_df = pd.read_csv("precipitation_oviedo.csv", parse_dates=True, index_col='DATE')

# streamflow data
runoff_df = pd.read_excel("streamflow little econlockhatchee river.xlsx", parse_dates=True, 
                          index_col='datetime')
precip_cdf = pd.read_excel("precipitation_2.xlsx")
precip_cdf.head()
runoff_fdc = pd.read_excel("streamflow_fdc.xlsx")
runoff_fdc.head()
precip_df.head()
runoff_df.head()
precip_df.describe()
print("Beginning date of precipitation data: ", precip_df.DATE.min())
print("Last date of precipitation data: ", precip_df.DATE.max())
# change the rainfall from inches to mm
precip_df["RAINFALL (mm)"] = precip_df['RAINFALL (in)'] * 25.4
precip_df.head()<jupyter_output><empty_output><jupyter_text>Annual precipitation (mm/year) for each year<jupyter_code># annual precipitation (mm/year) for each year
precip_df_annual = precip_df.resample('A').sum()
precip_df_annual
precip_df_annual.describe()<jupyter_output><empty_output><jupyter_text>Mean monthly precipitation (mm/month)<jupyter_code># mean monthly precipitation (mm/month)
precip_df_monthly = precip_df.resample('M').mean()
precip_df_monthly
# number of days with zero precipitation
precip_df[precip_df['RAINFALL (mm)']==0].count()<jupyter_output><empty_output><jupyter_text>Annual runoff (mm/year) for each year<jupyter_code># annual runoff (mm/year) for each year
runoff_df_annual = runoff_df.resample('A').sum()
runoff_df_annual
runoff_df_annual.describe()
print(runoff_df.index.min())
print(runoff_df.index.max())<jupyter_output>1996-10-01 00:00:00
2021-09-01 00:00:00<jupyter_text>Mean monthly runoff (mm/month)<jupyter_code>runoff_df_monthly = runoff_df.resample('M').sum()
runoff_df_monthly
runoff_df.head()<jupyter_output><empty_output><jupyter_text>Visualization<jupyter_code>plt.style.use("seaborn")
plt.figure(figsize=(15, 10))
plt.plot(precip_df.index.values, precip_df['RAINFALL (mm)'])
plt.xlabel("Time", fontsize=12)
plt.ylabel("Precipitation (mm)", fontsize=12)
plt.title("Precipitation Time Series on Weather Station 00640275: SJR at SR46 at Geneva(RN)", 
          fontsize=18, y=1.03)
plt.xticks(rotation=90)
plt.savefig("Precipitation Time Series", dpi=300)
    
plt.show()    
plt.style.use("seaborn")
plt.figure(figsize=(15, 10))
plt.plot(runoff_df.index.values, runoff_df['discharge (mm/day)'])
plt.xlabel("Time", fontsize=14)
plt.ylabel("Runoff (mm/day)", fontsize=14)
plt.title("Runoff Time Series for Little Econlockhatchee River (1996-2021)", 
          fontsize=18, y=1.03)
plt.xticks(fontsize=13)
plt.yticks(fontsize=13)
plt.savefig("Runoff Time Series", dpi=300)
    
plt.show()<jupyter_output><empty_output><jupyter_text>Plot annual precipitation time series<jupyter_code># plot the annual precipitation time series
plt.style.use("seaborn")
plt.figure(figsize=(15, 10))
plt.plot(precip_df_annual.index.values, precip_df_annual['RAINFALL (mm)'], label="Annual Precipitation")
plt.axhline(y=1145.3, label='Long-term Average Annual Precipitation', color='r')
plt.xlabel("Time", fontsize=12)
plt.ylabel("Annual Precipitation (mm)", fontsize=12)
plt.title("Annual Precipitation Time Series on Weather Station 00640275: SJR at SR46 at Geneva (RN)", 
          fontsize=18, y=1.03)
# plt.xticks(rotation=90)
plt.legend()
plt.savefig("Annual Precipitation Time Series", dpi=300)
    
plt.show()<jupyter_output><empty_output><jupyter_text>Plot monthly precipitation time series and seasonality<jupyter_code># plot the monthly precipitation time series
plt.style.use("seaborn")
plt.figure(figsize=(15, 10))
plt.plot(precip_df_monthly.index.values, precip_df_monthly['RAINFALL (mm)'], label="Monthly Precipitation")

plt.xlabel("Time", fontsize=12)
plt.ylabel("Monthly Precipitation (mm)", fontsize=12)
plt.title("Monthly Precipitation Time Series on Weather Station 00640275: SJR at SR46 at Geneva (RN)", 
          fontsize=18, y=1.03)
# plt.xticks(rotation=90)
plt.legend()
plt.savefig("Monthly Precipitation Time Series", dpi=300)
    
plt.show()    

Precipitation = [57.9867, 55.5961, 96.5051, 50.9195, 69.6707, 139.6253, 159.3327, 156.8076, 143.4204,
                     114.6287, 50.8448, 49.9633]

Month = "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 

precip_monthly_avg = pd.DataFrame({"Precipitation (mm)": Precipitation, "Months": Month})
precip_monthly_avg
# plot the monthly precipitation time series
plt.style.use("seaborn")
plt.figure(figsize=(15, 10))
plt.bar(precip_monthly_avg.Months, precip_monthly_avg['Precipitation (mm)'])

plt.xlabel("Months", fontsize=14)
plt.ylabel("Precipitation (mm)", fontsize=14)
plt.title("Seasonality of Precipitation on Weather Station 00640275: SJR at SR46 at Geneva (RN)", 
          fontsize=18, y=1.03)
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)
# plt.legend()
plt.savefig("Seasonality Precipitation Time Series", dpi=300)
    
plt.show()<jupyter_output><empty_output><jupyter_text>Plot CDF (cumulative distribution function) for non-zero daily precipitation<jupyter_code>plt.style.use("seaborn")
plt.figure(figsize=(15, 10))
plt.plot(precip_cdf['RAINFALL (mm)'], precip_cdf.CDF, "o-", color='b', markerfacecolor='r')
plt.xlabel("Precipitation (mm)", fontsize=14)
plt.ylabel("CDF", fontsize=14)
plt.title("CDF for Daily Non-zero Precipitation at Weather Station 00640275: SJR at SR46 at Geneva (RN)", 
          fontsize=18, y=1.03)
plt.xticks(fontsize=13)
plt.yticks(fontsize=13)
plt.savefig("CDF", dpi=300)
    
plt.show()<jupyter_output><empty_output><jupyter_text>Plot Annual and Average Annual Runoff<jupyter_code>plt.style.use("seaborn")
plt.figure(figsize=(15, 10))
plt.plot(runoff_df_annual.index.values, runoff_df_annual['discharge (mm/day)'], label="Annual Runoff")
plt.axhline(y=594.963, label='Long-term Average Annual Runoff', color='r')
plt.xlabel("Time", fontsize=14)
plt.ylabel("Annual Runoff (mm/year)", fontsize=14)
plt.title("Annual and Average Annual Runoff for Little Econlockhatchee River (1996-2021)", 
          fontsize=18, y=1.03)
plt.xticks(fontsize=13)
plt.yticks(fontsize=13)
plt.legend()
plt.savefig("Annual Runoff Time Series", dpi=300)
    
plt.show()<jupyter_output><empty_output><jupyter_text>Plot monthly runoff time series<jupyter_code># plot the monthly runoff time series
plt.style.use("seaborn")
plt.figure(figsize=(15, 10))
plt.plot(runoff_df_monthly.index.values, runoff_df_monthly['discharge (mm/day)'], color='b')

plt.xlabel("Time", fontsize=14)
plt.ylabel("Monthly Runoff (mm/month)", fontsize=14)
plt.title("Monthly Runoff for Little Econlockhatchee River (1996-2021))", 
          fontsize=18, y=1.03)
plt.xticks(fontsize=13)
plt.yticks(fontsize=13)

plt.savefig("Monthly Runoff Time Series", dpi=300)
    
plt.show()    

runoff = [33.8585, 30.1919, 32.3401, 23.3014, 22.5602, 53.4572, 84.2414, 92.4559, 92.9060,
                     61.6555, 32.5798, 35.4153]

Month = "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 

runoff_monthly_avg = pd.DataFrame({"Monthly Runoff (mm/month)": runoff, "Months": Month})
runoff_monthly_avg
# plot the monthly runoff 
plt.style.use("seaborn")
plt.figure(figsize=(15, 10))
plt.bar(runoff_monthly_avg.Months, runoff_monthly_avg['Monthly Runoff (mm/month)'])

plt.xlabel("Months", fontsize=14)
plt.ylabel("Monthly Runoff (mm/month)", fontsize=14)
plt.title("Seasonality of Runoff for Little Econlockhatchee River (1996-2021)", 
          fontsize=18, y=1.03)
plt.xticks(fontsize=13)
plt.yticks(fontsize=13)
# plt.legend()
plt.savefig("Seasonality Runoff", dpi=300)
    
plt.show()<jupyter_output><empty_output><jupyter_text>Plot FDC for runoff<jupyter_code>plt.style.use("seaborn")
plt.figure(figsize=(15, 10))
plt.plot(runoff_fdc['Exceedance prob'], runoff_fdc['discharge (cfs)'], color='b')
plt.xlabel("Exceedance Probability", fontsize=14)
plt.ylabel("Discharge (cfs)", fontsize=14)
plt.title("Flow Duration Curve for Little Econlockhatchee River", 
          fontsize=18, y=1.03)
plt.xticks(fontsize=13)
plt.yscale('log')
plt.yticks(fontsize=13)
plt.savefig("FDC", dpi=300)
    
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14729470236078165, 'fraction_numerical': 0.05399299672427426, 'mean_word_length': 6.434089000839631, 'pattern_counts': {'":': 4, '<': 53, '<?xml version=': 0, '>': 53, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '519669', 'license': 'MIT', 'n_tokens_mistral': 3787, 'n_tokens_neox': 3296, 'n_words': 658, 'path': 'Homework 1/hw1_hydrologic signatures.ipynb', 'repo_name': 'javedali99/water-resources-in-changing-environment', 'size': '8856'}