@@ -252,6 +252,15 @@ class RandomForestRegressorCriterion(str, Enum):
252
252
poisson = "poisson"
253
253
254
254
255
+ class ThresholdCriteria (str , Enum ):
256
+ """Threshold criteria for distance to anomaly."""
257
+
258
+ lower = "lower"
259
+ higher = "higher"
260
+ in_between = "in_between"
261
+ outside = "outside"
262
+
263
+
255
264
INPUT_FILE_OPTION = Annotated [
256
265
Path ,
257
266
typer .Option (
@@ -1177,6 +1186,47 @@ def create_constant_raster_from_template_cli(
1177
1186
typer .echo (f"Creating constant raster completed, writing raster to { output_raster } ." )
1178
1187
1179
1188
1189
+ # DISTANCE TO ANOMALY
1190
+ @app .command ()
1191
+ def distance_to_anomaly_cli (
1192
+ input_raster : INPUT_FILE_OPTION ,
1193
+ output_raster : OUTPUT_FILE_OPTION ,
1194
+ threshold_criteria : Annotated [ThresholdCriteria , typer .Option (case_sensitive = False )],
1195
+ first_threshold_criteria_value : float = typer .Option (),
1196
+ second_threshold_criteria_value : float = None ,
1197
+ ):
1198
+ """
1199
+ Calculate distance from each raster cell to nearest anomaly cell.
1200
+
1201
+ Uses only the first band of the raster.
1202
+ """
1203
+ from eis_toolkit .raster_processing .distance_to_anomaly import distance_to_anomaly
1204
+
1205
+ typer .echo ("Progress: 10%" )
1206
+
1207
+ if second_threshold_criteria_value is not None :
1208
+ threshold_criteria_value = (first_threshold_criteria_value , second_threshold_criteria_value )
1209
+ else :
1210
+ threshold_criteria_value = first_threshold_criteria_value
1211
+
1212
+ with rasterio .open (input_raster ) as raster :
1213
+ typer .echo ("Progress: 25%" )
1214
+ out_image , out_meta = distance_to_anomaly (
1215
+ anomaly_raster_profile = raster .profile ,
1216
+ anomaly_raster_data = raster .read (1 ),
1217
+ threshold_criteria_value = threshold_criteria_value ,
1218
+ threshold_criteria = get_enum_values (threshold_criteria ),
1219
+ )
1220
+
1221
+ typer .echo ("Progress: 75%" )
1222
+
1223
+ with rasterio .open (output_raster , "w" , ** out_meta ) as dest :
1224
+ dest .write (out_image , 1 )
1225
+ typer .echo ("Progress: 100%" )
1226
+
1227
+ typer .echo (f"Computing distance to anomaly completed, writing raster to { output_raster } ." )
1228
+
1229
+
1180
1230
# EXTRACT VALUES FROM RASTER
1181
1231
@app .command ()
1182
1232
def extract_values_from_raster_cli (
0 commit comments