openPMD / openPMD-viewer

:snake: Python visualization tools for openPMD files
https://openpmd-viewer.readthedocs.io/
Other
65 stars 49 forks source link

Add an API to iterate over all timesteps #191

Open RemiLehe opened 6 years ago

RemiLehe commented 6 years ago

As pointed out by @MaxThevenet and @soerenjalas, it is often useful to call openPMD-viewer methods for each timestep of a timeseries, and it would be nice to have an API that does this automatically. This would be useful for:

RemiLehe commented 6 years ago

One relatively easy way of doing it would be to introduce e.g. a ts.iterate function:

In summary:

RemiLehe commented 6 years ago

@soerenjalas @MaxThevenet: Any opinion, preference or better suggestions on the above?

From my point of view, here are the advantages and drawbacks:

Advantages:

Drawbacks:

soerenjalas commented 6 years ago

This pretty much the exact thing I was thinking of. I think for now it is okay to have only one selection for the full loop. Maybe we come up with an elegant solution in the future.

For your second drawback: One could list append them (i.e. list of list), but this also has its own drawback. I don't have a strong opinion but I guess numpy arrays are nicer to handle.

RemiLehe commented 6 years ago

OK, thanks! If @MaxThevenet also agrees with this approach, then I can try to do a PR. I think I see more or less how to implement this.

MaxThevenet commented 6 years ago

Yep I agree with this approach. Doing it this way, we'll loop over all iterations once per method. If that is taking too much time for some analysis, we can probably adapt ts.iterate in the future, so that it takes several routines as @soerenjalas suggested initially, and does the loop only once.