Commit b5e7162f authored by Simeon Doetsch's avatar Simeon Doetsch

Changed PlutoData construction from Simulation, fixed attributes for multiprocessing

parent 79f0f1d6
......@@ -6,14 +6,6 @@ import subprocess
from .plutodata import PlutoData
from .simulation import Simulation
def render_frames(sim: Simulation, plot_func, output_path: str='',
plot_args: dict={'vmin': None, 'vmax': None},
save_args: dict={'bbox_inches': 'tight'}):
for frame in sim.memory_iter():
fig = plot_func(frame, **plot_args)
fig.savefig(f"{output_path}{frame.n:04d}.png", **save_args)
def parameter_generator(sim: Simulation, plot_func, output_path,
plot_args: dict={'vmin': None, 'vmax': None},
save_args: dict={'bbox_inches': 'tight'}):
......@@ -20,11 +20,11 @@ class PlutoData(object):
vars [dict]: variables for manual construction
parent [Simulation]: parent Simulation, missing attributes are tried to fetch from there
self.wdir = wdir = {}
self.format = format
# Read all information in if object is not an child to Simulation
if variables is None:
if parent is None:
self.wdir = wdir
# read info about data file
......@@ -38,15 +38,11 @@ class PlutoData(object):
# construct object from preloaded information
if variables and grid and parent:
self.grid = grid
for key, value in variables.items():
setattr(self, key, value)
self.parent = parent
raise Exception('For PlutoData construction from preloaded information, '
'variables, grid and parent have to be provided')
# construct object from parent simulation
self.parent = parent
self.wdir, self.grid, self.vars = parent.wdir, parent.grid, parent.vars
self.n, self.t, self.dt, self.nstep = n, parent.t[n], parent.dt[n], parent.nstep[n]
def __getattribute__(self, name):
"""Get grid/data attributes from corresponding dict, or load it"""
......@@ -55,10 +51,9 @@ class PlutoData(object):
return object.__getattribute__(self, name)
except AttributeError:
# grid
return self.grid[name]
return object.__getattribute__(self, 'grid')[name]
except KeyError:
......@@ -42,8 +42,8 @@ class Simulation:
# grid
return self.grid[name]
return object.__getattribute__(self, 'grid')[name]
except KeyError:
# vars
......@@ -113,12 +113,7 @@ class Simulation:
"""Load data frame"""
key = self._index(key)
D = PlutoData(wdir=self.wdir, coordinates=self.coordinate_system, format=self.format, grid=self.grid,
variables={'vars': self.vars, 'n':key, 't': self.t[key], 'dt': self.dt[key],
'nstep': self.nstep[key]},
return D
return PlutoData(n=key, parent=self)
def __iter__(self) -> Generator[PlutoData, None, None]:
"""Iterate over all data frames"""
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment