ecoscape-utilities 0.0.32__py3-none-any.whl → 0.0.34__py3-none-any.whl

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.

@@ -486,42 +486,12 @@ A module for common functionality in the validaiton process using ebird data
486
486
  """
487
487
  class Validation(object):
488
488
 
489
- def __init__(self, obs_fn, geotiff_fn):
489
+ def __init__(self, obs_fn):
490
490
  """
491
491
  Generates a class for validation.
492
- It first tries to read the cached version of obs_fn for the specified geotiff_fn.
493
- If the cached version is not found, it is created.
494
- The cached version contains pre-translated coordinates to pixel values.
495
492
  :param obs_fn: Observations filename.
496
- :param geotiff_fn: name of a geotiff (repopulation is preferred) used
497
- for translating coordinates to pixel coordinates.
498
493
  """
499
494
  self.obs_fn = obs_fn
500
- self.geotiff_fn = geotiff_fn
501
- h = hashlib.sha1(obs_fn.encode('utf-8'))
502
- h.update(geotiff_fn.encode('utf-8'))
503
- cached_fn = obs_fn + "." + h.hexdigest() + ".csv"
504
- if not os.path.exists(cached_fn):
505
- self._create_cached_observations(cached_fn)
506
- self.observations = pd.read_csv(cached_fn)
507
-
508
-
509
- def _create_cached_observations(self, cached_fn):
510
- """Creates a cached version of the observations that also contains
511
- pixel coordinates."""
512
- geotiff = GeoTiff.from_file(self.geotiff_fn)
513
- def f(row):
514
- square = row["Square"]
515
- if (isinstance(square, str)):
516
- coords = format_coords(square)
517
- else:
518
- coords = square
519
- lat, lng = coords
520
- pix_x, pix_y = transform_coords(geotiff, coords)
521
- return lat, lng, pix_x, pix_y
522
- df = pd.read_csv(self.obs_fn)
523
- df["lat"], df["lng"], df["pix_x"], df["pix_y"] = zip(*df.apply(f, axis=1))
524
- df.to_csv(cached_fn)
525
495
 
526
496
 
527
497
  def filter_CA_rectangle(self, observation_ratios, bigsquare=False):
@@ -594,8 +564,6 @@ class Validation(object):
594
564
  :param weighted_tile_size: size of the tile to attribute grouped weights to
595
565
  :returns: a dataframe with columns repopulation, observation ratio, and weights
596
566
  '''
597
- assert repop_tif.crs == hab.crs, "Repopulation and habitat geotiffs must have the same CRS"
598
- assert repop_tif.size == hab.size, "Repopulation and habitat geotiffs must have the same size"
599
567
  df = pd.DataFrame(columns=['repop', 'hab', 'max_repop', 'max_hab', 'obs_ratio', 'lat', 'lng', 'x', 'y', ])
600
568
  count = defaultdict(int)
601
569
  for (square, ratio) in observation_ratios:
@@ -604,9 +572,10 @@ class Validation(object):
604
572
  else:
605
573
  coords = square
606
574
  lat, lng = coords
607
- coords = transform_coords(repop_tif, coords)
608
- repop_tile = repop_tif.get_tile_from_coord(coords, tile_scale=tile_scale)
609
- hab_tile = hab.get_tile_from_coord(hab, coords, tile_scale=tile_scale)
575
+ repop_pix_coords = transform_coords(repop_tif, coords)
576
+ hab_pix_coords = transform_coords(hab, coords)
577
+ repop_tile = repop_tif.get_tile_from_coord(repop_pix_coords, tile_scale=tile_scale)
578
+ hab_tile = hab.get_tile_from_coord(hab_pix_coords, tile_scale=tile_scale)
610
579
  if repop_tile is None or hab_tile is None:
611
580
  continue
612
581
  x, y = repop_tif.get_pixel_from_coord(coords)
@@ -638,11 +607,18 @@ class Validation(object):
638
607
  :param hab_tif: habitat geotiff used to compute repop
639
608
  :param tile_scale: size of the tile around square
640
609
  """
641
- df = self.observations.copy()
610
+ df = pd.read_csv(self.obs_fn)
642
611
  def f(row):
