KMarkert / servir-vic-training

Training materials for the VIC hydrologic model setup developed for the @SERVIR program
GNU General Public License v3.0
36 stars 33 forks source link

ValueError: arange: cannot compute length #6

Closed Tarikbouram closed 4 years ago

Tarikbouram commented 6 years ago

I'm using a script on python "format_snow_param.py". This script takes geotiff data for snow band parameterization and converts it to the needed text format for the VIC model

Usage:


> python format_snow_params.py <template raster> <elevation raster>
> <output snow band file> <interval for snow bands>

on the terminal I type the following command:

Format elevation band file:

$ python format_snow_params.py
../data/input/gis/Nyando_grid.tif
../data/input/gis/Nyando_basin_SRTMSnap.tif ../data/input/snow.param 100

The results give this error:


> Traceback (most recent call last):  

>  File "format_snow_params.py", line 203, in <module>
>     main()     File "format_snow_params.py", line 197, in main
>     format_snow_params(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])  
> File "format_snow_params.py", line 112, in format_snow_params
>     bands = np.arange(minelv, maxelv+interval, interval) ValueError: arange: cannot compute length

the output results of the command gdalinfo -stats Nyando_basin_SRTMSnap.tif :


> gdalinfo: Relink `/home/lgee/miniconda3/bin/../lib/libpng16.so.16' with `/lib/x86_64-linux-gnu/libpthread.so.0' for IFUNC symbol `longjmp'
> Driver: GTiff/GeoTIFF
> Files: Nyando_basin_SRTMSnap.tif
> Size is 3300, 1500
> Coordinate System is `'
> Origin = (34.750000000000000,0.050000000000000)
> Pixel Size = (0.000303030303030,-0.000333333333333)
> Image Structure Metadata:
>   INTERLEAVE=BAND
> Corner Coordinates:
> Upper Left  (  34.7500000,   0.0500000) 
> Lower Left  (  34.7500000,  -0.4500000) 
> Upper Right (  35.7500000,   0.0500000) 
> Lower Right (  35.7500000,  -0.4500000) 
> Center      (  35.2500000,  -0.2000000) 
> Band 1 Block=3300x1 Type=Float32, ColorInterp=Gray
>   Minimum=1134.000, Maximum=2862.000, Mean=1735.713, StdDev=473.560
>   NoData Value=-3.4028234663852886e+38
>   Metadata:
>     STATISTICS_MAXIMUM=2862
>     STATISTICS_MEAN=1735.7128876922
>     STATISTICS_MINIMUM=1134
>     STATISTICS_STDDEV=473.55999424241

the output results of the command gdalinfo -stats Nyando_grid.tif :

gdalinfo: Relink /home/lgee/miniconda3/bin/../lib/libpng16.so.16' with/lib/x86_64-linux-gnu/libpthread.so.0' for IFUNC symbol longjmp' Driver: GTiff/GeoTIFF Files: Nyando_grid.tif Size is 20, 10 Coordinate System is' Origin = (34.750000000000000,0.050000000000000) Pixel Size = (0.050000000000000,-0.050000000000000) Image Structure Metadata: INTERLEAVE=BAND Corner Coordinates: Upper Left ( 34.7500000, 0.0500000) Lower Left ( 34.7500000, -0.4500000) Upper Right ( 35.7500000, 0.0500000) Lower Right ( 35.7500000, -0.4500000) Center ( 35.2500000, -0.2000000) Band 1 Block=20x10 Type=Byte, ColorInterp=Gray Minimum=1.000, Maximum=1.000, Mean=1.000, StdDev=0.000 NoData Value=0 Metadata: STATISTICS_MAXIMUM=1 STATISTICS_MEAN=1 STATISTICS_MINIMUM=1 STATISTICS_STDDEV=0

We can notice that the basin mask has a different pixel size and a different shape (rows and cols) to your elevation grid. From what I can see, the basin mask should be the same size for the code to work. Knowing that I followed exactly the command tutorial and All other parameters have been successfully calculated, except snow.param

KMarkert commented 6 years ago

The code expects that the elevation dataset be at a higher resolution than the grid cell so that it can calculate the fraction of elevation bands, so that is fine. This issue you found was happening because the code masked any elevation data below 0 to prevent no data values from skewing the mean band elevation values. When that happened sometimes the grid cell would have no data to calculate elevation bands for, giving the error. To fix this, I changed the code to where it does not mask data anymore but manually checks for valid data. I tested it, hopefully it works now. Please download the updated scripts and try again. Please let me know if it works or not.

Tarikbouram commented 6 years ago

I think it worked since I no longer have this error, however there is another one that appears with this script

python format_snow_params.py ../data/input/gis/Nyando_grid.tif ../data/input/gis/Nyando_basin_SRTMSnap.tif ../data/input/snow.param 100
Traceback (most recent call last):
  File "format_snow_params.py", line 218, in <module>
    main()
  File "format_snow_params.py", line 212, in main
    format_snow_params(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])
  File "format_snow_params.py", line 188, in format_snow_params
    maxbands = max(nbands) # maximum number of bands for a pixel
ValueError: max() arg is an empty sequence
giaMSU commented 4 years ago

Hi Tarikbouram, Do you successfully complete the VIC model? If yes, could you please share your experience to me?

Tarikbouram commented 4 years ago

Hello

The webinar on the VIC model, is one of the best I have attended so far. I have successfully finished the model, and I have been able to apply it to other study areas. The only issue that unfortunately has not been solved until today is the fact that I have not received my certificate of participation.

Best regards

Le jeu. 19 mars 2020 à 23:53, gia_nguyen notifications@github.com a écrit :

Hi Tarikbouram, Do you successfully complete the VIC model? If yes, could you please share your experience to me?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/KMarkert/servir-vic-training/issues/6#issuecomment-601453263, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI7LR7B33UCNXA77EU2QO5TRIKO43ANCNFSM4E3JUDAQ .

-- T. Bouramtane

KMarkert commented 4 years ago

Hi @Tarikbouram, glad to hear you were able to successfully set up the model and execute it for your domain. However, I am sorry you have not received your certificate yet...unfortunately I have no control over this but you should try emailing the ARSET team to explain your situation with the certificate and see if they can help you out.