@@ -1778,24 +1778,26 @@ def predict_with_trained_model_cli(
1778
1778
# AND OVERLAY
1779
1779
@app .command ()
1780
1780
def and_overlay_cli (
1781
- input_raster : Annotated [ Path , INPUT_FILE_OPTION ] ,
1781
+ input_rasters : INPUT_FILES_ARGUMENT ,
1782
1782
output_raster : Annotated [Path , OUTPUT_FILE_OPTION ],
1783
1783
):
1784
1784
"""Compute an 'and' overlay operation with fuzzy logic."""
1785
1785
from eis_toolkit .prediction .fuzzy_overlay import and_overlay
1786
+ from eis_toolkit .utilities .file_io import read_and_stack_rasters
1786
1787
1787
1788
typer .echo ("Progress: 10%" )
1788
1789
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 )
1795
1794
typer .echo ("Progress: 75%" )
1796
1795
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 )
1799
1801
typer .echo ("Progress: 100%" )
1800
1802
1801
1803
typer .echo (f"'And' overlay completed, writing raster to { output_raster } ." )
@@ -1804,24 +1806,26 @@ def and_overlay_cli(
1804
1806
# OR OVERLAY
1805
1807
@app .command ()
1806
1808
def or_overlay_cli (
1807
- input_raster : Annotated [ Path , INPUT_FILE_OPTION ] ,
1809
+ input_rasters : INPUT_FILES_ARGUMENT ,
1808
1810
output_raster : Annotated [Path , OUTPUT_FILE_OPTION ],
1809
1811
):
1810
1812
"""Compute an 'or' overlay operation with fuzzy logic."""
1811
1813
from eis_toolkit .prediction .fuzzy_overlay import or_overlay
1814
+ from eis_toolkit .utilities .file_io import read_and_stack_rasters
1812
1815
1813
1816
typer .echo ("Progress: 10%" )
1814
1817
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 )
1821
1822
typer .echo ("Progress: 75%" )
1822
1823
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 )
1825
1829
typer .echo ("Progress: 100%" )
1826
1830
1827
1831
typer .echo (f"'Or' overlay completed, writing raster to { output_raster } ." )
@@ -1830,24 +1834,26 @@ def or_overlay_cli(
1830
1834
# PRODUCT OVERLAY
1831
1835
@app .command ()
1832
1836
def product_overlay_cli (
1833
- input_raster : Annotated [ Path , INPUT_FILE_OPTION ] ,
1837
+ input_rasters : INPUT_FILES_ARGUMENT ,
1834
1838
output_raster : Annotated [Path , OUTPUT_FILE_OPTION ],
1835
1839
):
1836
- """Compute a 'product' overlay operation with fuzzy logic."""
1840
+ """Compute an 'product' overlay operation with fuzzy logic."""
1837
1841
from eis_toolkit .prediction .fuzzy_overlay import product_overlay
1842
+ from eis_toolkit .utilities .file_io import read_and_stack_rasters
1838
1843
1839
1844
typer .echo ("Progress: 10%" )
1840
1845
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 )
1847
1850
typer .echo ("Progress: 75%" )
1848
1851
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 )
1851
1857
typer .echo ("Progress: 100%" )
1852
1858
1853
1859
typer .echo (f"'Product' overlay completed, writing raster to { output_raster } ." )
@@ -1856,51 +1862,53 @@ def product_overlay_cli(
1856
1862
# SUM OVERLAY
1857
1863
@app .command ()
1858
1864
def sum_overlay_cli (
1859
- input_raster : Annotated [ Path , INPUT_FILE_OPTION ] ,
1865
+ input_rasters : INPUT_FILES_ARGUMENT ,
1860
1866
output_raster : Annotated [Path , OUTPUT_FILE_OPTION ],
1861
1867
):
1862
- """Compute a 'sum' overlay operation with fuzzy logic."""
1868
+ """Compute an 'sum' overlay operation with fuzzy logic."""
1863
1869
from eis_toolkit .prediction .fuzzy_overlay import sum_overlay
1870
+ from eis_toolkit .utilities .file_io import read_and_stack_rasters
1864
1871
1865
1872
typer .echo ("Progress: 10%" )
1866
1873
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 )
1873
1878
typer .echo ("Progress: 75%" )
1874
1879
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 )
1877
1885
typer .echo ("Progress: 100%" )
1878
1886
1879
1887
typer .echo (f"'Sum' overlay completed, writing raster to { output_raster } ." )
1880
1888
1881
1889
1882
1890
# GAMMA OVERLAY
1883
1891
@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
1888
1894
):
1889
- """Compute a 'gamma' overlay operation with fuzzy logic."""
1895
+ """Compute an 'gamma' overlay operation with fuzzy logic."""
1890
1896
from eis_toolkit .prediction .fuzzy_overlay import gamma_overlay
1897
+ from eis_toolkit .utilities .file_io import read_and_stack_rasters
1891
1898
1892
1899
typer .echo ("Progress: 10%" )
1893
1900
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 )
1900
1905
typer .echo ("Progress: 75%" )
1901
1906
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 )
1904
1912
typer .echo ("Progress: 100%" )
1905
1913
1906
1914
typer .echo (f"'Gamma' overlay completed, writing raster to { output_raster } ." )
0 commit comments