from datetime import datetime import pandas as pd #import matplotlib.pyplot as plt import numpy as np import seaborn as sns import re as re def normalize(x): return max(min(x, 30), 10) def get_gdd_until(date): temp=pd.read_csv('~/tmp/temp', sep=',') y=int(temp[temp.Datum==date].index.values) GDD_date=0 for x in range(y+1): gdd_of_day = ((normalize(temp.min_temp[x])+normalize(temp.max_temp[x]))/2)-10 GDD_date+=gdd_of_day return GDD_date def predict_blooming(date,gdd_infile='~/tmp/wachstumsgradtag.csv',climate_infile='~/tmp/climate_heidelberg_tima_and_date.csv'): gdd_date = get_gdd_until(date) gdd_trees = pd.read_csv(gdd_infile, sep=',', encoding='utf-8') monthly_temp = pd.read_csv(climate_infile,sep='\t') #monthly_temp i=0 for x in monthly_temp.Min: if x<10: monthly_temp.Min.iloc[i]=10 if x>30: monthly_temp.Min.iloc[i]=30 i=i+1 i=0 for x in monthly_temp.Max: if x <10: monthly_temp.Max.iloc[i]=10 if x>30: monthly_temp.Max.iloc[i]=30 i=i+1 #temp monthly_temp['average_weekly_gdd']=((monthly_temp.Max+monthly_temp.Min)/2-10)*7 #monthly_temp month=int(re.findall('\d{2}[.](\d{2})[.]\d{4}',date)[0]) #month averg_gdd=float(monthly_temp[monthly_temp.Month==month].average_weekly_gdd) #averg_gdd prdctd=gdd_date+averg_gdd #prdctd #gdd_trees blooming=gdd_trees[(gdd_trees["minGDD"] <= prdctd) & (gdd_trees["minGDD"] >= gdd_date)].Deutsch.tolist() return blooming if __name__ == '__main__': bls = predict_blooming('20.05.2019') print(bls)