<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>Insang Song</title>
<link>https://sigmafelix.github.io/</link>
<atom:link href="https://sigmafelix.github.io/index.xml" rel="self" type="application/rss+xml"/>
<description>Insang Song&#39;s personal webpage and weblog</description>
<generator>quarto-1.9.37</generator>
<lastBuildDate>Tue, 14 Apr 2026 00:00:00 GMT</lastBuildDate>
<item>
  <title>Visualizing Simple Trajectories as Funnel Polygons</title>
  <dc:creator>Insang Song</dc:creator>
  <link>https://sigmafelix.github.io/posts/tornado-trajectories/</link>
  <description><![CDATA[ 





<section id="overview" class="level2">
<h2 class="anchored" data-anchor-id="overview">Overview</h2>
<p>This post demonstrates a novel approach for visualizing a two-point segment (trajectory) as a funnel-shaped polygon. Rather than representing a tornado as a simple line from start to end point, this method creates a polygon where the width expands or contracts based on observed phenomena intensity at each point along the path.</p>
</section>
<section id="the-function" class="level2">
<h2 class="anchored" data-anchor-id="the-function">The Function</h2>
<p>The <code>conv_point_trajectory()</code> function converts two points (start/end of a tornado path) into a funnel-shaped polygon. It works by:</p>
<ol type="1">
<li>Densifying the line between start and end points at regular intervals</li>
<li>Creating buffers around each densified point with radii that interpolate between start and end widths</li>
<li>Optionally applying a custom function to modify the radius along the trajectory</li>
<li>Aggregating all buffers into a single polygon representing the funnel</li>
</ol>
<div id="4ab3035e" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;vscode&quot;,&quot;value&quot;:{&quot;languageId&quot;:&quot;r&quot;}}" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb1-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">library</span>(terra)</span></code></pre></div></div>
<div class="cell-output cell-output-stderr">
<pre><code>terra 1.9.1
</code></pre>
</div>
</div>
<div id="6ece015c" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;vscode&quot;,&quot;value&quot;:{&quot;languageId&quot;:&quot;r&quot;}}" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb3-1">conv_point_trajectory <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb3-2">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(</span>
<span id="cb3-3">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start_point =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb3-4">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">end_point =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>),</span>
<span id="cb3-5">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interval =</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e2</span>,</span>
<span id="cb3-6">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wd_start =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb3-7">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wd_end =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">numeric</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb3-8">    <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NULL</span></span>
<span id="cb3-9">  ) {</span>
<span id="cb3-10">    start_point <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb3-11">      terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vect</span>(</span>
<span id="cb3-12">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(start_point, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb3-13">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EPSG:4326"</span>,</span>
<span id="cb3-14">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"points"</span></span>
<span id="cb3-15">      )</span>
<span id="cb3-16">    end_point <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb3-17">      terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vect</span>(</span>
<span id="cb3-18">        <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matrix</span>(end_point, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>),</span>
<span id="cb3-19">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">crs =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"EPSG:4326"</span>,</span>
<span id="cb3-20">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"points"</span></span>
<span id="cb3-21">      )</span>
<span id="cb3-22">    spatvector <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">vect</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(start_point, end_point))</span>
<span id="cb3-23">    line <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.lines</span>(spatvector)</span>
<span id="cb3-24">    line<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">$</span>id <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb3-25">    linedens <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">densify</span>(line, interval)</span>
<span id="cb3-26">    linedensp <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">as.points</span>(linedens)</span>
<span id="cb3-27">    radius <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq</span>(wd_start, wd_end, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length.out =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">nrow</span>(linedensp))</span>
<span id="cb3-28">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">is.null</span>(fun)) {</span>
<span id="cb3-29">      radius <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fun</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">seq_along</span>(radius))</span>
<span id="cb3-30">    }</span>
<span id="cb3-31">    linedenspb <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span></span>
<span id="cb3-32">      terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">buffer</span>(</span>
<span id="cb3-33">        linedensp,</span>
<span id="cb3-34">        radius,</span>
<span id="cb3-35">        <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">quadsegs =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">90</span>L</span>
<span id="cb3-36">      )</span>
<span id="cb3-37">    linedenspbm <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> terra<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">::</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">aggregate</span>(linedenspb)</span>
<span id="cb3-38">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">return</span>(linedenspbm)</span>
<span id="cb3-39">  }</span></code></pre></div></div>
</div>
<div id="b88dabb6" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;vscode&quot;,&quot;value&quot;:{&quot;languageId&quot;:&quot;r&quot;}}" data-execution_count="9">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb4-1">start_point <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>)</span>
<span id="cb4-2">end_point <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">79.7</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">35.3</span>)</span>
<span id="cb4-3">interval <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1e2</span></span>
<span id="cb4-4"></span>
<span id="cb4-5">trajpoly1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">conv_point_trajectory</span>(start_point, end_point, interval, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10000</span>)</span></code></pre></div></div>
</div>
<div id="3ab24a4f" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;vscode&quot;,&quot;value&quot;:{&quot;languageId&quot;:&quot;r&quot;}}" data-execution_count="10">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb5-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(trajpoly1)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://sigmafelix.github.io/posts/tornado-trajectories/index_files/figure-html/cell-5-output-1.png" width="420" height="420" class="figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="example-tornado-trajectories" class="level2">
<h2 class="anchored" data-anchor-id="example-tornado-trajectories">Example: Tornado Trajectories</h2>
<p>Below are simulated extreme weather events in the United States. We use these to create visualizations of the funnel-shaped polygons representing the tornado paths with varying intensities.</p>
<div id="7fcbdf30" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;vscode&quot;,&quot;value&quot;:{&quot;languageId&quot;:&quot;r&quot;}}">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb6-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Simulated trajectory data</span></span>
<span id="cb6-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Event 1: near Kansas</span></span>
<span id="cb6-3">event1_start <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">98.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">38.8</span>)</span>
<span id="cb6-4">event1_end <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">98.2</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">38.95</span>)</span>
<span id="cb6-5"></span>
<span id="cb6-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Event 2: near Oklahoma</span></span>
<span id="cb6-7">event2_start <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">97.3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">35.4</span>)</span>
<span id="cb6-8">event2_end <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">97.0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">35.6</span>)</span>
<span id="cb6-9"></span>
<span id="cb6-10"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Event 3: near Nebraska</span></span>
<span id="cb6-11">event3_start <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">103.8</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.2</span>)</span>
<span id="cb6-12">event3_end <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">103.5</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.4</span>)</span>
<span id="cb6-13"></span>
<span id="cb6-14"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Event 1: Narrow start (200m), wide end (4000m) - intensifying</span></span>
<span id="cb6-15">t1 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">conv_point_trajectory</span>(</span>
<span id="cb6-16">  event1_start, event1_end,</span>
<span id="cb6-17">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interval =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,</span>
<span id="cb6-18">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wd_start =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,</span>
<span id="cb6-19">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wd_end =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4000</span></span>
<span id="cb6-20">)</span>
<span id="cb6-21"></span>
<span id="cb6-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Event 2: Moderate widths with custom function</span></span>
<span id="cb6-23"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Width increases more rapidly in the middle of the path</span></span>
<span id="cb6-24">t2 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">conv_point_trajectory</span>(</span>
<span id="cb6-25">  event2_start, event2_end,</span>
<span id="cb6-26">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interval =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,</span>
<span id="cb6-27">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wd_start =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">200</span>,</span>
<span id="cb6-28">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wd_end =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3200</span>,</span>
<span id="cb6-29">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fun =</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span>(x) <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3200</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span> <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.25</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cos</span>(pi <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (x <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span> ) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">60</span>)) <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span></span>
<span id="cb6-30">)</span>
<span id="cb6-31"></span>
<span id="cb6-32"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Event 3: Widening</span></span>
<span id="cb6-33">t3 <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">&lt;-</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">conv_point_trajectory</span>(</span>
<span id="cb6-34">  event3_start, event3_end,</span>
<span id="cb6-35">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">interval =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>,</span>
<span id="cb6-36">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wd_start =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4000</span>,</span>
<span id="cb6-37">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">wd_end =</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">15000</span></span>
<span id="cb6-38">)</span></code></pre></div></div>
</div>
</section>
<section id="visualizing-the-trajectories" class="level2">
<h2 class="anchored" data-anchor-id="visualizing-the-trajectories">Visualizing the Trajectories</h2>
<p>Now we plot all three funnel polygons on a single map to show their geographic extent and relative widths.</p>
<div id="b920e7c4" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;vscode&quot;,&quot;value&quot;:{&quot;languageId&quot;:&quot;r&quot;}}" data-execution_count="22">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb7-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot all trajectories</span></span>
<span id="cb7-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">par</span>(<span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">mar =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bg =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"white"</span>)</span>
<span id="cb7-3"></span>
<span id="cb7-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot each one with different colors</span></span>
<span id="cb7-5"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(</span>
<span id="cb7-6">  t1,</span>
<span id="cb7-7">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rgb</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>),</span>
<span id="cb7-8">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">border =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb7-9">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">104</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">97</span>),</span>
<span id="cb7-10">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">35</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">41</span>),</span>
<span id="cb7-11">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">main =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Simulated Tornado Trajectory Funnels - example"</span>,</span>
<span id="cb7-12">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Longitude"</span>,</span>
<span id="cb7-13">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylab =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Latitude"</span></span>
<span id="cb7-14">)</span>
<span id="cb7-15"></span>
<span id="cb7-16"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add tornado 2</span></span>
<span id="cb7-17"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(t2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rgb</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">border =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">add =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb7-18"></span>
<span id="cb7-19"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add tornado 3</span></span>
<span id="cb7-20"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(t3, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rgb</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">border =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">add =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">TRUE</span>)</span>
<span id="cb7-21"></span>
<span id="cb7-22"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Add legend</span></span>
<span id="cb7-23"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">legend</span>(</span>
<span id="cb7-24">  <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"topright"</span>,</span>
<span id="cb7-25">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Event 1: Kansas"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Event 2: Oklahoma"</span>, <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Event 3: Nebraska"</span>),</span>
<span id="cb7-26">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fill =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rgb</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rgb</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>), <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rgb</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>)),</span>
<span id="cb7-27">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">border =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>,</span>
<span id="cb7-28">  <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">bty =</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span></span>
<span id="cb7-29">)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://sigmafelix.github.io/posts/tornado-trajectories/index_files/figure-html/cell-7-output-1.png" width="420" height="420" class="figure-img"></p>
</figure>
</div>
</div>
</div>
<div id="aa6164e9" class="cell" data-quarto-private-1="{&quot;key&quot;:&quot;vscode&quot;,&quot;value&quot;:{&quot;languageId&quot;:&quot;r&quot;}}" data-execution_count="21">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode r code-with-copy"><code class="sourceCode r"><span id="cb8-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># zoom in on each event</span></span>
<span id="cb8-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(t1, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rgb</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">border =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">98.8</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">98.0</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">38.6</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">39.15</span>))</span>
<span id="cb8-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(t2, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rgb</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">border =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">97.4</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">96.9</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">35.3</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">35.7</span>))</span>
<span id="cb8-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>(t3, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rgb</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.4</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">border =</span> <span class="cn" style="color: #8f5902;
background-color: null;
font-style: inherit;">NA</span>, <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">xlim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">103.9</span>, <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">103.4</span>), <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ylim =</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.1</span>, <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">40.5</span>))</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://sigmafelix.github.io/posts/tornado-trajectories/index_files/figure-html/cell-8-output-1.png" width="420" height="420" class="figure-img"></p>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://sigmafelix.github.io/posts/tornado-trajectories/index_files/figure-html/cell-8-output-2.png" width="420" height="420" class="figure-img"></p>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://sigmafelix.github.io/posts/tornado-trajectories/index_files/figure-html/cell-8-output-3.png" width="420" height="420" class="figure-img"></p>
</figure>
</div>
</div>
</div>
</section>
<section id="key-insights" class="level2">
<h2 class="anchored" data-anchor-id="key-insights">Key Insights</h2>
<ol type="1">
<li><p><strong>Visual Impact</strong>: The funnel representation immediately conveys both the path and intensity of the extreme weather event, such as tornado, especially when the limited observations are available.</p></li>
<li><p><strong>Customizable Width Functions</strong>: Beyond linear interpolation, you can apply custom functions to model real-world phenomena:</p>
<ul>
<li>Intensifying ones that start small</li>
<li>Peak-intensity patterns (bell curve)</li>
<li>Logarithmic or exponential growth patterns</li>
</ul></li>
<li><p><strong>Comparison</strong>: Multiple events can be overlaid to compare their geographic impact and path characteristics.</p></li>
<li><p><strong>Spatial Analysis</strong>: These polygons can be used for subsequent spatial analysis operations like intersection with populated areas, land-use analysis, or risk assessment.</p></li>
</ol>


