SciTools / iris

A powerful, format-agnostic, and community-driven Python package for analysing and visualising Earth science data
https://scitools-iris.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
635 stars 283 forks source link

Linear/Nearest neighbour regrid doesn't support zonal means #2951

Closed cpelley closed 6 years ago

cpelley commented 6 years ago

Here is our workaround:

def regrid(src_cube, tgt_cube):                                             
    # Munge the source (duplicate source latitudes) so that we can utilise     
    # Linear regridding
     src_cube2 = src_cube.copy()
    src_cube2.coord(axis='x').points = -90
    src_cube2.coord(axis='x').bounds = [-180, 0]
    src_cube.coord(axis='x').points = 90
    src_cube.coord(axis='x').bounds = [0, 180]
    src_cube = iris.cube.CubeList([src_cube, src_cube2]).concatenate_cube()

    return src_cube.regrid(tgt_cube, iris.analysis.Linear())

Target grids can be global UM grids or whatever regional models like UKV etc.

pp-mo commented 6 years ago

Don't get what is meant here, in either case ?

So the appropriate choice would seem to be an area-weighted regrid to a bounded cell in latitude. But I think we can do that, regridding from any parallel lat-lon grid, with iris.analysis.AreaWeighted.

So what exactly is it we are missing here ?

cpelley commented 6 years ago

Hi @pp-mo, thanks for your interest.

Let's say:

source:      (latitude: 30; longitude: 1)
target:      (latitude: 10; longitude: 1)

Where longitude is identical between source and target. We are having to test for this and unnecessarily run it through the interpolation API. What do you think?

Cheers

pp-mo commented 6 years ago

Let's say:

Interesting. Could you be more specific about :

Not asking much here 😁

cpelley commented 6 years ago

Hi @pp-mo, thanks for your response. I'll pop around for a quick offline chat I think (at a time of your convenience). Prob. save us an unnecessary to-and-fro.

Cheers

pelson commented 6 years ago

Closing until we have more detail. Happy to reopen when ready. 👍

pp-mo commented 6 years ago

Discussed offline today.

@cpelley does that summarise it ?

cpelley commented 6 years ago

Thanks @pp-mo, yes. I'll fluff out the ticket description using your comment along with my workaround for this.

pelson commented 6 years ago

IMO the minimum length of a dimension should be part of the interpolation scheme's definition. There should be no magic numbers - it entirely depends on the scheme. For example:

For that reason, I'm completely supportive of loosening the check if it is in the regrid method, as I believe this should be a fundamental responsibility of the regridding scheme being used.

cpelley commented 6 years ago

Thanks @pelson. I think that sounds reasonable to me. Hopefully if regridding uses the interpolation code (which in an ideal world I guess it would, but perhaps it doesn't currently -TBD) that there isn't a pre-existing creep of responsibility by the interpolation in this regard.

nhsavage commented 6 years ago

this is a common problem for making ancillary files where some of the important data sets are zonal means and so I have an interest in this.

I am slowly understanding the problem here, but I think I need to look at the ANTS code now to understand exactly how the regrid is used.

cpelley commented 6 years ago

Thanks for your interest @nhsavage

...I need to look at the ANTS code now...

You may want to look at the workaround in the ticket description. That pretty much comes out of the ozone application. Happy to clarify if it's not clear.

Cheers

nhsavage commented 6 years ago

I have to admit, I couldn't find the work around in the branch 756_OZONE_GEN as I'd missed the new function ancil_ozone.py ...

cpelley commented 6 years ago
nhsavage commented 6 years ago

I see how that is unambiguous and uncontroversial. I am not sure how easy that is to achieve in the Iris code though. Any thoughts about this @pelson @pp-mo?