In Python I am trying to reconvert the array obtained by masking a raster file to a raster.
More specifically: I have two rasters a) data raster with deforestation year b) mask raster where are reported the area mapped (=1), the null areas and the water bodies (respectively = 0 and = 2).
I have produced a masked array where I have substituted the null values based on the original rasters:
# Define relative paths
treeloss_path = os.path.join("/path/lossyear_congo.tif")
datamask_path = os.path.join("/path/datamask_congo.tif")`
# Open making layer
with rio.open(datamask_path) as datamask_cl:
datamask = datamask_cl.read()
datamask_ext = plotting_extent(datamask_cl)
# Open the baseman layer for your
with rio.open(treeloss_path) as treeloss_cl:
treeloss = treeloss_cl.read()
treeloss_ext = plotting_extent(treeloss_cl)`
Then I have created my masked array as follow:
import earthpy.mask as em
treecover_free_masked = em.mask_pixels(treeloss, datamask, vals=[0, 2])
Now I need to create a raster with the masked array (treecover_free_masked) with all the same features in space and geo referencing of the original data. Any suggestion on how to reach this step?
Thanks!