</section>

 ]]></description>
  <category>spatial</category>
  <category>R</category>
  <category>geospatial</category>
  <guid>https://sigmafelix.github.io/posts/tornado-trajectories/</guid>
  <pubDate>Tue, 14 Apr 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Welcome To My Blog</title>
  <dc:creator>Insang Song</dc:creator>
  <link>https://sigmafelix.github.io/posts/welcome/</link>
  <description><![CDATA[ 





<p>This is the first post in Insang Song’s Quarto blog. Welcome!</p>



 ]]></description>
  <category>news</category>
  <guid>https://sigmafelix.github.io/posts/welcome/</guid>
  <pubDate>Mon, 26 Jan 2026 00:00:00 GMT</pubDate>
</item>
<item>
  <title>Pycensuskr example</title>
  <dc:creator>Insang Song</dc:creator>
  <link>https://sigmafelix.github.io/posts/post-with-code/</link>
  <description><![CDATA[ 





<p>This post demonstrates how to use the <a href="https://github.com/sigmafelix/pycensuskr"><code>pycensuskr</code></a> package to analyze Korean census data.</p>
<p><img src="https://sigmafelix.github.io/posts/post-with-code/gat.jpg" class="img-fluid"></p>
<section id="installation" class="level2">
<h2 class="anchored" data-anchor-id="installation">Installation</h2>
<p>You can install <code>pycensuskr</code> via pip:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode bash code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">pip</span> install pycensuskr</span></code></pre></div></div>
</section>
<section id="basic-usage" class="level2">
<h2 class="anchored" data-anchor-id="basic-usage">Basic Usage</h2>
<p>Here is a basic example of how to load census data and district boundaries.</p>
<div id="3cc5e061" class="cell" data-execution_count="1">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> pycensuskr <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> CensusKR</span>
<span id="cb2-2"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span> matplotlib <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> pyplot <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> plt</span>
<span id="cb2-3"><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">import</span> geopandas <span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">as</span> gpd</span>
<span id="cb2-4"></span>
<span id="cb2-5"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Create a CensusData instance</span></span>
<span id="cb2-6">census <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> CensusKR()</span>
<span id="cb2-7"></span>
<span id="cb2-8"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load specific year data (e.g., 2020)</span></span>
<span id="cb2-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># This returns a dictionary containing various census datasets</span></span>
<span id="cb2-10">data_2020 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> census.load_data(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2020</span>)</span>
<span id="cb2-11"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(data_2020.keys())</span>
<span id="cb2-12"></span>
<span id="cb2-13"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># load district boundaries for a specific year</span></span>
<span id="cb2-14">districts_2020 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> census.load_districts(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2020</span>)</span>
<span id="cb2-15"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">print</span>(districts_2020.head())</span></code></pre></div></div>
<div class="cell-output cell-output-stdout">
<pre><code>Index(['year', 'adm1', 'adm1_code', 'adm2', 'adm2_code', 'type', 'class1',
       'class2', 'unit', 'value'],
      dtype='object')
   year  adm2_code                                           geometry
0  2020      21140  POLYGON ((1147104.09 1689056.052, 1147080.539 ...
1  2020      21020  POLYGON ((1137762.765 1683520.509, 1137613.699...
2  2020      21010  POLYGON ((1139121.024 1678920.638, 1139128.662...
3  2020      21040  POLYGON ((1144618.022 1676795.027, 1144559.535...
4  2020      21070  POLYGON ((1142639.495 1682655.233, 1142678.184...</code></pre>
</div>
</div>
<div id="e5614736" class="cell" data-execution_count="2">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Example: Process and visualize tax data</span></span>
<span id="cb4-2"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># First, basic processing of district codes to match data aggregation level</span></span>
<span id="cb4-3">districts_2020[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"adm2_re"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> districts_2020[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"adm2_code"</span>].astype(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>).<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">str</span>.<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>,<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb4-4"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># aggregate geometries by adm2_re</span></span>
<span id="cb4-5">districts_2020 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> districts_2020.dissolve(by<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"adm2_re"</span>, as_index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">False</span>)</span>
<span id="cb4-6">districts_2020[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"adm2_code"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> districts_2020[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"adm2_re"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"0"</span></span>
<span id="cb4-7">districts_2020[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"adm2_code"</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> districts_2020[<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"adm2_code"</span>].astype(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">int</span>)</span>
<span id="cb4-8"></span>
<span id="cb4-9"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Retrieve tax data</span></span>
<span id="cb4-10">df_tax_2020 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> census.anycensus(year <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2020</span>, <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">type</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tax"</span>, aggregator <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sum"</span>)</span>
<span id="cb4-11"></span>
<span id="cb4-12"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Merge spatial data with tax data</span></span>
<span id="cb4-13">districts_tax_2020 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> districts_2020.merge(df_tax_2020, on<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"adm2_code"</span>)</span>
<span id="cb4-14"></span>
<span id="cb4-15"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># Plot labor income</span></span>
<span id="cb4-16">districts_tax_2020.plot(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"income_labor_mil"</span>, legend<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">True</span>, figsize<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>, <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span>))</span>
<span id="cb4-17">plt.title(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Labor Income by District (2020)"</span>)</span>
<span id="cb4-18">plt.show()</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="https://sigmafelix.github.io/posts/post-with-code/index_files/figure-html/cell-3-output-1.png" width="737" height="772" class="figure-img"></p>
</figure>
</div>
</div>
</div>


</section>

 ]]></description>
  <category>news</category>
  <category>code</category>
  <category>analysis</category>
  <guid>https://sigmafelix.github.io/posts/post-with-code/</guid>
  <pubDate>Mon, 26 Jan 2026 00:00:00 GMT</pubDate>
</item>
</channel>
</rss>
