Broadcasting with missing values in order to merge cubes?

27 views
Skip to first unread message

Joshua Dorrington

unread,
May 22, 2019, 4:52:31 AM5/22/19
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
I have two cubes that I would like to merge together over a "forecast_reference_time" coordinate, however they have different numbers of ensemble members:

>>print(cube1)

2 metre temperature / (K)           (realization: 25; forecast_period: 7; latitude: 29; longitude: 36)
     Dimension coordinates:
          realization                           x                    -            -              -
          forecast_period                       -                    x            -              -
          latitude                              -                    -            x              -
          longitude                             -                    -            -              x
     Scalar coordinates:
          central_lead_time: 9.0
          forecast_reference_time: 2016-11-02 00:00:00
     Attributes:
          Conventions: CF-1.5

>>print(cube2)

2 metre temperature / (K)           (realization: 51; forecast_period: 7; latitude: 29; longitude: 36)
     Dimension coordinates:
          realization                           x                    -            -              -
          forecast_period                       -                    x            -              -
          latitude                              -                    -            x              -
          longitude                             -                    -            -              x
     Scalar coordinates:
          central_lead_time: 9.0
          forecast_reference_time: 2017-11-02 00:00:00
     Attributes:
          Conventions: CF-1.5

I would like the merged cube to be of shape (forecast_reference_time: 2; realization: 51; forecast_period: 7; latitude: 29; longitude: 36), where the missing 31 members from cube1 are masked.

Does anyone know how I could implement this? Ideally I'd like a method that worked for a whole CubeList, who's members might have any arbitrary number of realizations.

Peter W

unread,
Jun 6, 2019, 5:28:57 AM6/6/19
to SciTools (iris, cartopy, cf_units, etc.) - https://github.com/scitools
My suggestion would be to make a new cube, with the same number of realisations as the cube with the largest number, for each of the other cubes in your cubelist, and copy the data and coordinate values and mask out the data values for realisations that don't exist. Then the resulting cubes should merge I think.

You could also consider just working with the numpy data arrays, if iris' advantages of keeping track of metadata don't outweigh the complexity of using it (though creating new cubes is not that hard - it's just a few lines of code, so it depends what your purpose is).
Reply all
Reply to author
Forward
0 new messages