1

I'm an absolutely new one in R (it's my second day), it's a little bit difficult for me. So, sorry for this question, but I really need help.

I've already read R - Plotting netcdf climate data Plot NetCDF variable-grid data file using ggplot2: "Vector is too large" error but still don't understand.

I've got to plot NMF2 from this set of data in geo coordinates https://drive.google.com/file/d/0B6IqnlmRMSpcNFBXWWlha1JUUzQ/view?usp=sharing

The easiest way to do it was:

>library(raster)
>varRaster<-raster("F18-SSUSI_EDR-NIGHT-DISK_DD.20150107_SN.26920-00_DF.NC", varname="NMF2_DISK")
>cols <- rev(rainbow(255))
>plot(varRaster, col=cols)

Now I've got a plot, but the grid is not a geo one. So there are two questions:

  1. What I have to do to get the correct grid?
  2. How is it possible to add the world map layer?

Thank you in advance for your help.

UPGRADE

Taking a better look to my data I found out that I have to change missval to NA and also I need to transpose. The best variant I've found is this tutorial and everything is almost all right but the data is now strained all ower the map...And it has to be just a wide track of sattelites scan.

I can't put here the image, because my reputation is very low:(

library(raster)
library(ncdf)
data = open.ncdf("F18-SSUSI_EDR-NIGHT-DISK_DD.20150107_SN.26920-00_DF.NC")

lon=get.var.ncdf(data,"PIERCEPOINT_NIGHT_LONGITUDE")
lat=get.var.ncdf(data,"PIERCEPOINT_NIGHT_LATITUDE")
lon<-lon-180
dim(lat)

nmf2=get.var.ncdf( ex.nc, "NMF2_DISK")
nmf2[nmf2 == -1e+30] <- NA
dim(nmf2)

nmf2_un=get.var.ncdf( ex.nc, "NMF2_DISK_UNCERTAINTY")
nmf2_un[nmf2_un == -1e+30] <- NA

nmf2_1 <- raster(t(nmf2)[ncol(nmf2):1, ])
nmf2_un_1 <- raster(t(nmf2_un)[ncol(nmf2_un):1, ])

w <- brick(nmf2_1, nmf2_un_1)

projection(w) <- CRS("+init=epsg:4326")
extent(w) <- c(min(lon), max(lon), min(lat), max(lat))
plot(w[[1]])

library(maptools)
data(wrld_simpl)
plot(wrld_simpl, add = TRUE)

I would be very glad if somebody can tell me what's wrong!

UPDATE 2

Tried to use raster only. Still have a mistake with projection library(raster)

inputfile <- "F18-SSUSI_EDR-NIGHT-DISK_DD.20150107_SN.26920-00_DF.NC"

lat <- raster(inputfile, varname="PIERCEPOINT_NIGHT_LATITUDE")
lon <- raster(inputfile, varname="PIERCEPOINT_NIGHT_LONGITUDE")

plat <- rasterToPoints(lat)
plon <- rasterToPoints(lon)
lonlat <- cbind(plon[,3], plat[,3])

lonlat <- SpatialPoints(lonlat, proj4string = CRS("+proj=longlat    +datum=WGS84"))
extent(lonlat)
#class       : Extent 
#xmin        : 0.008961686 
#xmax        : 359.983 
#ymin        : -84.95161 
#ymax        : 89.68419 

pr <- raster(inputfile, varname="NMF2_DISK")
extent(pr) <- extent(lonlat)
pr
#class       : RasterLayer 
#dimensions  : 408, 13, 5304  (nrow, ncol, ncell)
#resolution  : 27.69031, 0.4280289  (x, y)
#extent      : 0.008961686, 359.983, -84.95161, 89.68419  (xmin, xmax, ymin,  ymax)
#coord. ref. : NA 
#data source : C:\Users\Svetlana\Science\GUVI\R\SSUSI\F18-SSUSI_EDR-NIGHT- DISK_DD.20150107_SN.26920-00_DF.NC 
#names       : NMF2_DISK 
#zvar        : NMF2_DISK 

r <- projectRaster(pr, crs=CRS("+proj=longlat +datum=WGS84"))
#Error in projectRaster(pr, crs = CRS("+proj=longlat +datum=WGS84")) : 
#  input projection is NA

What's wrong?

And the other question is how to work with missval while using raster? I mean that in spite of using NA there is 8 000 000 for missed values of data. What I have to do with this?

Community
  • 1
  • 1
  • Use ggplot and rasterVis! For remapping to a lat-lon grid, which is what you need for plotting, you can try [this answer](https://gis.stackexchange.com/questions/120900/plotting-netcdf-file-using-lat-and-lon-contained-in-variables); also have a look [here](http://zevross.com/blog/2014/07/16/mapping-in-r-using-the-ggplot2-package/). For adding a world map in ggplot you can use e.g. [map_data](http://docs.ggplot2.org/0.9.3.1/map_data.html), or put the data in a dataframe and plot with `geom_path()`. For projections you can look at [coord_map](http://docs.ggplot2.org/current/coord_map.html). – AF7 Mar 25 '15 at 08:29
  • Thank you so much for your answer. Unfortunately I still have some problems. – Svetlana Kalashnikova Mar 25 '15 at 22:19
  • I've described in upgrade:) Taking a better look to my data I found out that I have to change missval to NA and also I need to transpose. The best variant I've found is this [tutorial](https://rpubs.com/alobo/vectorplot) and everything is almost all right but the data is now strained all ower the map...And it has to be just a wide track of sattelites scan. – Svetlana Kalashnikova Mar 26 '15 at 11:55
  • Do not use both ncdf (by the way you should use ncdf4) and raster. Use only raster, like in the example I linked, this will help you in the future. For example, for shifting by 180 degrees, you can use rotate(). Can you upload an example of your data somewhere? It's difficult to understand what you want to do without access to the data and to a picture of the result. – AF7 Mar 26 '15 at 12:10
  • Thank you! I've shared it, here is the [example of data](https://drive.google.com/file/d/0B6IqnlmRMSpcNFBXWWlha1JUUzQ/view?usp=sharing) – Svetlana Kalashnikova Mar 26 '15 at 12:31
  • Thank you @AF7 ! I tried to use raster only as in the example, but there still an error. I've described it in the Update 2. – Svetlana Kalashnikova Mar 27 '15 at 11:29
  • The error is just what it says: you forgot to set the projection for pr: `projection(pr) <- whatever_crs`...What crs your data has I don't know, you must find out yourself. – AF7 Mar 27 '15 at 15:40

0 Answers0