unpicking and re-arranging a "complex" cube

122 views
Skip to first unread message

Bernd Becker

unread,
Jan 19, 2015, 11:56:23 AM1/19/15
to scitoo...@googlegroups.com

If you cannot sleep tonight, you may wish to solve this puzzle:

here is a cube : with 13 consecutive forecast with 2 lead time step predicted:

how could you re-arrange the times in the cube to end up with a cube describing a consecutive time series ?


keep_gusts1  unknown / (unknown)                 (forecast_period: 2; forecast_reference_time: 13; latitude: 1152; longitude: 1536)
     Dimension coordinates:
          forecast_period                                          x                           -                                          -                -
          forecast_reference_time                              -                           x                                           -                -
          latitude                                                      -                           -                                           x                -
          longitude                                                   -                           -                                           -                x
     Auxiliary coordinates:
          time                                                           x                           x                                            -                -
     Scalar coordinates:
          height: 10.0 m
     Attributes:
          STASH: m01s03i463
          source: Data from Met Office Unified Model
          um_version: 8.5
keep_gusts1  AuxCoord
     ([[2015-01-02 21:00:00, 2015-01-03 00:00:00],
       [2015-01-03 03:00:00, 2015-01-03 06:00:00],
       [2015-01-03 09:00:00, 2015-01-03 12:00:00],
       [2015-01-03 15:00:00, 2015-01-03 18:00:00],
       [2015-01-03 21:00:00, 2015-01-04 00:00:00],
       [2015-01-04 03:00:00, 2015-01-04 06:00:00],
       [2015-01-04 09:00:00, 2015-01-04 12:00:00],
       [2015-01-04 15:00:00, 2015-01-04 18:00:00],
       [2015-01-04 21:00:00, 2015-01-05 00:00:00],
       [2015-01-05 03:00:00, 2015-01-05 06:00:00],
       [2015-01-05 09:00:00, 2015-01-05 12:00:00],
       [2015-01-05 15:00:00, 2015-01-05 18:00:00],
       [2015-01-05 21:00:00, 2015-01-06 00:00:00]], standard_name='time', calendar='gregorian')
 [[ 394509.  394512.]
 [ 394515.  394518.]
 [ 394521.  394524.]
 [ 394527.  394530.]
 [ 394533.  394536.]
 [ 394539.  394542.]
 [ 394545.  394548.]
 [ 394551.  394554.]
 [ 394557.  394560.]
 [ 394563.  394566.]
 [ 394569.  394572.]
 [ 394575.  394578.]
 [ 394581.  394584.]]
DimCoord
     ([2015-01-02 18:00:00, 2015-01-03 00:00:00, 2015-01-03 06:00:00,
       2015-01-03 12:00:00, 2015-01-03 18:00:00, 2015-01-04 00:00:00,
       2015-01-04 06:00:00, 2015-01-04 12:00:00, 2015-01-04 18:00:00,
       2015-01-05 00:00:00, 2015-01-05 06:00:00, 2015-01-05 12:00:00,
       2015-01-05 18:00:00], standard_name='forecast_reference_time', calendar='gregorian')


Target:
keep_gusts2  unknown / (unknown)                 (time: 26; latitude: 1152; longitude: 1536)

Many thanks!
Bernd.

Richard Hattersley

unread,
Jan 20, 2015, 5:01:52 AM1/20/15
to scitoo...@googlegroups.com
Have you tried slicing it into individual time steps and using CubeList.concatenate()?

Perhaps something like:
timesteps = [iris.util.new_axis(timestep, 'time') for timestep in keep_gusts1.slices_over('time')]
timeseries = iris.cube.CubeList(timesteps).concatenate()

Regards,
Richard

Bernd Becker

unread,
Jan 20, 2015, 11:35:00 AM1/20/15
to scitoo...@googlegroups.com


Ok nice idea! let us try this on a simple set of files: two consecutive lead times.

 filenames=['prods_op_gl-mn_20140728_06_003.gpcs.pp', 'prods_op_gl-mn_20140728_06_006.gpcs.pp']
a =iris.load_cube(filenames)
>>> a
<iris 'Cube' of unknown / (unknown) (time: 2; latitude: 1152; longitude: 1536)>   Wow! that was cool!

Let us spice things up a bit and take the first  2 times steps from the next forecast:

filenames=['prods_op_gl-mn_20140728_06_003.gpcs.pp', 'prods_op_gl-mn_20140728_06_006.gpcs.pp','prods_op_gl-mn_20140728_12_003.gpcs.pp', 'prods_op_gl-mn_20140728_12_006.gpcs.pp']
>>> b =iris.load_cube(filenames)
>>> b
<iris 'Cube' of unknown / (unknown) (forecast_period: 2; forecast_reference_time: 2; latitude: 1152; longitude: 1536)>
>>>
print b.coord('time')
AuxCoord([[2014-07-28 09:00:00, 2014-07-28 12:00:00],
       [2014-07-28 15:00:00, 2014-07-28 18:00:00]], standard_name='time', calendar='gregorian')

uups, not so cool. No continuous time dimension even if it stares right at you.

