Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make_water_map cannot write temporary files on Windows machines #137

Open
jhkennedy opened this issue Aug 18, 2022 · 1 comment
Open

make_water_map cannot write temporary files on Windows machines #137

jhkennedy opened this issue Aug 18, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@jhkennedy
Copy link
Contributor

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
@jhkennedy jhkennedy added the bug Something isn't working label Aug 18, 2022
@jhkennedy
Copy link
Contributor Author

It's possible this is related to converting Path() objects to strings for GDAL via str() and may be resolved by switching to os.fspath:
OSGeo/gdal#1613 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant