<p>There are two ways to get this done:</p>

<p>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 <a href="https://cds.climate.copernicus.eu/cdsapp#!/search?type=dataset&amp;text=era5" rel="nofollow noreferrer">this</a>). 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 <a href="https://retostauffer.org/code/Download-ERA5/" rel="nofollow noreferrer">nice post by Reto Stauffer</a> (of course there are other ways to do this). </p>

<p>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 <code>sellonlatbox</code> with a command like</p>

<pre><code>cdo sellonlatbox,LON1,LON2,LAT1,LAT2 Input_file_Name.nc Output_file_Name.nc
</code></pre>

<p>Or you could use <code>R</code>, as for your case, doing something like: </p>

<pre><code>library(raster)
library(rgdal)

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

#read netCDF
setwd("path_to_ERA5_files_folder")
pr_data&lt;-stack("ERA5_file.nc")

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

#then you can transform this in a data frame and write it as a csv
</code></pre>

<p>As reference for basic operations with spatial data in <code>R</code>, I would suggest this <a href="http://www.spatialecology.com/beyer/assets/Beyer_Introduction_to_geospatial_analysis_in_R.pdf" rel="nofollow noreferrer">introduction guide</a>.</p>

<p>Hope this helps.</p>

CC BY-SA 4.0
2019-08-29T09:04:09.373Z
2019-08-29T10:30:18.473Z
2019-08-29T10:30:18.473Z
Nemesi
<p>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.  </p>

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

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

CC BY-SA 4.0
2019-08-28T20:37:56.920Z
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.
Semidiurnal Simon
CC BY-SA 4.0
2019-08-28T20:58:33.893Z
@SemidiurnalSimon I've made an edit, how does it look?
uhoh
CC BY-SA 4.0
2019-08-28T21:26:38.667Z
I'd suggest something like "How to read only parts of a netCDF file in R" or similar.
Semidiurnal Simon
<climate><era>
downloading ERA5 netCDF daily data for a decade, how to restrict location to reduce data size?
Ila
# downloading ERA5 netCDF daily data for a decade, how to restrict location to reduce data size?

(Asked by: username_0 on 2019-08-28)

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?

**Tags:** climate, era

> **Comments:**
> **username_1**: 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.  
> **username_2**: @username_1 I've made an edit, how does it look?  
> **username_1**: I'd suggest something like "How to read only parts of a netCDF file in R" or similar.  

---

## 1 answers

### Answer by username_3 on 2019-08-29. Score: 2

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](https://cds.climate.copernicus.eu/cdsapp#!/search?type=dataset&text=era5)). 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](https://retostauffer.org/code/Download-ERA5/) (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](http://www.spatialecology.com/beyer/assets/Beyer_Introduction_to_geospatial_analysis_in_R.pdf).

Hope this helps.


---

