Esempio n. 1
0
def thorn(year, latitude, df, model):
    data = df.loc[df['yil'] == year][model].values
    # lat = 37
    lat = deg2rad(latitude)
    mmdlh = monthly_mean_daylight_hours(lat, year)
    evapo = np.array(thornthwaite(data, mmdlh))
    return evapo
Esempio n. 2
0
def thorn_clima(year, latitude, df, model, senario):
    data = df.loc[(df['Yıl'] == year) & (df['Model'] == model) &
                  (df['Senaryo'] == senario), 'Ortalama_Sıcaklık'].values
    # lat = 37
    if len(data) != 12:
        data = data[0:12]
    lat = deg2rad(latitude)
    mmdlh = monthly_mean_daylight_hours(lat, year)
    evapo = np.array(thornthwaite(data, mmdlh))
    return data, evapo
Esempio n. 3
0
    def test_thornthwaite(self):
        # Test values obtained from a worked example in Hydrology: An
        # Environmental Approach, pp 435-436 by Ian Watson.
        test_monthly_t = [
            2.1, 2.5, 4.8, 7.1, 8.3, 10.7, 13.4, 14.5, 11.1, 8.2, 5.4, 3.7
        ]
        test_monthly_mean_dlh = [
            9.4, 10.6, 11.9, 13.4, 14.6, 15.2, 14.9, 13.9, 12.6, 11.1, 9.8, 9.1
        ]
        test_pet = [
            10.67, 14.08, 28.49, 45.85, 57.47, 75.20, 89.91, 90.29, 64.26,
            43.34, 26.24, 17.31
        ]

        # NOTE: The test PET was calculated using rounded coefficients, rounded
        # intermediate values and doesn't adjust for the number of days in
        # the month. This results in a small difference in estimated monthly
        # PET of up to +/- 4 mm.
        pet = pyeto.thornthwaite(test_monthly_t, test_monthly_mean_dlh)
        for m in range(12):
            diff = abs(pet[m] - test_pet[m])
            self.assertLess(diff, 4)

        # Test with non-leap year
        pet_non_leap = pyeto.thornthwaite(test_monthly_t,
                                          test_monthly_mean_dlh,
                                          year=2015)
        # Test results are same as above when year argument is set
        for m in range(12):
            self.assertEqual(pet[m], pet_non_leap[m])

        # Test with leap year
        pet_leap = pyeto.thornthwaite(test_monthly_t,
                                      test_monthly_mean_dlh,
                                      year=2016)
        for m in range(12):
            # 29 days in Feb so PET should be higher than in non-leap year
            # results
            if m == 1:  # Feb
                self.assertGreater(pet_leap[m], pet_non_leap[m])
            else:
                self.assertEqual(pet_leap[m], pet_non_leap[m])

        # Test with wrong length args
        with self.assertRaises(ValueError):
            _ = pyeto.thornthwaite(list(range(11)), test_monthly_mean_dlh)
        with self.assertRaises(ValueError):
            _ = pyeto.thornthwaite(list(range(13)), test_monthly_mean_dlh)
        with self.assertRaises(ValueError):
            _ = pyeto.thornthwaite(test_monthly_t, list(range(11)))
        with self.assertRaises(ValueError):
            _ = pyeto.thornthwaite(test_monthly_t, list(range(13)))
