Skip to content

Commit

Permalink
deploy: 9b64b96
Browse files Browse the repository at this point in the history
  • Loading branch information
SahitiSarva committed Jun 4, 2024
1 parent 3c72faf commit 8a04a08
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 69 deletions.
21 changes: 14 additions & 7 deletions _sources/notebooks/conflict/acled.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"sys.path.append(join(git_root, \"src\", \"red_sea_monitoring\"))\n",
"import visuals\n",
"import acled\n",
"#from red_sea_monitoring.acled import *\n",
"# from red_sea_monitoring.acled import *\n",
"\n",
"from datetime import date\n",
"\n",
Expand Down Expand Up @@ -541,7 +541,12 @@
],
"source": [
"m = grouped_data.explore(\n",
" column=\"nr_fatalities\", zoom_start=5.1, marker_kwds={\"radius\": 5}, vmin=1, vmax=50, cmap ='viridis'\n",
" column=\"nr_fatalities\",\n",
" zoom_start=5.1,\n",
" marker_kwds={\"radius\": 5},\n",
" vmin=1,\n",
" vmax=50,\n",
" cmap=\"viridis\",\n",
")\n",
"m"
]
Expand Down Expand Up @@ -1257,7 +1262,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Weekly Conflict Events in the Red Sea Region (excluding protests)"
"### Weekly Conflict Events in the South Red Sea Region (excluding protests)"
]
},
{
Expand Down Expand Up @@ -1385,9 +1390,7 @@
"outputs": [],
"source": [
"conflict_red_sea = (\n",
" conflict_red_sea.groupby(\n",
" [\"country\", \"event_date\", \"location\"]\n",
" )[\"fatalities\"]\n",
" conflict_red_sea.groupby([\"country\", \"event_date\", \"location\"])[\"fatalities\"]\n",
" .agg([\"sum\", \"count\"])\n",
" .reset_index()\n",
")\n",
Expand Down Expand Up @@ -1485,7 +1488,11 @@
{
"cell_type": "code",
"execution_count": 82,
"metadata": {},
"metadata": {
"tags": [
"remove-input"
]
},
"outputs": [
{
"data": {
Expand Down
25 changes: 14 additions & 11 deletions _sources/notebooks/houthis/houthis-tax.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n"
"import pandas as pd"
]
},
{
Expand All @@ -37,9 +36,9 @@
},
"outputs": [],
"source": [
"fbx = pd.read_excel('../../data/Freightos Baltic Index.xlsx')\n",
"fbx['date'] = fbx['date'].apply(lambda x: pd.to_datetime(x))\n",
"fbx['FBX'] = fbx['FBX'].astype(float)"
"fbx = pd.read_excel(\"../../data/Freightos Baltic Index.xlsx\")\n",
"fbx[\"date\"] = fbx[\"date\"].apply(lambda x: pd.to_datetime(x))\n",
"fbx[\"FBX\"] = fbx[\"FBX\"].astype(float)"
]
},
{
Expand Down Expand Up @@ -87,7 +86,7 @@
" bab_el_mandeb.groupby(pd.Grouper(key=\"date\", freq=\"W\"))[\"n_total\"]\n",
" .sum()\n",
" .reset_index()\n",
")#.merge(fbx, on = 'date')"
") # .merge(fbx, on = 'date')"
]
},
{
Expand Down Expand Up @@ -160,7 +159,7 @@
],
"source": [
"from bokeh.plotting import figure, show, output_notebook\n",
"from bokeh.models import Legend, Span, LinearAxis, Range1d, Label, Spacer, Div\n",
"from bokeh.models import Legend, Span, LinearAxis, Range1d, Label, Div\n",
"from bokeh.layouts import column\n",
"\n",
"# Call this to display plots inline in a Jupyter Notebook\n",
Expand All @@ -182,7 +181,7 @@
"subtitle = Div(\n",
" text=f\"<div style='text-align:center;font-size:12pt;color:gray;'>{subtitle_text}</div>\",\n",
" width=1000,\n",
" height=30\n",
" height=30,\n",
")\n",
"\n",
"# Add a subtitle\n",
Expand All @@ -199,7 +198,9 @@
"\n",
"\n",
"# Plot multiple lines\n",
"p1 = p.line(bab_el_mandeb[\"date\"], bab_el_mandeb[\"n_total\"], line_width=2, color=\"#B07AA1\")\n",
"p1 = p.line(\n",
" bab_el_mandeb[\"date\"], bab_el_mandeb[\"n_total\"], line_width=2, color=\"#B07AA1\"\n",
")\n",
"p.y_range = Range1d(start=0, end=600)\n",
"p.extra_y_ranges = {\"y2\": Range1d(start=900, end=4000)}\n",
"p.add_layout(LinearAxis(y_range_name=\"y2\", axis_label=\"y2\"), \"right\")\n",
Expand All @@ -213,7 +214,6 @@
")\n",
"\n",
"\n",
"\n",
"legend_items = [\n",
" (\"Number of Vessels\", [p1]),\n",
" # (\"Number of events in Yemen\", [p2]),\n",
Expand Down Expand Up @@ -277,7 +277,10 @@
"p.add_layout(conflict_label)\n",
"\n",
"\n",
"layout = column(p, subtitle,)\n",
"layout = column(\n",
" p,\n",
" subtitle,\n",
")\n",
"# Show the plot\n",
"show(layout)"
]
Expand Down
61 changes: 11 additions & 50 deletions notebooks/conflict/acled.html
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ <h2> Contents </h2>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#insights">Insights</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#visualizing-conflict-fatalities-between-january-1st-2023-and-april-9th-2024">Visualizing conflict fatalities between January 1st 2023 and April 9th 2024</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#ports-of-interest-in-the-red-sea-region">Ports of Interest in the Red Sea Region</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#weekly-conflict-events-in-the-red-sea-region-excluding-protests">Weekly Conflict Events in the Red Sea Region (excluding protests)</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#weekly-conflict-events-in-the-south-red-sea-region-excluding-protests">Weekly Conflict Events in the South Red Sea Region (excluding protests)</a><ul class="nav section-nav flex-column">
<li class="toc-h4 nav-item toc-entry"><a class="reference internal nav-link" href="#observations-and-limitations">Observations and Limitations</a></li>
</ul>
</li>
Expand Down Expand Up @@ -477,7 +477,12 @@ <h3>Visualizing conflict fatalities between January 1st 2023 and April 9th 2024<
</summary>
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="n">m</span> <span class="o">=</span> <span class="n">grouped_data</span><span class="o">.</span><span class="n">explore</span><span class="p">(</span>
<span class="n">column</span><span class="o">=</span><span class="s2">&quot;nr_fatalities&quot;</span><span class="p">,</span> <span class="n">zoom_start</span><span class="o">=</span><span class="mf">5.1</span><span class="p">,</span> <span class="n">marker_kwds</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;radius&quot;</span><span class="p">:</span> <span class="mi">5</span><span class="p">},</span> <span class="n">vmin</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">vmax</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span> <span class="n">cmap</span> <span class="o">=</span><span class="s1">&#39;viridis&#39;</span>
<span class="n">column</span><span class="o">=</span><span class="s2">&quot;nr_fatalities&quot;</span><span class="p">,</span>
<span class="n">zoom_start</span><span class="o">=</span><span class="mf">5.1</span><span class="p">,</span>
<span class="n">marker_kwds</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;radius&quot;</span><span class="p">:</span> <span class="mi">5</span><span class="p">},</span>
<span class="n">vmin</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
<span class="n">vmax</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span>
<span class="n">cmap</span><span class="o">=</span><span class="s2">&quot;viridis&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">m</span>
</pre></div>
Expand Down Expand Up @@ -1417,8 +1422,8 @@ <h3>Ports of Interest in the Red Sea Region<a class="headerlink" href="#ports-of
})(window);</script></div>
</div>
</section>
<section id="weekly-conflict-events-in-the-red-sea-region-excluding-protests">
<h3>Weekly Conflict Events in the Red Sea Region (excluding protests)<a class="headerlink" href="#weekly-conflict-events-in-the-red-sea-region-excluding-protests" title="Permalink to this heading">#</a></h3>
<section id="weekly-conflict-events-in-the-south-red-sea-region-excluding-protests">
<h3>Weekly Conflict Events in the South Red Sea Region (excluding protests)<a class="headerlink" href="#weekly-conflict-events-in-the-south-red-sea-region-excluding-protests" title="Permalink to this heading">#</a></h3>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<div class="output text_html"><div class="bk-root">
Expand Down Expand Up @@ -2045,51 +2050,7 @@ <h4>Observations and Limitations<a class="headerlink" href="#observations-and-li
}
})(window);</script></div>
</div>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">bokeh.plotting</span> <span class="kn">import</span> <span class="n">show</span><span class="p">,</span> <span class="n">output_notebook</span>
<span class="kn">import</span> <span class="nn">bokeh</span>
<span class="kn">from</span> <span class="nn">bokeh.core.validation.warnings</span> <span class="kn">import</span> <span class="n">EMPTY_LAYOUT</span><span class="p">,</span> <span class="n">MISSING_RENDERERS</span>
<span class="kn">from</span> <span class="nn">bokeh.models</span> <span class="kn">import</span> <span class="n">Panel</span><span class="p">,</span> <span class="n">Tabs</span>

