NetCDF files in QGIS completely flipped
Added by Oscar Mira over 6 years ago
Hi all,
It seems that there is not an easy way to deal with NetCDF files in QGIS, but is frequently used as format for sharing data.
I'm trying to open some environmental data from CEDA, but they appear as if QGIS was reading the Latitude as longitude, and vice versa.
the layer appears mirrored and rotated 90 degrees
After searching here and in other forums I installed CDO in Cygwin and was able to flip it either vertically or horizontally with invertlon and invertlan
$ cdo invertlat ATS_LST_3PUUOL200208XX_0.50X0.50_CS3_LSM.nc fileinvertlat.nc Warning (cdf_set_var): Inconsistent variable definition for lat! Warning (cdf_set_var): Inconsistent variable definition for lon! Warning (cdf_read_coordinates): Coordinate variable lon has to many dimensions (3), skipped! Warning (cdf_read_coordinates): Coordinate variable lat has to many dimensions (3), skipped! cdo invertlat: Processed 4147200 values from 8 variables over 1 timestep [0.30s 39MB] $ cdo invertlon ATS_LST_3PUUOL200208XX_0.50X0.50_CS3_LSM.nc fileinvertlon.nc Warning (cdf_set_var): Inconsistent variable definition for lat! Warning (cdf_set_var): Inconsistent variable definition for lon! Warning (cdf_read_coordinates): Coordinate variable lon has to many dimensions (3), skipped! Warning (cdf_read_coordinates): Coordinate variable lat has to many dimensions (3), skipped! cdo invertlon: Processed 4147200 values from 8 variables over 1 timestep [0.28s 39MB]
So now it's not mirrored, but still not in place.
I don't know how should proceed next to rotate it, or even if this is the right approach to solve the problem.
The layers are from here: http://data.ceda.ac.uk/neodc/aatsr_multimission/aatsr-v2.1/data/UOL_LST_3P/monthly/2002/
If you don't have access I saved a sample here: https://www.dropbox.com/sh/c2ua7q7n3ki0h3m/AAD1Ny8-E0z-zbbNzIAOwJ_Qa?dl=0
Any input?
flipped.jpg (147 KB) flipped.jpg | first step | ||
EX129.jpg (179 KB) EX129.jpg |
Replies (8)
RE: NetCDF files in QGIS completely flipped - Added by Ralf Mueller over 6 years ago
check operator transxy
- it's not documented, but does what you what, I guess.
RE: NetCDF files in QGIS completely flipped - Added by Oscar Mira over 6 years ago
Thanks, that did de trick. Although the layer is still oversized and out of place.
I tried again different CRS (EPSG: 4326, 3035, 3857, 27700, 23035) after using "transxy" just in case, but that didn't work. Now I'm really stuck here
notfixed.jpg (236 KB) notfixed.jpg |
RE: NetCDF files in QGIS completely flipped - Added by Ralf Mueller over 6 years ago
I have No idea, what you want to achieve. Crs epsg doesnt Tell me anything. Do you want to interpolate to a coarser Grid?
RE: NetCDF files in QGIS completely flipped - Added by Oscar Mira over 6 years ago
Well, I'll like to fit those netCDF layers with the rest and then use "point sampling tool" or similar to extract the info from those nc layer in the location of my sampling points.
I have done this before, but never had such problem working with different layers.
RE: NetCDF files in QGIS completely flipped - Added by Ralf Mueller over 6 years ago
so you want to merge several files (one for each layer) into a single file?
RE: NetCDF files in QGIS completely flipped - Added by Oscar Mira over 6 years ago
No, I only want to see all the layer/files in the same project, I'll develop it:
I have the coordinates of 50 localities and I want to know the temperature, solar radiation, and the values of other variables at those locations in different years.
I have done this kind of work several times in QGIS:
-create a csv table with the names and coordinates of the localities.
-Create a project in QGIS
-Add delimited text layer > create a shapefile layer of points with the csv table (layer 1)
-look for / request raster layers with the information you need. For example, I have worked previously with georeferenced tifs of climate data from WorldClim and NASA webpages.
-Then add each downloaded file as a raster layer in the QGIS project. Let's say we add two layers, one with average temperature and one with average pluviosity.
-Use "point sampling tool" or other similar tools (In QGIS there is various ways to do this) to extract the information from the raster layers at the same location of the datapoints/localities (layer 1). You can do this because all the files are properly georeferenced and scaled and they overlap. Let's say that the point that corresponds to the locality of London in layer 1 appears where London is supposed to be in the raster layers.
-You'll end up with a csv table, in each row there will be the coordinates of one locality/datapoint and the value of average temperature and pluviosity at that point.
This time I was trying to do the same with those NetCDF files, I downloaded them and the authors told me they are in WSG84, but I'm unable to overlap them with the other layers, so I can't project my datapoints in them to extract the values of the variables. At first I thought It was only a problem of Coordinate Reference System, but it seems is not. Then I used GLDA in OSGeo4W to mirror it, but I couldn't rotate it. Then I discovered CDO and it seems the way to go, but still don't know how to fix it. As you can see in the last picture Europe in the NetCDF layer is not i the same place and position that in other layers (the pink Europe coastline added as reference).
RE: NetCDF files in QGIS completely flipped - Added by Renato Cruz Senna about 6 years ago
Oscar Mira wrote:
Hi all,
It seems that there is not an easy way to deal with NetCDF files in QGIS, but is frequently used as format for sharing data.
I'm trying to open some environmental data from CEDA, but they appear as if QGIS was reading the Latitude as longitude, and vice versa.the layer appears mirrored and rotated 90 degrees
After searching here and in other forums I installed CDO in Cygwin and was able to flip it either vertically or horizontally with invertlon and invertlan
[...]
So now it's not mirrored, but still not in place.
I don't know how should proceed next to rotate it, or even if this is the right approach to solve the problem.
The layers are from here: http://data.ceda.ac.uk/neodc/aatsr_multimission/aatsr-v2.1/data/UOL_LST_3P/monthly/2002/
If you don't have access I saved a sample here: https://www.dropbox.com/sh/c2ua7q7n3ki0h3m/AAD1Ny8-E0z-zbbNzIAOwJ_Qa?dl=0Any input?
Hello...
I'm new here, and I apologize in advance for my English,
I had the same problem, and the solution was to use some other file (NetCDF) read correctly by QGIS, and follow the following steps:
- use of the "remapbil" for the same specifications of the flipped file.
- adjustment of variable names with "chname"
- replace the variable with the "replace" command.
RE: NetCDF files in QGIS completely flipped - Added by Karin Meier-Fleischer about 6 years ago
Hi,
just to get this more clear, QGIS seems to read the input (time,latitude,longitude) but the variables have the dimensions (time,longitude,latitude) = (diurnal,nlon,nlat). The reordering can't be done with CDO because the dimensions of the variables lat and lon are (diurnal,nlon,nlat). CDO approves only 1D and 2D coordinate variables like
lat(nlat)
lon(nlon)
lat(nlon,nlat)
lon(nlon,nlat)
lat(nlat,nlon)
lat(nlat,nlon)
and they shouldn't have the attribute coordinates.
Besides the lat and lon variable contents of diurnal=0 and diurnal=1 are the same.
To remove the diurnal dimension of the lon and lat variables, to reorder the dimensions, and to delete their coordinates attribute you can use e.g. NCL.
script.ncl:
f = addfile("ATS_LST_3PUUOL200208XX_0.50X0.50_CS3_LSM.nc","r") LSM = f->LSM LST = f->LST LST_uncertainty = f->LST_uncertainty NDVI = f->NDVI utc = f->utc zva = f->zva ncld = f->ncld n = f->n lon = f->lon lat = f->lat ;-- night lon/lat; ncl adds attributes diurnal to lon_night = lon(0,:,:) lat_night = lat(0,:,:) ;-- day lon/lat lon_day = lon(1,:,:) lat_day = lat(1,:,:) if(all(lon_night .eq. lon_day)) then print("--> lon equal") end if if(all(lat_night .eq. lat_day)) then print("--> lat equal") end if ;-- delete lon/lat attributes coordinates delete(lat_night@coordinates) delete(lon_night@coordinates) LSM := LSM(diurnal|:,nlat|:,nlon|:) LST := LST(diurnal|:,nlat|:,nlon|:) LST_uncertainty := LST_uncertainty(diurnal|:,nlat|:,nlon|:) NDVI := NDVI(diurnal|:,nlat|:,nlon|:) utc := utc(diurnal|:,nlat|:,nlon|:) zva := zva(diurnal|:,nlat|:,nlon|:) ncld := ncld(diurnal|:,nlat|:,nlon|:) n := n(diurnal|:,nlat|:,nlon|:) lon_night := lon_night(nlat|:,nlon|:) lat_night := lat_night(nlat|:,nlon|:) ;-- write data to file system("rm -rf outfile_ncl.nc") o = addfile("outfile_ncl.nc","c") o->LSM = LSM o->LST = LST o->LST_uncertainty = LST_uncertainty o->NDVI = NDVI o->utc = utc o->zva = zva o->ncld = ncld o->n = n o->lon = lon_night o->lat = lat_nightRun the NCL script
ncl script.ncl
cdo sinfov outfile_ncl.nc File format : NetCDF -1 : Institut Source T Steptype Levels Num Points Num Dtype : Parameter name 1 : unknown unknown c instant 2 1 259200 1 I16 : LSM 2 : unknown unknown c instant 2 1 259200 1 I16 : LST 3 : unknown unknown c instant 2 1 259200 1 I16 : LST_uncertainty 4 : unknown unknown c instant 2 1 259200 1 I16 : NDVI 5 : unknown unknown c instant 2 1 259200 1 I16 : utc 6 : unknown unknown c instant 2 1 259200 1 I16 : zva 7 : unknown unknown c instant 2 1 259200 1 I32 : ncld 8 : unknown unknown c instant 2 1 259200 1 I32 : n Grid coordinates : 1 : curvilinear : points=259200 (720x360) lon : -179.75 to 179.75 by 0.5 degrees_east circular lat : -89.75 to 89.75 by 0.5 degrees_north Vertical coordinates : 1 : generic : levels=2 diurnal : 0 to 1 1 cdo sinfon: Processed 8 variables [0.02s 28MB]
-Karin
Bildschirmfoto.png (219 KB) Bildschirmfoto.png | variable LST |