Skip to content

Commit a261d5f

Browse files
committed
Fixed CLI functions for fuzzy overlay methods
1 parent 272e78d commit a261d5f

File tree

1 file changed

+59
-51
lines changed

1 file changed

+59
-51
lines changed

eis_toolkit/cli.py

+59-51
Original file line numberDiff line numberDiff line change
@@ -1778,24 +1778,26 @@ def predict_with_trained_model_cli(
17781778
# AND OVERLAY
17791779
@app.command()
17801780
def and_overlay_cli(
1781-
input_raster: Annotated[Path, INPUT_FILE_OPTION],
1781+
input_rasters: INPUT_FILES_ARGUMENT,
17821782
output_raster: Annotated[Path, OUTPUT_FILE_OPTION],
17831783
):
17841784
"""Compute an 'and' overlay operation with fuzzy logic."""
17851785
from eis_toolkit.prediction.fuzzy_overlay import and_overlay
1786+
from eis_toolkit.utilities.file_io import read_and_stack_rasters
17861787

17871788
typer.echo("Progress: 10%")
17881789

1789-
with rasterio.open(input_raster) as raster:
1790-
data = raster.read() # NOTE: Overlays take in data while for example transforms rasters, consistentency?
1791-
typer.echo("Progress: 25%")
1792-
out_image = and_overlay(data)
1793-
out_meta = raster.meta.copy()
1794-
out_meta["count"] = 1
1790+
data, profiles = read_and_stack_rasters(input_rasters)
1791+
typer.echo("Progress: 25%")
1792+
1793+
out_image = and_overlay(data)
17951794
typer.echo("Progress: 75%")
17961795

1797-
with rasterio.open(output_raster, "w", **out_meta) as dst:
1798-
dst.write(out_image, out_meta["count"])
1796+
out_profile = profiles[0]
1797+
out_profile["count"] = 1
1798+
out_profile["nodata"] = -9999
1799+
with rasterio.open(output_raster, "w", **out_profile) as dst:
1800+
dst.write(out_image, 1)
17991801
typer.echo("Progress: 100%")
18001802

18011803
typer.echo(f"'And' overlay completed, writing raster to {output_raster}.")
@@ -1804,24 +1806,26 @@ def and_overlay_cli(
18041806
# OR OVERLAY
18051807
@app.command()
18061808
def or_overlay_cli(
1807-
input_raster: Annotated[Path, INPUT_FILE_OPTION],
1809+
input_rasters: INPUT_FILES_ARGUMENT,
18081810
output_raster: Annotated[Path, OUTPUT_FILE_OPTION],
18091811
):
18101812
"""Compute an 'or' overlay operation with fuzzy logic."""
18111813
from eis_toolkit.prediction.fuzzy_overlay import or_overlay
1814+
from eis_toolkit.utilities.file_io import read_and_stack_rasters
18121815

18131816
typer.echo("Progress: 10%")
18141817

1815-
with rasterio.open(input_raster) as raster:
1816-
data = raster.read() # NOTE: Overlays take in data while for example transforms rasters, consistentency?
1817-
typer.echo("Progress: 25%")
1818-
out_image = or_overlay(data)
1819-
out_meta = raster.meta.copy()
1820-
out_meta["count"] = 1
1818+
data, profiles = read_and_stack_rasters(input_rasters)
1819+
typer.echo("Progress: 25%")
1820+
1821+
out_image = or_overlay(data)
18211822
typer.echo("Progress: 75%")
18221823

1823-
with rasterio.open(output_raster, "w", **out_meta) as dst:
1824-
dst.write(out_image, out_meta["count"])
1824+
out_profile = profiles[0]
1825+
out_profile["count"] = 1
1826+
out_profile["nodata"] = -9999
1827+
with rasterio.open(output_raster, "w", **out_profile) as dst:
1828+
dst.write(out_image, 1)
18251829
typer.echo("Progress: 100%")
18261830

18271831
typer.echo(f"'Or' overlay completed, writing raster to {output_raster}.")
@@ -1830,24 +1834,26 @@ def or_overlay_cli(
18301834
# PRODUCT OVERLAY
18311835
@app.command()
18321836
def product_overlay_cli(
1833-
input_raster: Annotated[Path, INPUT_FILE_OPTION],
1837+
input_rasters: INPUT_FILES_ARGUMENT,
18341838
output_raster: Annotated[Path, OUTPUT_FILE_OPTION],
18351839
):
1836-
"""Compute a 'product' overlay operation with fuzzy logic."""
1840+
"""Compute an 'product' overlay operation with fuzzy logic."""
18371841
from eis_toolkit.prediction.fuzzy_overlay import product_overlay
1842+
from eis_toolkit.utilities.file_io import read_and_stack_rasters
18381843

18391844
typer.echo("Progress: 10%")
18401845

1841-
with rasterio.open(input_raster) as raster:
1842-
data = raster.read() # NOTE: Overlays take in data while for example transforms rasters, consistentency?
1843-
typer.echo("Progress: 25%")
1844-
out_image = product_overlay(data)
1845-
out_meta = raster.meta.copy()
1846-
out_meta["count"] = 1
1846+
data, profiles = read_and_stack_rasters(input_rasters)
1847+
typer.echo("Progress: 25%")
1848+
1849+
out_image = product_overlay(data)
18471850
typer.echo("Progress: 75%")
18481851

1849-
with rasterio.open(output_raster, "w", **out_meta) as dst:
1850-
dst.write(out_image, out_meta["count"])
1852+
out_profile = profiles[0]
1853+
out_profile["count"] = 1
1854+
out_profile["nodata"] = -9999
1855+
with rasterio.open(output_raster, "w", **out_profile) as dst:
1856+
dst.write(out_image, 1)
18511857
typer.echo("Progress: 100%")
18521858

18531859
typer.echo(f"'Product' overlay completed, writing raster to {output_raster}.")
@@ -1856,51 +1862,53 @@ def product_overlay_cli(
18561862
# SUM OVERLAY
18571863
@app.command()
18581864
def sum_overlay_cli(
1859-
input_raster: Annotated[Path, INPUT_FILE_OPTION],
1865+
input_rasters: INPUT_FILES_ARGUMENT,
18601866
output_raster: Annotated[Path, OUTPUT_FILE_OPTION],
18611867
):
1862-
"""Compute a 'sum' overlay operation with fuzzy logic."""
1868+
"""Compute an 'sum' overlay operation with fuzzy logic."""
18631869
from eis_toolkit.prediction.fuzzy_overlay import sum_overlay
1870+
from eis_toolkit.utilities.file_io import read_and_stack_rasters
18641871

18651872
typer.echo("Progress: 10%")
18661873

1867-
with rasterio.open(input_raster) as raster:
1868-
data = raster.read() # NOTE: Overlays take in data while for example transforms rasters, consistentency?
1869-
typer.echo("Progress: 25%")
1870-
out_image = sum_overlay(data)
1871-
out_meta = raster.meta.copy()
1872-
out_meta["count"] = 1
1874+
data, profiles = read_and_stack_rasters(input_rasters)
1875+
typer.echo("Progress: 25%")
1876+
1877+
out_image = sum_overlay(data)
18731878
typer.echo("Progress: 75%")
18741879

1875-
with rasterio.open(output_raster, "w", **out_meta) as dst:
1876-
dst.write(out_image, out_meta["count"])
1880+
out_profile = profiles[0]
1881+
out_profile["count"] = 1
1882+
out_profile["nodata"] = -9999
1883+
with rasterio.open(output_raster, "w", **out_profile) as dst:
1884+
dst.write(out_image, 1)
18771885
typer.echo("Progress: 100%")
18781886

18791887
typer.echo(f"'Sum' overlay completed, writing raster to {output_raster}.")
18801888

18811889

18821890
# GAMMA OVERLAY
18831891
@app.command()
1884-
def gamme_overlay_cli(
1885-
input_raster: Annotated[Path, INPUT_FILE_OPTION],
1886-
output_raster: Annotated[Path, OUTPUT_FILE_OPTION],
1887-
gamma: float = typer.Option(),
1892+
def gamma_overlay_cli(
1893+
input_rasters: INPUT_FILES_ARGUMENT, output_raster: Annotated[Path, OUTPUT_FILE_OPTION], gamma: float = 0.5
18881894
):
1889-
"""Compute a 'gamma' overlay operation with fuzzy logic."""
1895+
"""Compute an 'gamma' overlay operation with fuzzy logic."""
18901896
from eis_toolkit.prediction.fuzzy_overlay import gamma_overlay
1897+
from eis_toolkit.utilities.file_io import read_and_stack_rasters
18911898

18921899
typer.echo("Progress: 10%")
18931900

1894-
with rasterio.open(input_raster) as raster:
1895-
data = raster.read() # NOTE: Overlays take in data while for example transforms rasters, consistentency?
1896-
typer.echo("Progress: 25%")
1897-
out_image = gamma_overlay(data, gamma)
1898-
out_meta = raster.meta.copy()
1899-
out_meta["count"] = 1
1901+
data, profiles = read_and_stack_rasters(input_rasters)
1902+
typer.echo("Progress: 25%")
1903+
1904+
out_image = gamma_overlay(data, gamma)
19001905
typer.echo("Progress: 75%")
19011906

1902-
with rasterio.open(output_raster, "w", **out_meta) as dst:
1903-
dst.write(out_image, out_meta["count"])
1907+
out_profile = profiles[0]
1908+
out_profile["count"] = 1
1909+
out_profile["nodata"] = -9999
1910+
with rasterio.open(output_raster, "w", **out_profile) as dst:
1911+
dst.write(out_image, 1)
19041912
typer.echo("Progress: 100%")
19051913

19061914
typer.echo(f"'Gamma' overlay completed, writing raster to {output_raster}.")

0 commit comments

Comments
 (0)