ukcp-data / ukcp-data-processor

Python library for reading, writing, processing and plotting UKCP data.
6 stars 1 forks source link

xlocator (and maybe ylocator) issue for small bounding boxes #4

Closed agstephens closed 5 years ago

agstephens commented 5 years ago

Hi @antony-wilson ,

I have found where the error lies for our request:

https://ukcp18-wps-demo.ceda.ac.uk/submit/form?TemporalAverage=aug&Collection=land-prob&Baseline=b8100&Scenario=rcp85&ImageFormat=png&Area=bbox%7C54400.05%7C-42266.67%7C449066.65%7C437733.33&SpatialSelectionType=bbox&TimeSliceDuration=20y&DataFormat=csv&FontSize=m&TimeSlice=2080-2099&Variable=tasminAnom&proc_id=LS1_Maps_01&ImageSize=1200

The ukcp_dp library sets the xlocator and ylocator attributes of the Gridliner object in cartopy:

https://github.com/ukcp-data/ukcp-data-processor/blob/master/ukcp_dp/plotters/utils/_map_utils.py#L431

It copes if a big chunk of the map is selected but if you select a subset, e.g. the size of Wales: then you get this error:

ValueError: min() arg is an empty sequence

This occurs when the Gridliner._add_gridline_label() method is called and the code starts to loop through the self.xlines and self.ylines. At this point it finds out that x_ticks (and presumably, if too small) y_ticks is an empty Array - and it fails when calling min(x_ticks).

I have worked out how it is possible to get the plots out by unsetting the xlocator property. Howevre, there are likely to be side-effects and I'm not sure where the appropriate fix is for this.

@antony-wilson: do you know why we needed to set the xlocator and ylocator properties of the Gridliner objects?

pbett commented 5 years ago

This makes sure the gridlines are where we want them to be.

It might be best if EITHER we switch off trying to plot gridlines if the plot is less than 3 (?) grid widths across OR we adjust the gridline spacing if the plot is less than 3 (?) grid widths across

I can't remember if the grid spacing is set by the user - if not, then we might want to adjust it automatically. But the easiest thing might be to just switch them off when they're likely to cause trouble.

antony-wilson commented 5 years ago

I think this is due to the last minute change to using projection_x_coordinate and projection_y_coordinate in place of lat and long. The previous lines assume lat and long xgridpts = [xgridpt for xgridpt in xgridpts if ( xgridpt >= -180 and xgridpt <= 360)] ygridpts = [ygridpt for ygridpt in ygridpts if ( ygridpt >= -90 and ygridpt <= 90)] Also looks like I made a mistake trying to switch the grid lines off elsewhere. If I fix that then this issue goes away (tested on demo)

agstephens commented 5 years ago

@antony-wilson : good stuff. If you send me the fix I can try it on my version.

antony-wilson commented 5 years ago

replace lines50 and 51 https://github.com/ukcp-data/ukcp-data-processor/blob/master/ukcp_dp/plotters/_map_plotter.py#50 with plot_settings.gridlcol = None

antony-wilson commented 5 years ago

my mistake, you still need lines 50 and 51, just add in the extra line

agstephens commented 5 years ago

@antony-wilson : Works for me on the wps-dev version. I'll leave it to you to test if there are any side-effects and how it gets rolled out. Thanks :-)

antony-wilson commented 5 years ago

fixed by commit 2e9019f9dc57aad40e72078fc13c4ccac3c8fa6c