ssb-sgis 1.0.6__py3-none-any.whl → 1.0.7__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.
sgis/helpers.py CHANGED
@@ -130,6 +130,12 @@ def in_jupyter() -> bool:
130
130
  return False
131
131
 
132
132
 
133
+ def _fix_path(path: str) -> str:
134
+ return (
135
+ str(path).replace("\\", "/").replace(r"\"", "/").replace("//", "/").rstrip("/")
136
+ )
137
+
138
+
133
139
  def get_all_files(root: str, recursive: bool = True) -> list[str]:
134
140
  """Fetch all files in a directory.
135
141
 
@@ -141,11 +147,11 @@ def get_all_files(root: str, recursive: bool = True) -> list[str]:
141
147
  A list of file paths.
142
148
  """
143
149
  if not recursive:
144
- return [path for path in glob.glob(str(Path(root)) + "/**")]
150
+ return [_fix_path(path) for path in glob.glob(str(Path(root)) + "/**")]
145
151
  paths = []
146
152
  for root_dir, _, files in os.walk(root):
147
153
  for file in files:
148
- path = os.path.join(root_dir, file)
154
+ path = _fix_path(os.path.join(root_dir, file))
149
155
  paths.append(path)
150
156
  return paths
151
157
 
sgis/maps/explore.py CHANGED
@@ -194,8 +194,6 @@ def _single_band_to_arr(band, mask, name, raster_data_dict):
194
194
  gpd.GeoSeries(box(*band.bounds), crs=band.crs).to_crs(4326).geometry.values
195
195
  ).bounds
196
196
  )
197
- # if np.max(arr) > 0:
198
- # arr = arr / 255
199
197
  try:
200
198
  raster_data_dict["cmap"] = band.get_cmap(arr)
201
199
  except Exception:
@@ -533,8 +531,6 @@ class Explore(Map):
533
531
  arr = arr.data
534
532
  if "bool" in str(arr.dtype):
535
533
  arr = np.where(arr, 1, 0)
536
- # if np.max(arr[~np.isnan(arr)]) > 255:
537
- # arr = (arr - np.min(arr)) / (np.max(arr) - np.min(arr))
538
534
  try:
539
535
  arr = (arr - np.min(arr)) / (np.max(arr) - np.min(arr))
540
536
  except Exception:
@@ -1182,28 +1178,17 @@ class Explore(Map):
1182
1178
  break
1183
1179
 
1184
1180
  crs = red_band.crs
1185
-
1186
- bounds: tuple = (
1187
- _any_to_bbox_crs4326(mask, crs)
1188
- if mask is not None
1189
- else (
1190
- union_all(
1191
- gpd.GeoSeries(box(*red_band.bounds), crs=crs)
1192
- .to_crs(4326)
1193
- .geometry.values
1194
- ).bounds
1195
- )
1196
- )
1181
+ bounds = to_bbox(to_gdf(red_band.bounds, crs).to_crs(4326))
1197
1182
 
1198
1183
  red_band = red_band.values
1199
1184
  blue_band = blue_band.values
1200
1185
  green_band = green_band.values
1201
1186
 
1202
- if red_band.shape[0] == 0:
1203
- continue
1204
- if blue_band.shape[0] == 0:
1205
- continue
1206
- if green_band.shape[0] == 0:
1187
+ if (
1188
+ red_band.shape[0] == 0
1189
+ or blue_band.shape[0] == 0
1190
+ or green_band.shape[0] == 0
1191
+ ):
1207
1192
  continue
1208
1193
 
1209
1194
  # to 3d array in shape (x, y, 3)
@@ -1268,16 +1253,10 @@ def _determine_label(
1268
1253
  )
1269
1254
  if does_not_have_generic_name:
1270
1255
  return obj_name
1271
- # try:
1272
- # if obj.tile and obj.date:
1273
- # name = f"{obj.tile}_{obj.date[:8]}"
1274
- # except (ValueError, AttributeError):
1275
- # name = None
1276
-
1277
1256
  try:
1278
1257
  # Images/Bands/Collections constructed from arrays have no path stems
1279
- if obj.stem:
1280
- name = obj.stem
1258
+ if obj.name:
1259
+ name = obj.name
1281
1260
  else:
1282
1261
  name = str(obj)[:23]
1283
1262
  except (AttributeError, ValueError):
sgis/maps/map.py CHANGED
@@ -14,7 +14,11 @@ import numpy as np
14
14
  import pandas as pd
15
15
  from geopandas import GeoDataFrame
16
16
  from geopandas import GeoSeries
17
- from jenkspy import jenks_breaks
17
+
18
+ try:
19
+ from jenkspy import jenks_breaks
20
+ except ImportError:
21
+ pass
18
22
  from mapclassify import classify
19
23
  from pandas.errors import PerformanceWarning
20
24
  from shapely import Geometry
sgis/raster/base.py CHANGED
@@ -189,30 +189,6 @@ def _gdf_to_geojson_with_col(gdf: GeoDataFrame, values: np.ndarray) -> list[dict
189
189
  ]
190
190
 
191
191
 
192
- def _shapely_to_raster(
193
- geometry: Geometry,
194
- res: int | float,
195
- fill: int = 0,
196
- all_touched: bool = False,
197
- merge_alg: Callable = MergeAlg.replace,
198
- default_value: int = 1,
199
- dtype: Any | None = None,
200
- ) -> np.array:
201
- shape = _get_shape_from_bounds(geometry.bounds, res=res, indexes=1)
202
- transform = _get_transform_from_bounds(geometry.bounds, shape)
203
-
204
- return features.rasterize(
205
- [(geometry, default_value)],
206
- out_shape=shape,
207
- transform=transform,
208
- fill=fill,
209
- all_touched=all_touched,
210
- merge_alg=merge_alg,
211
- default_value=default_value,
212
- dtype=dtype,
213
- )
214
-
215
-
216
192
  @contextmanager
217
193
  def memfile_from_array(array: np.ndarray, **profile) -> rasterio.MemoryFile:
218
194
  """Yield a memory file from a numpy array."""
@@ -228,33 +204,3 @@ def get_index_mapper(df: pd.DataFrame) -> tuple[dict[int, int], str]:
228
204
  idx_mapper = dict(enumerate(df.index))
229
205
  idx_name = df.index.name
230
206
  return idx_mapper, idx_name
231
-
232
-
233
- NESSECARY_META = [
234
- "path",
235
- "type",
236
- "bounds",
237
- "crs",
238
- ]
239
-
240
- PROFILE_ATTRS = [
241
- "driver",
242
- "dtype",
243
- "nodata",
244
- "crs",
245
- "height",
246
- "width",
247
- "blockysize",
248
- "blockxsize",
249
- "tiled",
250
- "compress",
251
- "interleave",
252
- "count", # TODO: this should be based on band_index / array depth, so will have no effect
253
- "indexes", # TODO
254
- ]
255
-
256
- ALLOWED_KEYS = (
257
- NESSECARY_META
258
- + PROFILE_ATTRS
259
- + ["array", "res", "transform", "name", "date", "regex"]
260
- )