643
- coords = (row["pix_x"], row["pix_y"])
644
- repop_tile = repop_tif.get_tile_from_coord(coords, tile_scale=tile_scale)
645
- hab_tile = hab_tif.get_tile_from_coord(coords, tile_scale=tile_scale)
612
+ square = row["Square"]
613
+ if (isinstance(square, str)):
614
+ coords = format_coords(square)
615
+ else:
616
+ coords = square
617
+ lat, lng = coords
618
+ repop_pix_coords = transform_coords(repop_tif, coords)
619
+ hab_pix_coords = transform_coords(hab_tif, coords)
620
+ repop_tile = repop_tif.get_tile_from_coord(repop_pix_coords, tile_scale=tile_scale)
621
+ hab_tile = hab_tif.get_tile_from_coord(hab_pix_coords, tile_scale=tile_scale)
646
622
  if repop_tile is None or hab_tile is None:
647
623
  return pd.NA, pd.NA, pd.NA, pd.NA
648
624
  avg_repop = np.average(repop_tile.m)
@@ -652,7 +628,7 @@ class Validation(object):
652
628
  if div_by_255:
653
629
  avg_repop /= 255.
654
630
  max_repop /= 255.
655
- return avg_repop, avg_hab, max_repop, max_hab
656
- df["avg_repop"], df["avg_hab"], df["max_repop"], df["max_hab"] = zip(*df.apply(f, axis=1))
631
+ return avg_repop, avg_hab, max_repop, max_hab, lat, lng
632
+ df["avg_repop"], df["avg_hab"], df["max_repop"], df["max_hab"], df["lat"], df["lng"] = zip(*df.apply(f, axis=1))
657
633
  return df
658
634
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ecoscape-utilities
3
- Version: 0.0.32
3
+ Version: 0.0.34
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
@@ -0,0 +1,8 @@
1
+ ecoscape_utilities/__init__.py,sha256=LXt1rL9JVsjnCmsNZwZ2aoElphIK-koaEDdW6ffZsMQ,50
2
+ ecoscape_utilities/bird_runs.py,sha256=v43PfH_4ojpkTE-EFOJxr0oOW3M9suNm_1zMjZ9P-eI,5409
3
+ ecoscape_utilities/ebird_db.py,sha256=4c7QihjkO_sqygtQKlk-GdOojTaYq8ZkU1S5q0UqfSQ,30124
4
+ ecoscape_utilities-0.0.34.dist-info/licenses/LICENSE.md,sha256=3vh2mpA_XIR3FJot6a5F9DqktAoq45sEGIRkYjvAEeU,1304
5
+ ecoscape_utilities-0.0.34.dist-info/METADATA,sha256=Aj9MAVUYgt_vM7TG1Yp1H46I0BLOBuxPpKiM-bdomB4,1382
6
+ ecoscape_utilities-0.0.34.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
7
+ ecoscape_utilities-0.0.34.dist-info/top_level.txt,sha256=jLf7iMlySaJg0Vh8z4lbAaqOc5W5ruMgKFvp797CryQ,19
8
+ ecoscape_utilities-0.0.34.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- ecoscape_utilities/__init__.py,sha256=LXt1rL9JVsjnCmsNZwZ2aoElphIK-koaEDdW6ffZsMQ,50
2
- ecoscape_utilities/bird_runs.py,sha256=v43PfH_4ojpkTE-EFOJxr0oOW3M9suNm_1zMjZ9P-eI,5409
3
- ecoscape_utilities/ebird_db.py,sha256=A3xoeymVIZbnxhYwlS9Ex22NJdeUVJDI_PATT0BGL3k,31321
4
- ecoscape_utilities-0.0.32.dist-info/licenses/LICENSE.md,sha256=3vh2mpA_XIR3FJot6a5F9DqktAoq45sEGIRkYjvAEeU,1304
5
- ecoscape_utilities-0.0.32.dist-info/METADATA,sha256=7o3bGeSdY49LAM57i-Cknxwt3hHBGMdAHZNTfszgMw0,1382
6
- ecoscape_utilities-0.0.32.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
7
- ecoscape_utilities-0.0.32.dist-info/top_level.txt,sha256=jLf7iMlySaJg0Vh8z4lbAaqOc5W5ruMgKFvp797CryQ,19
8
- ecoscape_utilities-0.0.32.dist-info/RECORD,,