0

I have a NetCDF file of salinity in Indonesia water with 4 dimensions (lon, lat, depth and time). How to create create weekly composite from my data download data here: https://onedrive.live.com/redir?resid=6FFDD661570C7D0A%21177 output map here: https://onedrive.live.com/redir?resid=6FFDD661570C7D0A%21176

I would like to convert the raster into vector and the use apply to get the mean, but I have problem to plot the vector data using rasterVis

www
  • 38,575
  • 12
  • 48
  • 84
Eko Susilo
  • 250
  • 2
  • 15
  • It is not strictly weekly mean but rather 5-day mean or pentad mean. –  Apr 15 '15 at 01:46

1 Answers1

0

With your example, nor really complicated:

# load needed librairies
library(rasterVis)

# open the data
salinity <- brick("data.nc", varname = "salinity")

salinity
# class       : RasterBrick 
# dimensions  : 61, 61, 3721, 5  (nrow, ncol, ncell, nlayers)
# resolution  : 0.08333333, 0.08333333  (x, y)
# extent      : 104.9583, 110.0417, -5.041667, 0.04166667  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=longlat +datum=WGS84 
# data source : data.nc 
# names       : X252331200, X252417600, X252504000, X252590400, X252676800 
# z-value     : 252331200, 252417600, 252504000, 252590400, 252676800 
# varname     : salinity 
# level       : 1 

# Calculate the mean
m.salinity <- mean(salinity)

m.salinity

# class       : RasterLayer 
# dimensions  : 61, 61, 3721  (nrow, ncol, ncell)
# resolution  : 0.08333333, 0.08333333  (x, y)
# extent      : 104.9583, 110.0417, -5.041667, 0.04166667  (xmin, xmax, ymin, ymax)
# coord. ref. : +proj=longlat +datum=WGS84 
# data source : in memory
# names       : layer 
# values      : 18.85652, 31.84299  (min, max)

enter image description here

  • @EkoSusilo If you have daily data for a year, it will be off course more complex. –  Apr 16 '15 at 09:08
  • Yes you right,this is only sample data. Actually i have more than 5 year data. In my opinion, i have to use loop with 7-days range to make raster from my data that only consist 7-days data – Eko Susilo Apr 16 '15 at 13:06
  • @EkoSusilo You should gave a look a the `rts` package. –  Apr 17 '15 at 01:07
  • a simple question about hoe to define the fix value for color ramp, i want to display all this data with range 10-60. I tried to use **at** but still not working **levelplot(subset(salinity, 1), contour=T, at=seq(10, 60, 5), margin=FALSE)** – Eko Susilo Apr 18 '15 at 14:27