{"id":173,"date":"2008-08-03T12:46:36","date_gmt":"2008-08-03T12:46:36","guid":{"rendered":"http:\/\/ahay.org\/blog\/?p=173"},"modified":"2015-09-09T19:05:26","modified_gmt":"2015-09-09T19:05:26","slug":"extending-python-interface","status":"publish","type":"post","link":"https:\/\/ahay.org\/blog\/2008\/08\/03\/extending-python-interface\/","title":{"rendered":"Extending Python interface"},"content":{"rendered":"<p>Work is under way on extending the <a href=\"http:\/\/www.python.org\/\">Python<\/a> interface to Madagascar. With new tools, you should be able to use an interactive Python session rather than a Unix shell to run Madagascar modules. Here are some examples:<\/p>\n<div class=\"code-box\"><div class=\"code-title\"><i class=\"fa fa-code\"><\/i> <div class=\"pull-right\"><a href=\"#\" class=\"btn btn-default btn-xs toggle-code\" data-toggle=\"tooltip\" title=\"Toggle code\"><i class=\"fa fa-toggle-up\"><\/i><\/a><\/div><\/div><pre ><code class=\"python\">import m8r as sf\nimport numpy, pylab\n\nf = sf.spike(n1=1000,k1=300)[0]\n\n# sf.spike is an operator\n# f is an RSF file object\n\nf.attr()\n\n# Inspect the file with sfattr\n\nb = sf.bandpass(fhi=2,phase=1)[f]\n\n# Now f is filtered through sfbandpass\n\nc = sf.spike(n1=1000,k1=300).bandpass(fhi=2,phase=1)[0]\n\n# c is equivalent to b but created with a pipe\n\ng = c.wiggle(clip=0.02,title='Welcome to Madagascar')\n\n# g is a Vplot file object\n\ng.show()\n\n# Display it on the screen\n\nd = b - c\n\n# Elementary arithmetic operations on files are defined\n\ng = g + d.wiggle(wanttitle=False)\n\n# So are operations on plots\n\ng.show()\n\n# This shows a movie\n\npylab.show(pylab.plot(b))\nc = numpy.clip(b,0,0.01)\n\n# RSF file objects can be passed to pylab or numpy\n\nc.attr()\ns = c[300:310]\n\nprint s\n\n# Taking a slice outputs a numpy array\n\nc = sf.clip(clip=0.01)[b]\nc.attr()\n\n# Alternatively, apply sfclip\n<\/code><\/pre><\/div>\n<p>For doing <a href=\"\/wiki\/Reproducible_computational_experiments_using_SCons\">reproducible research<\/a>, one can also use the new syntax inside <strong>SConstruct<\/strong> files, as follows: <\/p>\n<div class=\"code-box\"><div class=\"code-title\"><i class=\"fa fa-code\"><\/i> <div class=\"pull-right\"><a href=\"#\" class=\"btn btn-default btn-xs toggle-code\" data-toggle=\"tooltip\" title=\"Toggle code\"><i class=\"fa fa-toggle-up\"><\/i><\/a><\/div><\/div><pre ><code class=\"python\">from rsf.proj import *\nimport m8r as sf\n\nFlow('filter',None,sf.spike(n1=1000,k1=300).bandpass(fhi=2,phase=1))\nResult('filter',sf.wiggle(clip=0.02,title='Welcome to Madagascar'))\n\nEnd()\n<\/code><\/pre><\/div>\n<p>See also a 4-line <a href=\"https:\/\/github.com\/ahay\/src\/blob\/master\/user\/fomels\/dottest.py\">dot-product test<\/a> and 20-line <a href=\"https:\/\/github.com\/ahay\/src\/blob\/master\/user\/fomels\/conjgrad.py\">conjugate-gradient algorithm<\/a>. <\/p>\n<p>The picture shows a screenshot of an interactive session in a <a href=\"http:\/\/www.sagemath.org\/\">SAGE<\/a> web-based notebook <\/p>\n<p><img decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2015\/08\/sage1.png\" alt=\"\" title=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Work is under way on extending the Python interface to Madagascar. With new tools, you should be able to use an interactive Python session rather than a Unix shell to run Madagascar modules. Here are some examples: import m8r as sf import numpy, pylab f = sf.spike(n1=1000,k1=300)[0] # sf.spike is an operator # f is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","activitypub_content_warning":"","activitypub_content_visibility":"local","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-173","post","type-post","status-publish","format-standard","hentry","category-systems"],"_links":{"self":[{"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/posts\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/comments?post=173"}],"version-history":[{"count":3,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/posts\/173\/revisions"}],"predecessor-version":[{"id":22534,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/posts\/173\/revisions\/22534"}],"wp:attachment":[{"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/media?parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/categories?post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ahay.org\/blog\/wp-json\/wp\/v2\/tags?post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}