forpy から inline 命令出せない?
IPython.core.getipython.get_ipython().magic('matplotlib inline') によって、実行命令で inline マジックコマンドが発行できるかとも思ったが、出来ない模様。
Module: core.getipython — IPython 6.5.0 documentation
IPython.core.getipython.get_ipython() で戻り値が None になっているので、Jupyter の中で動いているとはいえ、forpy は独立した Python 処理系で動いているのだから、Ipython のインスタンスが取れなくても当然のような気がする。したがって、forpy からの呼び出しで inline 化は出来ないような気がする。
Python Kernel の場合
import IPython.core.getipython ip = IPython.core.getipython.get_ipython() ip.magic('matplotlib inline') print(ip) <ipykernel.zmqshell.ZMQInteractiveShell object at 0x0000020B2527DDD8>
もっとも、CMD 窓の サーバーのメッセージには ZMQ は closed channel にデータ受けたとかメッセージを返しているので、別の手法で乗り越えられるのかもしれない。
画像 inline 表示について
なお、ファイルの画像は MIME type を変えるだけで、png/gif/jpeg/bmp なんでもござれと分かった。拡張子を写せばいいが jpg だけは jpeg。
よく分からないが、タグで適切に修飾して send_response というサブルーチンに文字列を渡せば、ブラウザの受信になる模様。ASCII化した画像のみならず平文テキストからなんでも同じ。notebook には、これが溜まってゆくので画像などがあるとサイズが膨らみそう。
IDL kernel から丸写し
#plot figure tmp = magics['fig'] if p.returncode == 0 and os.path.exists(tmp[0]): _, ext = os.path.splitext(tmp[0]) ext = ext[1:] if ext == 'jpg': # MIME type ext = 'jpeg' image_type = 'image/' + ext image = open(tmp[0], 'rb').read() data = {image_type: b64encode(image).decode('ascii')} self.send_response(self.iopub_socket, 'display_data',{'data':data,'metadata':{}}) if tmp[0] == 'tmp.png': os.remove('tmp.png')
Magic コマンド
coarray fortran kernel から丸写し
def _filter_magics(self, code): magics = {'fcflags': [], 'ldflags': [], 'module': [], 'args': [], 'fig': ['tmp.png'], } for line in code.splitlines(): if line.strip().startswith('%'): key, value = line.strip().strip('%').split(":", 1) key = key.lower() if key in ['ldflags', 'fcflags', 'args']: magics[key] = shsplit(value) elif key in ['module', 'Module']: magics['module'] = shsplit(value) magics['ldflags'].append('-c') elif key in ['fig', 'Fig', 'figure', 'Figure']: magics['fig'] = shsplit(value) else: pass # need to add exception handling return magics
HTML 部分
本当は carriage control のように先頭1文字目だけで指定したい><;
def _write_to_stdout(self, contents): if contents[0:6] == '<HTML>': data = {'text/html': contents} self.send_response(self.iopub_socket, 'display_data',{'data':data,'metadata':{}}) else: self.send_response(self.iopub_socket, 'stream', {'name': 'stdout', 'text': contents})
Classical Fortran: Programming for Engineering and Scientific Applications, Second Edition
- 作者: Michael Kupferschmid
- 出版社/メーカー: CRC Press
- 発売日: 2009/01/20
- メディア: ハードカバー
- この商品を含むブログを見る
- 作者: Michael Metcalf,John Reid,Malcolm Cohen
- 出版社/メーカー: Oxford Univ Pr
- 発売日: 2018/11/06
- メディア: ハードカバー
- この商品を含むブログを見る
Modern Fortran: Style and Usage
- 作者: Norman S. Clerman,Walter Spector
- 出版社/メーカー: Cambridge University Press
- 発売日: 2012/02/23
- メディア: ペーパーバック
- この商品を含むブログを見る
- 作者: Arjen Markus
- 出版社/メーカー: Cambridge University Press
- 発売日: 2012/08/30
- メディア: ペーパーバック
- この商品を含むブログを見る
Numerical Computing with Modern Fortran (Applied Mathematics)
- 作者: Richard J. Hanson,Tim Hopkins
- 出版社/メーカー: Society for Industrial and Applied Mathematics
- 発売日: 2014/01/16
- メディア: ペーパーバック
- この商品を含むブログを見る
Modern Fortran: Tricks of the Software Engineering Trade (Chapman & Hall/CRC Computational Science)
- 作者: Damian Rouson,Salvatore Filippone,Sameer Shende
- 出版社/メーカー: CRC Press
- 発売日: 2019/07/22
- メディア: ハードカバー
- この商品を含むブログを見る