Skip to content

Commit

Permalink
Adding boutdata.restart.scalevar
Browse files Browse the repository at this point in the history
o Scales variables in-place
  • Loading branch information
bendudson committed Sep 17, 2015
1 parent 46dd8a2 commit c2655b8
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tools/pylib/boutdata/restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def addnoise(path=".", var=None, scale=1e-5):
file_list = glob.glob(os.path.join(path, "BOUT.restart.*"))
nfiles = len(file_list)

print("Number of data files: ", nfiles)
print("Number of restart files: %d" % (nfiles,))

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

def scalevar(var, factor, path="."):
"""
Scales a variable by a given factor, modifying
restart files in place
Inputs
------
var Name of the variable (string)
factor Factor to multiply (float)
path Path to the restart files
Returns
-------
None
"""

file_list = glob.glob(os.path.join(path, "BOUT.restart.*"))
nfiles = len(file_list)

print("Number of restart files: %d" % (nfiles,))
for file in file_list:
print(file)
with DataFile(file, write=True) as d:
d[var] = d[var] * factor



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

0 comments on commit c2655b8

Please sign in to comment.