Skip to content

Commit

Permalink
Add method to read config file contents and improve plot file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
perceptualrobots committed Jan 3, 2025
1 parent cc5a588 commit 1fad554
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 17 deletions.
14 changes: 6 additions & 8 deletions nbs/19_pct_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,14 @@
" Plot one item of the history of the hierarchy.\n",
" \"\"\"\n",
"\n",
" from os import sep\n",
" from os import sep, path, makedirs\n",
"\n",
" plotfile=None\n",
" if plots_dir:\n",
" plotfile = plots_dir + sep + plot['title'] + '-' + str(self.hierarchy.get_namespace()) + '.png'\n",
" fig = self.hierarchy.hierarchy_plots(title=plot['title'], plot_items=plot['plot_items'], figsize=plots_figsize, file=plotfile, history=history_data)\n",
" if not path.exists(plots_dir):\n",
" makedirs(plots_dir)\n",
" plotfile = plots_dir + sep + title_prefix + plot['title'] + '-' + str(self.hierarchy.get_namespace()) + '.png'\n",
" fig = self.hierarchy.hierarchy_plots(title=title_prefix + plot['title'], plot_items=plot['plot_items'], figsize=plots_figsize, file=plotfile, history=history_data)\n",
" # import matplotlib.pyplot as plt\n",
" # plt.close(fig) # Close the figure here\n",
" \n",
Expand All @@ -225,13 +227,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.9.11"
}
},
"nbformat": 4,
Expand Down
134 changes: 130 additions & 4 deletions nbs/52_pct_examples_usage.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pct/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,8 @@
'pct.pct_examples.PCTExamples.draw': ('pct_examples.html#pctexamples.draw', 'pct/pct_examples.py'),
'pct.pct_examples.PCTExamples.get_config': ( 'pct_examples.html#pctexamples.get_config',
'pct/pct_examples.py'),
'pct.pct_examples.PCTExamples.get_config_file_contents': ( 'pct_examples.html#pctexamples.get_config_file_contents',
'pct/pct_examples.py'),
'pct.pct_examples.PCTExamples.get_history_keys': ( 'pct_examples.html#pctexamples.get_history_keys',
'pct/pct_examples.py'),
'pct.pct_examples.PCTExamples.plot_history': ( 'pct_examples.html#pctexamples.plot_history',
Expand Down
17 changes: 12 additions & 5 deletions pct/pct_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ def set_history_data(self):

return None



def get_config_file_contents(self):
"""
Reads and returns the contents of the config file.
"""
with open(self.config_file, 'r') as file:
return file.read()

def plot_history(self, plots=None, title_prefix='', plots_dir=None, plots_figsize=(12, 6), history_data=None):
"""
Plots the history of the hierarchy.
Expand All @@ -135,12 +140,14 @@ def plot_single(self, plot=None, title_prefix='', plots_dir=None, plots_figsize=
Plot one item of the history of the hierarchy.
"""

from os import sep
from os import sep, path, makedirs

plotfile=None
if plots_dir:
plotfile = plots_dir + sep + plot['title'] + '-' + str(self.hierarchy.get_namespace()) + '.png'
fig = self.hierarchy.hierarchy_plots(title=plot['title'], plot_items=plot['plot_items'], figsize=plots_figsize, file=plotfile, history=history_data)
if not path.exists(plots_dir):
makedirs(plots_dir)
plotfile = plots_dir + sep + title_prefix + plot['title'] + '-' + str(self.hierarchy.get_namespace()) + '.png'
fig = self.hierarchy.hierarchy_plots(title=title_prefix + plot['title'], plot_items=plot['plot_items'], figsize=plots_figsize, file=plotfile, history=history_data)
# import matplotlib.pyplot as plt
# plt.close(fig) # Close the figure here

Expand Down

0 comments on commit 1fad554

Please sign in to comment.