add columns flip

This commit is contained in:
rstiskalek 2022-10-12 11:47:11 +01:00
parent e97609da05
commit b3c7d687b7
2 changed files with 25 additions and 1 deletions

View file

@ -15,4 +15,4 @@
from .readsim import (get_sim_path, open_particle, open_unbinding,
read_particle, read_clumpid, read_clumps,
convert_mass_cols, convert_position_cols)
convert_mass_cols, convert_position_cols, flip_cols)

View file

@ -363,3 +363,27 @@ def convert_position_cols(arr, cols, zero_centered=False):
arr[col] *= BOXSIZE
if zero_centered:
arr[col] -= BOXSIZE / 2
def flip_cols(arr, col1, col2):
"""
Flip values in columns `col1` and `col2`. `arr` is passed by reference and
is not explicitly returned back.
Parameters
----------
arr : structured array
The array whose columns are to be converted.
col1 : str
The first column name.
col2 : str
The second column name.
Returns
-------
nothing
"""
dum = numpy.copy(arr[col1])
arr[col1] = arr[col2]
arr[col2] = dum