Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Globe keyword doesn't work as expected #24

Closed
bradyrx opened this issue Jul 9, 2019 · 2 comments
Closed

Globe keyword doesn't work as expected #24

bradyrx opened this issue Jul 9, 2019 · 2 comments
Labels

Comments

@bradyrx
Copy link
Collaborator

bradyrx commented Jul 9, 2019

I'm trying to use globe=True on a 2D map, and it doesn't seem to wrap the data correctly.

Here's a sample netCDF being used: http://s000.tinyupload.com/index.php?file_id=09194045931802153007 (I know this is bad practice, but this is the easiest way to reproduce it right now).

import xarray as xr
import proplot as plot
ds = xr.open_dataset('global_corr.nc')
f, ax = plot.subplots(proj='pcarree', axwidth=8, colorbar='r')
p = ax.contourf(global_corr.lon, global_corr.lat, global_corr, 
               levels=plot.arange(-0.7, 0.7, 0.1), cmap='RdBu_r',
                globe=False)
f.rightpanel.colorbar(p)

Okay, so we have the seam as expected:

Screen Shot 2019-07-09 at 10 54 02 AM

Issue 1: globe=True does not work with raw xarray objects. Perhaps this could be mitigated by passing .values whenever you see a pandas/xarray object. We use an is_xarray decorator in climpred to detect xarray objects. Maybe something similar could be done here. Or maybe I should just live with passing .values with my xarray objects.

ValueError: dimensions () must have the same length as the number of data dimensions, ndim=1

Issue 2: globe=True seems to change the colorbar/data/land (?) creating the wrong map:

ds = xr.open_dataset('/Users/ribr5703/Desktop/global_corr.nc')
f, ax = plot.subplots(proj='pcarree', axwidth=8, colorbar='r')
p = ax.contourf(global_corr.lon.values, global_corr.lat.values, global_corr.values, 
               levels=plot.arange(-0.7, 0.7, 0.1), cmap='RdBu_r',
                globe=True)
f.rightpanel.colorbar(p)

Screen Shot 2019-07-09 at 10 56 11 AM

If I just use the cartopy utility, I get the right map.

from cartopy.util import add_cyclic_point
cyclic_data, cyclic_lons = add_cyclic_point(global_corr.values, coord=global_corr.lon.values)

ds = xr.open_dataset('/Users/ribr5703/Desktop/global_corr.nc')
f, ax = plot.subplots(proj='pcarree', axwidth=8, colorbar='r')
p = ax.contourf(cyclic_lons, global_corr.lat.values, cyclic_data, 
               levels=plot.arange(-0.7, 0.7, 0.1), cmap='RdBu_r',
                globe=False)
f.rightpanel.colorbar(p)

Screen Shot 2019-07-09 at 10 57 56 AM

@lukelbd
Copy link
Collaborator

lukelbd commented Jul 9, 2019

Thanks for posting this. The issue was that your latitudes are sorted north-to-south (descending) instead of south-to-north. I should have accounted for this possibility. Commit d1193ce fixes things; try the example again.

import xarray as xr
import numpy as np
import proplot as plot
ds = xr.open_dataarray('/Users/ldavis/tmp/global_corr.nc')
f, ax = plot.subplots(proj='pcarree', basemap=0, axwidth=8, colorbar='r')
p = ax.contourf(ds.lon, ds.lat, ds, levels=plot.arange(-0.7, 0.7, 0.1), cmap='BuRd', globe=True)
f.rightpanel.colorbar(p)

ProPlot doesn't just fix longitudinal seams, it also "interpolates" to the poles, i.e. adds vectors populated with the mean of the highest/lowest-latitude coordinate data to the top and bottom of the data array (see this docs page). This isn't so important for cylindrical projections but removes an ugly "hole" in your data when using polar projections. In this example, after the fix, the coordinates looked like [-90, 89, 88, ..., -88, -89, 90]. Which drew a contour patch extending over the whole map and covering the negative contours.

I also improved the gridfix wrappers by making sure they respect masked arrays/do not destroy the masks.

@lukelbd lukelbd closed this as completed Jul 9, 2019
@bradyrx
Copy link
Collaborator Author

bradyrx commented Jul 9, 2019

Good catch! THanks.

@lukelbd lukelbd added the bug label Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants