Project

General

Profile

WRF file in QGIS

Added by Manuel Ariza almost 5 years ago

Good morning to everyone,

I am trying to load .nc file in QGIS that I got doing in a simulation in WRF.
There are two ways of doing it, one is by adding Raster layer, which loads the .nc file but is not capable of reading the coordinates, so it loads it in a random place.
The other way is by using the plugging NETCDF browser (only works in versions older than 3.0) and the same problem happens.

I try to load it in ArcGIS, and it does work, but I need to set it in QGIS.

I have read multiple forums and the main problem seems to be that WRF files are not compliant with CF. There is a tool that converts wrf to cf, but it does not work, I don't know why: http://foehn.colorado.edu/wrfout_to_cf/

I have been thinking that the problem is that the type of coordinates are curvilinear, and they should be Lonlat, I have been trying to change them by using sellonlatbox or setgridtype in cdo, but also does not work.

Anyone knows how to solve it?. Here is the output of cdo sinfo.

File format : NetCDF4
-1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter ID
1 : unknown unknown c instant 1 1 7 1 F64 : -1
2 : unknown unknown c instant 1 1 147456 2 F64 : -2
3 : unknown unknown c instant 1 1 147456 2 F64 : -3
4 : unknown unknown c instant 1 1 147456 2 F64 : -4
5 : unknown unknown v instant 1 1 147456 2 F64 : -5
6 : unknown unknown c instant 1 1 147456 2 F64 : -6
7 : unknown unknown v instant 1 1 147456 2 F64 : -7
8 : unknown unknown v instant 7 2 147456 2 F64 : -8
9 : unknown unknown v instant 7 2 147456 2 F64 : -9
10 : unknown unknown v instant 7 2 147456 2 F64 : -10
11 : unknown unknown v instant 1 1 147456 2 F64 : -11
12 : unknown unknown v instant 1 1 147456 2 F64 : -12
13 : unknown unknown v instant 7 2 147456 2 F64 : -13
14 : unknown unknown v instant 1 1 147456 2 F64 : -14
15 : unknown unknown v instant 1 1 147456 2 F64 : -15
16 : unknown unknown v instant 7 2 147456 2 F64 : -16
17 : unknown unknown v instant 1 1 147456 2 F64 : -17
18 : unknown unknown v instant 7 2 147456 2 F64 : -18
19 : unknown unknown v instant 1 1 147456 2 F64 : -19
20 : unknown unknown v instant 1 1 147456 2 F64 : -20
21 : unknown unknown v instant 1 1 147456 2 F64 : -21
Grid coordinates :
1 : generic : points=7
2 : curvilinear : points=147456 (384x384)
XLONG : -82.47966 to -72.04327 by 0.02724907 degrees_east
XLAT : -6.91111 to 3.506271 by 0.02719943 degrees_north
Vertical coordinates :
1 : surface : levels=1
2 : generic : levels=7
Time coordinate : 25 steps
RefTime = 0001-01-01 00:00:00 Units = minutes Calendar = standard
YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss YYYY-MM-DD hh:mm:ss
2017-01-23 05:00:00 2017-01-23 06:00:00 2017-01-23 07:00:00 2017-01-23 08:00:00
2017-01-23 09:00:00 2017-01-23 10:00:00 2017-01-23 11:00:00 2017-01-23 12:00:00
2017-01-23 13:00:00 2017-01-23 14:00:00 2017-01-23 15:00:00 2017-01-23 16:00:00
2017-01-23 17:00:00 2017-01-23 18:00:00 2017-01-23 19:00:00 2017-01-23 20:00:00
2017-01-23 21:00:00 2017-01-23 22:00:00 2017-01-23 23:00:00 2017-01-24 00:00:00
2017-01-24 01:00:00 2017-01-24 02:00:00 2017-01-24 03:00:00 2017-01-24 04:00:00
2017-01-24 05:00:00
cdo sinfo: Processed 21 variables over 25 timesteps [0.01s 53MB]

And the output of gdalinfo :

