Concatenate/join/merge two cubes along 'ensemble_member' axis

123 views
Skip to first unread message

Ag Stephens

unread,
Oct 18, 2017, 12:14:52 PM10/18/17
to Iris
Hi folks,

I have 2 four-dimensional cubes, as follows:

```
air_temperature / (K)               (Ensemble member: 1; time: 12; projection_y_coordinate: 25; projection_x_coordinate: 15)

air_temperature / (K)               (Ensemble member: 1; time: 12; projection_y_coordinate: 25; projection_x_coordinate: 15)
```

The Ensemble member coordinate variable axis is of length one in each file and has values [1] and [2] in the two separate files. I want Iris to concatenate them into this cube:

```
air_temperature / (K)               (Ensemble member: 2; time: 12; projection_y_coordinate: 25; projection_x_coordinate: 15)
```

I have tried `cubelist.concatenate()` and `cubelist.merge()` but it returns two separate cubes each time. Is there a way to do this?

The input files are here (they are small):



And the code I'm using is:

```
    import iris
    print "\nTrying to group ensemble members now...\n"

    cl = iris.load(files)
    c = cl.concatenate()
    print c
```

Thanks,

Ag

Simon Peatman

unread,
Oct 18, 2017, 12:24:16 PM10/18/17
to Iris
Ag,

Your Cubes each have 'ensemble_member' in their attributes dictionary, one with the value 'r1i1p1' and the other 'r1i1p2'.  Iris won't concatenate the Cubes if the metadata are different like this.  I recommend deleting 'ensemble_member' from the attributes dictionary when you load the Cubes, using a callback function (see https://groups.google.com/forum/#!topic/scitools-iris/oXvGhHP1o3E for details).

Simon

Ag Stephens

unread,
Oct 18, 2017, 4:20:27 PM10/18/17
to Iris
Thanks Simon,

I will give it a try.

Cheers,

Ag

Ag Stephens

unread,
Oct 18, 2017, 4:43:19 PM10/18/17
to Iris
Hi Simon,

Thanks again for your response. I tried this on each of the cubes:

```
del cube.metadata.attributes['ensemble_member']
```

However, the concatenation still failed.

Any idea what else I could try?

Thanks,
Ag

Phil Elson

unread,
Oct 19, 2017, 4:11:42 AM10/19/17
to Ag Stephens, Iris
Hi Ag,

Are you aware of the concatenate_cube method? It will return a concatenated cube, or an exception telling you why it couldn't. In these situations, that is invaluable.

HTH

Phil

--
You received this message because you are subscribed to the Google Groups "Iris" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scitools-iris+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon Peatman

unread,
Oct 19, 2017, 4:47:49 AM10/19/17
to Iris
Hmm, it works for me:

import iris
iris
.FUTURE.netcdf_promote = True

cubes
= iris.load('tas_rcp85_ukcp18-land-gcm-uk-monthly_r1i1p?_mon_20100101-20101201.nc', 'air_temperature')

for cube in cubes:
   
del cube.attributes['ensemble_member']

print cubes.concatenate_cube()

Ag Stephens

unread,
Oct 20, 2017, 7:29:32 AM10/20/17
to Iris
Hi Simon,

Just tried exactly your code and found that I wasn't quite doing the same thing. It works for me too!

Many thanks to all :-)

Ag
Reply all
Reply to author
Forward
0 new messages