[plotter] read label from file

This commit is contained in:
Noe Brucy
2021-06-22 12:26:40 +02:00
parent baed67fd47
commit f0bea238c1
+19 -15
View File
@@ -330,7 +330,7 @@ class Plotter(Aggregator, BaseProcessor):
# Find plot save # Find plot save
if from_cells or rule.kind == "cells": if from_cells or rule.kind == "cells":
if not os.exists(self.pp[run][num].cells_filename): if not os.path.exists(self.pp[run][num].cells_filename):
self.pp[run][num].load_cells() self.pp[run][num].load_cells()
self.pp[run][num].unload_cells() self.pp[run][num].unload_cells()
save = tables.open_file(self.pp[run][num].cells_filename) save = tables.open_file(self.pp[run][num].cells_filename)
@@ -435,7 +435,7 @@ class Plotter(Aggregator, BaseProcessor):
ext=self.pp_params.out.ext, ext=self.pp_params.out.ext,
) )
def _label_run(self, run, node, label, nml_key, time=None): def get_label_run(self, run, label=None, nml_key=None, time=None):
""" """
Set up a label for the run from the namelist and parameters Set up a label for the run from the namelist and parameters
""" """
@@ -446,7 +446,7 @@ class Plotter(Aggregator, BaseProcessor):
prop_label = self.label_convert[prop_name] prop_label = self.label_convert[prop_name]
else: else:
prop_label = prop_name prop_label = prop_name
prop_value = self.comp.get_nml(nml_key, run) prop_value = self.study.get_nml(nml_key, run)
if prop_name in self.value_convert: if prop_name in self.value_convert:
prop_value_str = self.value_convert[prop_name](prop_value) prop_value_str = self.value_convert[prop_name](prop_value)
elif type(prop_value) in [int, float]: elif type(prop_value) in [int, float]:
@@ -455,14 +455,18 @@ class Plotter(Aggregator, BaseProcessor):
prop_value_str = str(prop_value) prop_value_str = str(prop_value)
return r"{} = {}".format(prop_label, prop_value_str) return r"{} = {}".format(prop_label, prop_value_str)
if nml_key is None and label is None: def get_label_file(run):
if ( label_filename = f"{self.path}/{run}/{self.pp_params.input.label_filename}"
"attrs" in self.save.root._v_attrs if os.path.exists(label_filename):
and run in self.save.root._v_attrs.attrs with open(label_filename, "r") as label_file:
): label = label_file.readline()[:-1]
label_run = r"{}".format(self.save.root._v_attrs.attrs[run].label) label_file.close()
else: else:
label_run = run label = run
return label
if nml_key is None and label is None:
label_run = get_label_file(run)
elif nml_key is not None: elif nml_key is not None:
if not type(nml_key) == list: if not type(nml_key) == list:
nml_key = [nml_key] nml_key = [nml_key]
@@ -506,8 +510,8 @@ class Plotter(Aggregator, BaseProcessor):
return label, unit_old, unit return label, unit_old, unit
def _snapshot_title(self, run, node, title, nml_key, put_time, unit_time=U.Myr): def snapshot_title(self, run, title, nml_key, put_time, unit_time=U.Myr):
title = self._label_run(run, node, title, nml_key) title = self.get_label_run(run, title, nml_key)
if put_time: if put_time:
time = self.save.root._v_attrs.time * self.comp.info["unit_time"] time = self.save.root._v_attrs.time * self.comp.info["unit_time"]
@@ -607,7 +611,7 @@ class Plotter(Aggregator, BaseProcessor):
cbar = plt.colorbar() cbar = plt.colorbar()
if put_title: if put_title:
title = self._snapshot_title(run, node, title, nml_key, put_time, unit_time) title = self.snapshot_title(run, title, nml_key, put_time, unit_time)
plt.title(title) plt.title(title)
if label is not None: if label is not None:
@@ -908,7 +912,7 @@ class Plotter(Aggregator, BaseProcessor):
width = centers[1] - centers[0] width = centers[1] - centers[0]
# Set title # Set title
title = self._snapshot_title(run, node, title, nml_key, put_time, unit_time) title = self.snapshot_title(run, title, nml_key, put_time, unit_time)
if put_title: if put_title:
plt.title(title) plt.title(title)
if label is None: if label is None:
@@ -1108,7 +1112,7 @@ class Plotter(Aggregator, BaseProcessor):
if smooth > 0: if smooth > 0:
y = gaussian_filter1d(y, sigma=smooth) y = gaussian_filter1d(y, sigma=smooth)
if run is not None: if run is not None:
label = self._label_run(run, node_y, label, nml_key) label = self.get_label_run(run, label, nml_key)
# Look if special colors method is used # Look if special colors method is used
if colors is None: if colors is None: