ecoscape-utilities 0.0.35__tar.gz → 0.0.37__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of ecoscape-utilities might be problematic. Click here for more details.
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/PKG-INFO +1 -1
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities/ebird_db.py +42 -106
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities.egg-info/PKG-INFO +1 -1
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/pyproject.toml +1 -1
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/LICENSE.md +0 -0
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/README.md +0 -0
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities/__init__.py +0 -0
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities/bird_runs.py +0 -0
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities.egg-info/SOURCES.txt +0 -0
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities.egg-info/dependency_links.txt +0 -0
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities.egg-info/requires.txt +0 -0
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities.egg-info/top_level.txt +0 -0
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/requirements.txt +0 -0
- {ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ecoscape-utilities
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.37
|
|
4
4
|
Summary: A collection of EcoScape utilities.
|
|
5
5
|
Author-email: Luca de Alfaro <luca@ucsc.edu>, Coen Adler <ctadler@ucsc.edu>, Artie Nazarov <anazarov@ucsc.edu>, Natalia Ocampo-Peñuela <nocampop@ucsc.edu>, Jasmine Tai <cjtai@ucsc.edu>, Natalie Valett <nvalett@ucsc.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/ecoscape-earth/ecoscape-utilities
|
|
@@ -72,35 +72,39 @@ class EbirdObservations(Connection):
|
|
|
72
72
|
super().__init__(db_file)
|
|
73
73
|
|
|
74
74
|
def get_all_squares(self, state=None,
|
|
75
|
-
breeding=
|
|
76
|
-
lat_range=None, lng_range=None, max_dist=2,
|
|
75
|
+
breeding=None, date_range=None,
|
|
76
|
+
lat_range=None, lng_range=None, max_dist=2, min_time=None,
|
|
77
77
|
verbose=False):
|
|
78
78
|
"""
|
|
79
79
|
Gets all squares with bird (any bird) observations, for a certain state,
|
|
80
80
|
and withing certain lat, lng, and date ranges.
|
|
81
81
|
:param state (str): state code
|
|
82
|
-
:param breeding
|
|
82
|
+
:param breeding: None, or pair of months delimiting the breeding season, e.g. ("04", "06").
|
|
83
83
|
:param date_range: tuple of 2 date-strings in format "YYYY-MM-DD" to get only observations in this date range
|
|
84
84
|
:param lat_range: tuple of 2 floats for the lower and upper bounds for latitude
|
|
85
85
|
:param lng_range: tuple of 2 floats for the lower and upper bounds for longitude
|
|
86
86
|
:param max_dist (int): max kilometers traveled for the checklist for any observation we consider
|
|
87
87
|
(any of further distance will be too noisy, and should be disreguarded)
|
|
88
|
+
:param min_time (int): minimum time in minutes for the checklist for any observation we consider
|
|
88
89
|
:returns: list of squares which fall within the query parameters
|
|
89
90
|
"""
|
|
90
91
|
query_string=['select DISTINCT SQUARE from checklist where "ALL SPECIES REPORTED" = 1']
|
|
91
92
|
query_string.append('and "PROTOCOL TYPE" != "Incidental"')
|
|
92
93
|
query_string.append('and "EFFORT DISTANCE KM" <= :dist')
|
|
93
94
|
d = {"dist": max_dist}
|
|
95
|
+
if min_time is not None:
|
|
96
|
+
query_string.append('and "DURATION MINUTES" >= :min_time')
|
|
97
|
+
d["min_time"] = min_time
|
|
94
98
|
if state is not None:
|
|
95
99
|
query_string.append('and "STATE CODE" = :state')
|
|
96
100
|
d['state'] = state
|
|
97
101
|
# Adds breeding portion
|
|
98
|
-
if breeding:
|
|
102
|
+
if breeding is not None:
|
|
99
103
|
query_string.extend([
|
|
100
|
-
'and
|
|
101
|
-
'
|
|
102
|
-
'OR substr("OBSERVATION DATE", 6, 2) = "06")'
|
|
104
|
+
'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
|
|
105
|
+
'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
|
|
103
106
|
])
|
|
107
|
+
d['br1'], d['br2'] = breeding
|
|
104
108
|
if date_range is not None:
|
|
105
109
|
query_string.append('and "OBSERVATION DATE" >= :min_date')
|
|
106
110
|
query_string.append('and "OBSERVATION DATE" <= :max_date')
|
|
@@ -120,20 +124,21 @@ class EbirdObservations(Connection):
|
|
|
120
124
|
return [sq[0] for sq in squares_list]
|
|
121
125
|
|
|
122
126
|
def get_square_observations(self, square, bird,
|
|
123
|
-
breeding=
|
|
124
|
-
lat_range=None, lng_range=None, max_dist=2,
|
|
127
|
+
breeding=None, date_range=None,
|
|
128
|
+
lat_range=None, lng_range=None, max_dist=2, min_time=None,
|
|
125
129
|
verbose=False):
|
|
126
130
|
"""
|
|
127
131
|
Get the number of checklists, number of checklists with a bird,
|
|
128
132
|
total time, total distance, and total bird sightings, for a square.
|
|
129
133
|
:param square: tuple of 2 floats, representing (lat, lng) of the square
|
|
130
134
|
:param bird: bird
|
|
131
|
-
:param breeding
|
|
135
|
+
:param breeding: pair of months delimiting breeding season, or None (e.g., ("04", "06")).
|
|
132
136
|
:param date_range: tuple of 2 date-strings in format "YYYY-MM-DD" to get only observations in this date range
|
|
133
137
|
:param lat_range: tuple of 2 floats for the lower and upper bounds for latitude
|
|
134
138
|
:param lng_range: tuple of 2 floats for the lower and upper bounds for longitude
|
|
135
139
|
:param max_dist (int): max kilometers traveled for the checklist for any observation we consider
|
|
136
140
|
(any of further distance will be too noisy, and should be disreguarded)
|
|
141
|
+
:param min_time (int): minimum time in minutes for the checklist for any observation we consider
|
|
137
142
|
:returns: num_checklists, num_bird_checklists, num_birds for the given square.
|
|
138
143
|
"""
|
|
139
144
|
# Gets the number of checklists, the total time, the total distance, and the total number of birds.
|
|
@@ -144,13 +149,16 @@ class EbirdObservations(Connection):
|
|
|
144
149
|
query_string.append('and "PROTOCOL TYPE" != "Incidental"')
|
|
145
150
|
query_string.append('and "EFFORT DISTANCE KM" <= :dist')
|
|
146
151
|
d["dist"] = max_dist
|
|
152
|
+
if min_time is not None:
|
|
153
|
+
query_string.append('and "DURATION MINUTES" >= :min_time')
|
|
154
|
+
d["min_time"] = min_time
|
|
147
155
|
# Adds breeding portion
|
|
148
|
-
if breeding:
|
|
156
|
+
if breeding is not None:
|
|
149
157
|
query_string.extend([
|
|
150
|
-
'and
|
|
151
|
-
'
|
|
152
|
-
'OR substr("OBSERVATION DATE", 6, 2) = "06")'
|
|
158
|
+
'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
|
|
159
|
+
'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
|
|
153
160
|
])
|
|
161
|
+
d['br1'], d['br2'] = breeding
|
|
154
162
|
if date_range is not None:
|
|
155
163
|
query_string.append('and "OBSERVATION DATE" >= :min_date')
|
|
156
164
|
query_string.append('and "OBSERVATION DATE" <= :max_date')
|
|
@@ -187,12 +195,12 @@ class EbirdObservations(Connection):
|
|
|
187
195
|
query_string.append('and checklist."EFFORT DISTANCE KM" <= :dist')
|
|
188
196
|
d["dist"] = max_dist
|
|
189
197
|
# Adds breeding portion
|
|
190
|
-
if breeding:
|
|
198
|
+
if breeding is not None:
|
|
191
199
|
query_string.extend([
|
|
192
|
-
'and
|
|
193
|
-
'
|
|
194
|
-
'OR substr(checklist."OBSERVATION DATE", 6, 2) = "06")'
|
|
200
|
+
'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
|
|
201
|
+
'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
|
|
195
202
|
])
|
|
203
|
+
d['br1'], d['br2'] = breeding
|
|
196
204
|
if date_range is not None:
|
|
197
205
|
query_string.append('and checklist."OBSERVATION DATE" >= :min_date')
|
|
198
206
|
query_string.append('and checklist."OBSERVATION DATE" <= :max_date')
|
|
@@ -229,7 +237,7 @@ class EbirdObservations(Connection):
|
|
|
229
237
|
)
|
|
230
238
|
|
|
231
239
|
def get_square_individual_checklists(self, square, bird,
|
|
232
|
-
breeding=
|
|
240
|
+
breeding=None, date_range=None,
|
|
233
241
|
lat_range=None, lng_range=None, max_dist=2,
|
|
234
242
|
verbose=False):
|
|
235
243
|
"""
|
|
@@ -239,7 +247,7 @@ class EbirdObservations(Connection):
|
|
|
239
247
|
and total bird sightings, for a square.
|
|
240
248
|
:param square: tuple of 2 floats, representing (lat, lng) of the square
|
|
241
249
|
:param bird (str): name of bird
|
|
242
|
-
:param breeding
|
|
250
|
+
:param breeding: None, or pair of months delimiting breeding season ("04", "06").
|
|
243
251
|
:param date_range: tuple of 2 date-strings in format "YYYY-MM-DD" to get only observations in this date range
|
|
244
252
|
:param lat_range: tuple of 2 floats for the lower and upper bounds for latitude
|
|
245
253
|
:param lng_range: tuple of 2 floats for the lower and upper bounds for longitude
|
|
@@ -256,12 +264,12 @@ class EbirdObservations(Connection):
|
|
|
256
264
|
query_string.append('and "EFFORT DISTANCE KM" <= :dist')
|
|
257
265
|
d["dist"] = max_dist
|
|
258
266
|
# Adds breeding portion
|
|
259
|
-
if breeding:
|
|
267
|
+
if breeding is not None:
|
|
260
268
|
query_string.extend([
|
|
261
|
-
'and
|
|
262
|
-
'
|
|
263
|
-
'OR substr("OBSERVATION DATE", 6, 2) = "06")'
|
|
269
|
+
'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
|
|
270
|
+
'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
|
|
264
271
|
])
|
|
272
|
+
d['br1'], d['br2'] = breeding
|
|
265
273
|
if date_range is not None:
|
|
266
274
|
query_string.append('and "OBSERVATION DATE" >= :min_date')
|
|
267
275
|
query_string.append('and "OBSERVATION DATE" <= :max_date')
|
|
@@ -291,12 +299,12 @@ class EbirdObservations(Connection):
|
|
|
291
299
|
query_string.append('and checklist."EFFORT DISTANCE KM" <= :dist')
|
|
292
300
|
d["dist"] = max_dist
|
|
293
301
|
# Adds breeding portion
|
|
294
|
-
if breeding:
|
|
302
|
+
if breeding is not None:
|
|
295
303
|
query_string.extend([
|
|
296
|
-
'and
|
|
297
|
-
'
|
|
298
|
-
'OR substr(checklist."OBSERVATION DATE", 6, 2) = "06")'
|
|
304
|
+
'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
|
|
305
|
+
'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
|
|
299
306
|
])
|
|
307
|
+
d['br1'], d['br2'] = breeding
|
|
300
308
|
if date_range is not None:
|
|
301
309
|
query_string.append('and checklist."OBSERVATION DATE" >= :min_date')
|
|
302
310
|
query_string.append('and checklist."OBSERVATION DATE" <= :max_date')
|
|
@@ -323,14 +331,14 @@ class EbirdObservations(Connection):
|
|
|
323
331
|
checklists_df["Count"] = checklists_df.apply(lambda row : counts[row["SAMPLING EVENT IDENTIFIER"]], axis=1)
|
|
324
332
|
return checklists_df
|
|
325
333
|
|
|
326
|
-
def get_squares_with_bird(self, bird, max_dist=1, breeding=
|
|
334
|
+
def get_squares_with_bird(self, bird, max_dist=1, breeding=None,
|
|
327
335
|
date_range=None, lat_range=None, lng_range=None,
|
|
328
336
|
state=None, verbose=False):
|
|
329
337
|
"""Gets all the squares where a bird has been sighted. This is used
|
|
330
338
|
primarily to refine the terrain resistance.
|
|
331
339
|
:param bird: Common name of the bird
|
|
332
340
|
:param max_dist: max length of the checklist in Km
|
|
333
|
-
:param breeding:
|
|
341
|
+
:param breeding: pair of months delimiting breeding season, or None.
|
|
334
342
|
:param date_range: date range in years, as a string tuple of yyyy-mm-dd dates
|
|
335
343
|
:param lat_range: range of latitudes to consider, as number tuple, optional.
|
|
336
344
|
:param lng_range: range of longitudes to consider, as number tuple, optional.
|
|
@@ -350,12 +358,12 @@ class EbirdObservations(Connection):
|
|
|
350
358
|
query_string.append('and checklist."PROTOCOL TYPE" != "Incidental"')
|
|
351
359
|
query_string.append('and checklist."EFFORT DISTANCE KM" <= :dist')
|
|
352
360
|
# Adds breeding portion
|
|
353
|
-
if breeding:
|
|
361
|
+
if breeding is not None:
|
|
354
362
|
query_string.extend([
|
|
355
|
-
'and
|
|
356
|
-
'
|
|
357
|
-
'OR substr(checklist."OBSERVATION DATE", 6, 2) = "06")'
|
|
363
|
+
'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
|
|
364
|
+
'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
|
|
358
365
|
])
|
|
366
|
+
d['br1'], d['br2'] = breeding
|
|
359
367
|
if date_range is not None:
|
|
360
368
|
query_string.append('and checklist."OBSERVATION DATE" >= :min_date')
|
|
361
369
|
query_string.append('and checklist."OBSERVATION DATE" <= :max_date')
|
|
@@ -376,78 +384,6 @@ class EbirdObservations(Connection):
|
|
|
376
384
|
return [row[0] for row in r]
|
|
377
385
|
|
|
378
386
|
|
|
379
|
-
def get_observation_ratios(self, bird, min_checklists, bigsquare=False,
|
|
380
|
-
max_dist=1, verbose=False,
|
|
381
|
-
state=None, breeding=True):
|
|
382
|
-
"""This function is not used now. It was the old, deprecated way of
|
|
383
|
-
doing validation, and we are keeping the code for reference only."""
|
|
384
|
-
# First, I create a dictionary of squares to checklist counts.
|
|
385
|
-
query_string = [
|
|
386
|
-
'select "SAMPLING EVENT IDENTIFIER",',
|
|
387
|
-
'BIGSQUARE' if bigsquare else 'SQUARE',
|
|
388
|
-
'from checklist where',
|
|
389
|
-
'"ALL SPECIES REPORTED" = 1',
|
|
390
|
-
]
|
|
391
|
-
d = {'dist': max_dist}
|
|
392
|
-
query_string.append('and "PROTOCOL TYPE" != "Incidental"')
|
|
393
|
-
query_string.append('and "EFFORT DISTANCE KM" <= :dist')
|
|
394
|
-
if state is not None:
|
|
395
|
-
query_string.append('and "STATE CODE" = :state')
|
|
396
|
-
d['state'] = state
|
|
397
|
-
# Adds breeding portion
|
|
398
|
-
if breeding:
|
|
399
|
-
query_string.extend([
|
|
400
|
-
'and (substr("OBSERVATION DATE", 6, 2) = "04"',
|
|
401
|
-
'OR substr("OBSERVATION DATE", 6, 2) = "05"',
|
|
402
|
-
'OR substr("OBSERVATION DATE", 6, 2) = "06")'
|
|
403
|
-
])
|
|
404
|
-
query_string = " ".join(query_string)
|
|
405
|
-
if verbose:
|
|
406
|
-
print("Query:", query_string)
|
|
407
|
-
observations = self.execute_query((query_string, d))
|
|
408
|
-
checklists_per_square = defaultdict(int)
|
|
409
|
-
for _, sq in observations:
|
|
410
|
-
checklists_per_square[sq] += 1
|
|
411
|
-
# Now I keep only the squares with a minimum of checklists.
|
|
412
|
-
checklists_per_square = {sq: c for sq, c in checklists_per_square.items() if c >= min_checklists}
|
|
413
|
-
# Ok, I care only about these squares.
|
|
414
|
-
# Now I want to know, for each of these squares, how many checklists there are that
|
|
415
|
-
# contain the bird.
|
|
416
|
-
query_string = [
|
|
417
|
-
'select DISTINCT checklist."SAMPLING EVENT IDENTIFIER",',
|
|
418
|
-
'checklist.BIGSQUARE' if bigsquare else 'checklist.SQUARE',
|
|
419
|
-
'from checklist join observation on',
|
|
420
|
-
'checklist."SAMPLING EVENT IDENTIFIER" = observation."SAMPLING EVENT IDENTIFIER"',
|
|
421
|
-
'where observation."COMMON NAME" = :bird',
|
|
422
|
-
'and checklist."ALL SPECIES REPORTED" = 1',
|
|
423
|
-
]
|
|
424
|
-
d = {'dist': max_dist ,'bird': bird}
|
|
425
|
-
query_string.append('and checklist."PROTOCOL TYPE" != "Incidental"')
|
|
426
|
-
query_string.append('and checklist."EFFORT DISTANCE KM" <= :dist')
|
|
427
|
-
if state is not None:
|
|
428
|
-
query_string.append('and checklist."STATE CODE" = :state')
|
|
429
|
-
d['state'] = state
|
|
430
|
-
if breeding:
|
|
431
|
-
query_string.extend([
|
|
432
|
-
'and (substr(checklist."OBSERVATION DATE", 6, 2) = "04"',
|
|
433
|
-
'OR substr(checklist."OBSERVATION DATE", 6, 2) = "05"',
|
|
434
|
-
'OR substr(checklist."OBSERVATION DATE", 6, 2) = "06")',
|
|
435
|
-
])
|
|
436
|
-
query_string = " ".join(query_string)
|
|
437
|
-
if verbose:
|
|
438
|
-
print("Query:", query_string)
|
|
439
|
-
observations = self.execute_query((query_string, d))
|
|
440
|
-
good_checklists_per_square = defaultdict(int)
|
|
441
|
-
for _, sq in observations:
|
|
442
|
-
if sq in checklists_per_square: # Otherwise, too few observations.
|
|
443
|
-
good_checklists_per_square[sq] += 1
|
|
444
|
-
for sq in checklists_per_square:
|
|
445
|
-
if good_checklists_per_square[sq] > checklists_per_square[sq]:
|
|
446
|
-
print("Too many checklists at", sq, good_checklists_per_square[sq], checklists_per_square[sq])
|
|
447
|
-
return {sq: (good_checklists_per_square[sq] / checklists_per_square[sq])
|
|
448
|
-
for sq in checklists_per_square}
|
|
449
|
-
|
|
450
|
-
|
|
451
387
|
def format_coords(coords, bigsquare=False):
|
|
452
388
|
"""
|
|
453
389
|
formats coords from the eBird database format '4406;-12131' to
|
{ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities.egg-info/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ecoscape-utilities
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.37
|
|
4
4
|
Summary: A collection of EcoScape utilities.
|
|
5
5
|
Author-email: Luca de Alfaro <luca@ucsc.edu>, Coen Adler <ctadler@ucsc.edu>, Artie Nazarov <anazarov@ucsc.edu>, Natalia Ocampo-Peñuela <nocampop@ucsc.edu>, Jasmine Tai <cjtai@ucsc.edu>, Natalie Valett <nvalett@ucsc.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/ecoscape-earth/ecoscape-utilities
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities.egg-info/requires.txt
RENAMED
|
File without changes
|
{ecoscape_utilities-0.0.35 → ecoscape_utilities-0.0.37}/ecoscape_utilities.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|