Another option is to use itertools
to build the product of all coordinate points and flatten the cube's data array:
points_prod = itertools.product(cube.coord('height').points,
cube.coord('latitude').points,
cube.coord('longitude').points)
flat_data = cube.data.reshape(-1)
The itertools
product is a generator, which we can consume by converting it into a list. We can then index the list of products and the flattened data array. The index i
of the list of products will be the coordinate points for the data value i
in the flattened data array:
points_prod_list = list(points_prod)
print '{} -- {}'.format(points_prod_list[i], flat_data[i])
Thinking about specific data orderings and ensuring you have the right coordinates for each data point...
So long as you get the order of the dimensions the same as the order that they are printed, this will always link the right coordinate point values to the data value that those point values describe.
This is quite hard to describe but can be demonstrated reasonably simply using the code above. It relates to the fact that the first printed dimension coordinate describes the outermost axis of the cube's data array, and the orders in which itertools.product creates the product of all input combinations, and the order in which NumPy flattens an array. Fundamentally though, Iris itself is relying on these orderings to make sure its coordinate points values describe the right data values!