ecoscape-utilities 0.0.39__tar.gz → 0.0.41__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.39
3
+ Version: 0.0.41
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,6 +4,7 @@ import os
4
4
  import pandas as pd
5
5
  import sqlite3
6
6
  from sqlite3 import Error
7
+ import warnings
7
8
 
8
9
  from collections import defaultdict
9
10
  from pyproj import Transformer
@@ -129,8 +130,8 @@ class EbirdObservations(Connection):
129
130
  # Adds breeding portion
130
131
  if breeding is not None:
131
132
  query_string.extend([
132
- 'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
133
- 'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
133
+ 'and substr("OBSERVATION DATE", 6, 2) >= :br1',
134
+ 'and substr("OBSERVATION DATE", 6, 2) <= :br2',
134
135
  ])
135
136
  d['br1'], d['br2'] = breeding
136
137
  if date_range is not None:
@@ -170,6 +171,8 @@ class EbirdObservations(Connection):
170
171
  :param min_time (int): minimum time in minutes for the checklist for any observation we consider
171
172
  :returns: num_checklists, num_bird_checklists, num_birds for the given square.
172
173
  """
174
+ # Adds deprecation warning.
175
+ warnings.warn("This function is deprecated. Use get_square_checklists instead.", DeprecationWarning)
173
176
  # Gets the number of checklists, the total time, the total distance, and the total number of birds.
174
177
  query_string=['select COUNT(*), SUM("EFFORT DISTANCE KM"), SUM("DURATION MINUTES")',
175
178
  'FROM checklist where SQUARE = :square']
@@ -184,8 +187,8 @@ class EbirdObservations(Connection):
184
187
  # Adds breeding portion
185
188
  if breeding is not None:
186
189
  query_string.extend([
187
- 'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
188
- 'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
190
+ 'and substr("OBSERVATION DATE", 6, 2) >= :br1',
191
+ 'and substr("OBSERVATION DATE", 6, 2) <= :br2',
189
192
  ])
190
193
  d['br1'], d['br2'] = breeding
191
194
  if date_range is not None:
@@ -226,8 +229,8 @@ class EbirdObservations(Connection):
226
229
  # Adds breeding portion
227
230
  if breeding is not None:
228
231
  query_string.extend([
229
- 'and substr(checklist."OBSERVATION DATE", 6, 2) >= ":br1"',
230
- 'and substr(checklist."OBSERVATION DATE", 6, 2) <= ":br2"',
232
+ 'and substr(checklist."OBSERVATION DATE", 6, 2) >= :br1',
233
+ 'and substr(checklist."OBSERVATION DATE", 6, 2) <= :br2',
231
234
  ])
232
235
  d['br1'], d['br2'] = breeding
233
236
  if min_time is not None:
@@ -268,6 +271,119 @@ class EbirdObservations(Connection):
268
271
  total_km=total_km,
269
272
  total_minutes=total_minutes,
270
273
  )
274
+
275
+ def get_state_checklists(self, state, bird,
276
+ breeding=None, date_range=None,
277
+ lat_range=None, lng_range=None, max_dist=2,
278
+ verbose=False):
279
+ """Returns a dataframe consisting of all checklists in a square, with data
280
+ on a (possible) occurrence of a bird."""
281
+ query_string = [
282
+ 'SELECT checklist."SQUARE", ',
283
+ 'checklist."SAMPLING EVENT IDENTIFIER", ',
284
+ 'checklist."PROTOCOL TYPE", ',
285
+ 'checklist."EFFORT DISTANCE KM", ',
286
+ 'checklist."DURATION MINUTES", ',
287
+ 'checklist."OBSERVATION DATE", ',
288
+ 'checklist."TIME OBSERVATIONS STARTED", ',
289
+ 'checklist."OBSERVER ID", ',
290
+ 'checklist."LATITUDE", ',
291
+ 'checklist."LONGITUDE", ',
292
+ 'observation."OBSERVATION COUNT" ',
293
+ 'FROM checklist LEFT JOIN observation ',
294
+ 'ON checklist."SAMPLING EVENT IDENTIFIER" = observation."SAMPLING EVENT IDENTIFIER" ',
295
+ 'AND observation."COMMON NAME" = :bird ',
296
+ 'WHERE ',
297
+ 'checklist."STATE CODE" = :state',
298
+ 'and checklist."ALL SPECIES REPORTED" = 1',
299
+ 'and checklist."PROTOCOL TYPE" != "Incidental" ',
300
+ 'and checklist."EFFORT DISTANCE KM" <= :dist',
301
+ ]
302
+ # Main query parameters
303
+ d = {"state": state, "dist": max_dist, "bird": bird.name}
304
+ # Adds breeding portion
305
+ if breeding is not None:
306
+ query_string.extend([
307
+ 'and substr(checklist."OBSERVATION DATE", 6, 2) >= :br1',
308
+ 'and substr(checklist."OBSERVATION DATE", 6, 2) <= :br2',
309
+ ])
310
+ d['br1'], d['br2'] = breeding
311
+ if date_range is not None:
312
+ query_string.append('and checklist."OBSERVATION DATE" >= :min_date')
313
+ query_string.append('and checklist."OBSERVATION DATE" <= :max_date')
314
+ d["min_date"], d["max_date"] = date_range
315
+ if lat_range is not None:
316
+ query_string.append('and checklist."LATITUDE" >= :min_lat')
317
+ query_string.append('and checklist."LATITUDE" <= :max_lat')
318
+ d["min_lat"], d["max_lat"] = lat_range
319
+ if lng_range is not None:
320
+ query_string.append('and checklist."LONGITUDE" >= :min_lng')
321
+ query_string.append('and checklist."LONGITUDE" <= :max_lng')
322
+ d["min_lng"], d["max_lng"] = lng_range
323
+ # Submits the query.
324
+ query_string = " ".join(query_string)
325
+ if verbose:
326
+ print("Query:", query_string)
327
+ print("Expanded query:", expand_sqlite_query(query_string, d))
328
+ checklists_df = pd.read_sql_query(query_string, self.conn, params=d)
329
+ return checklists_df
330
+
331
+
332
+ def get_square_checklists(self, square, bird,
333
+ breeding=None, date_range=None,
334
+ lat_range=None, lng_range=None, max_dist=2,
335
+ verbose=False):
336
+ """Returns a dataframe consisting of all checklists in a square, with data
337
+ on a (possible) occurrence of a bird."""
338
+ query_string = [
339
+ 'SELECT checklist."SQUARE", ',
340
+ 'checklist."SAMPLING EVENT IDENTIFIER", ',
341
+ 'checklist."PROTOCOL TYPE", ',
342
+ 'checklist."EFFORT DISTANCE KM", ',
343
+ 'checklist."DURATION MINUTES", ',
344
+ 'checklist."OBSERVATION DATE", ',
345
+ 'checklist."TIME OBSERVATIONS STARTED", ',
346
+ 'checklist."OBSERVER ID", ',
347
+ 'checklist."LATITUDE", ',
348
+ 'checklist."LONGITUDE", ',
349
+ 'observation."OBSERVATION COUNT" ',
350
+ 'FROM checklist LEFT JOIN observation ',
351
+ 'ON checklist."SAMPLING EVENT IDENTIFIER" = observation."SAMPLING EVENT IDENTIFIER" ',
352
+ 'AND observation."COMMON NAME" = :bird ',
353
+ 'WHERE ',
354
+ 'checklist.SQUARE = :square',
355
+ 'and checklist."ALL SPECIES REPORTED" = 1',
356
+ 'and checklist."PROTOCOL TYPE" != "Incidental" ',
357
+ 'and checklist."EFFORT DISTANCE KM" <= :dist',
358
+ ]
359
+ # Main query parameters
360
+ d = {"square": square, "dist": max_dist, "bird": bird.name}
361
+ # Adds breeding portion
362
+ if breeding is not None:
363
+ query_string.extend([
364
+ 'and substr(checklist."OBSERVATION DATE", 6, 2) >= :br1',
365
+ 'and substr(checklist."OBSERVATION DATE", 6, 2) <= :br2',
366
+ ])
367
+ d['br1'], d['br2'] = breeding
368
+ if date_range is not None:
369
+ query_string.append('and checklist."OBSERVATION DATE" >= :min_date')
370
+ query_string.append('and checklist."OBSERVATION DATE" <= :max_date')
371
+ d["min_date"], d["max_date"] = date_range
372
+ if lat_range is not None:
373
+ query_string.append('and checklist."LATITUDE" >= :min_lat')
374
+ query_string.append('and checklist."LATITUDE" <= :max_lat')
375
+ d["min_lat"], d["max_lat"] = lat_range
376
+ if lng_range is not None:
377
+ query_string.append('and checklist."LONGITUDE" >= :min_lng')
378
+ query_string.append('and checklist."LONGITUDE" <= :max_lng')
379
+ d["min_lng"], d["max_lng"] = lng_range
380
+ # Submits the query.
381
+ query_string = " ".join(query_string)
382
+ if verbose:
383
+ print("Query:", query_string)
384
+ print("Expanded query:", expand_sqlite_query(query_string, d))
385
+ checklists_df = pd.read_sql_query(query_string, self.conn, params=d)
386
+ return checklists_df
271
387
 
272
388
  def get_square_individual_checklists(self, square, bird,
273
389
  breeding=None, date_range=None, min_time=None,
@@ -288,6 +404,8 @@ class EbirdObservations(Connection):
288
404
  (any of further distance will be too noisy, and should be disreguarded)
289
405
  :returns: list of squares which fall within the query parameters
290
406
  """
