-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_objects.py
executable file
·112 lines (90 loc) · 3.28 KB
/
data_objects.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python
import re
import os
import sys
import math
import cast
#
class DataObject(object):
def __init__(self, headers=[], values=[]):
for header, value in zip(headers, values):
setattr(self, header, cast.cast(value))
pass
def __add__(self, other):
res = DataObject(self.__dict__.keys(), self.__dict__.values())
res.__dict__.update(other.__dict__)
return res
def __repr__(self):
return str(self.__dict__)
pass
#
class CompiledData(DataObject):
def eat_starch_data(self, dobj):
self.plantspparcelle = dobj.plantspparcelle
self.planted = dobj.planted
self.terminated = dobj.terminated
self.cultivar = dobj.cultivar
self.breeder = dobj.breeder
self.reifegruppe = dobj.reifegruppe
self.sub_id = int(dobj.sub_id)
self.sub_limsid = int(dobj.sub_limsid)
self.elevation = dobj.elevation
self.longitude_e = dobj.longitude_e
self.latitude_n = dobj.latitude_n
self.knollenmasse_kgfw_parzelle = dobj.knollenmasse_kgfw_parzelle
# self.treatment = int(dobj.treatment)
pass
pass
#
class StarchData(DataObject):
def __init__(self, headers=[], values=[]):
min_starch = 100
max_starch = 300
warning = 'Warning: Starch content out of bounds in\n%s.\n'
super(StarchData, self).__init__(headers=headers, values=values)
if self.staerkegehalt_g_kg < min_starch:
# sys.stdout.write(warning % str(self))
self.staerkegehalt_g_kg *= 10.0
elif self.staerkegehalt_g_kg > max_starch:
sys.stdout.write(warning % str(self))
"""
if hasattr(self, 'cultivar'):
if self.cultivar.startswith('JA'):
self.cultivar = 'JASIA'
elif re.match('KOR?MORAN', self.cultivar):
self.cultivar = 'KORMORAN'
"""
starch_content = self.staerkegehalt_g_kg
yield_tuber = self.knollenmasse_kgfw_parzelle
nplants = self.plantspparcelle
self.starch_abs = StarchData.calc_starch_abs(starch_content,
yield_tuber,
nplants=nplants)
pass
@staticmethod
def calc_starch_abs(starch_content, yield_tuber, nplants=16):
return starch_content * yield_tuber / float(nplants)
pass
#
class ClimateData(DataObject):
def __init__(self, headers=[], values=[]):
warning = 'Warning: Missing climate data in\n%s.\n'
super(ClimateData, self).__init__(headers=headers, values=values)
try:
self.heat_sum = ClimateData.calc_heat_sum(self.tmin, self.tmax)
except:
sys.stdout.write(warning % str(self))
self.heat_sum = None
pass
@staticmethod
def calc_heat_sum(tmin, tmax, tbase=6.0):
"""
Daily heat summation is defined as:
heat_sum_d = max(tx - tbase, 0), with
tx = (tmin + tmax)/2 and
tmax = min(tmax_measured, 30.0)
"""
tmax = min(tmax, 30.0)
tx = (tmin + tmax) / 2.0
return max(tx - tbase, 0.0)
if __name__ == '__main__': main(sys.argv[1:])