amepproject / amep

The Active Matter Evaluation Package (AMEP) - a Python library for the analysis of particle-based and continuum simulation data of soft and active matter systems
https://amepproject.de/
GNU General Public License v3.0
11 stars 2 forks source link

BUG: error running evaluate.PCFangle #71

Open kay-ro opened 1 week ago

kay-ro commented 1 week ago

Description:

Running the evaluate.PCFangle function fails due to an error in incorrect shapes.

Code for reproduction:

path="./examples/data/lammps.h5amep"
traj= amep.load.traj(path)
pcfangle=amep.evaluate.PCFangle(traj, nav=1)

Error message:

(500, 100) (100, 500) (100, 500)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[6], line 1
----> 1 pcfangle=amep.evaluate.PCFangle(traj, nav=1)

File ~/Documents/git_amep/amep/evaluate.py:917, in PCFangle.__init__(self, traj, skip, nav, ptype, other, **kwargs)
    914 self.__other  = other
    915 self.__kwargs = kwargs
--> 917 self.__frames, res, self.__indices = average_func(
    918     self.__compute, self.__traj, skip = self.__skip,
    919     nr = self.__nav, indices = True
    920 )
    922 self.__times = self.__traj.times[self.__indices]
    923 self.__avg   = res[0]

File ~/Documents/git_amep/amep/utils.py:144, in average_func(func, data, skip, nr, indices, **kwargs)
    142 func_result = [func(x, **kwargs) for x in tqdm(data[evaluated_indices])]
    143 print(np.shape(func_result[0][0]), np.shape(func_result[0][1]), np.shape(func_result[0][2]))
--> 144 evaluated = np.array(func_result)
    145 if indices:
    146     return evaluated, np.mean(evaluated, axis=0), evaluated_indices

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (1, 3) + inhomogeneous part.

Python and AMEP versions:

1.0.2

Additional information:

No response

How did you install AMEP?

None

hechtprojects commented 6 days ago

The format of the returned 2d arrays for the pcf data and for the distances and angles is different. In particular, the pcf data has to be transposed. Possible bug fix (in amep.spatialcor.pcf_angle):

Change the return from

return res, R, T

to

return res.T, R, T

This should already fix the bug.