3
$\begingroup$

I have download ERA5 netCDF file in order to get precipitation monthly/daily rates for 11 years. But I have realized, there is no option to select my area of interest. It seems it is a big file to handle.

However, I am currently using R language and but still in the basic level.

My question is about if there is anyway to extract precipitation values for a certain area?

$\endgroup$
3
  • $\begingroup$ Please edit your title to reflect the actual question. To answer, there is almost certainly a way in R to read just a part of a netCDF file - but I'm not enough of an R user to tell you what it is. Hopefully somebody will come along and aswer. $\endgroup$ Aug 28, 2019 at 20:37
  • $\begingroup$ @SemidiurnalSimon I've made an edit, how does it look? $\endgroup$
    – uhoh
    Aug 28, 2019 at 20:58
  • $\begingroup$ I'd suggest something like "How to read only parts of a netCDF file in R" or similar. $\endgroup$ Aug 28, 2019 at 21:26

1 Answer 1

2
$\begingroup$

There are two ways to get this done:

1- you can select the specific domain of interest when downloading the files. This is highly preferred when you have to download a large number of variables and years. ERA5 netCDF are offered in two different formats: either at hourly time steps, or at monthly averages (see this). If you need a sub-monthly time steps the global files for many variables for long time periods are extremely heavy in terms of disk space. You could set up a python script to download the data selecting only the domain by following a procedure like the one suggested in this nice post by Reto Stauffer (of course there are other ways to do this).

2- you can download the global netCDF of the variable and year under consideration ad use a software to extract your domain of interest. One of the most efficient systems to do that is using the Climate Data Operator CDO. you could use the sellonlatbox with a command like

cdo sellonlatbox,LON1,LON2,LAT1,LAT2 Input_file_Name.nc Output_file_Name.nc

Or you could use R, as for your case, doing something like:

library(raster)
library(rgdal)

#load your area of interest
setwd("path_domain_shapefile")
domain_shp<-readOGR("shapefile.shp")

#read netCDF
setwd("path_to_ERA5_files_folder")
pr_data<-stack("ERA5_file.nc")

#extract the data for your area of interest
pr_data_domain<-extract(pr_data, domain_shp)

#then you can transform this in a data frame and write it as a csv

As reference for basic operations with spatial data in R, I would suggest this introduction guide.

Hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.