407
+ # Adds deprecation warning.
408
+ warnings.warn("This function is deprecated. Use get_square_checklists instead.", DeprecationWarning)
291
409
  # First the checklists, with or without the bird.
292
410
  query_string=['select DISTINCT("SAMPLING EVENT IDENTIFIER")',
293
411
  'FROM checklist where SQUARE = :square']
@@ -296,16 +414,16 @@ class EbirdObservations(Connection):
296
414
  query_string.append('and "PROTOCOL TYPE" != "Incidental"')
297
415
  query_string.append('and "EFFORT DISTANCE KM" <= :dist')
298
416
  d["dist"] = max_dist
417
+ if min_time is not None:
418
+ query_string.append('and "DURATION MINUTES" >= :min_time')
419
+ d["min_time"] = min_time
299
420
  # Adds breeding portion
300
421
  if breeding is not None:
301
422
  query_string.extend([
302
- 'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
303
- 'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
423
+ 'and substr("OBSERVATION DATE", 6, 2) >= :br1',
424
+ 'and substr("OBSERVATION DATE", 6, 2) <= :br2',
304
425
  ])
305
426
  d['br1'], d['br2'] = breeding
306
- if min_time is not None:
307
- query_string.append('and "DURATION MINUTES" >= :min_time')
308
- d["min_time"] = min_time
309
427
  if date_range is not None:
