Skip to content

Commit

Permalink
Update compute_forest to account for 3 or 4 bands
Browse files Browse the repository at this point in the history
  • Loading branch information
ghislainv committed May 30, 2024
1 parent 6853101 commit 22c481f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions forestatrisk/data/compute/compute_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def compute_forest(proj, extent, verbose=False):
# Rasterize country border
# (by default: zero outside, without nodata value)
gdal.Rasterize("ctry_PROJ.tif", "ctry_PROJ.gpkg",
layers="ADM_ADM_0",
outputBounds=extent,
xRes=30, yRes=30, targetAlignedPixels=True,
burnValues=[1], outputType=gdal.GDT_Byte,
Expand Down
27 changes: 15 additions & 12 deletions forestatrisk/data/country_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from osgeo import gdal

from ..misc import make_dir
from .compute import compute_biomass_avitabile, compute_osm
from .compute import compute_srtm, compute_wdpa
from .compute import compute_forest
from .compute import compute_srtm, compute_wdpa, compute_osm
from .compute import compute_biomass_avitabile
from .get_vector_extent import get_vector_extent


Expand Down Expand Up @@ -103,30 +103,33 @@ def country_compute(
wd = os.getcwd()
os.chdir(temp_dir)
# Perform computations
compute_forest(iso3, proj, extent_reg)
compute_forest(proj, extent_reg)
# Create directories
make_dir(os.path.join(wd, output_dir, "forest"))
make_dir(os.path.join(wd, output_dir, "validation"))
make_dir(os.path.join(wd, output_dir, "forecast"))
# Copy files for modelling
ifiles = ["dist_edge_t1.tif", "fcc12.tif"]
ofiles = ["dist_edge.tif", "fcc.tif"]
ifiles = ["dist_edge_t1.tif", "dist_defor_t1.tif", "fcc12.tif"]
ofiles = ["dist_edge.tif", "dist_defor.tif", "fcc.tif"]
for (ifile, ofile) in zip(ifiles, ofiles):
copy2(ifile, os.path.join(wd, output_dir, ofile))
if os.path.isfile(ifile):
copy2(ifile, os.path.join(wd, output_dir, ofile))
# Copy files for validation
files = ["dist_edge_t2.tif", "dist_defor_t2.tif"]
for file in files:
copy2(file, os.path.join(wd, output_dir, "validation"))
if os.path.isfile(file):
copy2(file, os.path.join(wd, output_dir, "validation"))
# Copy files for forecast
files = ["dist_edge_t3.tif", "dist_defor_t3.tif"]
for file in files:
copy2(file, os.path.join(wd, output_dir, "forecast"))
if os.path.isfile(file):
copy2(file, os.path.join(wd, output_dir, "forecast"))
# Forest data
files = ["forest_t1.tif", "forest_t2.tif", "forest_t3.tif",
"forest_2005.tif", "forest_2015.tif", "fcc23.tif",
"fcc123.tif", "fcc12345.tif"]
files = [f"forest_t{i}.tif" for i in range(4)]
files.append("fcc123.tif")
for file in files:
copy2(file, os.path.join(wd, output_dir, "forest"))
if os.path.isfile(file):
copy2(file, os.path.join(wd, output_dir, "forest"))
os.chdir(wd)

# Keep or remove directory
Expand Down

0 comments on commit 22c481f

Please sign in to comment.