Ax-aware plotting, More PDFs, improve format

This commit is contained in:
Noe Brucy
2020-02-19 17:51:23 +01:00
parent a87abeb52d
commit 8d7c5296cc
5 changed files with 281 additions and 108 deletions
+50 -14
View File
@@ -1,9 +1,9 @@
f # coding: utf-8
# coding: utf-8
import sys
import os
import glob as glob
import copy
import tables
import pymses
@@ -87,7 +87,7 @@ class BaseProcessor:
elif type(pp_params) == str:
self.pp_params = load_params(pp_params)
else:
self.pp_params = pp_params
self.pp_params = copy.deepcopy(pp_params)
if tag is not None:
self.pp_params.out.tag = tag
@@ -229,16 +229,24 @@ class HDF5Container(BaseProcessor):
finally:
self.close()
def get_value(self, node_name):
def get_value(self, node_name, unit=None, unit_old=None):
self.open()
try:
node = self.save.get_node(node_name)
if "unit" in node._v_attrs:
unit_old = node._v_attrs.unit
if node._v_attrs.CLASS == "GROUP":
value = {}
for child_name in node._v_children:
value[child_name] = self.get_value(node_name + "/" + child_name)
value[child_name] = self.get_value(
node_name + "/" + child_name, unit, unit_old
)
else:
value = node.read()
if not (unit is None or unit_old is None or unit_old == cst.none):
value = value * unit_old.express(unit)
finally:
self.close()
return value
@@ -303,7 +311,8 @@ class HDF5Container(BaseProcessor):
self.save.get_node(name_full).attrs.unit = unit
if not attrs is None:
self.save.get_node(name_full).attrs.update(attrs)
for key in attrs:
self.save.get_node(name_full)._v_attrs[key] = attrs[key]
def set_value(self, node_name, data, description, unit):
self.open()
@@ -321,6 +330,14 @@ class HDF5Container(BaseProcessor):
self.close()
return attr
def set_attribute(self, node_name, attr_name, attr_value):
self.open()
try:
node = self.save.get_node(node_name)
node._v_attrs[attr_name] = attr_value
finally:
self.close()
def _transform(self, name, transform_fn, group="/maps", **kwargs):
src = self.save.get_node(group + "/" + name).read()
return transform_fn(src, **kwargs)
@@ -362,14 +379,33 @@ class HDF5Container(BaseProcessor):
name = transform_name + "_" + rule_src_name
self.rules[name] = Rule(
self,
fn,
group=group,
unit=unit,
description=description,
dependencies=[rule_src_name],
)
def apply(
self,
fn,
name_array_in,
name_array_out,
unit_out=cst.none,
description="",
recursive=True,
):
array_in = self.get_value(name_array_in)
if recursive and isinstance(array_in, dict):
for key in array_in:
self.apply(
fn,
name_array_in + "/" + key,
name_array_out + "/" + key,
unit_out,
description,
)
self.set_attribute(name_array_out, "unit", unit_out)
else:
try:
array_out = fn(array_in)
except TypeError:
array_out = array_in
self.set_value(name_array_out, array_out, description, unit_out)
def simple_getter(name, dset):