Skip to content
Snippets Groups Projects
Commit 1b2462cd authored by Jameson Rollins's avatar Jameson Rollins
Browse files

cli: tweaks to interactive mode

allow use of --no-plot option with interactive mode, and improve
banner and docs.
parent 3462a97d
No related branches found
No related tags found
No related merge requests found
Pipeline #128483 passed
......@@ -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
......
......@@ -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()
##########
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment