ecoscape-utilities 0.0.36__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ecoscape-utilities
3
- Version: 0.0.36
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,14 +72,14 @@ class EbirdObservations(Connection):
72
72
  super().__init__(db_file)
73
73
 
74
74
  def get_all_squares(self, state=None,
75
- breeding=True, date_range=None,
75
+ breeding=None, date_range=None,
76
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 (boolean): whether to filter observations by breeding months (getting only apr-june)
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
@@ -99,12 +99,12 @@ class EbirdObservations(Connection):
99
99
  query_string.append('and "STATE CODE" = :state')
100
100
  d['state'] = state
101
101
  # Adds breeding portion
102
- if breeding:
102
+ if breeding is not None:
103
103
  query_string.extend([
104
- 'and (substr("OBSERVATION DATE", 6, 2) = "04"',
105
- 'OR substr("OBSERVATION DATE", 6, 2) = "05"',
106
- 'OR substr("OBSERVATION DATE", 6, 2) = "06")'
104
+ 'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
105
+ 'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
107
106
  ])
107
+ d['br1'], d['br2'] = breeding
108
108
  if date_range is not None:
109
109
  query_string.append('and "OBSERVATION DATE" >= :min_date')
110
110
  query_string.append('and "OBSERVATION DATE" <= :max_date')
@@ -124,7 +124,7 @@ class EbirdObservations(Connection):
124
124
  return [sq[0] for sq in squares_list]
125
125
 
126
126
  def get_square_observations(self, square, bird,
127
- breeding=True, date_range=None,
127
+ breeding=None, date_range=None,
128
128
  lat_range=None, lng_range=None, max_dist=2, min_time=None,
129
129
  verbose=False):
130
130
  """
@@ -132,7 +132,7 @@ class EbirdObservations(Connection):
132
132
  total time, total distance, and total bird sightings, for a square.
133
133
  :param square: tuple of 2 floats, representing (lat, lng) of the square
134
134
  :param bird: bird
135
- :param breeding (boolean): whether to filter observations by breeding months (getting only apr-june)
135
+ :param breeding: pair of months delimiting breeding season, or None (e.g., ("04", "06")).
136
136
  :param date_range: tuple of 2 date-strings in format "YYYY-MM-DD" to get only observations in this date range
137
137
  :param lat_range: tuple of 2 floats for the lower and upper bounds for latitude
138
138
  :param lng_range: tuple of 2 floats for the lower and upper bounds for longitude
@@ -153,12 +153,12 @@ class EbirdObservations(Connection):
153
153
  query_string.append('and "DURATION MINUTES" >= :min_time')
154
154
  d["min_time"] = min_time
155
155
  # Adds breeding portion
156
- if breeding:
156
+ if breeding is not None:
157
157
  query_string.extend([
158
- 'and (substr("OBSERVATION DATE", 6, 2) = "04"',
159
- 'OR substr("OBSERVATION DATE", 6, 2) = "05"',
160
- 'OR substr("OBSERVATION DATE", 6, 2) = "06")'
158
+ 'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
159
+ 'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
161
160
  ])
161
+ d['br1'], d['br2'] = breeding
162
162
  if date_range is not None:
163
163
  query_string.append('and "OBSERVATION DATE" >= :min_date')
164
164
  query_string.append('and "OBSERVATION DATE" <= :max_date')
@@ -195,12 +195,12 @@ class EbirdObservations(Connection):
195
195
  query_string.append('and checklist."EFFORT DISTANCE KM" <= :dist')
196
196
  d["dist"] = max_dist
197
197
  # Adds breeding portion
198
- if breeding:
198
+ if breeding is not None:
199
199
  query_string.extend([
200
- 'and (substr(checklist."OBSERVATION DATE", 6, 2) = "04"',
201
- 'OR substr(checklist."OBSERVATION DATE", 6, 2) = "05"',
202
- 'OR substr(checklist."OBSERVATION DATE", 6, 2) = "06")'
200
+ 'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
201
+ 'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
203
202
  ])
203
+ d['br1'], d['br2'] = breeding
204
204
  if date_range is not None:
205
205
  query_string.append('and checklist."OBSERVATION DATE" >= :min_date')
206
206
  query_string.append('and checklist."OBSERVATION DATE" <= :max_date')
@@ -237,7 +237,7 @@ class EbirdObservations(Connection):
237
237
  )
238
238
 
239
239
  def get_square_individual_checklists(self, square, bird,
240
- breeding=True, date_range=None,
240
+ breeding=None, date_range=None,
241
241
  lat_range=None, lng_range=None, max_dist=2,
242
242
  verbose=False):
243
243
  """
@@ -247,7 +247,7 @@ class EbirdObservations(Connection):
247
247
  and total bird sightings, for a square.
248
248
  :param square: tuple of 2 floats, representing (lat, lng) of the square
249
249
  :param bird (str): name of bird
250
- :param breeding (boolean): whether to filter observations by breeding months (getting only apr-june)
250
+ :param breeding: None, or pair of months delimiting breeding season ("04", "06").
251
251
  :param date_range: tuple of 2 date-strings in format "YYYY-MM-DD" to get only observations in this date range
252
252
  :param lat_range: tuple of 2 floats for the lower and upper bounds for latitude
253
253
  :param lng_range: tuple of 2 floats for the lower and upper bounds for longitude
@@ -264,12 +264,12 @@ class EbirdObservations(Connection):
264
264
  query_string.append('and "EFFORT DISTANCE KM" <= :dist')
265
265
  d["dist"] = max_dist
266
266
  # Adds breeding portion
267
- if breeding:
267
+ if breeding is not None:
268
268
  query_string.extend([
269
- 'and (substr("OBSERVATION DATE", 6, 2) = "04"',
270
- 'OR substr("OBSERVATION DATE", 6, 2) = "05"',
271
- 'OR substr("OBSERVATION DATE", 6, 2) = "06")'
269
+ 'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
270
+ 'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
272
271
  ])
272
+ d['br1'], d['br2'] = breeding
273
273
  if date_range is not None:
274
274
  query_string.append('and "OBSERVATION DATE" >= :min_date')
275
275
  query_string.append('and "OBSERVATION DATE" <= :max_date')
@@ -299,12 +299,12 @@ class EbirdObservations(Connection):
299
299
  query_string.append('and checklist."EFFORT DISTANCE KM" <= :dist')
300
300
  d["dist"] = max_dist
301
301
  # Adds breeding portion
302
- if breeding:
302
+ if breeding is not None:
303
303
  query_string.extend([
304
- 'and (substr(checklist."OBSERVATION DATE", 6, 2) = "04"',
305
- 'OR substr(checklist."OBSERVATION DATE", 6, 2) = "05"',
306
- 'OR substr(checklist."OBSERVATION DATE", 6, 2) = "06")'
304
+ 'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
305
+ 'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
307
306
  ])
307
+ d['br1'], d['br2'] = breeding
308
308
  if date_range is not None:
309
309
  query_string.append('and checklist."OBSERVATION DATE" >= :min_date')
310
310
  query_string.append('and checklist."OBSERVATION DATE" <= :max_date')
@@ -331,14 +331,14 @@ class EbirdObservations(Connection):
331
331
  checklists_df["Count"] = checklists_df.apply(lambda row : counts[row["SAMPLING EVENT IDENTIFIER"]], axis=1)
332
332
  return checklists_df
333
333
 
334
- def get_squares_with_bird(self, bird, max_dist=1, breeding=False,
334
+ def get_squares_with_bird(self, bird, max_dist=1, breeding=None,
335
335
  date_range=None, lat_range=None, lng_range=None,
336
336
  state=None, verbose=False):
337
337
  """Gets all the squares where a bird has been sighted. This is used
338
338
  primarily to refine the terrain resistance.
339
339
  :param bird: Common name of the bird
340
340
  :param max_dist: max length of the checklist in Km
341
- :param breeding: whether to consider only the breeding period or not
341
+ :param breeding: pair of months delimiting breeding season, or None.
342
342
  :param date_range: date range in years, as a string tuple of yyyy-mm-dd dates
343
343
  :param lat_range: range of latitudes to consider, as number tuple, optional.
344
344
  :param lng_range: range of longitudes to consider, as number tuple, optional.
@@ -358,12 +358,12 @@ class EbirdObservations(Connection):
358
358
  query_string.append('and checklist."PROTOCOL TYPE" != "Incidental"')
359
359
  query_string.append('and checklist."EFFORT DISTANCE KM" <= :dist')
360
360
  # Adds breeding portion
361
- if breeding:
361
+ if breeding is not None:
362
362
  query_string.extend([
363
- 'and (substr(checklist."OBSERVATION DATE", 6, 2) = "04"',
364
- 'OR substr(checklist."OBSERVATION DATE", 6, 2) = "05"',
365
- 'OR substr(checklist."OBSERVATION DATE", 6, 2) = "06")'
363
+ 'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
364
+ 'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
366
365
  ])
366
+ d['br1'], d['br2'] = breeding
367
367
  if date_range is not None:
368
368
  query_string.append('and checklist."OBSERVATION DATE" >= :min_date')
369
369
  query_string.append('and checklist."OBSERVATION DATE" <= :max_date')
@@ -384,78 +384,6 @@ class EbirdObservations(Connection):
384
384
  return [row[0] for row in r]
385
385
 
386
386
 
387
- def get_observation_ratios(self, bird, min_checklists, bigsquare=False,
388
- max_dist=1, verbose=False,
389
- state=None, breeding=True):
390
- """This function is not used now. It was the old, deprecated way of
391
- doing validation, and we are keeping the code for reference only."""
392
- # First, I create a dictionary of squares to checklist counts.
393
- query_string = [
394
- 'select "SAMPLING EVENT IDENTIFIER",',
395
- 'BIGSQUARE' if bigsquare else 'SQUARE',
396
- 'from checklist where',
397
- '"ALL SPECIES REPORTED" = 1',
398
- ]
399
- d = {'dist': max_dist}
400
- query_string.append('and "PROTOCOL TYPE" != "Incidental"')
401
- query_string.append('and "EFFORT DISTANCE KM" <= :dist')
402
- if state is not None:
403
- query_string.append('and "STATE CODE" = :state')
404
- d['state'] = state
405
- # Adds breeding portion
406
- if breeding:
407
- query_string.extend([
408
- 'and (substr("OBSERVATION DATE", 6, 2) = "04"',
409
- 'OR substr("OBSERVATION DATE", 6, 2) = "05"',
410
- 'OR substr("OBSERVATION DATE", 6, 2) = "06")'
411
- ])
412
- query_string = " ".join(query_string)
413
- if verbose:
414
- print("Query:", query_string)
415
- observations = self.execute_query((query_string, d))
416
- checklists_per_square = defaultdict(int)
417
- for _, sq in observations:
418
- checklists_per_square[sq] += 1
419
- # Now I keep only the squares with a minimum of checklists.
420
- checklists_per_square = {sq: c for sq, c in checklists_per_square.items() if c >= min_checklists}
421
- # Ok, I care only about these squares.
422
- # Now I want to know, for each of these squares, how many checklists there are that
423
- # contain the bird.
424
- query_string = [
425
- 'select DISTINCT checklist."SAMPLING EVENT IDENTIFIER",',
426
- 'checklist.BIGSQUARE' if bigsquare else 'checklist.SQUARE',
427
- 'from checklist join observation on',
428
- 'checklist."SAMPLING EVENT IDENTIFIER" = observation."SAMPLING EVENT IDENTIFIER"',
429
- 'where observation."COMMON NAME" = :bird',
430
- 'and checklist."ALL SPECIES REPORTED" = 1',
431
- ]
432
- d = {'dist': max_dist ,'bird': bird}
433
- query_string.append('and checklist."PROTOCOL TYPE" != "Incidental"')
434
- query_string.append('and checklist."EFFORT DISTANCE KM" <= :dist')
435
- if state is not None:
436
- query_string.append('and checklist."STATE CODE" = :state')
437
- d['state'] = state
438
- if breeding:
439
- query_string.extend([
440
- 'and (substr(checklist."OBSERVATION DATE", 6, 2) = "04"',
441
- 'OR substr(checklist."OBSERVATION DATE", 6, 2) = "05"',
442
- 'OR substr(checklist."OBSERVATION DATE", 6, 2) = "06")',
443
- ])
444
- query_string = " ".join(query_string)
445
- if verbose:
446
- print("Query:", query_string)
447
- observations = self.execute_query((query_string, d))
448
- good_checklists_per_square = defaultdict(int)
449
- for _, sq in observations:
450
- if sq in checklists_per_square: # Otherwise, too few observations.
451
- good_checklists_per_square[sq] += 1
452
- for sq in checklists_per_square:
453
- if good_checklists_per_square[sq] > checklists_per_square[sq]:
454
- print("Too many checklists at", sq, good_checklists_per_square[sq], checklists_per_square[sq])
455
- return {sq: (good_checklists_per_square[sq] / checklists_per_square[sq])
456
- for sq in checklists_per_square}
457
-
458
-
459
387
  def format_coords(coords, bigsquare=False):
460
388
  """
461
389
  formats coords from the eBird database format '4406;-12131' to
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ecoscape-utilities
3
- Version: 0.0.36
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ecoscape-utilities"
7
- version = "0.0.36"
7
+ version = "0.0.37"
8
8
  authors = [
9
9
  {name="Luca de Alfaro", email="luca@ucsc.edu"},
10
10
  {name="Coen Adler", email="ctadler@ucsc.edu"},