<span class="n">output_notebook</span><span class="p">()</span>

<span class="n">bokeh</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">validation</span><span class="o">.</span><span class="n">silence</span><span class="p">(</span><span class="n">EMPTY_LAYOUT</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>
<span class="n">bokeh</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">validation</span><span class="o">.</span><span class="n">silence</span><span class="p">(</span><span class="n">MISSING_RENDERERS</span><span class="p">,</span> <span class="kc">True</span><span class="p">)</span>

<span class="n">conflict_by_country</span> <span class="o">=</span> <span class="n">conflict_by_country</span><span class="o">.</span><span class="n">sort_values</span><span class="p">(</span><span class="n">by</span><span class="o">=</span><span class="s2">&quot;country&quot;</span><span class="p">,</span> <span class="n">ascending</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

<span class="n">tabs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">measure_names</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;nrEvents&quot;</span><span class="p">:</span> <span class="s2">&quot;Number of Conflict Events&quot;</span><span class="p">,</span>
<span class="s2">&quot;nrFatalities&quot;</span><span class="p">:</span> <span class="s2">&quot;Number of Fatalities&quot;</span><span class="p">,</span>
<span class="p">}</span>
<span class="n">measure_colors</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;nrEvents&quot;</span><span class="p">:</span> <span class="s2">&quot;#4E79A7&quot;</span><span class="p">,</span> <span class="s2">&quot;nrFatalities&quot;</span><span class="p">:</span> <span class="s2">&quot;#F28E2B&quot;</span><span class="p">}</span>
<span class="c1"># acled_adm0 = get_acled_by_admin(syria_adm2_crs, acled, columns = [&#39;ADM2_EN&#39;, &#39;ADM1_EN&#39;])</span>
<span class="k">for</span> <span class="n">country</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">conflict_by_country</span><span class="p">[</span><span class="s2">&quot;country&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">unique</span><span class="p">()):</span>
<span class="n">tabs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
<span class="n">Panel</span><span class="p">(</span>
<span class="n">child</span><span class="o">=</span><span class="n">visuals</span><span class="o">.</span><span class="n">get_bar_chart</span><span class="p">(</span>
<span class="n">conflict_by_country</span><span class="p">,</span>
<span class="sa">f</span><span class="s2">&quot;Weekly Conflict Fatality Trend in </span><span class="si">{</span><span class="n">country</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span>
<span class="s2">&quot;Source: ACLED&quot;</span><span class="p">,</span>
<span class="n">subtitle</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="n">category</span><span class="o">=</span><span class="s2">&quot;country&quot;</span><span class="p">,</span>
<span class="n">measure</span><span class="o">=</span><span class="s2">&quot;nrFatalities&quot;</span><span class="p">,</span>
<span class="n">color_code</span><span class="o">=</span><span class="n">measure_colors</span><span class="p">[</span><span class="s2">&quot;nrFatalities&quot;</span><span class="p">],</span>
<span class="n">category_value</span><span class="o">=</span><span class="n">country</span><span class="p">,</span>
<span class="n">crisis_date</span><span class="o">=</span><span class="n">crisis_date</span><span class="p">,</span>
<span class="n">conflict_date</span><span class="o">=</span><span class="n">conflict_date</span><span class="p">,</span>
<span class="p">),</span>
<span class="n">title</span><span class="o">=</span><span class="n">country</span><span class="o">.</span><span class="n">title</span><span class="p">(),</span>
<span class="p">)</span>
<span class="p">)</span>

