ecoscape-utilities 0.0.32__tar.gz → 0.0.33__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.32
3
+ Version: 0.0.33
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
@@ -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)
@@ -640,9 +609,15 @@ class Validation(object):
640
609
  """
641
610
  df = self.observations.copy()
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
+ repop_pix_coords = transform_coords(repop_tif, coords)
618
+ hab_pix_coords = transform_coords(hab_tif, coords)
619
+ repop_tile = repop_tif.get_tile_from_coord(repop_pix_coords, tile_scale=tile_scale)
620
+ hab_tile = hab_tif.get_tile_from_coord(hab_pix_coords, tile_scale=tile_scale)
646
621
  if repop_tile is None or hab_tile is None:
647
622
  return pd.NA, pd.NA, pd.NA, pd.NA
648
623
  avg_repop = np.average(repop_tile.m)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ecoscape-utilities
3
- Version: 0.0.32
3
+ Version: 0.0.33
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.32"
7
+ version = "0.0.33"
8
8
  authors = [
9
9
  {name="Luca de Alfaro", email="luca@ucsc.edu"},
10
10
  {name="Coen Adler", email="ctadler@ucsc.edu"},