tommyod / KDEpy

Kernel Density Estimation in Python
https://kdepy.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
584 stars 90 forks source link

Custom grid in FFTKDE of 3D (x, y, z) data #119

Closed trungnth closed 2 years ago

trungnth commented 2 years ago

I'm confused how to evaluate kde of 3D (x, y, z) data on a custom grid. I am trying to run below code:

import numpy as np
import pandas as pd

data=pd.read_excel('xyz.xlsx').to_numpy()

#Create a regular 3D grid with 256 points in each dimension
xmin, ymin, zmin = data.min(axis=0)
xmax, ymax, zmax = data.max(axis=0)
xi, yi, zi = np.mgrid[xmin:xmax:256j, ymin:ymax:256j, zmin:zmax:256j]

from KDEpy import FFTKDE

density = FFTKDE().fit(data).evaluate((xi, yi, zi))

It shows me this error "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()", how can I fix this? My goal is calculate density of (x,y,z) data in a custom grid, then create isosurface plot from this custom grid and density. Thank you for your help.

Here is my 3D (x, y, z) data: https://docs.google.com/spreadsheets/d/1N0hoWf4jI9e7N_kov650jVxV8kdQI_La/edit?usp=sharing&ouid=108142352602992721076&rtpof=true&sd=true

jason1894 commented 2 years ago

the evaluated (xi,yi,zi) should be an ndarray like (xi,yi,zi)= array([[x1,y1,z1],[x2,y2,z2],[x3,y3,z3]]).