Reshaping cubes / multi-dimensional coordinates

14 views
Skip to first unread message

Duncan Watson-Parris

unread,
May 14, 2018, 5:09:44 PM5/14/18
to Iris-dev
Just cross-posting since the discussed functionality is something I would like to ultimately see in iris (rather than CIS): https://groups.google.com/forum/#!topic/scitools-iris/Kni1_QO7H1M

Any thoughts welcome.

Klaus Zimmermann

unread,
May 15, 2018, 4:51:35 AM5/15/18
to Iris-dev
Hi Duncan,

do you have a link to the cis discussion as well?

Anyway, the problem, I think, is that you are really fundamentally changing the data:
You already saw that you lose the one dimension coordinate and of course the other one
goes as well if you happen to select values from two columns.
You also lose the implied topological relationship, i.e. the points don't know their neighbors anymore.

These problems are, imho, not mere technicalities, but expressions of the underlying problem which is
that what you describe is usually not the end goal. That would normally be one of two things:
1) Plot(Treat) the selected data in the context of the original data keeping dim coords and topology intact.
2) Calculating some statistic like the mean over the selected data points.

Both use cases can be implemented by masking (as you already pointed out) and I think that is the way to go.
For example with

lat = cube.coord('latitude')
lon = cube.coord('longitude')
selection = (lat.points > 0.) & (lon.points > 4.)
mask = ~selection

the two use cases can be done as
1) cube.data.mask |= mask

2)
grid_areas = iris.analysis.cartography.area_weights(cube)
weights = grid_areas * selection
mean = cube.collapsed(['latitude', 'longitude'], iris.analysis.MEAN, weights=weights)

Of course, 2) here is the area weighted average; if you need it without area weights, simply pass in selection as weights.

Do you think this approach covers your use case?

I think the consistent alternative along the lines of your idea would be to create a one dimensional cube as you suggested,
but then all dim and aux coords should be transformed into one dimensional aux coords accordingly.

Cheers
Klaus

On Mon, May 14, 2018 at 11:09 PM, Duncan Watson-Parris <duncan...@gmail.com> wrote:
Just cross-posting since the discussed functionality is something I would like to ultimately see in iris (rather than CIS): https://groups.google.com/forum/#!topic/scitools-iris/Kni1_QO7H1M

Any thoughts welcome.

--
You received this message because you are subscribed to the Google Groups "Iris-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scitools-iris-dev+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

RuthC

unread,
May 17, 2018, 12:04:11 PM5/17/18
to Iris-dev
The 2D coordinate is not necessarily spatial. Here is a relevant discussion prompted by a user who wanted/expected a different shape:
https://github.com/SciTools/iris/issues/2766

Ruth

Reply all
Reply to author
Forward
0 new messages