Apply the magic suggested above:
timesteps = [iris.util.new_axis(timestep, 'time') for timestep in b.slices_over('time')]
>>> timeseries = iris.cube.CubeList(timesteps).concatenate()
>>> timeseries
[<iris 'Cube' of unknown / (unknown) (time: 1; latitude: 1152; longitude: 1536)>,
<iris 'Cube' of unknown / (unknown) (time: 1; latitude: 1152; longitude: 1536)>,
<iris 'Cube' of unknown / (unknown) (time: 1; latitude: 1152; longitude: 1536)>,
<iris 'Cube' of unknown / (unknown) (time: 1; latitude: 1152; longitude: 1536)>]

And I get a cube LIST! not a cube of dimension (4,1152,1536)

The list does not merge without effort either.
timeseries.merge()
[<iris 'Cube' of unknown / (unknown) (time: 1; latitude: 1152; longitude: 1536)>,
<iris 'Cube' of unknown / (unknown) (time: 1; latitude: 1152; longitude: 1536)>,
<iris 'Cube' of unknown / (unknown) (time: 1; latitude: 1152; longitude: 1536)>,
<iris 'Cube' of unknown / (unknown) (time: 1; latitude: 1152; longitude: 1536)>]
>>> timeseries.coord('time')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'CubeList' object has no attribute 'coord'

What else could I try?




Bernd Becker

unread,
Jan 21, 2015, 5:03:29 AM1/21/15
to scitoo...@googlegroups.com

other things I tried that appear odd:

>>> a
<iris 'Cube' of unknown / (unknown) (forecast_period: 2; forecast_reference_time: 13; latitude: 1152; longitude: 1536)>
>>> a.remove_coord('forecast_reference_time')
>>> a.remove_coord('forecast_period')
>>> a
<iris 'Cube' of unknown / (unknown) (-- : 2; -- : 13; latitude: 1152; longitude: 1536)>
>>> print a
unknown / (unknown)                 (-- : 2; -- : 13; latitude: 1152; longitude: 1536)
     Dimension coordinates:

          latitude                      -       -             x                -
          longitude                     -       -             -                x
     Auxiliary coordinates:
          time                          x       x             -                -
     Scalar coordinates:
          height: 10.0 m
     Attributes:
          STASH: m01s03i463
          source: Data from Met Office Unified Model
          um_version: 8.5
>>> print a.coord('time')
AuxCoord([[2015-01-16 03:00:00, 2015-01-16 06:00:00],
       [2015-01-16 09:00:00, 2015-01-16 12:00:00],
       [2015-01-16 15:00:00, 2015-01-16 18:00:00],
       [2015-01-16 21:00:00, 2015-01-17 00:00:00],
       [2015-01-17 03:00:00, 2015-01-17 06:00:00],
       [2015-01-17 09:00:00, 2015-01-17 12:00:00],
       [2015-01-17 15:00:00, 2015-01-17 18:00:00],
       [2015-01-17 21:00:00, 2015-01-18 00:00:00],
       [2015-01-18 03:00:00, 2015-01-18 06:00:00],
       [2015-01-18 09:00:00, 2015-01-18 12:00:00],
       [2015-01-18 15:00:00, 2015-01-18 18:00:00],
       [2015-01-18 21:00:00, 2015-01-19 00:00:00],
       [2015-01-19 03:00:00, 2015-01-19 06:00:00]], standard_name='time', calendar='gregorian')                                <= this is the "correct" time sequence
>>> print a.merge()     
>>> print a.cube_merge()                                                                                                                                            <= merge does not help here
>>> a[0]
<iris 'Cube' of unknown / (unknown) (-- : 13; latitude: 1152; longitude: 1536)>
>>> a[1]
<iris 'Cube' of unknown / (unknown) (-- : 13; latitude: 1152; longitude: 1536)>
>>> [ p.coord('time') for timestep in a.slices_over('time')]
>>> [ p.coord('time').points for p in a.slices_over('time')]
[array([ 394827.]), array([ 394833.]), array([ 394839.]), array([ 394845.]), array([ 394851.]), array([ 394857.]), array([ 394863.]), array([ 394869.]), array([ 394875.]), array([ 394881.]), array([ 394887.]), array([ 394893.]), array([ 394899.]), array([ 394830.]), array([ 394836.]), array([ 394842.]), array([ 394848.]), array([ 394854.]), array([ 394860.]), array([ 394866.]), array([ 394872.]), array([ 394878.]), array([ 394884.]), array([ 394890.]), array([ 394896.]), array([ 394902.])]
>>>
here, the time sequence is again different from what it was 7 lines further up. Odd.



Bernd Becker

unread,
Jan 21, 2015, 11:24:11 AM1/21/15
to scitoo...@googlegroups.com

The cube returned from iris.cube_load(bunch of pp-files) depends on the shape of the input data.

If the input files all show the same structure and contain a fixed number of time steps,
the time domain in the returned cube attains the  dimension of the number of time steps.

However, if there is a mix of input files holding a mixture of, i.e. lead times
the cube time dimension may be 1-D with a mix of times in sometimes surprising and not very predictable order.

If the goal is to unpick the cube with respect to time, each case needs a bespoke time filter.

Case closed.
Cheers,
Bernd.
Reply all
Reply to author
Forward
0 new messages