-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pandas:
ImpactXParticleContainer.to_df()
Copy all particles into a `pandas.DataFrame`. Supports local and MPI-gathered results.
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
This file is part of ImpactX | ||
Copyright 2023 ImpactX contributors | ||
Authors: Axel Huebl | ||
License: BSD-3-Clause-LBNL | ||
""" | ||
|
||
|
||
def ix_pc_to_df(self, local=True, comm=None, root_rank=0): | ||
""" | ||
Copy all particles into a pandas.DataFrame | ||
Parameters | ||
---------- | ||
self : amrex.ParticleContainer_* | ||
A ParticleContainer class in pyAMReX | ||
local : bool | ||
MPI-local particles | ||
comm : MPI Communicator | ||
if local is False, this defaults to mpi4py.MPI.COMM_WORLD | ||
root_rank : MPI root rank to gather to | ||
if local is False, this defaults to 0 | ||
Returns | ||
------- | ||
A concatenated pandas.DataFrame with particles from all levels. | ||
Returns None if no particles were found. | ||
If local=False, then all ranks but the root_rank will return None. | ||
""" | ||
df = super().to_df(local=local, comm=comm, root_rank=root_rank) | ||
|
||
# rename columns according to our attribute names | ||
if df is not None: | ||
# todo: check if currently in fixed s or fixed t and pick name accordingly | ||
|
||
names = [] | ||
for n in self.RealAoS.names_s: | ||
names.append(n) | ||
for n in self.RealSoA.names_s: | ||
names.append(n) | ||
|
||
df.columns.values[0 : len(names)] = names | ||
|
||
# todo: also rename runtime attributes (e.g., "s_lost") | ||
# https://github.com/ECP-WarpX/impactx/pull/398 | ||
|
||
return df | ||
|
||
|
||
def register_ImpactXParticleContainer_extension(): | ||
"""ImpactXParticleContainer helper methods""" | ||
|
||
# register member functions for ImpactXParticleContainer | ||
ImpactXParticleContainer.to_df = ix_pc_to_df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters