From 7bf681dc8e853aecad7a6cb1c8542971d0ff8290 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Fri, 3 Jan 2020 21:11:38 +0000 Subject: [PATCH] Merge pull request #137 from dstansby/bg-overwrite Prevent bg being modified in place --- doc/source/changes.rst | 6 ++++++ pfsspy/__init__.py | 4 +++- pfsspy/tracing.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 9341cdc8..4bfef54a 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -1,6 +1,12 @@ Changelog ========= +0.4.2 +----- + +- Fix a bug where :class`pfsspy.tracing.FotranTracer` would overwrite the + magnetic field values in an :class:`~pfsspy.Output` each time it was used. + 0.4.1 ----- diff --git a/pfsspy/__init__.py b/pfsspy/__init__.py index 136c8474..be33a224 100644 --- a/pfsspy/__init__.py +++ b/pfsspy/__init__.py @@ -362,7 +362,9 @@ def bg(self): bpg[i, :, :] /= (Sbp[:-1, :-1] + Sbp[1:, :-1] + Sbp[1:, 1:] + Sbp[:-1, 1:]) bsg *= -1 - return np.stack((bpg, bsg, brg), axis=-1) + out = np.stack((bpg, bsg, brg), axis=-1) + out.flags.writeable = False + return out def _common_b(self): """ diff --git a/pfsspy/tracing.py b/pfsspy/tracing.py index 5f67b4e6..3786cfe7 100644 --- a/pfsspy/tracing.py +++ b/pfsspy/tracing.py @@ -78,7 +78,7 @@ def trace(self, seeds, output): self.validate_seeds_shape(seeds) # The indexing order on the last index is (phi, s, r) - vectors = output.bg + vectors = output.bg.copy() # Correct s direction for coordinate system distortion sqrtsg = output.grid._sqrtsg_correction