[GRASS-user] using GDAL to view netcdf files in GRASS

Hello. I’m trying to use GDAL to convert my netcdf file into a GTiff so it can be read into GRASS. I tried using “gdal_translate -of GTiff -b 1 NETCDF:FILE.nc:Outfile Outfile.tiff”
but this won’t geolocate my file. I ran the same command, adding -a_ullr -90.32483 42.5327 -58.66088 26.8966, with the coordinates corresponding with the max/min of the lat/lon coordinates of the netcdf file. This is a bit better, with the resulting raster image now being in the general correct area. But the projection is wrong. The file is a Lambert conformal projection. Is there an “easy” way to tell GDAL how to geolocate this file (and for it to get the correct projection)? Or can I geolocate the file after the fact, in GRASS? Any suggestions would be appreciated, I’m getting quite frustrated with displaying netcdf files in GRASS.

Thanks,
Katie

For more information, here is the header to the netcdf file I’m trying to visualize in GRASS:
netcdf d03_heat_stress_2060_08 {
dimensions:
Time = UNLIMITED ; // (1 currently)
DateStrLen = 19 ;
west_east = 198 ;
south_north = 198 ;
bottom_top = 27 ;
bottom_top_stag = 28 ;
soil_layers_stag = 4 ;
west_east_stag = 199 ;
south_north_stag = 199 ;
variables:
char Times(Time, DateStrLen) ;
float HSI(Time, south_north, west_east) ;
HSI:FieldType = 104 ;
HSI:MemoryOrder = "XY " ;
HSI:description = “HEAT STRESS INDEX” ;
HSI:units = “deg C” ;
HSI:stagger = “” ;
HSI:coordinates = “XLONG XLAT” ;
float XLAT(Time, south_north, west_east) ;
XLAT:FieldType = 104 ;
XLAT:MemoryOrder = "XY " ;
XLAT:description = “LATITUDE, SOUTH IS NEGATIVE” ;
XLAT:units = “degree_north” ;
XLAT:stagger = “” ;
float XLONG(Time, south_north, west_east) ;
XLONG:FieldType = 104 ;
XLONG:MemoryOrder = "XY " ;
XLONG:description = “LONGITUDE, WEST IS NEGATIVE” ;
XLONG:units = “degree_east” ;
XLONG:stagger = “” ;

// global attributes:
:TITLE = " OUTPUT FROM WRF V3.1.1 MODEL" ;
:START_DATE = “2060-10-01_00:00:00” ;
:SIMULATION_START_DATE = “2059-01-01_00:00:00” ;
:WEST-EAST_GRID_DIMENSION = 199 ;
:SOUTH-NORTH_GRID_DIMENSION = 199 ;
:BOTTOM-TOP_GRID_DIMENSION = 28 ;
:DX = 12000.f ;
:DY = 12000.f ;
:GRIDTYPE = “C” ;
:DIFF_OPT = 1 ;
:KM_OPT = 4 ;
:DAMP_OPT = 0 ;
:DAMPCOEF = 0.01f ;
:KHDIF = 0.f ;
:KVDIF = 0.f ;
:MP_PHYSICS = 4 ;
:RA_LW_PHYSICS = 3 ;
:RA_SW_PHYSICS = 3 ;
:SF_SFCLAY_PHYSICS = 1 ;
:SF_SURFACE_PHYSICS = 2 ;
:BL_PBL_PHYSICS = 1 ;
:CU_PHYSICS = 1 ;
:SURFACE_INPUT_SOURCE = 1 ;
:SST_UPDATE = 1 ;
:GRID_FDDA = 0 ;
:GFDDA_INTERVAL_M = 360 ;
:GFDDA_END_H = 744000 ;
:GRID_SFDDA = 0 ;
:SGFDDA_INTERVAL_M = 0 ;
:SGFDDA_END_H = 0 ;
:SF_URBAN_PHYSICS = 0 ;
:FEEDBACK = 0 ;
:SMOOTH_OPTION = 0 ;
:SWRAD_SCAT = 1.f ;
:W_DAMPING = 1 ;
:MOIST_ADV_OPT = 1 ;
:SCALAR_ADV_OPT = 1 ;
:TKE_ADV_OPT = 1 ;
:DIFF_6TH_OPT = 0 ;
:DIFF_6TH_FACTOR = 0.12f ;
:OBS_NUDGE_OPT = 0 ;
:WEST-EAST_PATCH_START_UNSTAG = 1 ;
:WEST-EAST_PATCH_END_UNSTAG = 198 ;
:WEST-EAST_PATCH_START_STAG = 1 ;
:WEST-EAST_PATCH_END_STAG = 199 ;
:SOUTH-NORTH_PATCH_START_UNSTAG = 1 ;
:SOUTH-NORTH_PATCH_END_UNSTAG = 198 ;
:SOUTH-NORTH_PATCH_START_STAG = 1 ;
:SOUTH-NORTH_PATCH_END_STAG = 199 ;
:BOTTOM-TOP_PATCH_START_UNSTAG = 1 ;
:BOTTOM-TOP_PATCH_END_UNSTAG = 27 ;
:BOTTOM-TOP_PATCH_START_STAG = 1 ;
:BOTTOM-TOP_PATCH_END_STAG = 28 ;
:GRID_ID = 3 ;
:PARENT_ID = 2 ;
:I_PARENT_START = 18 ;
:J_PARENT_START = 24 ;
:PARENT_GRID_RATIO = 3 ;
:DT = 40.f ;
:CEN_LAT = 35.79343f ;
:CEN_LON = -76.1796f ;
:TRUELAT1 = 33.f ;
:TRUELAT2 = 45.f ;
:MOAD_CEN_LAT = 40.f ;
:STAND_LON = -97.f ;
:POLE_LAT = 90.f ;
:POLE_LON = 0.f ;
:GMT = 0.f ;
:JULYR = 2060 ;
:JULDAY = 275 ;
:MAP_PROJ = 1 ;
:MMINLU = “USGS” ;
:NUM_LAND_CAT = 24 ;
:ISWATER = 16 ;
:ISLAKE = -1 ;
:ISICE = 24 ;
:ISURBAN = 1 ;
:ISOILWATER = 14 ;
data:

Times =
“” ;

HSI =
-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999,
-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999,
-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999,
-999, -999, -999,

Carbonari, Katie (IS) wrote:

Hello. I'm trying to use GDAL to convert my netcdf file into a GTiff so it can be read into GRASS. I tried using "gdal_translate -of GTiff -b 1 NETCDF:FILE.nc:Outfile Outfile.tiff"

You probably need to specify a coordinate system, too. Do this with the -a_srs option.

See http://www.gdal.org/gdal_utilities.html for details. The easiest way is using the epsg codes. On my system, I can find them by:

cat /usr/share/proj/epsg | grep -i lambert -A 1

There is also a list at (http://www.epsg-registry.org/) - look under Projected CRS type. Choose the one that you need, and amend your code. e.g.

gdal_translate -of GTiff -a_srs epsg:12345 -b 1 NETCDF:FILE.nc:Outfile Outfile.tiff

You might also need to warp your map into the new projection

gdalwarp -t_srs epsg 12345 Outfile.tiff Outfile_warped.tiff

See the first parts of this tutorial for details
http://blog.thematicmapping.org/2008/03/generating-map-tiles-with-gdal2tiles.html

Hope that helps,

John

--

Dr John Stevenson
Postdoctoral Research Associate
School of Earth, Atmospheric and Environmental Sciences
Williamson Building (Room 2.42)
University of Manchester
Manchester M13 9PL, UK
tel. +44(0)161 306 6585; fax. +44(0)161 306 9361;
john.stevenson@manchester.ac.uk