310
428
  query_string.append('and "OBSERVATION DATE" >= :min_date')
311
429
  query_string.append('and "OBSERVATION DATE" <= :max_date')
@@ -337,8 +455,8 @@ class EbirdObservations(Connection):
337
455
  # Adds breeding portion
338
456
  if breeding is not None:
339
457
  query_string.extend([
340
- 'and substr(checklist."OBSERVATION DATE", 6, 2) >= ":br1"',
341
- 'and substr(checklist."OBSERVATION DATE", 6, 2) <= ":br2"',
458
+ 'and substr(checklist."OBSERVATION DATE", 6, 2) >= :br1',
459
+ 'and substr(checklist."OBSERVATION DATE", 6, 2) <= :br2',
342
460
  ])
343
461
  d['br1'], d['br2'] = breeding
344
462
  if date_range is not None:
@@ -400,8 +518,8 @@ class EbirdObservations(Connection):
400
518
  # Adds breeding portion
401
519
  if breeding is not None:
402
520
  query_string.extend([
403
- 'and substr("OBSERVATION DATE", 6, 2) >= ":br1"',
404
- 'and substr("OBSERVATION DATE", 6, 2) <= ":br2"',
521
+ 'and substr("OBSERVATION DATE", 6, 2) >= :br1',
522
+ 'and substr("OBSERVATION DATE", 6, 2) <= :br2',
405
523
  ])
406
524
  d['br1'], d['br2'] = breeding
407
525
  if min_time is not None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ecoscape-utilities
3
- Version: 0.0.39
3
+ Version: 0.0.41
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.39"
7
+ version = "0.0.41"
8
8
  authors = [
9
9
  {name="Luca de Alfaro", email="luca@ucsc.edu"},
10
10
  {name="Coen Adler", email="ctadler@ucsc.edu"},