ASFHyP3 / asf-tools

A collection of GIS tools for working with higher-level SAR products
BSD 3-Clause "New" or "Revised" License
16 stars 5 forks source link

Threshold too high! Using maximum threshold -23.0 db #93

Open falahfakhri-Iraq opened 2 years ago

falahfakhri-Iraq commented 2 years ago

Hi, I did many attempts of the parameters altering, however, I got the following error,

Threshold too high! Using maximum threshold -23.0 db Traceback (most recent call last): File "", line 1, in File "C:\anaconda\envs\SAR\lib\site-packages\asf_tools\water_map.py", line 265, in make_water_map write_cog(str(outraster).replace('.tif', f'{pol}_initial.tif'), water_map, transform=out_transform, File "C:\anaconda\envs\SAR\lib\site-packages\asf_tools\composite.py", line 208, in write_cog temp_geotiff = driver.Create(temp_file.name, data.shape[1], data.shape[0], 1, dtype) File "C:\anaconda\envs\SAR\lib\site-packages\osgeo\gdal.py", line 1997, in Create return _gdal.Driver_Create(self, *args, **kwargs) RuntimeError: Attempt to create new tiff file `C:\Users\FALAH FAKHRI\AppData\Local\Temp\tmp21abpre2' failed: Permission denied

following is the script,

import asf_tools from asf_tools.water_map import make_water_map

dirpath = 'D:/Australia_Project/image_data/WATER_MAP_TEST/'

vh = dirpath + 'VH/S1A_IW_GRDH_1SDV_20210324T191554_045F93_21DF_VH_NR_Orb_TC_res.tif'

vv = dirpath + 'VV/S1A_IW_GRDH_1SDV_20210324T191554_045F93_21DF_VV_NR_Orb_TC_res.tif'

out_raster = dirpath + 'water_map_20210324T191554_045F93_21DF.tif'

make_water_map( out_raster, vv, vh, hand_raster=None, tile_shape=(200, 200), # also (100, 100) has been tried out. max_vv_threshold=9.7, max_vh_threshold=-23.0, hand_threshold=15.0, hand_fraction=0.8, membership_threshold=0.45 )

It's worth mentioning that I got a result, despite the error!

jhkennedy commented 2 years ago

@falahfakhri-Iraq the Threshold too high! Using maximum threshold -23.0 db message is just a warning saying the max VH threshold you specified (max_vh_threshold=-23.0) is lower than the calculated threshold using the Expectation Maximization approach. You may want to play with raising/lowering the threshold for you scene.

The actual error you're seeing is due to a file permission error:

RuntimeError: Attempt to create new tiff file `C:\Users\FALAH FAKHRI\AppData\Local\Temp\tmp21abpre2' failed: Permission denied

asf_tools is trying to make temporary raster in C:\Users\FALAH FAKHRI\AppData\Local\Temp\tmp21abpre2 during the COG creation step, and doesn't have the permissions to do so. In the code, asf_tools is using Python's NamedTemporaryFile for creating the files, and this is likely a Windows vs Unix issue -- we haven't fully tested the package on windows and it'll take a bit of time for me to troubleshoot.

falahfakhri-Iraq commented 2 years ago

Dear Joseph, Thanks a lot for your kind response, I have other question with this regard, Do you have any hints of calculating vh, vv, threshold?

Is it possible to use Otsu's method for threshold calculation related to intensity our case in here? https://muthu.co/otsus-method-for-image-thresholding-explained-and-implemented/

After run Otus's method, I got the threshold as below, and I also tired to solve the error related to tempfile, however I got an error as well,

import tempfile out_raster = tempfile.NamedTemporaryFile(delete=False)

make_water_map( out_raster, vv, vh, hand_raster=None, tile_shape=(200, 200), max_vv_threshold=21, max_vh_threshold=18, hand_threshold=15.0, hand_fraction=0.8, membership_threshold=0.45 ) Traceback (most recent call last): File "", line 1, in File "C:\anaconda\envs\SAR\lib\site-packages\asf_tools\water_map.py", line 265, in make_water_map write_cog(str(outraster).replace('.tif', f'{pol}_initial.tif'), water_map, transform=out_transform, File "C:\anaconda\envs\SAR\lib\site-packages\asf_tools\composite.py", line 208, in write_cog temp_geotiff = driver.Create(temp_file.name, data.shape[1], data.shape[0], 1, dtype) File "C:\anaconda\envs\SAR\lib\site-packages\osgeo\gdal.py", line 1997, in Create return _gdal.Driver_Create(self, *args, **kwargs) RuntimeError: Attempt to create new tiff file `C:\Users\FALAH FAKHRI\AppData\Local\Temp\tmp7win4xiu' failed: Permission denied

Thanks a lot for you time, With my best wishes, Falah,