[R-sig-Geo] Combining different RasterBricks maintaining z-values (dates)

Stephen Stewart @tephen@@tew@rt85 @end|ng |rom gm@||@com
Sat Nov 30 00:37:46 CET 2019


 Hi Jesús,

You can use the getZ and setZ functions in the raster package to extract
and then reassign Z values.

> rain = brick("C:/Users/sbste/Downloads/2000.monthly_rain.nc")
> rain_z = getZ(rain)
>
> rain_x2 = stack(rain,rain)
> getZ(rain_x2)
NULL
> rain_x2 = setZ(rain_x2,c(rain_z,rain_z),name = "Date")
> rain_x2
class      : RasterStack
dimensions : 681, 841, 572721, 24  (nrow, ncol, ncell, nlayers)
resolution : 0.05, 0.05  (x, y)
extent     : 111.975, 154.025, -44.025, -9.975  (xmin, xmax, ymin, ymax)
crs        : +proj=longlat +datum=WGS84
names      : X2000.01.16.1, X2000.02.15.1, X2000.03.16.1, X2000.04.16.1,
X2000.05.16.1, X2000.06.16.1, X2000.07.16.1, X2000.08.16.1, X2000.09.16.1,
X2000.10.16.1, X2000.11.16.1, X2000.12.16.1, X2000.01.16.2, X2000.02.15.2,
X2000.03.16.2, ...
Date        : 2000-01-16 - 2000-12-16 (range)

Cheers,

Steve

On Sat, 30 Nov 2019 at 10:06, J Rojo <jru85yebe using hotmail.com> wrote:

> Hi everyone
> I am trying to combine different RasterBricks into one and if use the
> function ‘brick’ does not work, and with ‘stack’ remove the z-values as
> RasterStack does not include it.
> The objective is to do a loop for reading and processing one nc file for
> each iterative step, and include each Brick into a big general Brick
> One example with two RasterBricks
>
> > a <-
> brick("tasmax_day_BCSD_rcp45_r1i1p1_MIROC-ESM-CHEM/tasmax_day_BCSD_rcp45_r1i1p1_MIROC-ESM-CHEM_2020.nc”);
> a
>
> class      : RasterBrick
> dimensions : 720, 1440, 1036800, 366  (nrow, ncol, ncell, nlayers)
> resolution : 0.25, 0.25  (x, y)
> extent     : 0, 360, -90, 90  (xmin, xmax, ymin, ymax)
> crs        : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> source     :
> /Volumes/Copy/NASA/tasmax_day_BCSD_rcp45_r1i1p1_MIROC-ESM-CHEM/tasmax_day_BCSD_rcp45_r1i1p1_MIROC-ESM-CHEM_2020.nc
>
> names      : X2020.01.01, X2020.01.02, X2020.01.03, X2020.01.04,
> X2020.01.05, X2020.01.06, X2020.01.07, X2020.01.08, X2020.01.09,
> X2020.01.10, X2020.01.11, X2020.01.12, X2020.01.13, X2020.01.14,
> X2020.01.15, ...
> Date       : 2020-01-01, 2020-12-31 (min, max)
> varname    : tasmax
>
> > b <-
> brick("tasmax_day_BCSD_rcp45_r1i1p1_MIROC-ESM-CHEM/tasmax_day_BCSD_rcp45_r1i1p1_MIROC-ESM-CHEM_2021.nc”);
> b
>
> class      : RasterBrick
> dimensions : 720, 1440, 1036800, 365  (nrow, ncol, ncell, nlayers)
> resolution : 0.25, 0.25  (x, y)
> extent     : 0, 360, -90, 90  (xmin, xmax, ymin, ymax)
> crs        : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> source     :
> /Volumes/Copy/NASA/tasmax_day_BCSD_rcp45_r1i1p1_MIROC-ESM-CHEM/tasmax_day_BCSD_rcp45_r1i1p1_MIROC-ESM-CHEM_2021.nc
>
> names      : X2021.01.01, X2021.01.02, X2021.01.03, X2021.01.04,
> X2021.01.05, X2021.01.06, X2021.01.07, X2021.01.08, X2021.01.09,
> X2021.01.10, X2021.01.11, X2021.01.12, X2021.01.13, X2021.01.14,
> X2021.01.15, ...
> Date       : 2021-01-01, 2021-12-31 (min, max)
> varname    : tasmax
>
> ## Now I would like to combine both RasterBrick into one big RasterBrick
> with 731 layer, maintaining the Date as z-value
> > c <- stack(a, b) # If I do a ‘stack’ z-value is not considered
> > c <- brick(a, b) # If I do a ‘brick’ does not work and the file when
> saved is very weighted, and any case z-value is not maintained
>
> Any idea about how I can combine in easy way the layers for multiple
> bricks according to the z-value
> I am grateful any help, thank you so much
>
> Jesús Rojo
>
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list