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

redim() of xarray causes contours to be off #2758

Open
laleph opened this issue Jun 1, 2018 · 2 comments
Open

redim() of xarray causes contours to be off #2758

laleph opened this issue Jun 1, 2018 · 2 comments
Labels
type: bug Something isn't correct or isn't working

Comments

@laleph
Copy link
Contributor

laleph commented Jun 1, 2018

Redim() should be the correct approach to alter the dimensions, right?

First I generate some test data.

#### TEST
import numpy as np
import xarray as xr

def gauss2d(amp, xo, yo, sigma_x, sigma_y, xy, xdim, ydim):
    """2d Gaussian """
    
    x, y = xy

    model = amp * np.exp( -(x-xo)**2 / (2*sigma_x**2) - (y-yo)**2 / (2*sigma_y**2)) 
#     return xr.DataArray(model, coords=[xdim, ydim], dims=['xdim', 'ydim'])
    return xr.DataArray(model, coords=[ydim, xdim], dims=['ydim', 'xdim'])

amp = 50
xo = -0.08
yo = -0.04  # AXES SWAPPED?!?
sigma_x = 0.03
sigma_y = 0.03

x = np.linspace(-0.15,0.15,91)
y = np.linspace(-0.15,0.15,91)
x2, y2 = np.meshgrid(x,y)

model = gauss2d(amp, xo, yo, sigma_x, sigma_y, (x2, y2), x, y)

Then I plot without redim() and the output is fine.

# PLOTS CORRECTLY
import holoviews as hv
hv.notebook_extension('matplotlib',width=90)

%opts Image (cmap="viridis") [colorbar=True, fontsize={'ticks':18, 'title':22, 'ylabel':20, 'xlabel':20, 'legend':18, 'legend_title':20}] {+axiswise}
%output size=180 dpi=90

img = hv.Image(model)
img * hv.operation.contours(img)

image

With redim() the contours are off.

# CONTOURS OFF, when redim() is used
lim = 0.1
img = hv.Image(model).redim.range(xdim=(-lim,lim), ydim=(-lim,lim))
img * hv.operation.contours(img)

image

The center of the contours is wrong in both dimensions.
This is probably related to #2319.

And the axes seem to be switched. Or am I mistaken? The shifted center of the gaussian has swapped the x and y coordinates. Or at least the labelling is confusing when xarray is used.

@laleph
Copy link
Contributor Author

laleph commented Jun 6, 2018

Apparently, the dimensions in xarray have a different ordering.

import matplotlib.pyplot as plt

model.plot.contourf()
plt.show()

image

I think that is confusing.

Nonetheless, the contour operation in holoviews has another issue.

@philippjfr philippjfr added the type: bug Something isn't correct or isn't working label Jun 6, 2018
@philippjfr
Copy link
Member

Thanks @laleph, definitely a bug. Should hopefully be an easy fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
Development

No branches or pull requests

2 participants