wolfhece 2.1.50__py3-none-any.whl → 2.1.56__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.
wolfhece/rem/REMMaker.py CHANGED
@@ -1,13 +1,3 @@
1
- """
2
- Author: HECE - University of Liege, Pierre Archambeau
3
- Date: 2024
4
-
5
- Copyright (c) 2024 University of Liege. All rights reserved.
6
-
7
- This script and its content are protected by copyright law. Unauthorized
8
- copying or distribution of this file, via any medium, is strictly prohibited.
9
- """
10
-
11
1
  #!/usr/bin/env python
12
2
  import os
13
3
  import sys
@@ -228,8 +218,8 @@ class REMMaker(object):
228
218
  if self.count is not None and self.centerline_shp is None:
229
219
  raise ValueError(f'Obligation de donner un shapefile pour en sélectionner une géométrie.')
230
220
  if self.pres is not None:
231
- gdal.Warp(f'{self.dem_name}_warp.tif', self.dem, xRes=self.pres, yRes=self.pres)
232
- r = gdal.Open(f'{self.dem_name}_warp.tif', gdal.GA_ReadOnly)
221
+ gdal.Warp(os.path.join(self.out_dir, f'{self.dem_name}_warp.tif'), self.dem, xRes=self.pres, yRes=self.pres)
222
+ r = gdal.Open(os.path.join(self.out_dir, f'{self.dem_name}_warp.tif'), gdal.GA_ReadOnly)
233
223
  if self.bounds is not None:
234
224
  band = r.GetRasterBand(1)
235
225
  self.dem_array = band.ReadAsArray()
@@ -240,19 +230,19 @@ class REMMaker(object):
240
230
  min_x, max_x = sorted([upper_left_x, upper_left_x + x_size * cols])
241
231
  min_y, max_y = sorted([upper_left_y, upper_left_y + y_size * rows])
242
232
  if self.bounds[0] > min_x and self.bounds[1] > min_y and self.bounds[2] < max_x and self.bounds[3] < max_y:
243
- gdal.Translate(f'{self.dem_name}_crop.tif', r, projWin=(self.bounds[0],self.bounds[3],self.bounds[2],self.bounds[1]))
244
- r = gdal.Open(f'{self.dem_name}_crop.tif', gdal.GA_ReadOnly)
233
+ gdal.Translate(os.path.join(self.out_dir, f'{self.dem_name}_crop.tif'), r, projWin=(self.bounds[0],self.bounds[3],self.bounds[2],self.bounds[1]))
234
+ r = gdal.Open(os.path.join(self.out_dir, f'{self.dem_name}_crop.tif'), gdal.GA_ReadOnly)
245
235
  else:
246
236
  raise ValueError(f"bounds choisi hors DEM. Redéfinir des limites contenues dans x={min_x,max_x:.3f} et y={min_y,max_y:.3f}")
247
237
  if self.count is not None:
248
238
  self.rivers:gpd.GeoDataFrame
249
239
  self.rivers = read_file(self.centerline_shp)
250
240
  upper_left_x, x_size, x_rot, upper_left_y, y_rot, y_size = r.GetGeoTransform()
251
- gdal.Translate(f'{self.dem_name}_crop.tif', r, projWin=(self.rivers.bounds.iloc[self.count].minx-50*x_size,
241
+ gdal.Translate(os.path.join(self.out_dir, f'{self.dem_name}_crop.tif'), r, projWin=(self.rivers.bounds.iloc[self.count].minx-50*x_size,
252
242
  self.rivers.bounds.iloc[self.count].maxy-50*y_size,
253
243
  self.rivers.bounds.iloc[self.count].maxx+50*x_size,
254
244
  self.rivers.bounds.iloc[self.count].miny+50*y_size))
255
- r = gdal.Open(f'{self.dem_name}_crop.tif', gdal.GA_ReadOnly)
245
+ r = gdal.Open(os.path.join(self.out_dir, f'{self.dem_name}_crop.tif'), gdal.GA_ReadOnly)
256
246
  self.proj = osr.SpatialReference(wkt=r.GetProjection())
257
247
  self.epsg_code = self.proj.GetAttrValue('AUTHORITY', 1)
258
248
  self.h_unit = self.proj.GetAttrValue('UNIT')
@@ -426,9 +416,9 @@ class REMMaker(object):
426
416
  self.river_coords = self.ix2coords(self.river_indices)
427
417
  self.river_wses = self.dem_array[self.river_indices]
428
418
  else:
429
- self.rivers = read_file(f'{self.dem_name}_river_pts.shp')
419
+ self.rivers = os.path.join(self.out_dir, f'{self.dem_name}_river_pts.shp')
430
420
  self.rivers['curvi'] = self.river_curvi
431
- self.rivers.to_file(f'{self.dem_name}_river_pts.shp', driver='ESRI Shapefile')
421
+ self.rivers.to_file(os.path.join(self.out_dir, f'{self.dem_name}_river_pts.shp'), driver='ESRI Shapefile')
432
422
  self.river_coords = np.array([curpt.xy for curpt in self.rivers.geometry])
433
423
  self.river_wses = np.array([curpt.z for curpt in self.rivers.geometry])
434
424
  return
@@ -463,9 +453,9 @@ class REMMaker(object):
463
453
  logging.info("Interpolating river elevation across DEM extent.")
464
454
  if not self.k:
465
455
  self.k = self.estimate_k()
466
- self.rivers = read_file(f'{self.dem_name}_river_pts.shp')
456
+ self.rivers = read_file(self.river_shp)
467
457
  self.rivers['curvi'] = self.river_curvi
468
- self.rivers.to_file(f'{self.dem_name}_river_pts.shp', driver='ESRI Shapefile')
458
+ self.rivers.to_file(self.river_shp, driver='ESRI Shapefile')
469
459
  logging.info(f"Using k = {self.k} nearest neighbors.")
470
460
  # coords to interpolate over (don't interpolate where DEM is null or on centerline where REM = 0)
471
461
  interp_indices = np.where(~(np.isnan(self.dem_array) | (self.centerline_array == 1)))
@@ -513,9 +503,9 @@ class REMMaker(object):
513
503
  if self.bounds is None and self.count is None:
514
504
  r = gdal.Open(self.dem, gdal.GA_ReadOnly)
515
505
  if self.bounds is not None or self.count is not None:
516
- r = gdal.Open(f'{self.dem_name}_crop.tif', gdal.GA_ReadOnly)
506
+ r = gdal.Open(os.path.join(self.out_dir, f'{self.dem_name}_crop.tif'), gdal.GA_ReadOnly)
517
507
  if self.pres is not None and self.bounds is None and self.count is None:
518
- r = gdal.Open(f'{self.dem_name}_warp.tif', gdal.GA_ReadOnly)
508
+ r = gdal.Open(os.path.join(self.out_dir, f'{self.dem_name}_warp.tif'), gdal.GA_ReadOnly)
519
509
  driver = gdal.GetDriverByName("GTiff")
520
510
  rem = driver.CreateCopy(self.rem_ras, r, strict=0)
521
511
  # fill with REM array
@@ -565,9 +555,9 @@ class REMMaker(object):
565
555
  if self.bounds is None and self.count is None:
566
556
  dem_viz = RasterViz(self.dem, out_dir=self.cache_dir, out_ext=".tif")
567
557
  if self.bounds is not None or self.count is not None:
568
- dem_viz = RasterViz(f'{self.dem_name}_crop.tif', out_dir=self.cache_dir, out_ext=".tif")
558
+ dem_viz = RasterViz(os.path.join(self.out_dir, f'{self.dem_name}_crop.tif'), out_dir=self.cache_dir, out_ext=".tif")
569
559
  if self.pres is not None and self.bounds is None and self.count is None:
570
- dem_viz = RasterViz(f'{self.dem_name}_warp.tif', out_dir=self.cache_dir, out_ext=".tif")
560
+ dem_viz = RasterViz(os.path.join(self.out_dir, f'{self.dem_name}_warp.tif'), out_dir=self.cache_dir, out_ext=".tif")
571
561
  dem_viz.make_hillshade(multidirectional=True, z=z)
572
562
  # make color-relief of REM in cache dir
573
563
  rem_viz = RasterViz(self.rem_ras, out_dir=self.cache_dir, out_ext=".tif", make_png=make_png, make_kmz=make_kmz, *args, **kwargs)
wolfhece/rem/RasterViz.py CHANGED
@@ -1,13 +1,3 @@
1
- """
2
- Author: HECE - University of Liege, Pierre Archambeau
3
- Date: 2024
4
-
5
- Copyright (c) 2024 University of Liege. All rights reserved.
6
-
7
- This script and its content are protected by copyright law. Unauthorized
8
- copying or distribution of this file, via any medium, is strictly prohibited.
9
- """
10
-
11
1
  #!/usr/bin/env python
12
2
  import os
13
3
  import sys
@@ -26,46 +16,46 @@ This script can be called from Python using its class/methods or as a CLI utilit
26
16
 
27
17
  CLI Usage:
28
18
 
29
- "python RasterViz.py viz_type [-z (default=1)] [-alt (default=45)] [-azim (default=315)] [-multidirectional]
30
- [-cmap (default=terrain)] [-out_ext tif | img (default=tif)] [-make_png] [-make_kmz] [-docker] [-shell]
19
+ "python RasterViz.py viz_type [-z (default=1)] [-alt (default=45)] [-azim (default=315)] [-multidirectional]
20
+ [-cmap (default=terrain)] [-out_ext tif | img (default=tif)] [-make_png] [-make_kmz] [-docker] [-shell]
31
21
  /path/to/dem"
32
22
 
33
23
  Options:
34
-
35
- viz_type: string corresponding to raster product to be produced, one of the following strings:
24
+
25
+ viz_type: string corresponding to raster product to be produced, one of the following strings:
36
26
  ["hillshade", "slope", "aspect", "roughness", "color-relief", "hillshade-color"]
37
-
27
+
38
28
  -z: only if using "hillshade" or "hillshade-color" viz_type,
39
29
  factor to scale/exaggerate vertical topographic differences. Default 1 (no rescale).
40
-
41
- -alt: only if using "hillshade" or "hillshade-color" viz_type,
30
+
31
+ -alt: only if using "hillshade" or "hillshade-color" viz_type,
42
32
  altitude of light source in degrees [0-90]. Default 45.
43
-
44
- -azim: only if using "hillshade" or "hillshade-color" viz_type,
33
+
34
+ -azim: only if using "hillshade" or "hillshade-color" viz_type,
45
35
  azimuth of light source in degrees [0-360]. Default 315.
46
-
47
- -multidirectional: only if using "hillshade" or "hillshade-color" viz_type.
36
+
37
+ -multidirectional: only if using "hillshade" or "hillshade-color" viz_type.
48
38
  Makes multidirectional hillshade, overriding alt and azim args.
49
-
39
+
50
40
  -cmap: only if using "color-relief" viz_type, name of a matplotlib or seaborn colormap. Default "terrain".
51
41
  (see https://matplotlib.org/stable/gallery/color/colormap_reference.html)
52
-
42
+
53
43
  -out_ext: the extension/file format to use for geodata outputs (tif or img). Default "tif".
54
-
44
+
55
45
  -make_png: output a png version (EPSG:3857) of the viz_type in addition to the viz raster in source projection.
56
-
46
+
57
47
  -make_kmz: output a kmz version of the viz_type in addition to the viz raster in source projection.
58
-
48
+
59
49
  -docker: run GDAL commands from within the osgeo/gdal docker container. This makes it run slightly slower but will
60
50
  be needed to run all features if gdal install is on a version <2.2. If using docker, input path must be
61
51
  within the working directory path or a subdirectory.
62
-
52
+
63
53
  -shell: call GDAL functions (gdaldem, gdal_translate, gdalwarp) as shell commands instead of using Python bindings.
64
54
  This may be faster than using pure Python but requires additional environment configuration.
65
55
 
66
56
  /path/to/dem.tif: path to input DEM, currently assumed to be in GeoTIFF format.
67
57
 
68
- Notes: Output file naming convention uses the DEM basename as a prefix, then viz_type and file extension.
58
+ Notes: Output file naming convention uses the DEM basename as a prefix, then viz_type and file extension.
69
59
  E.g. output.tin.tif --> output_hillshade.tif, output_hillshade.png, output_hillshade.kmz.
70
60
  Outputs are saved to the working directory.
71
61