@@ -454,13 +454,14 @@ def format_progress_message(
454
454
message = f"{ hours_to_go } :{ min_to_go } left for { nb_todo - nb_done_total } todo at { nb_per_hour :0.0f} /h ({ nb_per_hour_latestbatch :0.0f} /h last batch)"
455
455
return message
456
456
457
- def prepare_calc (features_filepath : Path ,
458
- id_column : str ,
459
- image_path : Path ,
460
- output_filepath : Path ,
461
- temp_dir : Path ,
462
- log_dir : Path ,
463
- nb_parallel_max : int = 16 ) -> dict :
457
+ def prepare_calc (
458
+ features_filepath : Path ,
459
+ id_column : str ,
460
+ image_path : Path ,
461
+ output_filepath : Path ,
462
+ temp_dir : Path ,
463
+ log_dir : Path ,
464
+ nb_parallel_max : int = 16 ) -> dict :
464
465
"""
465
466
Prepare the inputs for a calculation.
466
467
@@ -473,18 +474,20 @@ def prepare_calc(features_filepath: Path,
473
474
logger .propagate = False
474
475
log_filepath = log_dir / f"{ datetime .now ():%Y-%m-%d_%H-%M-%S} _prepare_calc_{ os .getpid ()} .log"
475
476
fh = logging .FileHandler (filename = log_filepath )
476
- fh .setLevel (logging .DEBUG )
477
+ fh .setLevel (logging .INFO )
477
478
fh .setFormatter (logging .Formatter ('%(asctime)s|%(levelname)s|%(name)s|%(funcName)s|%(message)s' ))
478
479
logger .addHandler (fh )
479
480
480
481
ret_val = {}
481
482
482
483
# Prepare the image
484
+ logger .info (f"Start prepare_image for { image_path } to { temp_dir } " )
483
485
image_prepared_path = prepare_image (image_path , temp_dir )
484
486
logger .debug (f"Preparing ready, result: { image_prepared_path } " )
485
487
ret_val ['image_prepared_path' ] = image_prepared_path
486
488
487
489
# Get info about the image
490
+ logger .info (f"Start get_image_info for { image_prepared_path } " )
488
491
image_info = get_image_info (image_prepared_path )
489
492
logger .info (f"image_info: { image_info } " )
490
493
@@ -542,7 +545,7 @@ def prepare_calc(features_filepath: Path,
542
545
try :
543
546
features_gdf_batch .to_pickle (pickle_filepath )
544
547
except Exception as ex :
545
- raise Exception (f"Exception writing pickle: { pickle_filepath } " ) from ex
548
+ raise Exception (f"Exception writing pickle: { pickle_filepath } : { ex } " ) from ex
546
549
batch_info ["filepath" ] = pickle_filepath
547
550
batch_info ["nb_items" ] = len (features_gdf_batch .index )
548
551
ret_val ["feature_batches" ].append (batch_info )
@@ -986,9 +989,18 @@ def get_image_info(image_path: Path) -> dict:
986
989
image_datadir = image_path / image_datadirname
987
990
band_filepaths = list (image_datadir .glob ("*.img" ))
988
991
989
- # If no files were found, error!
992
+ # If no files were found, check if the images are in .tif format!
993
+ if len (band_filepaths ) == 0 :
994
+ tif_path = image_path / "Gamma0_VH.tif"
995
+ if tif_path .exists ():
996
+ band_filepaths .append (tif_path )
997
+ tif_path = image_path / "Gamma0_VV.tif"
998
+ if tif_path .exists ():
999
+ band_filepaths .append (tif_path )
1000
+
1001
+ # If no files were found, error
990
1002
if len (band_filepaths ) == 0 :
991
- message = f"No image files found in { image_datadir } !"
1003
+ message = f"No image files found in { image_datadir } or { image_path } !"
992
1004
logger .error (message )
993
1005
raise Exception (message )
994
1006
@@ -1003,19 +1015,18 @@ def get_image_info(image_path: Path) -> dict:
1003
1015
image_info ['image_crs' ] = str (src .crs )
1004
1016
image_info ['image_epsg' ] = image_info ['image_crs' ].upper ().replace ('EPSG:' , '' )
1005
1017
#logger.debug(f"Image metadata read: {image_info}")
1006
- band_filename = os .path .basename (band_filepath )
1007
- if band_filename == "Gamma0_VH.img" :
1018
+ if band_filepath .stem == 'Gamma0_VH' :
1008
1019
band = 'VH'
1009
- elif band_filename == " Gamma0_VV.img" :
1020
+ elif band_filepath . stem == ' Gamma0_VV' :
1010
1021
band = 'VV'
1011
1022
else :
1012
1023
raise NotImplementedError (f"Filename not supported: { band_filepath } " )
1013
1024
1014
1025
# Add specific info about the band
1015
1026
image_info ['bands' ][band ] = {}
1016
1027
image_info ['bands' ][band ]['filepath' ] = band_filepath
1017
- image_info ['bands' ][band ]['relative_filepath' ] = os . path . join ( image_datadirname , band_filename )
1018
- image_info ['bands' ][band ]['filename' ] = band_filename
1028
+ image_info ['bands' ][band ]['relative_filepath' ] = str ( band_filepath ). replace ( str ( image_path ) + os . pathsep , "" )
1029
+ image_info ['bands' ][band ]['filename' ] = band_filepath . name
1019
1030
image_info ['bands' ][band ]['bandindex' ] = 0
1020
1031
1021
1032
except Exception as ex :
0 commit comments