@@ -840,8 +840,8 @@ def compute_tvdi(
840840 lst_min_vals_list .append (np .min (lst_valid [bin_mask ]))
841841 if len (ndvi_bin_centers_list ) < 2 :
842842 logger .info (
843- 'Warning: Not enough data bins for regression in '
844- '{output_path}'
843+ f 'Warning: Not enough data bins for regression in '
844+ f '{ output_path } '
845845 )
846846 tvdi = np .full_like (ndvi , np .nan , dtype = np .float32 )
847847 profile .update (dtype = rasterio .float32 , count = 1 , compress = 'lzw' )
@@ -2809,7 +2809,7 @@ def getis_ord_gi_star(
28092809 (TEMP_DIR / output_path ).parent .mkdir (parents = True , exist_ok = True )
28102810 driver = gdal .GetDriverByName ('GTiff' )
28112811 out_ds = driver .Create (
2812- TEMP_DIR / output_path ,
2812+ str ( TEMP_DIR / output_path ) ,
28132813 xsize = gi_star .shape [1 ],
28142814 ysize = gi_star .shape [0 ],
28152815 bands = 1 ,
@@ -3575,8 +3575,10 @@ def percentage_change(self, a: float, b: float):
35753575 Returns:
35763576 - percent (float): The percentage change, computed as
35773577 ((b - a) / a) * 100. Positive values indicate increase,
3578- negative values indicate decrease.
3578+ negative values indicate decrease. Returns +inf if a = 0.
35793579 """
3580+ if a == 0 :
3581+ return float ('inf' )
35803582 percent = (b - a ) / a * 100
35813583 return float (percent )
35823584
@@ -4425,22 +4427,20 @@ def count_images_exceeding_threshold_ratio(
44254427 threshold that exceeds a specified ratio.
44264428
44274429 Args:
4428- image_paths (str or list):
4429- Path(s) to image file(s).
4430- value_threshold (float):
4431- Pixel value threshold (e.g., NDVI > 0.7).
4432- ratio_threshold (float):
4433- Percentage threshold for comparison (e.g., 20.0 means 20%).
4430+ image_paths (str or list): Path(s) to image file(s).
4431+ value_threshold (float): Pixel value threshold (e.g., NDVI > 0.7).
4432+ ratio_threshold (float): Percentage threshold for comparison
4433+ (e.g., 20.0 means 20%).
44344434 mode (str):
44354435 - 'above': pixels > value_threshold
44364436 - 'below': pixels < value_threshold
44374437 Default is 'above'.
4438- verbose (bool):
4439- If True, logger.infos detailed ratio results per image.
4438+ verbose (bool): If True, logger.infos detailed ratio results per
4439+ image.
44404440
44414441 Returns:
4442- int:
4443- Number of images whose pixel ratio exceeds the ratio_threshold.
4442+ int: Number of images whose pixel ratio exceeds the
4443+ ratio_threshold.
44444444
44454445 Example:
44464446 >>> count_images_exceeding_threshold_ratio(
@@ -4475,7 +4475,7 @@ def count_images_exceeding_threshold_ratio(
44754475 ratio = np .sum (selected_mask ) / total_pixels * 100
44764476 if ratio > ratio_threshold :
44774477 count_exceeding += 1
4478- status = 'wright '
4478+ status = 'right '
44794479 else :
44804480 status = 'wrong'
44814481 if verbose :
@@ -5105,15 +5105,17 @@ def grayscale_to_colormap(
51055105 out_ds .GetRasterBand (i + 1 ).WriteArray (
51065106 color_img_uint8 [:, :, i ]
51075107 )
5108- gt = ds .GetGeoTransform ()
5109- prj = ds .GetProjection ()
5110- if gt :
5111- out_ds .SetGeoTransform (gt )
5112- if prj :
5113- out_ds .SetProjection (prj )
5108+ gt = ds .GetGeoTransform ()
5109+ prj = ds .GetProjection ()
5110+ if gt :
5111+ out_ds .SetGeoTransform (gt )
5112+ if prj :
5113+ out_ds .SetProjection (prj )
51145114 out_ds .FlushCache ()
51155115 out_ds = None
5116+ ds = None
51165117 else :
5118+ ds = None
51175119 bgr_img = cv2 .cvtColor (color_img_uint8 , cv2 .COLOR_RGB2BGR )
51185120 cv2 .imwrite (str (save_path ), bgr_img )
51195121 return f'Result save at { save_path } '
0 commit comments