From 3623c6eea94b51aef954893bdb0e3ee3719fd65e Mon Sep 17 00:00:00 2001 From: Ben Dudson Date: Mon, 28 Jul 2025 17:22:14 -0700 Subject: [PATCH] restart.create: Add averageZ parameter Averages fields in Z. Smooth variation between 0 (no averaging) and 1 (full averaging). Intermediate values will retain some Z variation. --- src/boutdata/restart.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/boutdata/restart.py b/src/boutdata/restart.py index 4509d75..923a2b9 100644 --- a/src/boutdata/restart.py +++ b/src/boutdata/restart.py @@ -456,7 +456,13 @@ def scalevar(var, factor, path="."): def create( - averagelast=1, final=-1, path="data", output="./", informat="nc", outformat=None + averagelast=1, + averageZ=0.0, + final=-1, + path="data", + output="./", + informat="nc", + outformat=None, ): """Create restart files from data (dmp) files. @@ -475,12 +481,15 @@ def create( File extension of original files (default: "nc") outformat : str, optional File extension of new files (default: use the same as `informat`) - + averageZ : float, optional + Weight average in Z direction: 0 = no averaging, 1 = average in Z + e.g. averageZ = 0.99 will reduce Z fluctuations to 1% of original """ if outformat is None: outformat = informat + averageZ = min([averageZ, 1.0]) path = pathlib.Path(path) output = pathlib.Path(output) @@ -541,6 +550,13 @@ def create( data[(final - averagelast) : final, :, :, :], axis=0 ) + if averageZ > 0.0: + data_averaged = np.tile( + np.mean(data_slice, axis=-1)[..., np.newaxis], + (1, 1, data_slice.shape[-1]), + ) + data_slice = averageZ * data_averaged + (1 - averageZ) * data_slice + print(data_slice.shape) # This attribute results in the correct (x,y,z) dimension labels data_slice.attributes["bout_type"] = "Field3D"