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
12 stars 2 forks source link

BUG: average_func returns incorrect frames #60

Closed kay-ro closed 1 week ago

kay-ro commented 1 month ago

Description:

If nr=Noneˋ ornr>available frames` then one frame is missing.

Code for reproduction:

load amep
traj=amep.load.traj("test", skip=0.99999)
data=np.arange(0,100,5)
amep.utils.average_func(lambda t:t, data, nr=10)

Error message:

No response

Python and AMEP versions:

1.0.2

Additional information:

Solution:

if (nr==None or nr>...) then:
    Nr=int(N-skip*N+1)

How did you install AMEP?

None

kay-ro commented 1 month ago

proposed solution to be reviewed

    N = len(data)   # number of time steps

    if(nr == None or nr > N - skip * N):
        nr = max(1,int(N-skip*N))

    evaluated_indices = np.ceil(np.linspace(skip*N, N-1, nr,))
    func_result = [func(x, **kwargs) for x in tqdm(data[evaluated_indices])]
    evaluated = np.array(func_result)
    if indices:
        return evaluated, np.mean(evaluated, axis=0), evaluated_indices
    return evaluated, np.mean(evaluated, axis=0)
bemde42 commented 1 month ago

thanks, there is a small additional fix necessary:

    evaluated_indices = np.ceil(np.linspace(skip*N, N-1, nr,))

must be changed to

evaluated_indices = np.array(np.ceil(np.linspace(skip*N, N-1, nr,)), dtype=int)