0% found this document useful (0 votes)
9 views

Code

code to plot rainfall data
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
9 views

Code

code to plot rainfall data
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
import pandas as pd import matplotlib.pyplot as plt # Load the CHIRPS data data = pd.read_csv('C:\\Users\\Lenovo\ \Desktop\\Rainfall_data\\Nyamudeza.csv') # Repla # Convert date to datetime format data['Date'] = pd.to_datetime(data[ Date" )) # Group by month and calculate mean rainfall monthly_rainfall = data.groupby(data[ ‘Date’ ].dt.month)[ ‘Rainfall’ ].mean() # Plotting plt.figure(figsize=(10, 5)) plt.plot (monthly rainfall.index, monthly rainfall.values, marker='o') plt.title('mean Monthly Total Rainfall") plt.xlabel(‘Month”) plt.ylabel('Mean Rainfall (mm)") plt.xticks (monthly rainfall.index, [‘Jan', ‘Feb’, ‘Mar’, ‘Apr’, ‘May’, ‘Jun, "Jul", ‘A plt.grid() plt.show() Mean Monthly Total Rainfall jen Feb Morar May onslSCA)SSep tN Month # Group by year and calculate total rainfall data['year’] = data[ ‘Date’ ].dt.year annual_rainfall = data.groupby("year')(‘Rainfall' }.sum() # Plotting plt.figure(figsize=(10, 5)) plt.plot (annual_rainfall.index, annual_rainfall.values, marke plt.title(‘'Mean Annual Total Rainfall’) plt.xlabel(‘Year") plt.ylabel('Total Rainfall (mm)') plt.grid() plt.show() 10") Mean Annual Total Rainfall 1400 3200 E 1000 800 00 400 a import pandas as pd import numpy as np 4 Load the CHIRPS rainfall data (assuming it is in a CSV format) # The CSV should have columns: ‘date’ and ‘rainfall’ chirps_data = pd.read_csv("C:\Users\\Lenovo\\Desktop\\Rainfall_data\\Nyamudeza.csv") # Convert ‘date’ to datetime chirps_data[‘Date’] = pd.to_datetime(chirps_data[ ‘Date’ ]) # Define catchment area in square meters catchment_area = 414496444.64869976 # Example: 100 hectares # Define runoff coefficient (8.9 for 96% runoff) runoff_coefficient = 0.9 # Calculate annual rainfall chirps_data['year’] = chirps_data[ ‘Date’ ].dt.year annual_rainfall = chirps_data-groupby(*year')[‘Rainfall" ].sum().reset_index() # Calculate annual runoff volume annual_rainfall['‘runoff_volune_m3') = annual_rainfall['Rainfall'] * runoff_coefficient # Display results print (annual_rainfall([ "year", ‘runoff_volune_n’3"}]) year runoff_volume_n3 @ 1984 1.279192e+08 1 1985 5.1778566+08 2 1986 3,503260e+08 3 1987 2.901551e+08 4 1988 3.903353¢+08 5 1989 3.908132e+08 6 1998 3.508307e+08 7 1991 2.4028286+08 8 1992 2.414445e+08 9 1993 3.4550400+08 16 1994 3.100675e+08 11 1995 2.800015e+08 12° 1996 3. 63RAdGeOR 13 1997 5.11aRs3e+08 14 1998, 4.33624R0+08 15. 1999 3.716057e+08 16 2008 4,669748¢+08 17 2001 4,962429¢+08 18 2002 2.060140e+08 19 2003 2.873180e+08 20 2004 4.168600¢+08 21 2005 3.305777e+08 22 2886 2. 988400e+08 23. 2887 5.157085e+08 24 2068 4,331734¢+08 25 2869 3.784914e+08 26 2610 2.797004e+08 27, 2e11 3.859770e+08 28 2812 3.067485e+08 29° 2813 3.10d6ade+08 30 2814 4,338195¢+08 31 2815 2.209845e+08 32. 2616 2,919524e+08 33. 2617 4.422578¢+08 34 2018 3.464023e+08 35. 2819 3.196907e+08 36 2020 3.99951 7e+08 37. 2821 2.974522e+08 38 2822 4,542923¢+08 39° 2823 3,534585e+08 40 2024 1.263136¢+08 Amport nunpy as np import math def mitchel1_mpf (area): # Calculate MPF for a 10,000-year return period MPF_10000 = math.exp(((1.175 * math.log(area + 1)**0.755) + 3.133)) - 1 return MPF_10000 def calculate_return_levels(area): MPF_10008 = mitchel1_mpf (area) 4 Define scaling factors for different return periods scaling factors = { 508: 0.497, 1000: 0.600, 5000: 0.870, 10000: 1.000, } # Calculate return Levels using the scaling factors return_levels = (period: MPF_10000 * scaling factors{period] for period in scaling_ return return_levels # Catchment area catchment_area = 414.9 # Calculate return Levels return_levels = calculate_retur_levels(catchnent_area) # Display return Levels with units print(“Return Levels (in cubic meters per second):") for period, level in return_levels.itens(): print(f*Return Level for {period}-yrs return period = {level:.2f} m/s") Return Levels (in cubic meters per second): Return Level for 580-yrs return period = 1092.11 m*/s Return Level for 1000-yrs return period = 1318.44 m*/s Return Level for 5800-yrs return period = 1911.74 m*/s Return Level for 10000-yrs return period = 2197.40 m?/s cH#a*(125/3942) print(Q, ‘m3") 10595.039642947742 m3 MITCHELL’ CALCULATION wmitchell’s Formula import. math mpf =[] Az414.9 mitchell= (‘Seeyears" 0.497, "10eeyears* [MPF 10000 yr] for key, value in mitchell.items(): MPFie0eeyr = math.exp(((1-175 * math.log(A+l)**0.755)+3.133)) - 2 return_period= value * MPF1@000yr print(key,’ - ',int(return_period)) mpf.append(return_period) -688, "S000years" 878, '1e0¢eyears':1) S0dyears - 1092 100eyears - 1318 Seeeyears - 1911 100eeyears - 2197 mpf 1092. 109709824371, 1318.442305622983, 1911.7413431533255, 2197.403842704972] period=(500, 108, 5000,10000) strx= [] sdx = [] SCS UNIT HYDROGRAPH for i in pf: for x in period: intensity= ((i/(A*1*#6))*6.87) ‘SD=int (((2@50*nath. 1ogi@ ((x*1006. 41115) ~380) )/intensity)/(6e*6e*24)) strx-append( SD) sdx.append(So) print (intensity, Sb) 1,8083378420085394e-05 9188 2.1831040346179544e-05 7616 3. 165500850196034e-05 5248 3.6385067243632576e-05 4566 # Example discharge hydrograph data import numpy as np storm_duration = 20 # Number of time intervals in the storm event normalized_discharge = np.array(mpf) / max(mpf) ‘time_increnent = stormduration / (len(mpf) - 1) unit_hydrograph = np.zeros(1en(mpf)) for i, discharge_value in enunerate(nornalized_discharge): unit_hydrograph[i] = discharge_value * time_increment noralized_unit_hydrograph = unit_hydrograph / sum(unit_hydrograph) ‘time = np.arange(@, storm_duration + tine_increment, time_increnent) plt.plot(tine, normalized_unit_hydrograph) plt.xlabel(‘Time') plt.ylabel( ‘Normalized Discharge’) plt.title( ‘Unit Hydrograph') plt.grid(True) pit-show() In [4 Unit Hydrograph 0325 3 0250 0225 Normalized Discharge 0200 017s oo 25 50 75 100 m5 180 175 200 Time SYNDER METHOD. te = 7 # Time of concentration (in time intervals) n= 20 # Number of time intervals for the unit hydrograph unit_hydrograph2 = np.zeros(n) c= int(te / time_increnent) # Number of time intervals for time of concentration for g in range(n): if g c= c: unit_hydrograph2(g] = (g + 1) / (¢ + 1) else: unit_hydrograph2[i] = (n - g) / (n - ¢ #1) normalized_unit_hydrograph2 = unit_hydrograph2 / sum(unit_hydrograph2) ‘time = np.arange(@, storm_duration + time_increment, time_increment) plt.plot(time, normalized_unit_hydrograph) plt.xlabel(‘Tine") plt.ylabel( ‘Normalized Discharge’) plt.title('Scs Unit Hydrograph" ) plt.grid(True) plt.show() SCS Unit Hydrograph 0325 3 0250 0225 Normalized Discharge 0200 017s oo 25 50 75 100 m5 180 175 200 Time

You might also like