<span class="n">tabs</span> <span class="o">=</span> <span class="n">Tabs</span><span class="p">(</span><span class="n">tabs</span><span class="o">=</span><span class="n">tabs</span><span class="p">,</span> <span class="n">sizing_mode</span><span class="o">=</span><span class="s2">&quot;scale_both&quot;</span><span class="p">)</span>
<span class="n">show</span><span class="p">(</span><span class="n">tabs</span><span class="p">,</span> <span class="n">warn_on_missing_glyphs</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell tag_remove-input docutils container">
<div class="cell_output docutils container">
<div class="output text_html"><div class="bk-root">
<a href="https://bokeh.org" target="_blank" class="bk-logo bk-logo-small bk-logo-notebook"></a>
Expand Down Expand Up @@ -2471,7 +2432,7 @@ <h4>Observations and Limitations<a class="headerlink" href="#observations-and-li
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#insights">Insights</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#visualizing-conflict-fatalities-between-january-1st-2023-and-april-9th-2024">Visualizing conflict fatalities between January 1st 2023 and April 9th 2024</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#ports-of-interest-in-the-red-sea-region">Ports of Interest in the Red Sea Region</a></li>
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#weekly-conflict-events-in-the-red-sea-region-excluding-protests">Weekly Conflict Events in the Red Sea Region (excluding protests)</a><ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry"><a class="reference internal nav-link" href="#weekly-conflict-events-in-the-south-red-sea-region-excluding-protests">Weekly Conflict Events in the South Red Sea Region (excluding protests)</a><ul class="nav section-nav flex-column">
<li class="toc-h4 nav-item toc-entry"><a class="reference internal nav-link" href="#observations-and-limitations">Observations and Limitations</a></li>
</ul>
</li>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

0 comments on commit 8a04a08

Please sign in to comment.