Skip to content

Commit c2655b8

Browse files
committed
Adding boutdata.restart.scalevar
o Scales variables in-place
1 parent 46dd8a2 commit c2655b8

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tools/pylib/boutdata/restart.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def addnoise(path=".", var=None, scale=1e-5):
180180
file_list = glob.glob(os.path.join(path, "BOUT.restart.*"))
181181
nfiles = len(file_list)
182182

183-
print("Number of data files: ", nfiles)
183+
print("Number of restart files: %d" % (nfiles,))
184184

185185
for file in file_list:
186186
print(file)
@@ -198,6 +198,33 @@ def addnoise(path=".", var=None, scale=1e-5):
198198
data += normal(scale=scale, size=data.shape)
199199
d.write(var, data)
200200

201+
def scalevar(var, factor, path="."):
202+
"""
203+
Scales a variable by a given factor, modifying
204+
restart files in place
205+
206+
Inputs
207+
------
208+
209+
var Name of the variable (string)
210+
factor Factor to multiply (float)
211+
path Path to the restart files
212+
213+
Returns
214+
-------
215+
None
216+
"""
217+
218+
file_list = glob.glob(os.path.join(path, "BOUT.restart.*"))
219+
nfiles = len(file_list)
220+
221+
print("Number of restart files: %d" % (nfiles,))
222+
for file in file_list:
223+
print(file)
224+
with DataFile(file, write=True) as d:
225+
d[var] = d[var] * factor
226+
227+
201228

202229
def create(averagelast=1, final=-1, path="data", output="./", informat="nc", outformat=None):
203230
"""

0 commit comments

Comments
 (0)