Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: average_func returns incorrect frames #60

Closed
kay-ro opened this issue Oct 14, 2024 · 2 comments · Fixed by #70
Closed

BUG: average_func returns incorrect frames #60

kay-ro opened this issue Oct 14, 2024 · 2 comments · Fixed by #70
Assignees
Labels
bug Something isn't working module: utils release: patch Issues that need to be addressed in a patch release status: done Done and ready to merge

Comments

@kay-ro
Copy link
Member

kay-ro commented Oct 14, 2024

Description:

If nr=Noneˋ or nr>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 kay-ro added bug Something isn't working release: patch Issues that need to be addressed in a patch release status: to do Issues that someone needs to work on module: utils labels Oct 14, 2024
@kay-ro kay-ro added this to the release v1.0.3 milestone Oct 14, 2024
@kay-ro
Copy link
Member Author

kay-ro commented Oct 16, 2024

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
Copy link

bemde42 commented Oct 17, 2024

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)

@kay-ro kay-ro self-assigned this Oct 17, 2024
@kay-ro kay-ro added status: ready for review Needs to be reviewed and removed status: to do Issues that someone needs to work on labels Oct 17, 2024
kay-ro pushed a commit that referenced this issue Oct 17, 2024
@kay-ro kay-ro linked a pull request Oct 21, 2024 that will close this issue
@kay-ro kay-ro modified the milestones: release v1.0.3, release v1.1.0 Oct 22, 2024
@kay-ro kay-ro closed this as completed Nov 13, 2024
@hechtprojects hechtprojects added status: done Done and ready to merge and removed status: ready for review Needs to be reviewed labels Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module: utils release: patch Issues that need to be addressed in a patch release status: done Done and ready to merge
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants