From b3c7d687b7adbf9ae6fd1a2ac71a17405c3a52fd Mon Sep 17 00:00:00 2001 From: rstiskalek Date: Wed, 12 Oct 2022 11:47:11 +0100 Subject: [PATCH] add columns flip --- galomatch/io/__init__.py | 2 +- galomatch/io/readsim.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/galomatch/io/__init__.py b/galomatch/io/__init__.py index 3d34c77..26e9b4d 100644 --- a/galomatch/io/__init__.py +++ b/galomatch/io/__init__.py @@ -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) diff --git a/galomatch/io/readsim.py b/galomatch/io/readsim.py index 4852218..2ef8f3f 100644 --- a/galomatch/io/readsim.py +++ b/galomatch/io/readsim.py @@ -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