Skip to content

make_water_map cannot write temporary files on Windows machines #137

@jhkennedy

Description

@jhkennedy

As reported in our Gitter, running asf_tools.water_map.make_water_map on Windows results in a Permission Denied error when trying to write the water map rasters via GDAL.

Commands:

>>>  from asf_tools.water_map import make_water_map
>>> water_extent_raster = 'water_extent.tif'
>>> make_water_map(
...     out_raster=water_extent_raster, vv_raster=vv_raster, vh_raster=vh_raster, 
...     hand_raster='water_extent_HAND.tif', tile_shape=(100, 100), 
...     max_vv_threshold=-15.5, max_vh_threshold=-23., hand_threshold=15., hand_fraction=0.8,
... )

Stack trace:

RuntimeError Traceback (most recent call last)
Input In [18], in <cell line: 6>()
3 from asf_tools.water_map import make_water_map
5 water_extent_raster = 'water_extent.tif'
----> 6 make_water_map(out_raster=water_extent_raster, vv_raster=vv_raster, vh_raster=vh_raster,
7 hand_raster='water_extent_HAND.tif', tile_shape=(100, 100),
8 max_vv_threshold=-15.5, max_vh_threshold=-23., hand_threshold=15., hand_fraction=0.8)

File ~\Anaconda3\envs\asftools\lib\site-packages\asf_tools\water_map.py:270, in make_water_map(out_raster, vv_raster, vh_raster, hand_raster, tile_shape, max_vv_threshold, max_vh_threshold, hand_threshold, hand_fraction, membership_threshold)
267 water_map = np.ma.masked_less_equal(gaussian_array, gaussian_threshold).mask
268 water_map &= ~array.mask
--> 270 write_cog(str(outraster).replace('.tif', f'{pol}_initial.tif'), water_map, transform=out_transform,
271 epsg_code=out_epsg, dtype=gdal.GDT_Byte, nodata_value=False)
273 log.info(f'Refining initial {pol} water extent map using Fuzzy Logic')
274 array = np.ma.masked_where(~water_map, array)

File ~\Anaconda3\envs\asftools\lib\site-packages\asf_tools\composite.py:208, in write_cog(file_name, data, transform, epsg_code, dtype, nodata_value)
206 with NamedTemporaryFile() as temp_file:
207 driver = gdal.GetDriverByName('GTiff')
--> 208 temp_geotiff = driver.Create(temp_file.name, data.shape[1], data.shape[0], 1, dtype)
209 temp_geotiff.GetRasterBand(1).WriteArray(data)
210 if nodata_value is not None:

File ~\Anaconda3\envs\asftools\lib\site-packages\osgeo\gdal.py:1927, in Driver.Create(self, args, **kwargs)
1925 def Create(self, args, kwargs):
1926 r"""Create(Driver self, char const * utf8_path, int xsize, int ysize, int bands=1, GDALDataType eType=GDT_Byte, char options=None) -> Dataset"""
-> 1927 return _gdal.Driver_Create(self, args, *kwargs)

RuntimeError: Attempt to create new tiff file `C:\Users\james\AppData\Local\Temp\tmpgbz4o7hi' failed: Permission denied

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions