Expected behaviour
One large clump (set of adjacent masked cells) should be gathered in one single clump
Actual behaviour:
Not the case see bellow
Working example:
(not so minimal)
from clump_tracker.finder import find_clumps
import numpy as np
from dataclasses import dataclass
import numpy as np
from functools import cached_property
@dataclass
class FakeVTK:
xE: np.ndarray
yE: np.ndarray
zE:np.ndarray
data: dict[np.ndarray]
@cached_property
def x(self):
return np.convolve([0.5,0.5],self.xE,mode="valid")
@cached_property
def y(self):
return np.convolve([0.5,0.5],self.yE,mode="valid")
@cached_property
def z(self):
return np.convolve([0.5,0.5],self.zE,mode="valid")
def _data(Nx,Ny,Nz):
return {"RHO":np.zeros((Nx,Ny,Nz)),
"VX1":np.zeros((Nx,Ny,Nz)),
"VX2":np.zeros((Nx,Ny,Nz))}
def oneBump(Nx=1024,Ny=1024,Nz=1):
V = FakeVTK(np.linspace(-10,10,Nx+1),
np.linspace(-10,10,Ny+1),
np.linspace(-.5,.5,Nz+1),
_data(Nx,Ny,Nz))
xx,yy,zz = np.meshgrid(V.x,V.y,V.z,indexing="ij")
V.data["RHO"] += np.exp(-(xx*xx+yy*yy))*2
return V
def condition(data):
return np.asarray(data["RHO"] > 1)
V = oneBump(2048,2048)
coords = [V.x,V.y,V.z]
dcoords = [np.ediff1d(_) for _ in [V.xE,V.yE,V.zE]]
max_distance = 1.1*np.ediff1d(V.xE)[0]
clumps = find_clumps(V.data,*coords,*dcoords,
float(max_distance),gamma=2,condition=condition)
print(f"{len(clumps) = } should be 1")
len(clumps) = 50 should be 1
Illustration:
import matplotlib.pyplot as plt
xxE,yyE = np.meshgrid(V.xE,V.yE,indexing="ij")
fig, ax = plt.subplots()
for cl in clumps:
ax.plot(cl.x,cl.y,"r+",alpha=.5)
c = ax.pcolormesh(xxE,yyE,condition(V.data)[:,:,0],cmap="binary")
ax.set_aspect("equal")
fig.colorbar(c)
There should be only one single red cross in the middle of the black disc.
Expected behaviour
One large clump (set of adjacent masked cells) should be gathered in one single clump
Actual behaviour:
Not the case see bellow
Working example:
(not so minimal)
Illustration:
There should be only one single red cross in the middle of the black disc.