Improve log system

This commit is contained in:
Noe Brucy
2022-08-26 20:06:38 +02:00
parent 07017611ee
commit 67f8f014d6
4 changed files with 74 additions and 39 deletions
+11 -10
View File
@@ -239,6 +239,10 @@ class Plotter(Aggregator, BaseProcessor):
kwargs : Keyword arguments for RunSelector.
"""
# log info
self.log_id = "plot {}".format(tag)
super(Plotter, self).__init__(path, path_out, params, tag)
# Select runs
@@ -273,9 +277,6 @@ class Plotter(Aggregator, BaseProcessor):
# Get postprocesor objets for each run
self.snaps = self.study.snaps
# Define log prefix
self.log_id = "[plot {}] ".format(self.params.out.tag)
# Define rules
self.def_rules()
@@ -312,7 +313,7 @@ class Plotter(Aggregator, BaseProcessor):
try:
value = self.study.get_nml(param.key, run)
except KeyError as e:
self._log("key {} not found".format(e), "WARNING")
self.logger.warning("key {} not found".format(e))
if value is not None:
try:
@@ -858,7 +859,7 @@ class Plotter(Aggregator, BaseProcessor):
plt.xlim(xlim)
plt.ylim(ylim)
if self.params.astrophysics.generate:
if self.params.astrophysix.generate:
return PlotInfo(
plot_type=PlotType.IMAGE,
xaxis_values=np.linspace(im_extent[0], im_extent[1], dmap.shape[0] + 1),
@@ -1203,7 +1204,7 @@ class Plotter(Aggregator, BaseProcessor):
)
# returns PlotInfo (for Galactica)
if self.params.astrophysics.generate:
if self.params.astrophysix.generate:
edges = np.append(centers - width / 2.0, centers[-1] + width / 2.0)
return PlotInfo(
plot_type=PlotType.HISTOGRAM,
@@ -1429,7 +1430,7 @@ class Plotter(Aggregator, BaseProcessor):
if kind == "linear":
if yerr is None or np.sum(np.abs(yerr)) == 0:
(a, b, rho, _map_rule, stderr) = linregress(x, y)
self._log(
self.logger.info(
"Linear fit y = {} x + {} with R^2 = {} and error is {}".format(
a, b, rho, stderr
)
@@ -1443,7 +1444,7 @@ class Plotter(Aggregator, BaseProcessor):
c = fit[0]
residual = fit[1][0][0]
b, a = c[0], c[1]
self._log(
self.logger.info(
"Linear fit y = {} x + {} with residual {}".format(a, b, residual)
)
if label is None:
@@ -1452,7 +1453,7 @@ class Plotter(Aggregator, BaseProcessor):
elif kind == "power_law":
if yerr is None or np.sum(np.abs(yerr)) == 0:
(a, b, rho, _map_rule, stderr) = linregress(np.log10(x), np.log10(y))
self._log(
self.logger.info(
"Power law fit y = x^({}) * {} with R^2 = {} and error is {}".format(
a, 10 ** b, rho, stderr
)
@@ -1476,7 +1477,7 @@ class Plotter(Aggregator, BaseProcessor):
c = out[0]
b, a = c[0], c[1]
residual = errfunc(c, np.log10(x), np.log10(y), yerr / y)
self._log(
self.logger.info(
"Power law fit y = x^({}) * {} with residual {}".format(
a, 10 ** b, residual
)