Skip to content

Commit

Permalink
analysis: Improve log statements
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutH committed Nov 17, 2023
1 parent 9eb6cb4 commit 937e946
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ema_workbench/analysis/b_and_w_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def set_fig_to_bw(fig, style=HATCHING, line_style="continuous"):

if len(all_colors) > len(bw_mapping):
mapping_cycle = itertools.cycle(bw_mapping)
_logger.warning("more colors used than provided in B&W mapping, cycling over mapping")
_logger.warning(f"more colors ({len(all_colors)}) used than provided in B&W mapping ({len(bw_mapping)}), cycling over mapping")
else:
mapping_cycle = bw_mapping
colormap = dict(zip(all_colors, mapping_cycle))
Expand Down
4 changes: 2 additions & 2 deletions ema_workbench/analysis/pairs_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def do_text_ticks_labels(ax, i, j, field1, field2, ylabels, outcomes_to_show):
try:
ax.set_xlabel(ylabels.get(field2))
except KeyError:
_logger.info("no label specified for " + field2)
_logger.info(f"no label specified for {field2}")
else:
ax.set_xlabel(field2)

Expand All @@ -561,6 +561,6 @@ def do_text_ticks_labels(ax, i, j, field1, field2, ylabels, outcomes_to_show):
try:
ax.set_ylabel(ylabels.get(field1))
except KeyError:
_logger.info("no label specified for " + field1)
_logger.info(f"no label specified for {field1}")
else:
ax.set_ylabel(field1)
2 changes: 1 addition & 1 deletion ema_workbench/analysis/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def group_by_envelopes(outcomes, outcome_to_plot, time, density, ax, ax_d, fill,
try:
plot_envelope(ax, j, time, value, fill)
except ValueError:
_logger.exception(f"value error when plotting for {key}")
_logger.exception(f"ValueError when plotting for {key}")
raise

if density:
Expand Down
8 changes: 4 additions & 4 deletions ema_workbench/analysis/plotting_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def determine_kde(data, size_kde=1000, ymin=None, ymax=None):
# best_kde = grid.best_estimator_
# kde_x = np.exp(best_kde.score_samples(kde_y[:, np.newaxis]))
except Exception as e:
_logger.warning(e)
_logger.warning(f"error in determine_kde: {e}")
kde_x = np.zeros(kde_y.shape)

return kde_x, kde_y
Expand All @@ -508,7 +508,7 @@ def filter_scalar_outcomes(outcomes):
temp = {}
for key, value in outcomes.items():
if value.ndim < 2:
_logger.info(("{} not shown because it is " "not time series data").format(key))
_logger.info(f"outcome {key} not shown because it is not time series data")
else:
temp[key] = value
return temp
Expand Down Expand Up @@ -814,7 +814,7 @@ def do_titles(ax, titles, outcome):
try:
ax.set_title(titles[outcome])
except KeyError:
_logger.warning(f"key error in do_titles, no title provided for `{outcome}`")
_logger.warning(f"KeyError in do_titles, no title provided for outcome `{outcome}`")
ax.set_title(outcome)


Expand All @@ -839,7 +839,7 @@ def do_ylabels(ax, ylabels, outcome):
try:
ax.set_ylabel(ylabels[outcome])
except KeyError:
_logger.warning(f"key error in do_ylabels, no ylabel provided for `{outcome}`")
_logger.warning(f"KeyError in do_ylabels, no ylabel provided for outcome `{outcome}`")
ax.set_ylabel(outcome)


Expand Down
17 changes: 11 additions & 6 deletions ema_workbench/analysis/prim.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import altair as alt
except ImportError:
alt = None
warnings.warn(("altair based interactive " "inspection not available"), ImportWarning)
warnings.warn("altair based interactive inspection not available", ImportWarning)

from ..util import EMAError, temporary_filter, INFO, get_module_logger
from . import scenario_discovery_util as sdutil
Expand Down Expand Up @@ -108,7 +108,9 @@ def pca_preprocess(experiments, y, subsets=None, exclude=set()):
if not x.select_dtypes(exclude=np.number).empty:
raise RuntimeError("X includes non numeric columns")
if not set(np.unique(y)) == {0, 1}:
raise RuntimeError(f"y should only contain 0s and 1s, currently y contains {set(np.unique(y))}.")
raise RuntimeError(
f"y should only contain 0s and 1s, currently y contains {set(np.unique(y))}."
)

# if no subsets are provided all uncertainties with non dtype object
# are in the same subset, the name of this is r, for rotation
Expand Down Expand Up @@ -1026,7 +1028,9 @@ def __init__(
for column in x_nominal.columns.values:
if np.unique(x[column]).shape == (1,):
x = x.drop(column, axis=1)
_logger.info(f"{column} dropped from analysis " "because only a single category")
_logger.info(
f"column {column} dropped from analysis because it has only one category"
)

x_nominal = x.select_dtypes(exclude=np.number)
self.x_nominal = x_nominal.values
Expand Down Expand Up @@ -1100,7 +1104,7 @@ def find_box(self):
box._frozen = True

if self.yi_remaining.shape[0] == 0:
_logger.info("no data remaining")
_logger.info("no data remaining, exiting")
return

# log how much data and how many coi are remaining
Expand All @@ -1119,7 +1123,7 @@ def find_box(self):
box = self._paste(box)
_logger.debug("pasting completed")

message = "mean: {0}, mass: {1}, coverage: {2}, " "density: {3} restricted_dimensions: {4}"
message = "mean: {0}, mass: {1}, coverage: {2}, density: {3} restricted_dimensions: {4}"
message = message.format(box.mean, box.mass, box.coverage, box.density, box.res_dim)

if (self.threshold_type == ABOVE) & (box.mean >= self.threshold):
Expand All @@ -1133,7 +1137,8 @@ def find_box(self):
else:
# make a dump box
_logger.info(
f"box does not meet threshold criteria, value is {box.mean}, returning dump box"
f"box mean ({box.mean}) does not meet threshold criteria ({self.threshold_type} {self.threshold}),"
f"returning dump box"
)
box = PrimBox(self, self.box_init, self.yi_remaining[:])
self._boxes.append(box)
Expand Down

0 comments on commit 937e946

Please sign in to comment.