Driver: netCDF/Network Common Data Format
Files: NEWA_grid-2017-01-23.nc
NEWA_grid-2017-01-23.nc.aux.xml
Size is 512, 512
Coordinate System is `'
Metadata:
NC_GLOBAL#CDI=Climate Data Interface version 1.9.0 (http://mpimet.mpg.de/cdi)
NC_GLOBAL#CDO=Climate Data Operators version 1.9.0 (http://mpimet.mpg.de/cdo)
NC_GLOBAL#Conventions=CF-1.6
NC_GLOBAL#experiment=Production Run
NC_GLOBAL#history=Thu Jun 13 17:34:34 2019: cdo setgrid,grid.txt NEWA-2017-01-23.nc NEWA_grid-2017-01-23.nc
Thu Jun 13 16:13:42 2019: cdo seltimestep,-26/-2 2017_01_NEWA-2017-01-15_12-SP.nc NEWA-2017-01-23.nc
NC_GLOBAL#institution=The NEWA Consortium
NC_GLOBAL#title=NEWA Timeseries
Subdatasets:
SUBDATASET_1_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":XLONG
SUBDATASET_1_DESC=[384x384] longitude (32-bit floating-point)
SUBDATASET_2_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":XLAT
SUBDATASET_2_DESC=[384x384] latitude (32-bit floating-point)
SUBDATASET_3_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":XLAT_2
SUBDATASET_3_DESC=[384x384] XLAT_2 (64-bit floating-point)
SUBDATASET_4_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":XLON
SUBDATASET_4_DESC=[384x384] XLON (64-bit floating-point)
SUBDATASET_5_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":ALPHA
SUBDATASET_5_DESC=[384x384] ALPHA (64-bit floating-point)
SUBDATASET_6_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":HFX
SUBDATASET_6_DESC=[25x384x384] HFX (64-bit floating-point)
SUBDATASET_7_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":HGT
SUBDATASET_7_DESC=[384x384] HGT (64-bit floating-point)
SUBDATASET_8_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":PBLH
SUBDATASET_8_DESC=[25x384x384] PBLH (64-bit floating-point)
SUBDATASET_9_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":WS
SUBDATASET_9_DESC=[25x7x384x384] WS (64-bit floating-point)
SUBDATASET_10_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":WD
SUBDATASET_10_DESC=[25x7x384x384] WD (64-bit floating-point)
SUBDATASET_11_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":PD
SUBDATASET_11_DESC=[25x7x384x384] PD (64-bit floating-point)
SUBDATASET_12_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":PRECIP
SUBDATASET_12_DESC=[25x384x384] PRECIP (64-bit floating-point)
SUBDATASET_13_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":PSFC
SUBDATASET_13_DESC=[25x384x384] PSFC (64-bit floating-point)
SUBDATASET_14_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":Q
SUBDATASET_14_DESC=[25x7x384x384] Q (64-bit floating-point)
SUBDATASET_15_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":Q2
SUBDATASET_15_DESC=[25x384x384] Q2 (64-bit floating-point)
SUBDATASET_16_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":RHO
SUBDATASET_16_DESC=[25x384x384] RHO (64-bit floating-point)
SUBDATASET_17_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":T
SUBDATASET_17_DESC=[25x7x384x384] T (64-bit floating-point)
SUBDATASET_18_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":T2
SUBDATASET_18_DESC=[25x384x384] T2 (64-bit floating-point)
SUBDATASET_19_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":TKE
SUBDATASET_19_DESC=[25x7x384x384] TKE (64-bit floating-point)
SUBDATASET_20_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":TSK
SUBDATASET_20_DESC=[25x384x384] TSK (64-bit floating-point)
SUBDATASET_21_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":WD10
SUBDATASET_21_DESC=[25x384x384] WD10 (64-bit floating-point)
SUBDATASET_22_NAME=NETCDF:"NEWA_grid-2017-01-23.nc":WS10
SUBDATASET_22_DESC=[25x384x384] WS10 (64-bit floating-point)
Corner Coordinates:
Upper Left ( 0.0, 0.0)
Lower Left ( 0.0, 512.0)
Upper Right ( 512.0, 0.0)
Lower Right ( 512.0, 512.0)
Center ( 256.0, 256.0)

Thank you for your time.


Replies (6)

RE: WRF file in QGIS - Added by Uwe Schulzweida almost 5 years ago

cdo griddes -setgridtype,lonlat -selgrid,2 infile.nc > mygrid
cdo setgrid,mygrid infile.nc outfile.nc

RE: WRF file in QGIS - Added by Manuel Ariza almost 5 years ago

Thank you very much, it actually worked. I just had to select the grid to change

RE: WRF file in QGIS - Added by joao ferreira almost 3 years ago

Hi

Doing:

cdo griddes -setgridtype,lonlat -selgrid,2 infile.nc > mygrid
cdo setgrid,mygrid infile.nc outfile.nc

seemed to work for me to change from wrf curvilinear mercator projection to lon lat.

However the produced lat is not evenly spaced and packages based on gdal failed to put the pixels at the right place because they assume wrongly that lat is evenly spaced.

See for example the output of:

gdalinfo tg.nc

panoply maps it very well but it already did it with the original file

Can you help?

Thanks

tg.nc (487 KB) tg.nc

RE: WRF file in QGIS - Added by Karin Meier-Fleischer almost 3 years ago

Hi Manuel,

cdo sinfo tg.nc 

   File format : NetCDF4 classic
    -1 : Institut Source   T Steptype Levels Num    Points Num Dtype : Parameter name
     1 : unknown  unknown  v instant       1   1     59400   1  F64  : tg            
   Grid coordinates :
     1 : lonlat                   : points=59400 (180x330)
                              lon : -11.8279 to -5.427936 by 0.035754 degrees_east
                              lat : 35.93687 to 44.87202 degrees_north
   Vertical coordinates :
     1 : surface                  : levels=1
   Time coordinate :  1 step
     RefTime =  2015-01-01 23:59:59  Units = days  Calendar = proleptic_gregorian
  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
  2015-01-01 23:59:59

Target grid constant lat interval:

#
# gridID 1
#
gridtype  = lonlat
gridsize  = 59400
xsize     = 180
ysize     = 330
xname     = lon
xlongname = "longitude" 
xunits    = "degrees_east" 
yname     = lat
ylongname = "latitude" 
yunits    = "degrees_north" 
xfirst    = -11.8279008865356
xinc      = 0.0357539960125971
yfirst    = 35.9368667602539
yinc      = 0.02707612121212

Remap to regular lonlat grid:

cdo remapnn,grid_const.txt tg.nc o.nc

   File format : NetCDF4 classic
    -1 : Institut Source   T Steptype Levels Num    Points Num Dtype : Parameter ID
     1 : unknown  unknown  v instant       1   1     59400   1  F64  : -1            
   Grid coordinates :
     1 : lonlat                   : points=59400 (180x330)
                              lon : -11.8279 to -5.427936 by 0.035754 degrees_east
                              lat : 35.93687 to 44.84491 by 0.02707612 degrees_north
   Vertical coordinates :
     1 : surface                  : levels=1
   Time coordinate :  1 step
     RefTime =  2015-01-01 23:59:59  Units = days  Calendar = proleptic_gregorian
  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss  YYYY-MM-DD hh:mm:ss
  2015-01-01 23:59:59

-Karin

RE: WRF file in QGIS - Added by joao ferreira almost 3 years ago

Hi

Remaping involves errors and it was what i wanted to avoid in the first place.

this is a problem of software visualization.

In this case the software is based in gdal and gdal assumes constant lat spacing which is totally wrong and puts the pixels at the wrong places in latitude.

As i told, panoply and arcgis maps well but qgis and others dont... I wonder if i can introduce some info in the file that forces gdal to behave...

Thanks

Joao

RE: WRF file in QGIS - Added by Karin Meier-Fleischer almost 3 years ago

Sorry, I'm not a GDAL expert. You have to look for the requirements which are needed by GDAL.

    (1-6/6)