0

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!

  • Please run `datamask.meta` and `treeloss.meta`, and post the output on your edited question. – swatchai Oct 03 '20 at 13:36
  • Thanks for your answer @swatchai, I am really new to this environment so I hope my answer will fit your expectation. So as you can see from the procedure I used to open the file treeloss and datamask are 'numpy.ndarray' objects so have no attribute 'meta'. – HuoustonWeHaveProblems Oct 05 '20 at 10:57
  • Actually I mean `datamask_cl.meta` and `treeloss_cl.meta`. – swatchai Oct 10 '20 at 13:16

0 Answers0