tag:blogger.com,1999:blog-70680556060771054342024-01-22T19:30:34.844-08:00Robbie's Research BlogThis blog is for research!Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-7068055606077105434.post-6738722930330049052023-11-19T13:26:00.000-08:002023-11-19T13:26:15.933-08:00PFun Fiona, AI-MD<p> A sneak peek of PFun Fiona, AI-MD-- the one-and-only Physiofunctional Digital Health Assistant.</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm7xnBA1hdk8wMIij1FgNbzrbly5G11gmiqCG0rlLMdPuV2aaYC_mXE4YyhyphenhyphenZDp_1k8Ep7ZuSXUTFDkzLy644busw2gPK3uBUIT9oxrCTa-3DG0ybSR7S7TwqeHujLJ4gzsn_-GGp5-LZD0HhURAmBw4g_aDC03GwCgUdM230e1rKqRMvnZMlJehQG9BLU/s3120/Screenshot_20231119-131609.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="3120" data-original-width="1440" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhm7xnBA1hdk8wMIij1FgNbzrbly5G11gmiqCG0rlLMdPuV2aaYC_mXE4YyhyphenhyphenZDp_1k8Ep7ZuSXUTFDkzLy644busw2gPK3uBUIT9oxrCTa-3DG0ybSR7S7TwqeHujLJ4gzsn_-GGp5-LZD0HhURAmBw4g_aDC03GwCgUdM230e1rKqRMvnZMlJehQG9BLU/w185-h400/Screenshot_20231119-131609.png" title="PFun Fiona, AI-MD. The one-and-only Physiofunctional Digital Health Assistant." width="185" /></a></div><br /><p><br /></p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p><a href="https://pfun.one">Click to learn more about PFun Digital Health.</a><br /></p>Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.com0tag:blogger.com,1999:blog-7068055606077105434.post-88802139374022184502023-05-16T23:34:00.004-07:002023-09-01T05:53:36.126-07:00For fun!<p> </p><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='792' height='658' src='https://www.blogger.com/video.g?token=AD6v5dzagBHy7T8zHCZWd1KQLxsj05-PrOp-AhKWNjQxRdmQT3S6ZAkVCYwu-dRC3wYyC2_DVes-wL_p6EhzOi5X1w' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div><br /><p></p>
<!--Google tag (gtag.js)-->
<script async="" src="https://www.googletagmanager.com/gtag/js?id=G-JEKW4SWN4B"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-JEKW4SWN4B');
</script>Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.com0tag:blogger.com,1999:blog-7068055606077105434.post-59406237498759171412023-05-05T21:12:00.002-07:002023-05-27T10:18:10.747-07:00Messing around with music & stuff<h3 style="text-align: left;">(Updated: 2023-05-16)</h3><p>I've been messing around with the read/write methods in <code>scipy.io.wavfile</code> to make some "music" using the output of some of my biophysical models.</p><h2 style="text-align: left;">Example 1</h2><p>So for example, here's some simulation output with an audio track (<b>caution, may be loud</b>):</p><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='521' height='432' src='https://www.blogger.com/video.g?token=AD6v5dxr5potWm8vfDefSFHTb4K56ds5gPDWO16JacFocNDxseiyqLsRBwwxq3-JUNfWGxenZ-xZHBDA3jIyNTgZtw' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div><div><br /></div><p>So another interesting point... these sounds can be parametrized...</p><h2 style="text-align: left;">Example 2</h2><p>Here's another example with different parameters (<b>again, caution of loudness</b>):</p><p></p><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='489' height='407' src='https://www.blogger.com/video.g?token=AD6v5dytl-NoXKOBjCi4_g15KmzHtqXGr1YvIVxNYIYwf5Vy8dg45QlHCU-i6lSVk5cKevj2K4Efzn8nrSpHna9FXw' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div><br />So as you can see, there's a wide range of different sound patterns that can be produced, even with just this one model.<p></p><h2 style="text-align: left;"><b>Next Steps...</b></h2><p>I'm thinking I'll make a public API at some point in the near future so you can make your own physiological music... 😉</p><p><br /></p><h1 style="text-align: left;">Update!</h1><h3 style="text-align: left;">Some new examples... with rhythm!</h3><div>Thanks to my friend's sage advice, here are a few examples with a subset of parameters mapped to band pass filters.</div><h2 style="text-align: left;">Example 2-0</h2><div>We can get some rhythm by utilizing a binary column as a low-pass filter...</div><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='621' height='516' src='https://www.blogger.com/video.g?token=AD6v5dwlm8KLMGjNTz0IkyrG9KvK5W7Cq2HDskWihU6a_8oZMvRCIzCZwPKKV1v0QNPtLGW7NxXGJ9BDe1ypFtGjvw' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div><h2 style="text-align: left;">Example 2-1</h2><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='613' height='510' src='https://www.blogger.com/video.g?token=AD6v5dznGFI7L0SVixekFEuzRe-ZUhWFII099iw8V1CjDfFJ3hhCrEMGz8xuHxQWiRbO98jZJJBkfJqj5BNxcyMohA' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div><h2 style="text-align: left;">Example 2-2</h2><div>Here's another with a few different band-pass filters that produces an interesting pattern...</div><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='588' height='488' src='https://www.blogger.com/video.g?token=AD6v5dxPBD4sWNb-wcQG2KaOTNa7vVXORTRxFYZhEVVaqpCyQ7GEHnUrIdo-VkmbK9_SKm8XdCHNZ3M00UzsZ1Nf_Q' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div><br /><div><br /></div><div><br /></div><div><br /></div><div><br /></div>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-JEKW4SWN4B"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-JEKW4SWN4B');
</script>Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.com0tag:blogger.com,1999:blog-7068055606077105434.post-36968437569255710462023-04-25T14:03:00.004-07:002023-04-25T14:03:35.198-07:00<p> </p><div class="separator" style="clear: both; text-align: center;">This means <b>something... 😉</b></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZJzVZaMjAXmu3w_6SbNYzgjpb754wm5h8Nm7EKjdbn6MlBHRI9mkcCczXdLfNb3fwOvX6xlc1P7j5WW8g0eN_nUA2fuDMfryDStasrpCDEqXtmoo4-TPdYPdab_sfH2PQ4WQbHgsuHCQX5K3dbAQUUb3MffIQTwa6G4yWUiWTdrBmxZaC3G8NoYCrjg/s1000/visual-plan-screenshot_04-25-2023.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="500" data-original-width="1000" height="242" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZJzVZaMjAXmu3w_6SbNYzgjpb754wm5h8Nm7EKjdbn6MlBHRI9mkcCczXdLfNb3fwOvX6xlc1P7j5WW8g0eN_nUA2fuDMfryDStasrpCDEqXtmoo4-TPdYPdab_sfH2PQ4WQbHgsuHCQX5K3dbAQUUb3MffIQTwa6G4yWUiWTdrBmxZaC3G8NoYCrjg/w483-h242/visual-plan-screenshot_04-25-2023.png" width="483" /></a></div><br /><p></p>Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.com0tag:blogger.com,1999:blog-7068055606077105434.post-74086993106123257622022-10-14T15:47:00.009-07:002023-05-05T21:26:01.699-07:00Dawn of a new era!<div class="separator" style="text-align: left;"><p style="clear: left; float: left; height: 132px; margin-bottom: 1em; margin-right: 1em; text-align: left;">It's been a while! Here are some graphical non-sequiturs for your viewing pleasure:<img alt="" border="0" data-original-height="693" data-original-width="153" height="88" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb2nUgM8VhesUvITkS53hf-VyjKFQD-DNN1TzGF2TH1Vf4MbU5mmxvsDs07sT9o_GWoaRmPqlwZ6j0j4lMeQ15goVw6F8PyZbht0onjRUB4_n1txCsMIDVAKtm9XQAOej4bV3c8aTGQZJtMuYIn1cZ9z5INXb2D8B4IQO1TWrr-g3-m3rNZn358_Gruw/w20-h88/cgm-safe01.png" width="20" />
<img alt="" border="0" data-original-height="138" data-original-width="158" height="86" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoTsaJGDAJC7g5Gpfgfph29F8w0A5d9QHeSDeL4s88KMr_2WtdDKzLe-MH7zTmnvFu01_f8dDBScEyiMbvmmaslSWUW3woKEHoSoPDe6ZpdiLX0Msslc3Ydsks1-k-a7K3iObv_6U76_ebeBwxNd0zkAqgr2KZY509Fxmv6Ja86oPH5l-CTiygQ3YyTg/w99-h86/scn-safe.jpg" width="99" />
<img alt="" border="0" data-original-height="218" data-original-width="240" height="68" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHFjsxklOAJzJvZIn_8kOxdcM4zTzXMDojWCHR7NFEMV_rrOfH8mz8StTd6zbcHO7TPtBqpbAUg9QpleLYfyvKl00wBafUIUF-6uIXJNWucmTnSIZKDNU3q6ZK67L-VedJPwa9I-XIEjuoaC_hslZIV8qgajdzSRf_xMh8PhnWfW2o8mPFekrMCvynyw/w75-h68/unit-safe01.png" width="75" /></p></div>Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.com0tag:blogger.com,1999:blog-7068055606077105434.post-6042610989900930892018-05-14T06:40:00.001-07:002018-05-14T06:41:53.931-07:00Dynamical systems model of cardio-respiratory interactions<p>
Currently I'm working on a model of cardio-respiratory interactions. Given human experimental data, the model reproduces the average heart rate, the average respiratory phase duration (inspiration/expiration), and the <a href="https://en.wikipedia.org/wiki/Vagal_tone">Respiratory Sinus Arrhythmia (RSA)</a>. The most sophisticated part of the model is the respiratory central pattern generator (<a href="http://journals.plos.org/plosone/article?id=10.1371/journal.pone.0109894">previously published</a>). My current goal is to optimize the model so that it reproduces RSA for several individuals.
</p>
<p>
After I get it working with the current dataset-- which was <a href="https://physionet.org/physiobank/database/fantasia/">measured while participants watched Disney's Fantasia</a>-- the next step is to fit the model to real clinical data from septic ER patients. The end goal is for our collaborators to use our model as a basis for a machine learning algorithm that predicts the risk and most likely cause of death for septic patients.
</p>
<p>
Below are some pretty pictures generated by the model.
</p>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp4UvRQ5uUHYjMMw30zMYTCPQVnT8yCJMfHRqaIOdlMulyWHrU9wXlAjTCuz9BEdUmez1m64xw-C5IxMh7AXqUguwA6hn5DD3BABWWfnvH7Hwd8ox-jTndJ-5XfxZ-l1OW0XFaHmtXyrPv/s1600/ave_resp_f1y02_neurons.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjp4UvRQ5uUHYjMMw30zMYTCPQVnT8yCJMfHRqaIOdlMulyWHrU9wXlAjTCuz9BEdUmez1m64xw-C5IxMh7AXqUguwA6hn5DD3BABWWfnvH7Hwd8ox-jTndJ-5XfxZ-l1OW0XFaHmtXyrPv/s320/ave_resp_f1y02_neurons.png" width="320" height="240" data-original-width="640" data-original-height="480" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD2rZPDiqZNdD1atYEXTOIUETvYxH6umqIhq6e3L2palGWCsPo_4NPOoONiAqQXyr-hpL0377uZTsQA8hUV2Jp1oMq6cCKoag5MDa_9PFKePQxztaEyK4daqaWHhywu3xisU3tuxyBBINf/s1600/ave_resp_f1y02_result.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiD2rZPDiqZNdD1atYEXTOIUETvYxH6umqIhq6e3L2palGWCsPo_4NPOoONiAqQXyr-hpL0377uZTsQA8hUV2Jp1oMq6cCKoag5MDa_9PFKePQxztaEyK4daqaWHhywu3xisU3tuxyBBINf/s320/ave_resp_f1y02_result.png" width="320" height="240" data-original-width="640" data-original-height="480" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJ89LL6R3JFVJrhHUjpL7idSRxFyKJU-rI0yXakW7ZB9H1ePOGGmNv3FvgxVN_2GJugPa893v7zD2kLfcDs62SOVkU7AGbAKjm91APfGRyU10ymIN5mnGeeJjeedWky4nqSUzO3qE9rSUt/s1600/ave_resp_f1y02_signals.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJ89LL6R3JFVJrhHUjpL7idSRxFyKJU-rI0yXakW7ZB9H1ePOGGmNv3FvgxVN_2GJugPa893v7zD2kLfcDs62SOVkU7AGbAKjm91APfGRyU10ymIN5mnGeeJjeedWky4nqSUzO3qE9rSUt/s320/ave_resp_f1y02_signals.png" width="320" height="240" data-original-width="640" data-original-height="480" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL1b1m6ZVbKYR9Hm1R2poe1pJVCEKa2jhaQ6e9BhD09u_75XBEJnM-TUJRqzieJNT-7eXtDfpeJAGdBqLPYz9SxkSl6sr0e9X2PYXN6PmvQwhvbfe7gd4NDkzHYdX2Jq64a5AgJPZeJxgP/s1600/paramSpace_ave_resp_f1y02_cost.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiL1b1m6ZVbKYR9Hm1R2poe1pJVCEKa2jhaQ6e9BhD09u_75XBEJnM-TUJRqzieJNT-7eXtDfpeJAGdBqLPYz9SxkSl6sr0e9X2PYXN6PmvQwhvbfe7gd4NDkzHYdX2Jq64a5AgJPZeJxgP/s320/paramSpace_ave_resp_f1y02_cost.png" width="320" height="240" data-original-width="640" data-original-height="480" /></a></div>Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.com0tag:blogger.com,1999:blog-7068055606077105434.post-46364805853451173392017-01-16T08:45:00.001-08:002018-05-14T06:41:20.186-07:00Haiku Twitter Bot<p>Over summer 2016, I decided to make a Twitter bot just for fun. Here, I'll describe the bot's programming at a high level. But first, a little background...</p>
<p>
I started undergraduate as an english major... then graduated with a degree in neuroscience. Although I have pretty firmly switched my career plans toward math and science, I still appreciate and respect art. As a reflection on my artistic pipedream, I designed my bot to write <a href="https://www.poets.org/poetsorg/text/haiku-poetic-form">haikus</a>. If you don't remember haikus from high school, hit that link in the previous sentence.
</p>
<p>
For connecting to Twitter, I used the <a href="http://tweepy.readthedocs.io/en/v3.5.0/getting_started.html">tweepy library</a>. I simply wrote a subclass of <span style="font-family:Courier">StreamListener</span> to process incoming tweets and write them to a file called <span style="font-family:Courier">tweets.txt</span>. You can read more about this process in the tweepy docs (linked above).
<div><script src="https://gist.github.com/rocapp/be3a922fc92d2d57dc33f91fff18ea8e.js"></script></div>
</p>
<p>
Each time I start my bot, most of the high-level functionality is located in one function, <span style="font-family:Courier">do_tweet()</span>.
<div><script src="https://gist.github.com/rocapp/74ea88a440040f4d03b8385c30db07cc.js"></script></div>
</p>
<p>
For counting syllables and determining parts of speech, I used <a href="http://www.nltk.org/">NLTK</a>.
<br /><br />
Counting syllables:
<div><script src="https://gist.github.com/rocapp/3aeb4dfac79b072c3dd9ab233bc87f40.js"></script></div>
<br />
Choosing words for the haiku:
<div><script src="https://gist.github.com/rocapp/cb0df8b9a535a0bee00203e05e83edd0.js"></script></div>
<br />
</p>
<p>
As you can see, the algorithm randomly chooses a word of syllable length <span style="font-family:Courier">sw</span>, which is generated by the <span style="font-family:Courier">pick_syl()</span> function. If this is hard to interpret, don't worry. It took me a while to come up with an algorithm that would randomly choose words but still adhere to the 5/7/5 haiku format. The conditions like <span style="font-family:Courier">if ix == 0 and line == 0</span> are there to determine which line of the haiku is being written. In this case, the first word of the first line is being chosen. Then the lines:<br />
<blockquote><span style="font-family:Courier">sdict1 = dict([(sk, sv) for sk, sv in sdict.items() if pos_tag(word_tokenize(sk),<br /> tagset='universal')[0][1]=='NOUN'])</span> # Chooses a noun<br />
<span style="font-family:Courier">gsyls = syl_of_size(sdict1, sw)</span> # Chooses a noun of syllable length sw
</blockquote>
</p>
<p>
Then, setting up the haiku in order and writing to the file <span style="font-family:Courier">haiku.txt</span>:
<div><script src="https://gist.github.com/rocapp/cdcc7a0661beb1ea97db0da03272fcc4.js"></script></div>
</p>
<p>
So currently this bot would write haikus with randomly chosen words, which is cool... but we can do better! ;^)<br />
Eventually when I have a little more time, I'll give meta ai ai haiku more smarts, but for now the bot uses a simple algorithm for determining the "best" tweets, then recycles words from these tweets. Dumb, I know... it's a work in progress.
<div><script src="https://gist.github.com/rocapp/aafe619b828a801f53d074751b1f1bfb.js"></script></div>
<br />
The function <span style="font-family:Courier">get_best()</span> chooses tweets with the highest "weight" to include in the bot's corpus for writing future haikus.
<div><script src="https://gist.github.com/rocapp/5ada903e83cf0b1da848aa05820147b8.js"></script></div>
</p>
<p>
Here's a link to my Twitter bot meta ai ai haiku: <a href="http://robcapps.com/docs/haiku.html">robcapps.com/docs/haiku</a>. Please feel free to ask questions in the comments section!
</p>Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.com0tag:blogger.com,1999:blog-7068055606077105434.post-35197691405058431512016-09-12T11:59:00.002-07:002016-09-12T12:48:11.706-07:00Using plt.imshow to label timeseries data with matplotlib<span style="font-family: "arial" , "helvetica" , sans-serif;">Recently I've been trying to find the most effective way to color-code time series data using matplotlib.</span><br />
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></div>
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif;">For instance, if I have a raster plot like this:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhkX8kqyP47N3ZyweaHVmzYOjK4rD-joCmXnAGUj-o0qwW3Jx8KmuX91bbRQuPpJBnxyBZQn35uXmkBTnm6Eu_OCnt9eHwhGRZG0XigXOvdPTTxTGjh049OMI_BV-v5jhy2o9MaGaSU3la/s1600/_plainrast1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="203" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhkX8kqyP47N3ZyweaHVmzYOjK4rD-joCmXnAGUj-o0qwW3Jx8KmuX91bbRQuPpJBnxyBZQn35uXmkBTnm6Eu_OCnt9eHwhGRZG0XigXOvdPTTxTGjh049OMI_BV-v5jhy2o9MaGaSU3la/s400/_plainrast1.png" width="400" /></a></div>
<div>
<span style="font-family: "arial" , "helvetica" , sans-serif;">...and I want to label it like this:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9xqdRA8O9c3S3mw9BKCF-fjpJADfibkGqETjZWWxGLT6iZ6hj-cD5dsmGvPXErgeYnS6vV3a_Pf1sw2cqk3EbweVXBoAPAsmzAhNTCbu3T_OUMfiu4qwRr8aXOJrIDNc0JrfWS0YYbwKr/s1600/_rast1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9xqdRA8O9c3S3mw9BKCF-fjpJADfibkGqETjZWWxGLT6iZ6hj-cD5dsmGvPXErgeYnS6vV3a_Pf1sw2cqk3EbweVXBoAPAsmzAhNTCbu3T_OUMfiu4qwRr8aXOJrIDNc0JrfWS0YYbwKr/s400/_rast1.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">How?</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">After lots of failed attempts involving horrific for loops and </span><span style="font-family: "courier new" , "courier" , monospace;">ax.fill_between</span><span style="font-family: "arial" , "helvetica" , sans-serif;">, </span><span style="font-family: "courier new" , "courier" , monospace;">ax.fill, </span><span style="font-family: "arial" , "helvetica" , sans-serif;">and several other inferior solutions, I found a quick and easy fix:</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;">After plotting your time series raster plot,</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> Given: </span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> - an array </span><span style="font-family: "courier new" , "courier" , monospace;">colors</span><span style="font-family: "arial" , "helvetica" , sans-serif;"> in </span><span style="font-family: "courier new" , "courier" , monospace;">(R, G, B) </span><span style="font-family: "arial" , "helvetica" , sans-serif;">format (same length as your time series data)</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> - </span><span style="font-family: "courier new" , "courier" , monospace;">nr_neurons </span><span style="font-family: "arial" , "helvetica" , sans-serif;">is the number of axes (in this case, 4)</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> - </span><span style="font-family: "courier new" , "courier" , monospace;">vspace </span><span style="font-family: "arial" , "helvetica" , sans-serif;">is a float representing the space between each time axis</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"> - A timeline variable, </span><span style="font-family: "courier new" , "courier" , monospace;">tspace </span><span style="font-family: "arial" , "helvetica" , sans-serif;">(created with </span><span style="font-family: "courier new" , "courier" , monospace;">np.linspace</span><span style="font-family: "arial" , "helvetica" , sans-serif;">)</span></div>
<div>
<br /></div>
<div>
<script src="https://gist.github.com/rocapp/3e0d2512fc31faf74f661c893833bf71.js"></script>
</div>
<br />
<span style="font-family: "arial" , "helvetica" , sans-serif;">Note the parameter </span><span style="font-family: "courier new" , "courier" , monospace;">aspect='auto'</span><span style="font-family: "arial" , "helvetica" , sans-serif;">. This makes sure the image takes the shape of your existing axis.</span><br />
<table class="highlight tab-size js-file-line-container" data-tab-size="8" style="background-color: white; border-collapse: collapse; border-spacing: 0px; box-sizing: border-box; color: #333333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 14px; line-height: 21px; tab-size: 8;"><tbody style="box-sizing: border-box;">
</tbody></table>
Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.com0tag:blogger.com,1999:blog-7068055606077105434.post-10239188710634857332016-08-23T07:39:00.002-07:002016-08-28T15:43:32.457-07:00QGIS Area of Availability Plugin8/23/16<br />
<br />
I'm working on a set of QGIS plugins, and one that I think should be out there for grabs is an <a href="http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/network_analysis.html" target="_blank">area of availability</a> calculator. (EDIT: you should be able to install <a href="http://plugins.qgis.org/plugins/RoadNetwork/" target="_blank">the plugin via the public QGIS repository </a>soon)<br />
<br />
Given a start point and a maximum distance to travel, we want to find the boundary of accessible regions via a road network.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIA3YtcRQfGSPGPYvqTpGXylROT3-sXWItoSHPmgoGvWCSSoPbHgk6fzV38jgxvcZkdh3BJLhzKBiNOZaVoyKDblSwhmu6hE3z43WGTUmVPlzFMbNosL15IHsT7FQd5XtVvaaJ8PQE_Klz/s1600/DRIVING_DISTANCE.jpeg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIA3YtcRQfGSPGPYvqTpGXylROT3-sXWItoSHPmgoGvWCSSoPbHgk6fzV38jgxvcZkdh3BJLhzKBiNOZaVoyKDblSwhmu6hE3z43WGTUmVPlzFMbNosL15IHsT7FQd5XtVvaaJ8PQE_Klz/s400/DRIVING_DISTANCE.jpeg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: x-small;"><i>Boundary of area of availability, plotted as points</i></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: x-small;"><i><br /></i></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: x-small;"><i><br /></i></span></div>
We <a href="http://qgis.org/api/classQgsGraphBuilder.html" target="_blank">build a road network graph</a> and calculate the road distances using <a href="https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm" target="_blank">Dijkstra's algorithm</a>. We can then find the points corresponding to the outer boundary of the area of availability.<br />
<br />
The code for this calculation is below (taken from <a href="http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/network_analysis.html" target="_blank">this page</a>):<br />
<br />
<pre style="background-color: whitesmoke; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.14902); color: #333333; font-family: "Andale Mono", "Ubuntu Mono", "Courier New", Courier, monospace; font-size: 13px; line-height: 1.2rem; margin-bottom: 10px; overflow-x: auto; overflow-y: hidden; padding: 9.5px; white-space: pre-wrap; word-break: break-all; word-wrap: break-word;"><span class="kn" style="color: #007020; font-weight: bold;">from</span> <span class="nn" style="color: #0e84b5; font-weight: bold;">PyQt4.QtCore</span> <span class="kn" style="color: #007020; font-weight: bold;">import</span> <span class="o" style="color: #666666;">*</span>
<span class="kn" style="color: #007020; font-weight: bold;">from</span> <span class="nn" style="color: #0e84b5; font-weight: bold;">PyQt4.QtGui</span> <span class="kn" style="color: #007020; font-weight: bold;">import</span> <span class="o" style="color: #666666;">*</span>
<span class="kn" style="color: #007020; font-weight: bold;">from</span> <span class="nn" style="color: #0e84b5; font-weight: bold;">qgis.core</span> <span class="kn" style="color: #007020; font-weight: bold;">import</span> <span class="o" style="color: #666666;">*</span>
<span class="kn" style="color: #007020; font-weight: bold;">from</span> <span class="nn" style="color: #0e84b5; font-weight: bold;">qgis.gui</span> <span class="kn" style="color: #007020; font-weight: bold;">import</span> <span class="o" style="color: #666666;">*</span>
<span class="kn" style="color: #007020; font-weight: bold;">from</span> <span class="nn" style="color: #0e84b5; font-weight: bold;">qgis.networkanalysis</span> <span class="kn" style="color: #007020; font-weight: bold;">import</span> <span class="o" style="color: #666666;">*</span>
<span class="n">vl</span> <span class="o" style="color: #666666;">=</span> <span class="n">qgis</span><span class="o" style="color: #666666;">.</span><span class="n">utils</span><span class="o" style="color: #666666;">.</span><span class="n">iface</span><span class="o" style="color: #666666;">.</span><span class="n">mapCanvas</span><span class="p">()</span><span class="o" style="color: #666666;">.</span><span class="n">currentLayer</span><span class="p">()</span>
<span class="n">director</span> <span class="o" style="color: #666666;">=</span> <span class="n">QgsLineVectorLayerDirector</span><span class="p">(</span><span class="n">vl</span><span class="p">,</span> <span class="o" style="color: #666666;">-</span><span class="mi" style="color: #208050;">1</span><span class="p">,</span> <span class="s" style="color: #4070a0;">''</span><span class="p">,</span> <span class="s" style="color: #4070a0;">''</span><span class="p">,</span> <span class="s" style="color: #4070a0;">''</span><span class="p">,</span> <span class="mi" style="color: #208050;">3</span><span class="p">)</span>
<span class="n">properter</span> <span class="o" style="color: #666666;">=</span> <span class="n">QgsDistanceArcProperter</span><span class="p">()</span>
<span class="n">director</span><span class="o" style="color: #666666;">.</span><span class="n">addProperter</span><span class="p">(</span><span class="n">properter</span><span class="p">)</span>
<span class="n">crs</span> <span class="o" style="color: #666666;">=</span> <span class="n">qgis</span><span class="o" style="color: #666666;">.</span><span class="n">utils</span><span class="o" style="color: #666666;">.</span><span class="n">iface</span><span class="o" style="color: #666666;">.</span><span class="n">mapCanvas</span><span class="p">()</span><span class="o" style="color: #666666;">.</span><span class="n">mapRenderer</span><span class="p">()</span><span class="o" style="color: #666666;">.</span><span class="n">destinationCrs</span><span class="p">()</span>
<span class="n">builder</span> <span class="o" style="color: #666666;">=</span> <span class="n">QgsGraphBuilder</span><span class="p">(</span><span class="n">crs</span><span class="p">)</span>
<span class="n">pStart</span> <span class="o" style="color: #666666;">=</span> <span class="n">QgsPoint</span><span class="p">(</span><span class="mf" style="color: #208050;">65.5462</span><span class="p">,</span> <span class="mf" style="color: #208050;">57.1509</span><span class="p">)</span>
<span class="n">delta</span> <span class="o" style="color: #666666;">=</span> <span class="n">qgis</span><span class="o" style="color: #666666;">.</span><span class="n">utils</span><span class="o" style="color: #666666;">.</span><span class="n">iface</span><span class="o" style="color: #666666;">.</span><span class="n">mapCanvas</span><span class="p">()</span><span class="o" style="color: #666666;">.</span><span class="n">getCoordinateTransform</span><span class="p">()</span><span class="o" style="color: #666666;">.</span><span class="n">mapUnitsPerPixel</span><span class="p">()</span> <span class="o" style="color: #666666;">*</span> <span class="mi" style="color: #208050;">1</span>
<span class="n">rb</span> <span class="o" style="color: #666666;">=</span> <span class="n">QgsRubberBand</span><span class="p">(</span><span class="n">qgis</span><span class="o" style="color: #666666;">.</span><span class="n">utils</span><span class="o" style="color: #666666;">.</span><span class="n">iface</span><span class="o" style="color: #666666;">.</span><span class="n">mapCanvas</span><span class="p">(),</span> <span class="bp" style="color: #007020;">True</span><span class="p">)</span>
<span class="n">rb</span><span class="o" style="color: #666666;">.</span><span class="n">setColor</span><span class="p">(</span><span class="n">Qt</span><span class="o" style="color: #666666;">.</span><span class="n">green</span><span class="p">)</span>
<span class="n">rb</span><span class="o" style="color: #666666;">.</span><span class="n">addPoint</span><span class="p">(</span><span class="n">QgsPoint</span><span class="p">(</span><span class="n">pStart</span><span class="o" style="color: #666666;">.</span><span class="n">x</span><span class="p">()</span> <span class="o" style="color: #666666;">-</span> <span class="n">delta</span><span class="p">,</span> <span class="n">pStart</span><span class="o" style="color: #666666;">.</span><span class="n">y</span><span class="p">()</span> <span class="o" style="color: #666666;">-</span> <span class="n">delta</span><span class="p">))</span>
<span class="n">rb</span><span class="o" style="color: #666666;">.</span><span class="n">addPoint</span><span class="p">(</span><span class="n">QgsPoint</span><span class="p">(</span><span class="n">pStart</span><span class="o" style="color: #666666;">.</span><span class="n">x</span><span class="p">()</span> <span class="o" style="color: #666666;">+</span> <span class="n">delta</span><span class="p">,</span> <span class="n">pStart</span><span class="o" style="color: #666666;">.</span><span class="n">y</span><span class="p">()</span> <span class="o" style="color: #666666;">-</span> <span class="n">delta</span><span class="p">))</span>
<span class="n">rb</span><span class="o" style="color: #666666;">.</span><span class="n">addPoint</span><span class="p">(</span><span class="n">QgsPoint</span><span class="p">(</span><span class="n">pStart</span><span class="o" style="color: #666666;">.</span><span class="n">x</span><span class="p">()</span> <span class="o" style="color: #666666;">+</span> <span class="n">delta</span><span class="p">,</span> <span class="n">pStart</span><span class="o" style="color: #666666;">.</span><span class="n">y</span><span class="p">()</span> <span class="o" style="color: #666666;">+</span> <span class="n">delta</span><span class="p">))</span>
<span class="n">rb</span><span class="o" style="color: #666666;">.</span><span class="n">addPoint</span><span class="p">(</span><span class="n">QgsPoint</span><span class="p">(</span><span class="n">pStart</span><span class="o" style="color: #666666;">.</span><span class="n">x</span><span class="p">()</span> <span class="o" style="color: #666666;">-</span> <span class="n">delta</span><span class="p">,</span> <span class="n">pStart</span><span class="o" style="color: #666666;">.</span><span class="n">y</span><span class="p">()</span> <span class="o" style="color: #666666;">+</span> <span class="n">delta</span><span class="p">))</span>
<span class="n">tiedPoints</span> <span class="o" style="color: #666666;">=</span> <span class="n">director</span><span class="o" style="color: #666666;">.</span><span class="n">makeGraph</span><span class="p">(</span><span class="n">builder</span><span class="p">,</span> <span class="p">[</span><span class="n">pStart</span><span class="p">])</span>
<span class="n">graph</span> <span class="o" style="color: #666666;">=</span> <span class="n">builder</span><span class="o" style="color: #666666;">.</span><span class="n">graph</span><span class="p">()</span>
<span class="n">tStart</span> <span class="o" style="color: #666666;">=</span> <span class="n">tiedPoints</span><span class="p">[</span><span class="mi" style="color: #208050;">0</span><span class="p">]</span>
<span class="n">idStart</span> <span class="o" style="color: #666666;">=</span> <span class="n">graph</span><span class="o" style="color: #666666;">.</span><span class="n">findVertex</span><span class="p">(</span><span class="n">tStart</span><span class="p">)</span>
<span class="p">(</span><span class="n">tree</span><span class="p">,</span> <span class="n">cost</span><span class="p">)</span> <span class="o" style="color: #666666;">=</span> <span class="n">QgsGraphAnalyzer</span><span class="o" style="color: #666666;">.</span><span class="n">dijkstra</span><span class="p">(</span><span class="n">graph</span><span class="p">,</span> <span class="n">idStart</span><span class="p">,</span> <span class="mi" style="color: #208050;">0</span><span class="p">)</span>
<span class="n">upperBound</span> <span class="o" style="color: #666666;">=</span> <span class="p">[]</span>
<span class="n">r</span> <span class="o" style="color: #666666;">=</span> <span class="mf" style="color: #208050;">2000.0</span>
<span class="n">i</span> <span class="o" style="color: #666666;">=</span> <span class="mi" style="color: #208050;">0</span>
<span class="k" style="color: #007020; font-weight: bold;">while</span> <span class="n">i</span> <span class="o" style="color: #666666;"><</span> <span class="nb" style="color: #007020;">len</span><span class="p">(</span><span class="n">cost</span><span class="p">):</span>
<span class="k" style="color: #007020; font-weight: bold;">if</span> <span class="n">cost</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o" style="color: #666666;">></span> <span class="n">r</span> <span class="ow" style="color: #007020; font-weight: bold;">and</span> <span class="n">tree</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o" style="color: #666666;">!=</span> <span class="o" style="color: #666666;">-</span><span class="mi" style="color: #208050;">1</span><span class="p">:</span>
<span class="n">outVertexId</span> <span class="o" style="color: #666666;">=</span> <span class="n">graph</span><span class="o" style="color: #666666;">.</span><span class="n">arc</span><span class="p">(</span><span class="n">tree</span> <span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="o" style="color: #666666;">.</span><span class="n">outVertex</span><span class="p">()</span>
<span class="k" style="color: #007020; font-weight: bold;">if</span> <span class="n">cost</span><span class="p">[</span><span class="n">outVertexId</span><span class="p">]</span> <span class="o" style="color: #666666;"><</span> <span class="n">r</span><span class="p">:</span>
<span class="n">upperBound</span><span class="o" style="color: #666666;">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
<span class="n">i</span> <span class="o" style="color: #666666;">=</span> <span class="n">i</span> <span class="o" style="color: #666666;">+</span> <span class="mi" style="color: #208050;">1</span>
<span class="k" style="color: #007020; font-weight: bold;">for</span> <span class="n">i</span> <span class="ow" style="color: #007020; font-weight: bold;">in</span> <span class="n">upperBound</span><span class="p">:</span>
<span class="n">centerPoint</span> <span class="o" style="color: #666666;">=</span> <span class="n">graph</span><span class="o" style="color: #666666;">.</span><span class="n">vertex</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o" style="color: #666666;">.</span><span class="n">point</span><span class="p">()</span>
<span class="n">rb</span> <span class="o" style="color: #666666;">=</span> <span class="n">QgsRubberBand</span><span class="p">(</span><span class="n">qgis</span><span class="o" style="color: #666666;">.</span><span class="n">utils</span><span class="o" style="color: #666666;">.</span><span class="n">iface</span><span class="o" style="color: #666666;">.</span><span class="n">mapCanvas</span><span class="p">(),</span> <span class="bp" style="color: #007020;">True</span><span class="p">)</span>
<span class="n">rb</span><span class="o" style="color: #666666;">.</span><span class="n">setColor</span><span class="p">(</span><span class="n">Qt</span><span class="o" style="color: #666666;">.</span><span class="n">red</span><span class="p">)</span>
<span class="n">rb</span><span class="o" style="color: #666666;">.</span><span class="n">addPoint</span><span class="p">(</span><span class="n">QgsPoint</span><span class="p">(</span><span class="n">centerPoint</span><span class="o" style="color: #666666;">.</span><span class="n">x</span><span class="p">()</span> <span class="o" style="color: #666666;">-</span> <span class="n">delta</span><span class="p">,</span> <span class="n">centerPoint</span><span class="o" style="color: #666666;">.</span><span class="n">y</span><span class="p">()</span> <span class="o" style="color: #666666;">-</span> <span class="n">delta</span><span class="p">))</span>
<span class="n">rb</span><span class="o" style="color: #666666;">.</span><span class="n">addPoint</span><span class="p">(</span><span class="n">QgsPoint</span><span class="p">(</span><span class="n">centerPoint</span><span class="o" style="color: #666666;">.</span><span class="n">x</span><span class="p">()</span> <span class="o" style="color: #666666;">+</span> <span class="n">delta</span><span class="p">,</span> <span class="n">centerPoint</span><span class="o" style="color: #666666;">.</span><span class="n">y</span><span class="p">()</span> <span class="o" style="color: #666666;">-</span> <span class="n">delta</span><span class="p">))</span>
<span class="n">rb</span><span class="o" style="color: #666666;">.</span><span class="n">addPoint</span><span class="p">(</span><span class="n">QgsPoint</span><span class="p">(</span><span class="n">centerPoint</span><span class="o" style="color: #666666;">.</span><span class="n">x</span><span class="p">()</span> <span class="o" style="color: #666666;">+</span> <span class="n">delta</span><span class="p">,</span> <span class="n">centerPoint</span><span class="o" style="color: #666666;">.</span><span class="n">y</span><span class="p">()</span> <span class="o" style="color: #666666;">+</span> <span class="n">delta</span><span class="p">))</span>
<span class="n">rb</span><span class="o" style="color: #666666;">.</span><span class="n">addPoint</span><span class="p">(</span><span class="n">QgsPoint</span><span class="p">(</span><span class="n">centerPoint</span><span class="o" style="color: #666666;">.</span><span class="n">x</span><span class="p">()</span> <span class="o" style="color: #666666;">-</span> <span class="n">delta</span><span class="p">,</span> <span class="n">centerPoint</span><span class="o" style="color: #666666;">.</span><span class="n">y</span><span class="p">()</span> <span class="o" style="color: #666666;">+</span> <span class="n">delta</span><span class="p">))</span></pre>
<br />
I'm not quite finished with my plugin implementation, but you can check out the source code on my <a href="https://github.com/rocapp/qgis-market-analysis" target="_blank">GitHub.</a><br />
<br />
If you want to try your hand at developing a QGIS plugin, I strongly recommend starting with <a href="https://plugins.qgis.org/plugins/pluginbuilder/" target="_blank">Plugin Builder</a>.Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.com0tag:blogger.com,1999:blog-7068055606077105434.post-45003058303131863222016-07-31T07:48:00.003-07:002016-07-31T08:12:10.800-07:00<span style="font-family: "courier new" , "courier" , monospace;"><b>7/31/16, Current Work</b></span><br />
<span style="font-family: "courier new" , "courier" , monospace;"> Since December 2015, I've been collaborating on a research publication. The publication will be centered on a Python software package called FreqPy.</span><br />
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> FreqPy is a tool designed to assist with qualitative analysis of neural firing rate data and to bolster arguments for neural population coding in subpopulations of neurons.</span></div>
<div>
<div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> We're currently in the verification/justification stages; I synthesized some sine waves as test data to verify that our methodology is working and just finished creating a set of figures.</span></div>
</div>
</div>
<div>
<span style="font-family: "courier new" , "courier" , monospace;"> Check out the video below:</span></div>
<div>
<iframe allowfullscreen="" frameborder="0" height="344" src="https://www.youtube.com/embed/OQ-dH4k3F_M" width="459"></iframe></div>
Roberthttp://www.blogger.com/profile/17773529497659453282noreply@blogger.com0