

In the first function we must indicate the number of cores we want to use. Since our dataset is large, we include this function in parallelization functions.įor the parallelization we start and end always with the beginClusterr() and endCluster().

In the raster package we have the stackApply() function that allows us to apply another function on groups of layers, or rather, indexes. Therefore, the first thing we do is to create a vector, indicating the day of the year for the entire time series. In this step the objective is to calculate the average maximum temperature for each day of the year. So we can easily plot any day of the 41,638 days we have.

To access any layer we use ] with the corresponding index. It also tells us that it only points to the data source and has not imported them into the memory, which makes it easier to work with large datasets. The RasterBrick object details show you all the necessary metadata: the resolution, the dimensions or the type of projection, or the name of the variable. # crs : +proj=longlat +datum=WGS84 +no_defs Tmx <- brick("tmax_pen.nc", varname = "tx") # Loading required namespace: ncdf4 tmx # metadata # class : RasterBrick In our dataset we only have one variable, therefore it would not be necessary to use the varname argument. The first function only allows you to import a single layer, instead, the last two functions are used for multidimensional data. The main import functions are: raster(), stack() and brick(). In this post we will use the raster package since it is somewhat easier, with some very useful and more universal functions for all types of raster format. Actually, the raster package use the first package to import the netCDF datasets. nc extension can be imported via two main packages: 1) ncdf4 and 2) raster. If(!require("showtext")) install.packages("showtext")įor those with less experience with tidyverse, I recommend the short introduction on this blog ( post). If(!require("sysfonts")) install.packages("sysfonts") If(!require("raster")) install.packages("raster") If(!require("gifski")) install.packages("gifski") If(!require("ggthemes")) install.packages("ggthemes") If(!require("sf")) install.packages("sf") If(!require("lubridate")) install.packages("lubridate") If(!require("rnaturalearth")) install.packages("rnaturalearth") If(!require("tidyverse")) install.packages("tidyverse") Simple Feature: import, export and manipulate vector data In this post we will use the following packages: PackagesĬollection of packages (visualization, manipulation): ggplot2, dplyr, purrr, etc.
