Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

61 Zeilen
1.7KB

  1. from datetime import datetime
  2. import pandas as pd
  3. #import matplotlib.pyplot as plt
  4. import numpy as np
  5. import seaborn as sns
  6. import re as re
  7. def normalize(x):
  8. return max(min(x, 30), 10)
  9. def get_gdd_until(date):
  10. temp=pd.read_csv('/tmp/temp', sep=',')
  11. y=int(temp[temp.Datum==date].index.values)
  12. GDD_date=0
  13. for x in range(y+1):
  14. gdd_of_day = ((normalize(temp.min_temp[x])+normalize(temp.max_temp[x]))/2)-10
  15. GDD_date+=gdd_of_day
  16. return GDD_date
  17. def predict_blooming(date,gdd_infile='/tmp/wachstumsgradtag.csv',climate_infile='/tmp/climate_heidelberg_tima_and_date.csv'):
  18. gdd_date = get_gdd_until(date)
  19. gdd_trees = pd.read_csv(gdd_infile, sep=',', encoding='utf-8')
  20. monthly_temp = pd.read_csv(climate_infile,sep='\t')
  21. #monthly_temp
  22. i=0
  23. for x in monthly_temp.Min:
  24. if x<10:
  25. monthly_temp.Min.iloc[i]=10
  26. if x>30:
  27. monthly_temp.Min.iloc[i]=30
  28. i=i+1
  29. i=0
  30. for x in monthly_temp.Max:
  31. if x <10:
  32. monthly_temp.Max.iloc[i]=10
  33. if x>30:
  34. monthly_temp.Max.iloc[i]=30
  35. i=i+1
  36. #temp
  37. monthly_temp['average_weekly_gdd']=((monthly_temp.Max+monthly_temp.Min)/2-10)*7
  38. #monthly_temp
  39. month=int(re.findall('\d{2}[.](\d{2})[.]\d{4}',date)[0])
  40. #month
  41. averg_gdd=float(monthly_temp[monthly_temp.Month==month].average_weekly_gdd)
  42. #averg_gdd
  43. prdctd=gdd_date+averg_gdd
  44. #prdctd
  45. #gdd_trees
  46. blooming=gdd_trees[(gdd_trees["minGDD"] <= prdctd)
  47. & (gdd_trees["minGDD"] >= gdd_date)].Deutsch.tolist()
  48. return blooming
  49. if __name__ == '__main__':
  50. bls = predict_blooming('20.05.2019')
  51. print(bls)