rcompositerastervis

How to create weekly composite from 5-consecutive day


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


Solution

  • 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