-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from Simcornelis/master
Jupyter Notebook generation
- Loading branch information
Showing
14 changed files
with
864 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from npf.types.dataset import convert_to_xyeb | ||
from npf.variable import is_numeric, get_numeric | ||
import numpy as np | ||
|
||
class Graph: | ||
""" | ||
This is a structure holder for data to build a graph | ||
""" | ||
def __init__(self, grapher:'Grapher'): | ||
self.grapher = grapher | ||
self.subtitle = None | ||
self.data_types = None | ||
|
||
def statics(self): | ||
return dict([(var,list(values)[0]) for var,values in self.vars_values.items() if len(values) == 1]) | ||
|
||
def dyns(self): | ||
return [var for var,values in self.vars_values.items() if len(values) > 1] | ||
|
||
#Convert the series into the XYEB format (see types.dataset) | ||
def dataset(self, kind=None): | ||
if not self.data_types: | ||
|
||
self.data_types = convert_to_xyeb( | ||
datasets = self.series, | ||
run_list = self.vars_all, | ||
key = self.key, | ||
max_series=self.grapher.config('graph_max_series'), | ||
do_x_sort=self.do_sort, | ||
series_sort=self.grapher.config('graph_series_sort'), | ||
options=self.grapher.options, | ||
statics=self.statics(), | ||
y_group=self.grapher.configdict('graph_y_group'), | ||
color=[get_numeric(v) for v in self.grapher.configlist('graph_color')], | ||
kind=kind | ||
) | ||
|
||
return self.data_types | ||
|
||
# Divide all series by the first one, making a percentage of difference | ||
@staticmethod | ||
def series_prop(series, prop, exclusions = []): | ||
if len(series) == 1: | ||
raise Exception("Cannot make proportional series with only one serie !") | ||
newseries = [] | ||
if not is_numeric(prop): | ||
prop=1 | ||
if len(series[0]) < 3: | ||
raise Exception("Malformed serie !") | ||
base_results=series[0][2] | ||
for i, (script, build, all_results) in enumerate(series[1:]): | ||
new_results={} | ||
for run,run_results in all_results.items(): | ||
if not run in base_results: | ||
print(run,"FIXME is not in base") | ||
continue | ||
|
||
for result_type, results in run_results.items(): | ||
if not result_type in base_results[run]: | ||
run_results[result_type] = None | ||
print(result_type, "not in base for %s" % run) | ||
continue | ||
base = base_results[run][result_type] | ||
if len(base) > len(results): | ||
base = base[:len(results)] | ||
elif len(results) > len(base): | ||
results = results[:len(base)] | ||
base = np.array(base) | ||
results = np.array(results) | ||
if result_type not in exclusions: | ||
f = np.nonzero(base) | ||
results = (results[f] / base[f] * float(abs(prop)) + (prop if prop < 0 else 0)) | ||
run_results[result_type] = results | ||
new_results[run] = run_results | ||
build._pretty_name = build._pretty_name + " / " + series[0][1]._pretty_name | ||
newseries.append((script, build, new_results)) | ||
return newseries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from npf import npf | ||
|
||
# types of graphs: bar, line, boxplot, simple_bar | ||
|
||
|
||
def decide_graph_type(config, n_values, vars_values, key, result_type, ndyn, isubplot): | ||
graph_type = "bar" | ||
if ndyn == 0: | ||
graph_type = "boxplot" if n_values == 1 else "simple_bar" | ||
elif ndyn == 1 and n_values > 2 and npf.all_num(vars_values[key]): | ||
graph_type = "line" | ||
graph_types = config("graph_type", []) | ||
|
||
if len(graph_types) > 0 and (type(graph_types[0]) is tuple or type(graph_types) is tuple): | ||
if type(graph_types) is tuple: | ||
graph_types = dict([graph_types]) | ||
else: | ||
graph_types = dict(graph_types) | ||
if result_type in graph_types: | ||
graph_type = graph_types[result_type] | ||
elif "default" in graph_types: | ||
graph_type = graph_types["default"] | ||
elif "result" in graph_types: | ||
graph_type = graph_types["result"] | ||
else: | ||
graph_type = "line" | ||
|
||
else: | ||
if type(graph_types) is str: | ||
graph_types = [graph_types] | ||
graph_types.extend([graph_type, "line"]) | ||
graph_type = graph_types[isubplot if isubplot < len( | ||
graph_types) else len(graph_types) - 1] | ||
|
||
if ndyn == 0 and graph_type == "line": | ||
print("WARNING: Cannot graph", graph_type, | ||
"as a line without dynamic variables") | ||
graph_type = "simple_bar" | ||
|
||
return graph_type |
Oops, something went wrong.