From 1b2462cd6117ebceace6b2f3095e27860a24baa2 Mon Sep 17 00:00:00 2001
From: Jameson Graef Rollins <jameson.rollins@ligo.org>
Date: Thu, 21 May 2020 10:25:02 -0700
Subject: [PATCH] cli: tweaks to interactive mode

allow use of --no-plot option with interactive mode, and improve
banner and docs.
---
 README.md         | 17 +++++++++++++++++
 gwinc/__main__.py | 35 +++++++++++++++++++++++------------
 2 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md
index a316d18..bf267c4 100644
--- a/README.md
+++ b/README.md
@@ -83,6 +83,23 @@ the path to the budget module/package:
 $ python3 -m gwinc path/to/mybudget
 ```
 
+The command line interface also includes an "interactive" mode which
+provides an [IPython](https://ipython.org/) shell for interacting with a processed budget:
+```shell
+$ python3 -m gwinc -i Aplus
+GWINC interactive shell
+
+The 'ifo' Struct and 'traces' data are available for inspection.
+Use the 'whos' command to view the workspace.
+
+You may interact with the plot using the 'plt' functions, e.g.:
+
+In [.]: plt.title("foo")
+In [.]: plt.savefig("foo.pdf")
+
+In [1]: 
+```
+
 See command help for more info:
 ```shell
 $ python3 -m gwinc -h
diff --git a/gwinc/__main__.py b/gwinc/__main__.py
index ff11b17..64bf6be 100644
--- a/gwinc/__main__.py
+++ b/gwinc/__main__.py
@@ -74,7 +74,7 @@ parser.add_argument(
 group = parser.add_mutually_exclusive_group()
 group.add_argument(
     '--interactive', '-i', action='store_true',
-    help="interactive plot with interactive shell")
+    help="launch interactive shell with plotting capability after budget processing")
 group.add_argument(
     '--save', '-s', action='append',
     help="save plot (.png/.pdf/.svg) or budget traces (.hdf5/.h5) to file (may be specified multiple times)")
@@ -87,7 +87,7 @@ group.add_argument(
 group.add_argument(
     '--diff', '-d', metavar='IFO',
     help="show differences table between another IFO description and exit (budget not calculated)")
-group.add_argument(
+parser.add_argument(
     '--no-plot', '-np', action='store_false', dest='plot',
     help="supress plotting")
 parser.add_argument(
@@ -247,16 +247,26 @@ def main():
 
     # interactive shell plotting
     if args.interactive:
-        from IPython.terminal.embed import InteractiveShellEmbed
-        ipshell = InteractiveShellEmbed(
-            banner1='''
-GWINC interactive plotter
+        banner = """GWINC interactive shell
+
+The 'ifo' Struct and 'traces' data are available for inspection.
+Use the 'whos' command to view the workspace.
+"""
+        if not args.plot:
+            banner += """
+You may plot the budget using the 'plot_noise()' function:
 
-You may interact with plot using "plt." methods, e.g.:
+In [.]: plot_noise(freq, traces, **plot_style)
+"""
+        banner += """
+You may interact with the plot using the 'plt' functions, e.g.:
 
->>> plt.title("foo")
->>> plt.savefig("foo.pdf")
-''',
+In [.]: plt.title("foo")
+In [.]: plt.savefig("foo.pdf")
+"""
+        from IPython.terminal.embed import InteractiveShellEmbed
+        ipshell = InteractiveShellEmbed(
+            banner1=banner,
             user_ns={
                 'freq': freq,
                 'traces': traces,
@@ -266,8 +276,9 @@ You may interact with plot using "plt." methods, e.g.:
             },
         )
         ipshell.enable_pylab()
-        ipshell.ex("fig = plot_noise(freq, traces, **plot_style)")
-        ipshell.ex("plt.title('{}')".format(plot_style['title']))
+        if args.plot:
+            ipshell.ex("fig = plot_noise(freq, traces, **plot_style)")
+            ipshell.ex("plt.title('{}')".format(plot_style['title']))
         ipshell()
 
     ##########
-- 
GitLab