From 74d588f02b26a58cf45bdde75524ba4c01fa4365 Mon Sep 17 00:00:00 2001 From: Noe Brucy Date: Thu, 17 Jun 2021 11:02:28 +0200 Subject: [PATCH] [postprocessor] add namelist because we need it there --- postprocessor.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/postprocessor.py b/postprocessor.py index c788f50..d796b48 100644 --- a/postprocessor.py +++ b/postprocessor.py @@ -42,6 +42,9 @@ from baseprocessor import ( oct_vect_getter, ) +from run_selector import NamelistRecursive +import f90nml + # Getters @@ -340,7 +343,12 @@ class PostProcessor(HDF5Container): distance = self._radius # Get time - time = self._ro.info["time"] # time in codeunits + self.time = self._ro.info["time"] + + # Get namelist + self.namelist = None + path_nml = path + "/" + self.pp_params.input.nml_filename + self.namelist = NamelistRecursive(f90nml.read(path_nml)) # Set post processing attributes self.save.root._v_attrs.dir = os.path.dirname(path) @@ -348,7 +356,7 @@ class PostProcessor(HDF5Container): self.save.root._v_attrs.num = num self.save.root._v_attrs.lbox = self.lbox self.save.root._v_attrs.unit_length = self.info["unit_length"] - self.save.root._v_attrs.time = time + self.save.root._v_attrs.time = self.time if "/maps" not in self.save: self.save.create_group("/", "maps", "2D maps") @@ -381,9 +389,7 @@ class PostProcessor(HDF5Container): else: self.fil = None - time_in_right_unit = self.info["time"] * self.info["unit_time"].express( - unit_time - ) + time_in_right_unit = self.time * self.info["unit_time"].express(unit_time) self.snapshot = Snapshot( name=str(self.num), description="", @@ -476,6 +482,14 @@ class PostProcessor(HDF5Container): del self.cells self.cells_loaded = False + def get_nml(self, nml_key): + + if self.namelist is not None: + value = self.namelist[nml_key] + else: + raise AttributeError("No namelist associated with this snapshot") + return value + def getter_pos_disk(self, dset): """ Returns the position in normalized and centered units