Esempio n. 4
0
def main(lat, temp_mean, precip_mean, max_tsmd):	
    '''get evapotranspiration''' # taken from Richards pyeto, see doc in same folder for more informatios
    pyeto_lat = pyeto.deg2rad(lat)  # converts the degree to radians
    mean_month_list = [temp_mean[i] for i in temp_mean]
    monthly_mean_daylight = pyeto.monthly_mean_daylight_hours(pyeto_lat)
    eto = pyeto.thornthwaite(mean_month_list, monthly_mean_daylight)
    
    '''make a "month_number" : "evapo" dic'''
    eto_dict = {}
    for n,i in enumerate(eto):
        eto_dict[n+1] = eto[n]
    
    print "\nWaterbalance with maximum deficientcy of", max_tsmd
    acc_TSMD = {}
    acc_factor = 0
    budget = {}
    
    '''The following part is still a bit hacky. 
    Two for loops that first calculates the the water buget for every mongth 
    and then starts a second loop to substract the value of the month before from the current month
    '''
    print "month \t rain \t eto \t\t TSMD"
    for month, rain, etom in zip(range(1,13),precip_mean, eto_dict):
        TSMD = precip_mean[rain] - ( eto_dict[etom] * 0.75 )
        
        if TSMD <= max_tsmd:
            TSMD = max_tsmd
        
        print month,"\t", precip_mean[rain], "\t", eto_dict[etom],"\t", TSMD        
        budget[month] = TSMD if TSMD < 0 else 0

    for month, rain, etom in zip(range(1,13),precip_mean, eto_dict):
        TSMD = precip_mean[rain] - ( eto_dict[etom] * 0.75 )
        if month == 1:
            acc_TSMD[month] = TSMD + budget[12]
        else:
            acc_TSMD[month] = TSMD + budget[month -1] 
        
        if acc_TSMD[month] > 0 :
           acc_TSMD[month] = 0 
        
        if acc_TSMD[month] < max_tsmd:
            acc_TSMD[month] = max_tsmd

    print "\nWater budget" 
    p(budget)
    print ""    
    return acc_TSMD
Esempio n. 5
0
    def test_thornthwaite(self):
        # Test values obtained from a worked example in Hydrology: An
        # Environmental Approach, pp 435-436 by Ian Watson.
        test_monthly_t = [
            2.1, 2.5, 4.8, 7.1, 8.3, 10.7, 13.4, 14.5, 11.1, 8.2, 5.4, 3.7]
        test_monthly_mean_dlh = [
            9.4, 10.6, 11.9, 13.4, 14.6, 15.2, 14.9, 13.9, 12.6, 11.1, 9.8, 9.1]
        test_pet = [
            10.67, 14.08, 28.49, 45.85, 57.47, 75.20, 89.91, 90.29, 64.26,
            43.34, 26.24, 17.31]

        # NOTE: The test PET was calculated using rounded coefficients, rounded
        # intermediate values and doesn't adjust for the number of days in
        # the month. This results in a small difference in estimated monthly
        # PET of up to +/- 4 mm.
        pet = pyeto.thornthwaite(test_monthly_t, test_monthly_mean_dlh)
        for m in range(12):
            diff = abs(pet[m] - test_pet[m])
            self.assertLess(diff, 4)

        # Test with non-leap year
        pet_non_leap = pyeto.thornthwaite(
            test_monthly_t, test_monthly_mean_dlh, year=2015)
        # Test results are same as above when year argument is set
        for m in range(12):
            self.assertEqual(pet[m], pet_non_leap[m])

        # Test with leap year
        pet_leap = pyeto.thornthwaite(
            test_monthly_t, test_monthly_mean_dlh, year=2016)
        for m in range(12):
            # 29 days in Feb so PET should be higher than in non-leap year
            # results
            if m == 1:  # Feb
                self.assertGreater(pet_leap[m], pet_non_leap[m])
            else:
                self.assertEqual(pet_leap[m], pet_non_leap[m])

        # Test with wrong length args
        with self.assertRaises(ValueError):
            _ = pyeto.thornthwaite(list(range(11)), test_monthly_mean_dlh)
        with self.assertRaises(ValueError):
            _ = pyeto.thornthwaite(list(range(13)), test_monthly_mean_dlh)
        with self.assertRaises(ValueError):
            _ = pyeto.thornthwaite(test_monthly_t, list(range(11)))
        with self.assertRaises(ValueError):
            _ = pyeto.thornthwaite(test_monthly_t, list(range(13)))
Esempio n. 6
0
import pandas as pd
import numpy as np
import os
from pyeto import thornthwaite, monthly_mean_daylight_hours, deg2rad


os.chdir(r"C:\Users\PC3\Desktop\Hydro")

df = pd.read_csv('data.csv')

df['Date'] = pd.to_datetime(df['Date'])
df['Year'] = df['Date'].dt.year
df = df.set_index('Date')
df_m = df.resample("M").mean()


data = []
lat = deg2rad(41.3)
for i in range(2015,2019):

    mmdlh = monthly_mean_daylight_hours(lat, i)
    monthly_t = df_m['Temp'][(df_m.Year == i)]
    PET = thornthwaite(monthly_t.values.tolist(), mmdlh)
    data.append(PET)

print("a")