Add extractor for turb rms

This commit is contained in:
Noe Brucy
2019-12-10 17:03:00 +01:00
parent 10600f53df
commit 8e5813f6e2
4 changed files with 233 additions and 173 deletions
+51 -40
View File
@@ -20,7 +20,6 @@ from pymses.analysis import ScalarOperator, FractionOperator, MaxLevelOperator
from mypool import MyPool as Pool
from functools import partial
from abc import ABCMeta, abstractmethod
import contextlib
import bunch
from run_selector import *
@@ -167,7 +166,7 @@ class BaseProcessor:
self._log("Dependency {} for {} is unknown".format(dep, name), "ERROR")
def _needs_computation(self, overwrite, name_full):
return overwrite or not (name_full in self.save)
return overwrite
def _process_rule(self, name, rule, arg, overwrite=False, **kwargs):
if not arg is None:
@@ -265,6 +264,9 @@ class HDF5Container(BaseProcessor):
self.save.close()
self.opened = False
def _needs_computation(self, overwrite, name_full):
return overwrite or not (name_full in self.save)
def _process_rule(self, name, rule, arg, overwrite, **kwargs):
self.open()
try:
@@ -349,15 +351,7 @@ class PostProcessor(HDF5Container):
cells_loaded = False
def __init__(
self,
path=None,
num=None,
path_out=None,
pp_params=None,
tag=None,
variables=["rho", "vel", "Br", "Bl", "P", "g", "phi"],
):
def __init__(self, path=None, num=None, path_out=None, pp_params=None, tag=None):
"""
Creates the basic structures needed for the outputs
"""
@@ -381,9 +375,10 @@ class PostProcessor(HDF5Container):
self.path = path
self.run = os.path.basename(path)
self.num = num
self._ro = pymses.RamsesOutput(path, num, order=pp_params.pymses.order)
self.variables = variables
self._amr = self._ro.amr_source(self.variables)
self._ro = pymses.RamsesOutput(
path, num, order=pp_params.pymses.order, verbose=pp_params.pymses.verbose
)
self._amr = self._ro.amr_source(self.pp_params.pymses.variables)
self.info = self._ro.info.copy()
# Density operator
@@ -442,47 +437,55 @@ class PostProcessor(HDF5Container):
map_max_size=pp_params.out.map_size,
)
self._add_metadata()
self.close()
self.log_id = "[{}, {}] ".format(self.run, self.num)
self.def_rules()
def _add_metadata(self):
"""
Add additional metadata to the file
"""
# Label of the run in the label.txt file
label_filename = self.path + "/" + self.pp_params.input.label_filename
if os.path.exists(label_filename):
label_file = open(label_filename, "r")
self.label = label_file.readline()
label_file.close()
else:
self.label = self.run
self.save.root._v_attrs.label = self.label
# def open_pymlog(self):
# if self.pp_params.pymses.verbose:
# return sys.stdout
# else:
# return open(os.devnull, "w")
def load_cells(self):
"""
Load all cells from the source file in the memory.
Cells will be accessible trough self.cells
(/!\ Long and memory heavy)
"""
if not self.cells_loaded:
# with self.open_pymlog() as f, contextlib.redirect_stdout(f):
cell_source = CellsToPoints(self._amr)
self.cells = cell_source.flatten()
self.cells_loaded = True
def unload_cells(self):
"""
Free space in the memory by telling the garbage collectors that
self.cells is not needed
"""
if self.cells_loaded:
del self.cells
self.cells_loaded = False
def _slice(self, getter, ax_los="z", z=0, unit=cst.none):
"""
Slice process function.
Return a slice of the source box.
Parameters
----------
getter : callable
A callable that extract the wanted data from a pymses dataset
ax_los : string
The axis perpendicular to the slice plane
z : float
Coordinate of the slice on the ax_los axis
unit : cst.Unit
Unit of the resulting dataset
Returns
-------
A numpy array containing the slice
"""
op = ScalarOperator(getter, unit)
datamap = slicing.SliceMap(self._amr, self._cam[ax_los], op, z=z)
return datamap.map.T
@@ -490,6 +493,9 @@ class PostProcessor(HDF5Container):
def _ax_avg(
self, getter, ax_los, unit=cst.none, mass_weighted=True, surf_qty=False
):
"""
Map of the average of a quantity (given by getter) along an axis (ax_los)
"""
if mass_weighted:
def num(cells):
@@ -559,7 +565,7 @@ class PostProcessor(HDF5Container):
return dmap_P / dmap_rho
def _levels(self, ax_los):
self._amr.set_read_levelmax(20)
self._amr.set_read_levelmax(self.pp_params.pymses.levelmax)
level_op = MaxLevelOperator()
rt_level = raytracing.RayTracer(self._amr, self._ro.info, level_op)
datamap = rt_level.process(self._cam[ax_los], surf_qty=True)
@@ -632,6 +638,9 @@ class PostProcessor(HDF5Container):
return map_Q
def _radial_bins(self, _):
"""
Computes radial bins (for disk)
"""
pos_star = self.pp_params.disk.pos_star
im_extent = self.save.root.maps._v_attrs.im_extent
@@ -660,6 +669,9 @@ class PostProcessor(HDF5Container):
return rad_bins
def _rr(self, _):
"""
Computes the radius from the center
"""
im_extent = self.save.root.maps._v_attrs.im_extent
map_size = self.pp_params.out.map_size
pos_star = self.pp_params.disk.pos_star
@@ -1010,7 +1022,6 @@ class Comparator(Aggregator, HDF5Container):
# Get postprocesor objets for each run
self.pp_runs = {}
attrs = {}
for run in self.runs:
path_run = path + "/" + run
@@ -1041,7 +1052,7 @@ class Comparator(Aggregator, HDF5Container):
else:
saved_nums = self.save.get_node(name_full)._v_attrs.nums
missing_runs = len([run for run in self.nums if not run in saved_nums]) > 0
missing_nums = missing_runs and all(
missing_nums = missing_runs or all(
[
len([num for num in self.nums[run] if not num in saved_nums[run]])
> 0