fimeval 0.1.47__tar.gz → 0.1.49__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fimeval
3
- Version: 0.1.47
3
+ Version: 0.1.49
4
4
  Summary: A Framework for Automatic Evaluation of Flood Inundation Mapping Predictions Evaluation
5
5
  License: GPLv3
6
6
  Author: Surface Dynamics Modeling Lab
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "fimeval"
3
- version = "0.1.47"
3
+ version = "0.1.49"
4
4
  description = "A Framework for Automatic Evaluation of Flood Inundation Mapping Predictions Evaluation"
5
5
  authors = [
6
6
  "Surface Dynamics Modeling Lab",
@@ -4,6 +4,8 @@ from pathlib import Path
4
4
  import geopandas as gpd
5
5
  import rasterio
6
6
  import shutil
7
+ import subprocess
8
+ import platform
7
9
  import pandas as pd
8
10
  from rasterio.warp import reproject, Resampling
9
11
  from rasterio.io import MemoryFile
@@ -19,6 +21,30 @@ from .metrics import evaluationmetrics
19
21
  from .PWBs3 import get_PWB
20
22
  from ..utilis import MakeFIMsUniform
21
23
 
24
+ #giving the permission to the folder
25
+ def is_writable(path):
26
+ """Check if the directory and its contents are writable."""
27
+ path = Path(path)
28
+ return os.access(path, os.W_OK)
29
+
30
+ def fix_permissions(path):
31
+ path = Path(path).resolve()
32
+ script_path = Path(__file__).parent / "fix_permissions.sh"
33
+
34
+ if not script_path.exists():
35
+ raise FileNotFoundError(f"Shell script not found: {script_path}")
36
+
37
+ if is_writable(path):
38
+ return
39
+
40
+ try:
41
+ result = subprocess.run(["bash", str(script_path), str(path)],
42
+ check=True, capture_output=True, text=True)
43
+ print(result.stdout)
44
+ except subprocess.CalledProcessError as e:
45
+ print(f"Shell script failed:\n{e.stderr}")
46
+
47
+
22
48
  # Function for the evalution of the model
23
49
  def evaluateFIM(
24
50
  benchmark_path, candidate_paths, gdf, folder, method, output_dir, shapefile=None
@@ -333,7 +359,16 @@ def evaluateFIM(
333
359
  print(f"Evaluation metrics saved to {csv_file}")
334
360
  return results
335
361
 
336
-
362
+ #Safely deleting the folder
363
+ def safe_delete_folder(folder_path):
364
+ try:
365
+ shutil.rmtree(folder_path)
366
+ except PermissionError:
367
+ print(f"Permission denied: Could not delete {folder_path}")
368
+ except FileNotFoundError:
369
+ print(f"Folder not found: {folder_path}")
370
+ except Exception as e:
371
+ print(f"Error deleting {folder_path}: {e}")
337
372
 
338
373
  def EvaluateFIM(main_dir, method_name, output_dir, PWB_dir=None, shapefile_dir=None, target_crs=None, target_resolution=None):
339
374
  main_dir = Path(main_dir)
@@ -342,7 +377,12 @@ def EvaluateFIM(main_dir, method_name, output_dir, PWB_dir=None, shapefile_dir=N
342
377
  gdf = get_PWB()
343
378
  else:
344
379
  gdf = gpd.read_file(PWB_dir)
380
+
381
+ #Grant the permission to the main directory
382
+ print(f"Fixing permissions for {main_dir}...")
383
+ fix_permissions(main_dir)
345
384
 
385
+ #runt the process
346
386
  def process_TIFF(tif_files, folder_dir):
347
387
  benchmark_path = None
348
388
  candidate_path = []
@@ -384,12 +424,12 @@ def EvaluateFIM(main_dir, method_name, output_dir, PWB_dir=None, shapefile_dir=N
384
424
  if TIFFfiles_main_dir:
385
425
  MakeFIMsUniform(main_dir, target_crs=target_crs, target_resolution=target_resolution)
386
426
 
387
- #processing folder
427
+ # processing folder
388
428
  processing_folder = main_dir / "processing"
389
429
  TIFFfiles = list(processing_folder.glob("*.tif"))
390
430
 
391
431
  process_TIFF(TIFFfiles, main_dir)
392
- shutil.rmtree(processing_folder)
432
+ safe_delete_folder(processing_folder)
393
433
  else:
394
434
  for folder in main_dir.iterdir():
395
435
  if folder.is_dir():
@@ -397,13 +437,12 @@ def EvaluateFIM(main_dir, method_name, output_dir, PWB_dir=None, shapefile_dir=N
397
437
 
398
438
  if tif_files:
399
439
  MakeFIMsUniform(folder, target_crs=target_crs, target_resolution=target_resolution)
400
- #processing folder
440
+
401
441
  processing_folder = folder / "processing"
402
442
  TIFFfiles = list(processing_folder.glob("*.tif"))
403
443
 
404
444
  process_TIFF(TIFFfiles, folder)
405
- shutil.rmtree(processing_folder)
445
+ safe_delete_folder(processing_folder)
406
446
  else:
407
- print(
408
- f"Skipping {folder.name} as it doesn't contain any tif files."
409
- )
447
+ print(f"Skipping {folder.name} as it doesn't contain any tif files.")
448
+
@@ -0,0 +1,23 @@
1
+ #!/bin/bash
2
+
3
+ DIR="$1"
4
+
5
+ if [ -z "$DIR" ]; then
6
+ echo "No directory provided."
7
+ exit 1
8
+ fi
9
+ echo "Fixing permissions for: $DIR"
10
+
11
+ UNAME=$(uname)
12
+ if [[ "$UNAME" == "Darwin" || "$UNAME" == "Linux" ]]; then
13
+ chmod -R u+rwX "$DIR"
14
+ echo "Permissions granted for user (u+rwX)"
15
+
16
+ elif [[ "$UNAME" == *"MINGW"* || "$UNAME" == *"MSYS"* || "$UNAME" == *"CYGWIN"* ]]; then
17
+ icacls "$DIR" /grant Everyone:F /T > /dev/null
18
+ echo "Permissions granted for working folder"
19
+
20
+ else
21
+ echo "Unsupported OS: $UNAME"
22
+ exit 1
23
+ fi
File without changes
File without changes
File without changes