# Extracting data from netcdf stacked file

**URL:** https://discourse.julialang.org/t/extracting-data-from-netcdf-stacked-file/90927
**Category:** New to Julia
**Created:** [November 28, 2022, 12:33am UTC](https://discourse.julialang.org/t/extracting-data-from-netcdf-stacked-file/90927 "2022-11-28T00:33:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![lmonteiro](https://avatars.discourse-cdn.com/v4/letter/l/eb9ed0/32.png) [@lmonteiro](https://discourse.julialang.org/u/lmonteiro)
#### Post date: [November 28, 2022, 12:33am UTC](https://discourse.julialang.org/t/extracting-data-from-netcdf-stacked-file/90927/1 "2022-11-28T00:33:06Z")

</div>

Hi everybody,  
I have several nc files from AgERA5 database and I want to do 2 main tasks:  
1- stack them in a unique nc file; and  
2- extract the data series from a specific pair of lat lon coordinates from the stacked nc file.

Some ideas how to do it?

Many thanks in advance,

LM

---

<div class="post-metadata">

### Author: ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)
#### Post date: [November 28, 2022, 1:12am UTC](https://discourse.julialang.org/t/extracting-data-from-netcdf-stacked-file/90927/2 "2022-11-28T01:12:43Z")

</div>

Don’t know the structure of those `AgERA5` nc files but if they are 2D you may be able to do that with [GMT.jl](https://github.com/GenericMappingTools/GMT.jl). Use the [stackgrids](https://www.generic-mapping-tools.org/GMTjl_doc/documentation/utilfuns/#stackgrids) function to create the _cube_ and then use `grdinterpolate` to do the interpolation. Sorry, this module has not yet seen its manual fully _translated_ to [GMT.jl](https://github.com/GenericMappingTools/GMT.jl) so one still have to resort to the original GMT C man or the short doc provided by `?grdinterpolate`. The use should something like:

```julia
D = grdinterpolate("the_cube_file_name", track=(x,y))

```

or, if the cube is not too big, load it with into Julia with

```julia
C = grdinterpolate("the_cube_file_name");

```

and next do the interpolation with

```julia
D = grdinterpolate([x y], C)

```

Note, if you are on Linux you’ll probably will need to install GMT (the C lib) manually before installing GMT.jl (sorry, not my fault), or use Julia 1.9alpha.

---

<div class="post-metadata">

### Author: ![j\_u](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_u/32/219081_2.png) [@j\_u](https://discourse.julialang.org/u/j_u)
#### Post date: [November 28, 2022, 3:14am UTC](https://discourse.julialang.org/t/extracting-data-from-netcdf-stacked-file/90927/3 "2022-11-28T03:14:28Z")

</div>

How does _AgERA5_ differ from _ECMWF ERA5_? I guess, you could also probably use _cdo_ (its written in _Fortran_ with _CPython_ interface [[Climate Data Operators - Wikipedia](https://en.wikipedia.org/wiki/Climate_Data_Operators)]. Works pretty well with _Julia_ thanks to _PyCall.jl_ and _PythonCall.jl_. EDIT: Just took a quick look at _AgERA5_. I believe, provided suggestion, even though, not pure _Julia_, should work.
