Coverage for /usr/local/lib/python3.11/dist-packages/grond/plot/main.py: 77%
48 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-26 16:25 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-10-26 16:25 +0000
1import logging
2from grond.meta import GrondError, classes_with_have_get_plot_classes
3from grond.environment import Environment, GrondEnvironmentError
4from grond.plot.collection import PlotCollectionManager
5from grond.plot.config import PlotConfigCollection
7logger = logging.getLogger('grond.plots')
10def get_plot_names(env):
11 plot_classes = env.get_plot_classes()
12 return [plot_class.name for plot_class in plot_classes]
15def get_all_plot_classes():
16 plot_classes = set()
17 for cls in classes_with_have_get_plot_classes:
18 plot_classes.update(cls.get_plot_classes())
20 return sorted(list(plot_classes), key=lambda plot: plot.name)
23def get_plot_config_collection(env=None, plot_names=None):
25 if env is None:
26 plot_classes = get_all_plot_classes()
27 else:
28 plot_classes = env.get_plot_classes()
30 plots = []
31 for plot_class in plot_classes:
32 if plot_names is None or plot_class.name in plot_names:
33 plots.append(plot_class())
35 if plot_names is not None:
36 if set(plot_names) - set([p.name for p in plots]):
37 logger.warning(
38 'Plots %s not available!'
39 % ', '.join(set(plot_names) - set([p.name for p in plots])))
41 collection = PlotConfigCollection(plot_configs=plots)
43 return collection
46def make_plots(
47 env,
48 plot_config_collection=None,
49 plot_names=None,
50 plots_path=None,
51 show=False):
53 if plot_config_collection is None:
54 plot_config_collection = get_plot_config_collection(env, plot_names)
56 if plots_path is None:
57 plots_path = env.get_plots_path()
59 plots = plot_config_collection.plot_configs
60 manager = PlotCollectionManager(plots_path, show=show)
61 env.set_plot_collection_manager(manager)
63 for plot in plots:
64 try:
65 plot.make(env)
66 except (GrondEnvironmentError, GrondError) as e:
67 logger.warning('Cannot create plot %s: %s' % (
68 plot.name, str(e)))
71def make_movie(dirname, xpar_name, ypar_name, movie_filename):
72 env = Environment([dirname])
73 optimiser = env.get_optimiser()
74 problem = env.get_problem()
75 history = env.get_history()
76 movie_maker = optimiser.get_movie_maker(
77 problem, history, xpar_name, ypar_name, movie_filename)
79 movie_maker.render()
82__all__ = [
83 'get_plot_names',
84 'get_plot_config_collection',
85 'get_all_plot_classes',
86 'make_plots',
87 'make_movie']