OSGeo / grass-addons

GRASS GIS Addons Repository
https://grass.osgeo.org/grass-stable/manuals/addons/
GNU General Public License v2.0
98 stars 149 forks source link

[Bug] t.rast.import.netcdf: Dataset object is not subscriptable #1182

Closed veroandreo closed 1 week ago

veroandreo commented 3 weeks ago

Name of the addon t.rast.import.netcdf

Describe the bug

GRASS world_latlong_wgs84/PERMANENT:~ > t.rast.import.netcdf input="https://data.chc.ucsb.edu/products/CHIRPS-2.0/global_daily/netcdf/p05/chirps-v2.0.2011.days_p05.nc" output="chirps_2011" start_time="2011-01-01" end_time="2012-01-01" color="precipitation_daily" 
/usr/lib/python3/dist-packages/osgeo/gdal.py:287: FutureWarning: Neither gdal.UseExceptions() nor gdal.DontUseExceptions() has been explicitly called. In GDAL 4.0, exceptions will be enabled by default.
  warnings.warn(
Traceback (most recent call last):
  File "/home/vandreo/.grass8/addons/scripts/t.rast.import.netcdf", line 1228, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/vandreo/.grass8/addons/scripts/t.rast.import.netcdf", line 1048, in main
    inputs_dict = [
                  ^
  File "/home/vandreo/.grass8/addons/scripts/t.rast.import.netcdf", line 1049, in <listcomp>
    parse_netcdf(
  File "/home/vandreo/.grass8/addons/scripts/t.rast.import.netcdf", line 791, in parse_netcdf
    sds_metadata = s_d[0].GetMetadata()
                   ~~~^^^
TypeError: 'Dataset' object is not subscriptable

To Reproduce Run:

t.rast.import.netcdf input="https://data.chc.ucsb.edu/products/CHIRPS-2.0/global_daily/netcdf/p05/chirps-v2.0.2011.days_p05.nc" output="chirps_2011" start_time="2011-01-01" end_time="2012-01-01" color="precipitation_daily"

System description:

GRASS version: 8.5.0dev                                                         
Code revision: c53c938bac                                                       
Build date: 2024-08-04                                                          
Build platform: x86_64-pc-linux-gnu                                             
GDAL: 3.7.1                                                                     
PROJ: 9.2.1                                                                     
GEOS: 3.12.0                                                                    
SQLite: 3.42.0                                                                  
Python: 3.11.6                                                                  
wxPython: 4.2.1                                                                 
Platform: Linux-6.5.0-44-generic-x86_64-with-glibc2.38                          
ninsbl commented 3 weeks ago

Will look into this. I suspect the dataset does not adhere to the CF convention... Do you if it should or do you have a format documentation?

veroandreo commented 3 weeks ago

Will look into this. I suspect the dataset does not adhere to the CF convention... Do you if it should or do you have a format documentation?

Right, that's a possibility. I only found this readme a couple of levels up...

ninsbl commented 3 weeks ago

It seems it is CF-1.6 I think I found the issue... NC files without subdatasets -like this- are not handled properly. Will fix it...