# Tuple related error

**URL:** <https://discourse.julialang.org/t/tuple-related-error/107678>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 15, 2023, 5:06pm UTC](https://discourse.julialang.org/t/tuple-related-error/107678 "2023-12-15T17:06:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon6](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leon6/32/205483_2.png) [@Leon6](https://discourse.julialang.org/u/Leon6)\
**Post date:** [December 15, 2023, 5:06pm UTC](https://discourse.julialang.org/t/tuple-related-error/107678/1 "2023-12-15T17:06:02Z")

</div>

Would anyone please help me with this Tuple related error?

Here is my code:

```julia
if A == 1
   DL = 11;           
elseif A == 2
   DL = 21;                  
end
ds3 = NCDataset("$(P0)/Input/TSO2/xxx.nc");
T = ds3["abc"][:,:,DL]; 
close(ds3);

```

The variable abc is a 3-dimensional array with the size of 360x180x33.

Here is the error message:

```julia
**ERROR:** LoadError: BoundsError: attempt to access Tuple{Colon, Colon, Int64} at index [4]
Stacktrace:
[1] **getindex**
@ ./tuple.jl:29 [inlined]
[2] **ncsub2**
@ ~/.julia/packages/NCDatasets/st9Jz/src/variable.jl:436 [inlined]
[3] **getindex(**::NCDatasets.Variable{Float32, 4, NCDataset{Nothing}}, ::Colon, ::Colon, ::Int64**)**
@ NCDatasets ~/.julia/packages/NCDatasets/st9Jz/src/variable.jl:484
[4] **getindex(**::CommonDataModel.CFVariable{Union{Missing, Float32}, 4, NCDatasets.Variable{Float32, 4, NCDataset{Nothing}}, NCDatasets.Attributes{NCDataset{Nothing}}, NamedTuple{(:fillvalue, :missing_values, :scale_factor, :add_offset, :calendar, :time_origin, :time_factor), Tuple{Float32, Tuple{}, Vararg{Nothing, 5}}}}, ::Colon, ::Colon, ::Int64**)**
@ CommonDataModel ~/.julia/packages/CommonDataModel/pO4st/src/cfvariable.jl:390
[5] top-level scope

```

Many thanks.

---

<div class="post-metadata">

**Author:** ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)\
**Post date:** [December 15, 2023, 5:24pm UTC](https://discourse.julialang.org/t/tuple-related-error/107678/2 "2023-12-15T17:24:16Z")

</div>

Can you post a working example for testing? (see this [post](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757) on making it easier to get help)

Just looking at the error, I would wager a guess that the issue is your code is trying to access some element in the NETCDF file that doesn’t exist.

---

<div class="post-metadata">

**Author:** ![Leon6](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leon6/32/205483_2.png) [@Leon6](https://discourse.julialang.org/u/Leon6)\
**Post date:** [December 15, 2023, 5:32pm UTC](https://discourse.julialang.org/t/tuple-related-error/107678/3 "2023-12-15T17:32:48Z")

</div>

Many thanks for the reply.

I’m able to make it work by changing the code to below:

```julia
ds3 = NCDataset("$(P0)/Input/TSO2/xxx.nc");
T = ds3["abc"][:,:,:]; 
close(ds3);
T = T[:,:,DL];

```

This is so weird. Do you know why Julia is so picky here?

---

<div class="post-metadata">

**Author:** ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)\
**Post date:** [December 18, 2023, 1:07pm UTC](https://discourse.julialang.org/t/tuple-related-error/107678/4 "2023-12-18T13:07:09Z")

</div>

First I’ll just note that this doesn’t seem to be a “Julia” thing, meaning its not the language itself but rather the specifics of the package providing `NCDataset`.

I really don’t know the answer, but if I had to guess, maybe in the initial code you were trying to access the data before it was read, whereas in the solution the data has been read into variable `T` making it possible to index? 🤷‍♂️

It would probably be worth looking in the `NCDataset` documentation to see if there is a recommended way to do accomplish this task.

---

<div class="post-metadata">

**Author:** ![Alexander-Barth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexander-barth/32/3692_2.png) [@Alexander-Barth](https://discourse.julialang.org/u/Alexander-Barth)\
**Post date:** [February 19, 2024, 8:57pm UTC](https://discourse.julialang.org/t/tuple-related-error/107678/5 "2024-02-19T20:57:37Z")

</div>

The stack-traces indicates that the variable is actually 4D dimensional:

> [@Leon6](#):
>
> `CommonDataModel.CFVariable{Union{Missing, Float32}, 4, ...}`

The exact output of `size(ds3["abc"])` would be useful. In the case it its size is `(360,180,33,1)`, you can also use `ds3["abc"][:,:,DL,1]`.
