ssb-sgis 1.3.1__py3-none-any.whl → 1.3.2__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.
@@ -479,8 +479,10 @@ def make_grid(
479
479
 
480
480
  minx, miny, maxx, maxy = to_bbox(obj)
481
481
 
482
- minx = int(minx) if minx > 0 else int(minx - 1)
483
- miny = int(miny) if miny > 0 else int(miny - 1)
482
+ if not isinstance(minx, int) and not float(minx).is_integer():
483
+ minx = int(minx) if minx > 0 else int(minx - 1)
484
+ if not isinstance(miny, int) and not float(miny).is_integer():
485
+ miny = int(miny) if miny > 0 else int(miny - 1)
484
486
 
485
487
  grid = make_grid_from_bbox(minx, miny, maxx, maxy, gridsize=gridsize, crs=crs)
486
488
 
@@ -393,7 +393,9 @@ def get_bounds_series(
393
393
  paths = [paths]
394
394
 
395
395
  threads = (
396
- min(len(paths), int(multiprocessing.cpu_count())) or 1 if use_threads else 1
396
+ min(len(paths), int(multiprocessing.cpu_count() * 1.2)) or 1
397
+ if use_threads
398
+ else 1
397
399
  )
398
400
 
399
401
  with joblib.Parallel(n_jobs=threads, backend="threading") as parallel:
@@ -373,6 +373,10 @@ class ImageCollectionGroupBy:
373
373
  """Iterate over the group values and the ImageCollection groups themselves."""
374
374
  return iter(self.data)
375
375
 
376
+ def __reversed__(self) -> Iterator[tuple[tuple[Any, ...], "ImageCollection"]]:
377
+ """Iterate over the group values and the ImageCollection groups themselves."""
378
+ return iter(reversed(self.data))
379
+
376
380
  def __len__(self) -> int:
377
381
  """Number of ImageCollection groups."""
378
382
  return len(self.data)
@@ -573,9 +577,7 @@ class _ImageBase:
573
577
  Used in __init__ to select relevant paths fast.
574
578
  """
575
579
  df = pd.DataFrame({"file_path": list(file_paths)})
576
-
577
580
  df["file_name"] = df["file_path"].apply(lambda x: Path(x).name)
578
-
579
581
  df["image_path"] = df["file_path"].apply(
580
582
  lambda x: _fix_path(str(Path(x).parent))
581
583
  )
@@ -605,12 +607,10 @@ class _ImageBase:
605
607
  grouped["imagename"] = grouped["image_path"].apply(
606
608
  lambda x: _fix_path(Path(x).name)
607
609
  )
608
-
609
610
  if self.image_patterns and len(grouped):
610
611
  grouped = _get_regexes_matches_for_df(
611
612
  grouped, "imagename", self.image_patterns
612
613
  )
613
-
614
614
  return grouped
615
615
 
616
616
  def copy(self) -> "_ImageBase":
@@ -1498,6 +1498,7 @@ class Image(_ImageBandBase):
1498
1498
  df: pd.DataFrame | None = None,
1499
1499
  nodata: int | None = None,
1500
1500
  all_file_paths: list[str] | None = None,
1501
+ use_json_metadata: bool = True,
1501
1502
  **kwargs,
1502
1503
  ) -> None:
1503
1504
  """Image initialiser."""
@@ -1539,9 +1540,12 @@ class Image(_ImageBandBase):
1539
1540
  else:
1540
1541
  self._all_file_paths = None
1541
1542
 
1542
- if self.metadata is None or (
1543
- not len(self.metadata)
1544
- and "metadata.json" in {Path(x).name for x in self._all_file_paths}
1543
+ if use_json_metadata and (
1544
+ self.metadata is None
1545
+ or (
1546
+ not len(self.metadata)
1547
+ and "metadata.json" in {Path(x).name for x in self._all_file_paths}
1548
+ )
1545
1549
  ):
1546
1550
  with _open_func(
1547
1551
  next(
@@ -2191,7 +2195,7 @@ class ImageCollection(_ImageBase):
2191
2195
  index_aligned_kwargs: dict | None = None,
2192
2196
  masked: bool = True,
2193
2197
  processes: int | None = None,
2194
- ) -> np.ndarray | tuple[np.ndarray] | None:
2198
+ ) -> PixelwiseResults:
2195
2199
  """Run a function for each pixel.
2196
2200
 
2197
2201
  The function should take a 1d array as first argument. This will be
@@ -2218,7 +2222,7 @@ class ImageCollection(_ImageBase):
2218
2222
  ):
2219
2223
  mask_array = np.array(
2220
2224
  [
2221
- (band.values.mask) | (band.values.data == self.nodata)
2225
+ (band.values.mask) # | (band.values.data == self.nodata)
2222
2226
  for img in self
2223
2227
  for band in img
2224
2228
  ]
@@ -2680,10 +2684,18 @@ class ImageCollection(_ImageBase):
2680
2684
  if self._images is None:
2681
2685
  return self
2682
2686
 
2687
+ if not hasattr(other, "crs") or other.crs is None:
2688
+ try:
2689
+ crs = self.crs
2690
+ except ValueError as e:
2691
+ raise ValueError("Cannot filter bounds by object without crs") from e
2692
+ else:
2693
+ crs = other.crs
2683
2694
  other = to_shapely(other)
2684
2695
 
2696
+ union_func = functools.partial(_union_all_and_to_crs, crs=crs)
2685
2697
  with ThreadPoolExecutor() as executor:
2686
- bounds_iterable: Generator[Polygon] = executor.map(_union_all, self)
2698
+ bounds_iterable: Generator[Polygon] = executor.map(union_func, self)
2687
2699
 
2688
2700
  intersects_list: pd.Series = GeoSeries(list(bounds_iterable)).intersects(other)
2689
2701
 
@@ -3426,8 +3438,8 @@ def _open_raster(path: str | Path) -> rasterio.io.DatasetReader:
3426
3438
  return rasterio.open(file)
3427
3439
 
3428
3440
 
3429
- def _union_all(obj: _ImageBase) -> Polygon:
3430
- return obj.union_all()
3441
+ def _union_all_and_to_crs(obj: _ImageBase, crs) -> Polygon:
3442
+ return GeoSeries([obj.union_all()], crs=obj.crs).to_crs(crs).union_all()
3431
3443
 
3432
3444
 
3433
3445
  def _read_mask_array(self: Band | Image, **kwargs) -> np.ndarray:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ssb-sgis
3
- Version: 1.3.1
3
+ Version: 1.3.2
4
4
  Summary: GIS functions used at Statistics Norway.
5
5
  Home-page: https://github.com/statisticsnorway/ssb-sgis
6
6
  License: MIT
@@ -3,7 +3,7 @@ sgis/conf.py,sha256=pLqmvIKoKmXoW8chja3iQpbDUp9Z39vzl97MGH8ZHW0,2614
3
3
  sgis/debug_config.py,sha256=Tfr19kU46hSkkspsIJcrUWvlhaL4U3-f8xEPkujSCAQ,593
4
4
  sgis/exceptions.py,sha256=WNaEBPNNx0rmz-YDzlFX4vIE7ocJQruUTqS2RNAu2zU,660
5
5
  sgis/geopandas_tools/__init__.py,sha256=bo8lFMcltOz7TtWAi52_ekR2gd3mjfBfKeMDV5zuqFY,28
6
- sgis/geopandas_tools/bounds.py,sha256=PsA_rPEDIS0CopLtolWCB01UEdxc8gtsNbUqMd5AOLY,23855
6
+ sgis/geopandas_tools/bounds.py,sha256=Os9o4EZ1ax38reW-9cdJzgKHoX2il9lUEIZ7wc5CpBQ,23997
7
7
  sgis/geopandas_tools/buffer_dissolve_explode.py,sha256=z9HvakazR_prXH862e8-gEe7UFbeI4rRTbUaBgPeMBk,19552
8
8
  sgis/geopandas_tools/centerlines.py,sha256=Q65Sx01SeAlulBEd9oaZkB2maBBNdLcJwAbTILg4SPU,11848
9
9
  sgis/geopandas_tools/cleaning.py,sha256=fST0xFztmyn-QUOAfvjZmu7aO_zPiolWK7gd7TR6ffI,24393
@@ -23,7 +23,7 @@ sgis/geopandas_tools/utils.py,sha256=X0pRvB1tWgV_0BCrRS1HU9LtLGnZCpvVPxyqM9JGb0Y
23
23
  sgis/helpers.py,sha256=4N6vFWQ3TYVzRHNcWY_fNa_GkFuaZB3vtCkkFND-qs0,9628
24
24
  sgis/io/__init__.py,sha256=uyBr20YDqB2bQttrd5q1JuGOvX32A-MSvS7Wmw5f5qg,177
25
25
  sgis/io/_is_dapla.py,sha256=wmfkSe98IrLhUg3dtXZusV6OVC8VlY1kbc5EQDf3P-Q,358
26
- sgis/io/dapla_functions.py,sha256=YkS2QqNyZ_OcZXXUKnHEItvnO9vZ22k7RK30p-kGl0E,31861
26
+ sgis/io/dapla_functions.py,sha256=ZWtUv58GY0RowUGY7vJBk1rrpjoZq8iVZEmSV3GJShU,31883
27
27
  sgis/io/opener.py,sha256=HWO3G1NB6bpXKM94JadCD513vjat1o1TFjWGWzyVasg,898
28
28
  sgis/io/read_parquet.py,sha256=FvZYv1rLkUlrSaUY6QW6E1yntmntTeQuZ9ZRgCDO4IM,3776
29
29
  sgis/maps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -56,12 +56,12 @@ sgis/parallel/parallel.py,sha256=V7O5mEZdfJpcOPrmn2H4bEGtbzA0FggjQ8dGhznjr80,400
56
56
  sgis/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
57
  sgis/raster/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
58
  sgis/raster/base.py,sha256=8JdXXDj8CgJQt5WIkkNbpM5U0pYyQrWQY9dszfUaUQ4,7743
59
- sgis/raster/image_collection.py,sha256=QGTRfIZAOnNiiTuIJOaQJW-g4TIZKvJUtQKwTan1sv4,121876
59
+ sgis/raster/image_collection.py,sha256=ZWAJzL8CQOMqlDlyZ5idZlWZRnlL0wmnryPwXww7Z1Y,122584
60
60
  sgis/raster/indices.py,sha256=efJmgfPg_VuSzXFosXV661IendF8CwPFWtMhyP4TMUg,222
61
61
  sgis/raster/regex.py,sha256=4idTJ9vFtsGtbxcjJrx2VrpJJuDMP3bLdqF93Vc_cmY,3752
62
62
  sgis/raster/sentinel_config.py,sha256=nySDqn2R8M6W8jguoBeSAK_zzbAsqmaI59i32446FwY,1268
63
63
  sgis/raster/zonal.py,sha256=D4Gyptw-yOLTCO41peIuYbY-DANsJCG19xXDlf1QAz4,2299
64
- ssb_sgis-1.3.1.dist-info/LICENSE,sha256=np3IfD5m0ZUofn_kVzDZqliozuiO6wrktw3LRPjyEiI,1073
65
- ssb_sgis-1.3.1.dist-info/METADATA,sha256=mDvP7_0YnM5lKhKcu3IsX3OYwc-vMIL8mT09tBR_u6o,11624
66
- ssb_sgis-1.3.1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
67
- ssb_sgis-1.3.1.dist-info/RECORD,,
64
+ ssb_sgis-1.3.2.dist-info/LICENSE,sha256=np3IfD5m0ZUofn_kVzDZqliozuiO6wrktw3LRPjyEiI,1073
65
+ ssb_sgis-1.3.2.dist-info/METADATA,sha256=bXRithGOpGcmOzDI1FkZ-trISx9unb2erI1XXwfa91w,11624
66
+ ssb_sgis-1.3.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
67
+ ssb_sgis-1.3.2.dist-info/RECORD,,