Skip to content

Commit f6fac24

Browse files
committed
fix: fix nodata handling in wofe CLI functions
1 parent 17b26f8 commit f6fac24

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

eis_toolkit/cli.py

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from beartype.typing import List, Optional, Tuple, Union
1919
from typing_extensions import Annotated
2020

21+
from eis_toolkit.utilities.nodata import nan_to_nodata, nodata_to_nan
22+
2123
app = typer.Typer()
2224

2325

@@ -3135,6 +3137,7 @@ def weights_of_evidence_calculate_weights_cli(
31353137
out_rasters_dict = {}
31363138
file_name = input_raster.name.split(".")[0]
31373139
for key, array in arrays.items():
3140+
array = nan_to_nodata(array, raster_meta["nodata"])
31383141
output_raster_name = file_name + "_weights_" + weights_type + "_" + key
31393142
output_raster_path = output_dir.joinpath(output_raster_name + ".tif")
31403143
with rasterio.open(output_raster_path, "w", **raster_meta) as dst:
@@ -3183,13 +3186,15 @@ def weights_of_evidence_calculate_responses_cli(
31833186
if raster_weights is not None:
31843187
with rasterio.open(raster_weights) as src:
31853188
array_W = src.read(1)
3189+
array_W = nodata_to_nan(array_W, src.nodata)
31863190

31873191
if raster_profile is None:
31883192
raster_profile = src.profile
31893193

31903194
if raster_std is not None:
31913195
with rasterio.open(raster_std) as src:
31923196
array_S_W = src.read(1)
3197+
array_S_W = nodata_to_nan(array_S_W, src.nodata)
31933198

31943199
dict_array.append({"W+": array_W, "S_W+": array_S_W})
31953200

@@ -3200,12 +3205,15 @@ def weights_of_evidence_calculate_responses_cli(
32003205
)
32013206
typer.echo("Progress: 75%")
32023207

3208+
posterior_probabilities = nan_to_nodata(posterior_probabilities, raster_profile["nodata"])
32033209
with rasterio.open(output_probabilities, "w", **raster_profile) as dst:
32043210
dst.write(posterior_probabilities, 1)
32053211

3212+
posterior_probabilies_std = nan_to_nodata(posterior_probabilies_std, raster_profile["nodata"])
32063213
with rasterio.open(output_probabilities_std, "w", **raster_profile) as dst:
32073214
dst.write(posterior_probabilies_std, 1)
32083215

3216+
confidence_array = nan_to_nodata(confidence_array, raster_profile["nodata"])
32093217
with rasterio.open(output_confidence_array, "w", **raster_profile) as dst:
32103218
dst.write(confidence_array, 1)
32113219

@@ -3230,9 +3238,11 @@ def agterberg_cheng_CI_test_cli(
32303238

32313239
with rasterio.open(input_posterior_probabilities) as src:
32323240
posterior_probabilities = src.read(1)
3241+
posterior_probabilities = nodata_to_nan(posterior_probabilities, src.nodata)
32333242

32343243
with rasterio.open(input_posterior_probabilities_std) as src:
32353244
posterior_probabilities_std = src.read(1)
3245+
posterior_probabilities_std = nodata_to_nan(posterior_probabilities_std, src.nodata)
32363246

32373247
typer.echo("Progress: 25%")
32383248

0 commit comments

Comments
 (0)