alejandrobll / py-sphviewer

Py-SPHViewer is a framework for rendering cosmological simulations in Python using the Smoothed Particle Hydrodynamics scheme.
https://alejandrobll.github.com/py-sphviewer
GNU General Public License v3.0
70 stars 29 forks source link

ValueError: Data and query points must have same dimensions #14

Closed Eichhof closed 4 years ago

Eichhof commented 5 years ago

Hello

I have the following method:

def sphviewer_plot(x, y, nb=32, xsize=500, ysize=500):   
    xmin = np.min(x)
    xmax = np.max(x)
    ymin = np.min(y)
    ymax = np.max(y)

    x0 = (xmin+xmax)/2.
    y0 = (ymin+ymax)/2.

    pos = np.zeros([3, len(x)])
    pos[0,:] = x
    pos[1,:] = y
    w = np.ones(len(x))

    P = sph.Particles(pos, w, nb=nb)
    S = sph.Scene(P)
    S.update_camera(r='infinity', x=x0, y=y0, z=0, 
                    xsize=xsize, ysize=ysize)
    R = sph.Render(S)
    R.set_logscale()
    img = R.get_image()
    extent = R.get_extent()
    for i, j in zip(xrange(4), [x0,x0,y0,y0]):
        extent[i] += j
    return img, extent

I'm now calling this method with img, extent = sphviewer_plot(df_touch_main["x"].values, df_touch_main["y"].values, 16, xsize=1000, ysize=1000) where df_touch_main is a DataFrame. Both df_touch_main["x"].values and df_touch_main["y"].values are of size 645019. The detailed error I get is the following:


ValueError Traceback (most recent call last)

in 23 print(len(df_touch_main["x"])) 24 print(len(df_touch_main["y"])) ---> 25 img, extent = sphviewer_plot(df_touch_main["x"].values, df_touch_main["y"].values, 16, xsize=1000, ysize=1000) 26 img = np.flipud(img) 27 ax.imshow(img, extent=extent, origin='lower', cmap=mycmap) in sphviewer_plot(x, y, nb, xsize, ysize) 24 w = np.ones(len(x)) 25 ---> 26 P = sph.Particles(pos, w, nb=nb) 27 S = sph.Scene(P) 28 S.update_camera(r='infinity', x=x0, y=y0, z=0, ~\AppData\Local\Continuum\anaconda3\lib\site-packages\py_sphviewer-1.2.0-py3.7-win-amd64.egg\sphviewer\Particles.py in __init__(self, pos, mass, hsml, nb, verbose, sort) 86 87 if(hsml is None): ---> 88 hsml = self.__det_hsml(pos,nb) 89 90 if(sort): ~\AppData\Local\Continuum\anaconda3\lib\site-packages\py_sphviewer-1.2.0-py3.7-win-amd64.egg\sphviewer\Particles.py in __det_hsml(self, pos, nb) 182 def __det_hsml(self, pos, nb): 183 tree = self.__make_kdtree(pos) --> 184 hsml = self.__nbsearch(pos, nb, tree) 185 return hsml 186 ~\AppData\Local\Continuum\anaconda3\lib\site-packages\py_sphviewer-1.2.0-py3.7-win-amd64.egg\sphviewer\Particles.py in __nbsearch(self, pos, nb, tree) 176 177 def __nbsearch(self, pos, nb, tree): --> 178 d, idx = tree.query(pos, k=nb) 179 hsml = d[:,nb-1] 180 return hsml pykdtree/kdtree.pyx in pykdtree.kdtree.KDTree.query() ValueError: Data and query points must have same dimensions
AshKelly commented 5 years ago

I think it is because

    pos = np.zeros([3, len(x)])
    pos[0,:] = x
    pos[1,:] = y

should be,

    pos = np.zeros([len(x), 3])
    pos[:,0] = x
    pos[:,1] = y
Eichhof commented 5 years ago

Thanks a lot. Now I'm getting another error:


ImportError Traceback (most recent call last)

in 23 print(len(df_touch_main["x"])) 24 print(len(df_touch_main["y"])) ---> 25 img, extent = sphviewer_plot(df_touch_main["x"].values, df_touch_main["y"].values, 16, xsize=1000, ysize=1000) 26 img = np.flipud(img) 27 ax.imshow(img, extent=extent, origin='lower', cmap=mycmap) in sphviewer_plot(x, y, nb, xsize, ysize) 25 26 P = sph.Particles(pos, w, nb=nb) ---> 27 S = sph.Scene(P) 28 S.update_camera(r='infinity', x=x0, y=y0, z=0, 29 xsize=xsize, ysize=ysize) ~\AppData\Local\Continuum\anaconda3\lib\site-packages\py_sphviewer-1.2.0-py3.7-win-amd64.egg\sphviewer\Scene.py in __init__(self, Particles, Camera) 111 self._camera_params = self.Camera.get_params() 112 --> 113 self._x, self._y, self._hsml, self._kview = self.__compute_scene() 114 self._m = self._Particles._mass[self._kview] 115 ~\AppData\Local\Continuum\anaconda3\lib\site-packages\py_sphviewer-1.2.0-py3.7-win-amd64.egg\sphviewer\Scene.py in __compute_scene(self) 157 158 def __compute_scene(self): --> 159 from .extensions import scene 160 161 pos = self._Particles._pos ImportError: DLL load failed: %1 is not a valid Win32 application.
AshKelly commented 5 years ago

This seems like you have installed pysphviewer (and maybe python as a whole) as 64bit but you run on a 32bit system.

Are you able to check what Windows architecture you have installed, 32bit or 64bit? and also, maybe what python version you installed, again either 32bit or 64bit?

AshKelly commented 5 years ago

@alejandrobll likely knows more, my Windows knowledge is poor.

Eichhof commented 5 years ago

I'm running Windows 7 64-bit and Python 3.7.1 64-bit version. Perhaps the problem is connected to my previous problem: https://github.com/alejandrobll/py-sphviewer/issues/13 although I did not get any errors during installation.

Eichhof commented 5 years ago

@alejandrobll I'm not able to solve the problem. I would really appreciate if you could give some advice. Thank you very much.

JBorrow commented 4 years ago

Hi @Eichhof, how did you install py-sphviewer?

alejandrobll commented 4 years ago

I tested py-sphviewer on a Windows machine with a conda environment and it seems to work fine. Due to lack of further information on the issue, I'll close it now. This can be reopened if needed.