[GRASS-user] Help with export netCDF file

Hernán De Angelis variablestarlight at gmail.com
Wed Feb 26 03:20:59 PST 2025


Thomas

I have not tested, but have you looked into the "createopt" parameter in 
r.out.gdal?

 From the manual:
"createopt=string[,string,...]
     Creation option(s) to pass to the output format driver
     In the form of "NAME=VALUE", separate multiple entries with a comma"

So I believe that in principle you could pass the "BAND_NAMES" creation 
option from GDAL.

See:

https://gdal.org/en/stable/drivers/raster/netcdf.html#creation-options

https://grass.osgeo.org/grass85/manuals/r.out.gdal.html


Hope this helps

Hernán



Den 2025-02-25 kl. 17:26, skrev Thomas Adams via grass-user:
> Hi all,
>
> I really don't have a problem with exporting a netCDF file from GRASS 
> 8.4, but because of the intended use of the output file, I need to 
> have variable name defined specifically, instead of the generic Band1:
>
> ncdump -h sac_UZTWM.nc
>
> netcdf sac_UZTWM {
> dimensions:
> x = 2698 ;
> y = 2427 ;
> variables:
> double Band1(y, x) ;
> Band1:long_name = "GDAL Band Number 1" ;
> Band1:_FillValue = -999. ;
> Band1:grid_mapping = "lambert_conformal_conic" ;
> Band1:COLOR_TABLE_RULES_COUNT = 255 ;
> Band1:COLOR_TABLE_RULE_RGB_0 = "0.000000e+00 5.496153e-01 68 1 84 68 2 
> 86" ;
> Band1:COLOR_TABLE_RULE_RGB_1 = "5.496153e-01 1.099231e+00 68 2 86 69 4 
> 87" ;
> Band1:COLOR_TABLE_RULE_RGB_2 = "1.099231e+00 1.648846e+00 69 4 87 69 5 
> 89" ;
> Band1:COLOR_TABLE_RULE_RGB_3 = "1.648846e+00 2.199863e+00 69 5 89 70 7 
> 90" ;
> Band1:COLOR_TABLE_RULE_RGB_4 = "2.199863e+00 2.749479e+00 70 7 90 70 8 
> 92" ;
> Band1:COLOR_TABLE_RULE_RGB_5 = "2.749479e+00 3.299094e+00 70 8 92 70 
> 10 93" ;
> Band1:COLOR_TABLE_RULE_RGB_6 = "3.299094e+00 3.848709e+00 70 10 93 70 
> 11 94" ;
> Band1:COLOR_TABLE_RULE_RGB_7 = "3.848709e+00 4.398325e+00 70 11 94 71 
> 13 96" ;
>
> I need what I have below, using Climate Data Operators (cdo)...
>
> cdo -chname,Band1,sac_UZTWM sac_UZTWM.nc sac_UZTWM.nc.test
>
> I can change the variable name, which is exactly what I need:
>
> ncdump -h sac_UZTWM.nc
> netcdf sac_UZTWM {
> dimensions:
> x = 2698 ;
> y = 2427 ;
> variables:
> double x(x) ;
> x:standard_name = "projection_x_coordinate" ;
> x:long_name = "x coordinate of projection" ;
> x:units = "m" ;
> x:axis = "X" ;
> double y(y) ;
> y:standard_name = "projection_y_coordinate" ;
> y:long_name = "y coordinate of projection" ;
> y:units = "m" ;
> y:axis = "Y" ;
> char lambert_conformal_conic ;
> lambert_conformal_conic:grid_mapping_name = "lambert_conformal_conic" ;
> lambert_conformal_conic:longitude_of_central_meridian = 74. ;
> lambert_conformal_conic:false_easting = 0. ;
> lambert_conformal_conic:false_northing = 0. ;
> lambert_conformal_conic:latitude_of_projection_origin = 23. ;
> lambert_conformal_conic:standard_parallel = 33., 45. ;
> lambert_conformal_conic:long_name = "CRS definition" ;
> lambert_conformal_conic:longitude_of_prime_meridian = 0. ;
> lambert_conformal_conic:semi_major_axis = 6378137. ;
> lambert_conformal_conic:inverse_flattening = 298.257223563 ;
> lambert_conformal_conic:crs_wkt = 
> "PROJCS[\"unknown\",GEOGCS[\"wgs84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"latitude_of_origin\",23],PARAMETER[\"central_meridian\",74],PARAMETER[\"standard_parallel_1\",33],PARAMETER[\"standard_parallel_2\",45],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]" 
> ;
> lambert_conformal_conic:spatial_ref = 
> "PROJCS[\"unknown\",GEOGCS[\"wgs84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"latitude_of_origin\",23],PARAMETER[\"central_meridian\",74],PARAMETER[\"standard_parallel_1\",33],PARAMETER[\"standard_parallel_2\",45],PARAMETER[\"false_easting\",0],PARAMETER[\"false_northing\",0],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AXIS[\"Easting\",EAST],AXIS[\"Northing\",NORTH]]" 
> ;
> lambert_conformal_conic:GeoTransform = "-1567000 1000 0 2160000 0 
> -1000 " ;
> double sac_UZTWM(y, x) ;
> sac_UZTWM:long_name = "GDAL Band Number 1" ;
> sac_UZTWM:grid_mapping = "lambert_conformal_conic" ;
> sac_UZTWM:_FillValue = -999. ;
> sac_UZTWM:missing_value = -999. ;
>
> // global attributes:
> :CDI = "Climate Data Interface version 2.4.0 
> (https://mpimet.mpg.de/cdi)" ;
> :Conventions = "CF-1.5" ;
> :GDAL = "GDAL 3.9.3, released 2024/10/07 (debug build)" ;
> :history = "Tue Feb 25 06:31:46 2025: cdo -chname,Band1,sac_UZTWM 
> sac_UZTWM.nc sac_UZTWM.nc.test\n",
> "Tue Feb 25 06:30:38 2025: GDAL Create( 
> /media/teaiii/research/pakistan/parameters/sac_UZTWM.nc, ... )" ;
> :CDO = "Climate Data Operators version 2.4.0 
> (https://mpimet.mpg.de/cdo)" ;
> }
>
> But how using r.out.gdal can I do this; I tried something that I 
> thought should work, but I got an error
>
> r.out.gdal -c -m --overwrite input=uztwm at teaiii 
> output=/media/teaiii/research/pakistan/parameters/sac_UZTWM.nc 
> format=netCDF nodata=-999
>
> Thank you,
> Tom
>
>
>
>
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20250226/676a9f59/attachment.htm>


More information about the grass-user mailing list