-
Notifications
You must be signed in to change notification settings - Fork 0
/
locFilterUtils.py
189 lines (96 loc) · 3.37 KB
/
locFilterUtils.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Databricks notebook source
# x,y
NE=[nelng, nelat ]
SW= [swlng, swlat]
#######
'''
#[swlng,nelat] #X1 #NE
1 2
#X2 #X3 #X4
3 4
#SW #X5 #[nelng, swlat]
X1 = [(swlng+nelng)/2 , nelat]
X5 = [(swlng+nelng)/2 , swlat]
X3 = [(swlng+nelng)/2, (nelat+swlat)/2]
X4 =[nelng, (nelat+swlat)/2]
X2=[swlng, (nelat+swlat)/2]
boundingbox1= [X2, X1] # bottomleft, topright
boundingbox2= [X3, NE]
boundingbox3= [SW, X3]
boundingbox4= [X5, X4]
'''
nelat=83.1000000
nelng=-050.7500000
swlat=41.2833333
swlng=-140.8833333
NE=[nelng, nelat ]
SW= [swlng, swlat]
boundingbox= [SW, NE]
def breakBoundingBox(iconic_taxa ,datefrom, dateto, boundingbox):
# run test for number of values
SW = boundingbox[0]
NE = boundingbox[1]
loc = '&nelat='+ str(NE[1]) +'&nelng=' + str(NE[0]) +'&swlat=' + str(SW[1]) + '&swlng='+ str(SW[0])
time.sleep(3)
_, totalnumberofobservations = getObservationsC(iconic_taxa ,datefrom, dateto , '1', '1', loc) # don't need to download observations
print(totalnumberofobservations)
#if totalnumberofobservations!=0:
# print(boundingbox)
if totalnumberofobservations < 10000:
if totalnumberofobservations==0:
return []
return [boundingbox]
# calculate coordinates
swlng=SW[0]
swlat=SW[1]
nelng=NE[0]
nelat=NE[1]
a=(swlng+nelng)/2
b=(nelat+swlat)/2
X1 = [a , nelat]
X5 = [a , swlat]
X3 = [a, b]
X4 =[nelng, b]
X2=[swlng, b]
boundingbox1= [X2, X1]
boundingbox2= [X3, NE]
boundingbox3= [SW, X3]
boundingbox4= [X5, X4]
# check each boundingbox to have less observations than 10k if not break into smaller boxes
out=[]
boundingbox1=breakBoundingBox(iconic_taxa ,datefrom, dateto,boundingbox1)
if len(boundingbox1)!=0:
out=out+boundingbox1
boundingbox2=breakBoundingBox(iconic_taxa ,datefrom, dateto,boundingbox2)
if len(boundingbox2)!=0:
out=out+boundingbox2
boundingbox3=breakBoundingBox(iconic_taxa ,datefrom, dateto,boundingbox3)
if len(boundingbox3)!=0:
out=out+boundingbox3
boundingbox4=breakBoundingBox(iconic_taxa ,datefrom, dateto,boundingbox4)
if len(boundingbox4)!=0:
out=out+boundingbox4
return out
def save_obj(obj, name ):
with open('obj/'+ name + '.pkl', 'wb') as f:
pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL)
def load_obj(name ):
with open('obj/' + name + '.pkl', 'rb') as f:
return pickle.load(f)
try:
boundingBoxOfDate=load_obj('boundingbox.pkl' )
except:
boundingBoxOfDate={}
for date in newdates:
#if date not in boundingBoxOfDate.keys():
boundingBoxOfDate[date] = breakBoundingBox(iconic_taxa ,datefrom, dateto, boundingbox)
save_obj(boundingBoxOfDate, 'boundingbox' )
commentsAllWindows=pd.DataFrame()
for date in list_of_dates:
datefrom=date
dateto=date
boundingboxes= boundingBoxOfDate[date]
for loc in boundingboxes:
comments, commentStatus= getNewComments ( commentStatus,iconic_taxa ,datefrom, dateto,loc)
commentsAllWindows.append(comments)
# look for words here