Show More
@@ -4,7 +4,7 b'' | |||
|
4 | 4 | octavemagic |
|
5 | 5 | =========== |
|
6 | 6 | |
|
7 |
Magic |
|
|
7 | Magics for interacting with Octave via oct2py. | |
|
8 | 8 | |
|
9 | 9 | Usage |
|
10 | 10 | ===== |
@@ -30,17 +30,15 b' Usage' | |||
|
30 | 30 | # the file COPYING, distributed as part of this software. |
|
31 | 31 | #----------------------------------------------------------------------------- |
|
32 | 32 | |
|
33 | import sys | |
|
34 | 33 | import tempfile |
|
35 | 34 | from glob import glob |
|
36 | 35 | from shutil import rmtree |
|
37 | from getopt import getopt | |
|
38 | 36 | |
|
39 | 37 | import numpy as np |
|
40 | 38 | import oct2py |
|
41 | 39 | |
|
42 | 40 | from IPython.core.displaypub import publish_display_data |
|
43 |
from IPython.core.magic import (Magics, magics_class, |
|
|
41 | from IPython.core.magic import (Magics, magics_class, line_magic, | |
|
44 | 42 | line_cell_magic) |
|
45 | 43 | from IPython.testing.skipdoctest import skip_doctest |
|
46 | 44 | from IPython.core.magic_arguments import ( |
@@ -117,6 +115,7 b' class OctaveMagics(Magics):' | |||
|
117 | 115 | ''' |
|
118 | 116 | outputs = line.split(' ') |
|
119 | 117 | for output in outputs: |
|
118 | output = unicode_to_str(output) | |
|
120 | 119 | self.shell.push({output: self.oct.get(output)}) |
|
121 | 120 | |
|
122 | 121 | |
@@ -131,6 +130,10 b' class OctaveMagics(Magics):' | |||
|
131 | 130 | help='Names of variables to be pulled from Octave after executing cell body. Multiple names can be passed, separated by commas with no whitespace.' |
|
132 | 131 | ) |
|
133 | 132 | @argument( |
|
133 | '-s', '--size', action='append', | |
|
134 | help='Pixel size of plots. Default is "-s 400,250".' | |
|
135 | ) | |
|
136 | @argument( | |
|
134 | 137 | 'code', |
|
135 | 138 | nargs='*', |
|
136 | 139 | ) |
@@ -190,10 +193,15 b' class OctaveMagics(Magics):' | |||
|
190 | 193 | |
|
191 | 194 | if args.input: |
|
192 | 195 | for input in ','.join(args.input).split(','): |
|
196 | input = unicode_to_str(input) | |
|
193 | 197 | self.oct.put(input, self.shell.user_ns[input]) |
|
194 | 198 | |
|
195 | 199 | # generate plots in a temporary directory |
|
196 | 200 | plot_dir = tempfile.mkdtemp() |
|
201 | if args.size is not None: | |
|
202 | size = args.size[0] | |
|
203 | else: | |
|
204 | size = '400,240' | |
|
197 | 205 | |
|
198 | 206 | pre_call = ''' |
|
199 | 207 | global __ipy_figures = []; |
@@ -202,6 +210,7 b' class OctaveMagics(Magics):' | |||
|
202 | 210 | function fig_create(src, event) |
|
203 | 211 | global __ipy_figures; |
|
204 | 212 | __ipy_figures(size(__ipy_figures) + 1) = src; |
|
213 | set(src, "visible", "off"); | |
|
205 | 214 | end |
|
206 | 215 | |
|
207 | 216 | set(0, 'DefaultFigureCreateFcn', @fig_create); |
@@ -219,11 +228,13 b' class OctaveMagics(Magics):' | |||
|
219 | 228 | end |
|
220 | 229 | |
|
221 | 230 | for f = __ipy_figures |
|
222 | outfile = sprintf('%s/__ipy_oct_fig_%%03d.png', f) | |
|
223 | print(f, outfile, '-dpng') | |
|
231 | outfile = sprintf('%(plot_dir)s/__ipy_oct_fig_%%03d.png', f); | |
|
232 | print(f, outfile, '-dpng', '-S%(size)s'); | |
|
224 | 233 | end |
|
225 | 234 | |
|
226 | ''' % plot_dir | |
|
235 | # close all; | |
|
236 | ||
|
237 | ''' % {'plot_dir': plot_dir, 'size': size} | |
|
227 | 238 | |
|
228 | 239 | code = ' '.join((pre_call, code, post_call)) |
|
229 | 240 | try: |
@@ -266,7 +277,7 b' class OctaveMagics(Magics):' | |||
|
266 | 277 | |
|
267 | 278 | # Unfortunately, Octave doesn't have a "None" object, |
|
268 | 279 | # so we can't return any NaN outputs |
|
269 |
if np.isnan( |
|
|
280 | if np.isscalar(ans) and np.isnan(ans): | |
|
270 | 281 | ans = None |
|
271 | 282 | |
|
272 | 283 | return ans |
General Comments 0
You need to be logged in to leave comments.
Login now