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

Particle filter is not applied if dataset contains only one particle #351

Open
agolovanov opened this issue Dec 26, 2022 · 1 comment
Open
Labels

Comments

@agolovanov
Copy link

If particle data for a particular species contains only one particle, the select filter is not taken into account.

Take, for example, attached data which is an OpenPMD file containing a single particle dataset data/2997/particles/electrons_oxygen_7 with only one particle (all other datasets have been removed). Try reading with openPMD-viewer:

from openpmd_viewer import OpenPMDTimeSeries
ts = OpenPMDTimeSeries('hdf5/')
iteration = ts.iterations[0]
data = ts.get_particle(['uz'], species='electrons_oxygen_7', iteration = iteration, select={'uz' : [20, 150]})

Now data contains:

[array([0.4946678])]

The expected result is data should be empty as the value of 0.49 is not between 20 and 150, so this single data point should have been filtered out.

This happens because the utilities.apply_selection has the following condition which specifically ignores the filter for the case of 1 particle:

# Use select_array to reduce each quantity
for i in range(len(data_list)):
    if len(data_list[i]) > 1:  # Do not apply selection on scalar records
        data_list[i] = data_list[i][select_array]

Perhaps this condition is relevant to some other cases when the record is truly scalar. But in my case, the record is not scalar, just sometimes for some iterations and species the number of particles in species turns out to be exactly equal to 1, and then I get incorrect results. Correspondingly, for datasets with 0 or 2+ particles, filtering works correctly, so only 1 particle is problematic.

@ax3l ax3l added the bug label Apr 20, 2023
@ax3l
Copy link
Member

ax3l commented Apr 20, 2023

Oh, good catch!

@RemiLehe and I took a look at it. The comment is a typo, it meant to say skip constant records.

Anyway, we also want to filter constant records 😅

We will correct that, thx @RemiLehe for volunteering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants