-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated bar chart plotter from old datatypes
Updated datatypes and module. Added some new test data and a test pipeline that uses it.
- Loading branch information
Showing
18 changed files
with
152 additions
and
178 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
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
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,52 @@ | ||
# This file is part of Pimlico | ||
# Copyright (C) 2020 Mark Granroth-Wilding | ||
# Licensed under the GNU LGPL v3.0 - https://www.gnu.org/licenses/lgpl-3.0.en.html | ||
|
||
import json | ||
import os | ||
|
||
from pimlico.datatypes.base import PimlicoDatatype | ||
from pimlico.utils.core import cached_property | ||
|
||
|
||
class NumericResult(PimlicoDatatype): | ||
""" | ||
Simple datatype to contain a numeric value and a label, representing | ||
the result of some process, such as evaluation of a model on a task. | ||
Write using ``writer.write(label, value)``. The label must be a string, | ||
identifying what the result is, e.g. "f-score". The value can be any | ||
JSON-serializable type, e.g. int or float. | ||
For example, allows results to be plotted by passing them into a graph plotting module. | ||
""" | ||
datatype_name = "numeric_result" | ||
datatype_supports_python2 = True | ||
|
||
class Reader(object): | ||
class Setup(object): | ||
def get_required_paths(self): | ||
return ["data.json"] | ||
|
||
@cached_property | ||
def data(self): | ||
with open(os.path.join(self.data_dir, "data.json"), "r") as f: | ||
return json.load(f) | ||
|
||
@cached_property | ||
def label(self): | ||
return self.data["label"] | ||
|
||
@cached_property | ||
def value(self): | ||
return self.data["value"] | ||
|
||
class Writer(object): | ||
required_tasks = ["data"] | ||
|
||
def write(self, label, value): | ||
# Write out the data JSON file | ||
with open(os.path.join(self.data_dir, "data.json"), "w") as f: | ||
json.dump({"label": label, "value": value}, f) | ||
self.task_complete("data") |
File renamed without changes.
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
40 changes: 40 additions & 0 deletions
40
src/python/pimlico/modules/visualization/bar_chart/info.py
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 @@ | ||
# This file is part of Pimlico | ||
# Copyright (C) 2020 Mark Granroth-Wilding | ||
# Licensed under the GNU LGPL v3.0 - https://www.gnu.org/licenses/lgpl-3.0.en.html | ||
|
||
""" | ||
Simple plotting of a bar chart from numeric results data using Matplotlib. | ||
""" | ||
from pimlico.core.modules.options import comma_separated_strings | ||
|
||
from pimlico.core.modules.base import BaseModuleInfo | ||
from pimlico.datatypes.base import MultipleInputs | ||
from pimlico.datatypes.plotting import PlotOutput | ||
from pimlico.datatypes.results import NumericResult | ||
from pimlico.modules.visualization import matplotlib_dependency | ||
|
||
|
||
class ModuleInfo(BaseModuleInfo): | ||
module_type_name = "bar_chart" | ||
module_readable_name = "Bar chart plotter" | ||
module_inputs = [("results", MultipleInputs(NumericResult()))] | ||
module_outputs = [("plot", PlotOutput())] | ||
module_supports_python2 = True | ||
module_options = { | ||
"labels": { | ||
"help": "If given, a list of labels corresponding to the inputs to use in plots. " | ||
"Otherwise, inputs are numbered and the labels provided in their label fields are used", | ||
"type": comma_separated_strings, | ||
}, | ||
"colors": { | ||
"help": "Pyplot colors to use for each series. If shorter than the number of inputs, " | ||
"cycles round. Specify according to pyplot docs: https://matplotlib.org/2.0.2/api/colors_api.html. " | ||
"E.g. use single-letter color names, HTML color codes or HTML color names", | ||
"type": comma_separated_strings, | ||
"default": ["r", "g", "b", "y", "c", "m", "k"], | ||
}, | ||
} | ||
|
||
def get_software_dependencies(self): | ||
return [matplotlib_dependency] |
4 changes: 0 additions & 4 deletions
4
.../visualization/bar_chart/plot_template.py → .../visualization/bar_chart/plot_template.py
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
1 change: 0 additions & 1 deletion
1
src/python/pimlico/old_datatypes/modules/visualization/bar_chart/__init__.py
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
src/python/pimlico/old_datatypes/modules/visualization/bar_chart/info.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
{} |
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 @@ | ||
{"label": "A", "value": 6.5} |
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 @@ | ||
{} |
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 @@ | ||
{"label": "B", "value": 13.2} |
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 @@ | ||
{} |
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 @@ | ||
{"label": "C", "value": 10.76} |
Oops, something went wrong.