Skip to content

Commit 60416c2

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 214ea0b commit 60416c2

5 files changed

Lines changed: 178 additions & 109 deletions

File tree

notebooks/ais-analysis/01-lebanon.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3041,7 +3041,7 @@
30413041
" \"append\"\n",
30423042
" ).partitionBy(\"year\", \"month\").parquet(save_path)\n",
30433043
"\n",
3044-
" print(f\"Finished: {datetime.now()-start}\")\n",
3044+
" print(f\"Finished: {datetime.now() - start}\")\n",
30453045
" sdf.unpersist()"
30463046
]
30473047
},

notebooks/aviation-trends/aviation_update.ipynb

Lines changed: 99 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
},
2020
"outputs": [],
2121
"source": [
22-
"import pandas as pd\n",
23-
"import matplotlib.pyplot as plt"
22+
"import pandas as pd"
2423
]
2524
},
2625
{
@@ -120,8 +119,8 @@
120119
"for one_day in tqdm(daterange(start_date, end_date)):\n",
121120
" params = {\n",
122121
" \"access_key\": \"12925396bddce38222e47eed53e76e6c\",\n",
123-
" #\"dep_iata\": \"BEY\",\n",
124-
" 'arr_iata': 'BEY',\n",
122+
" # \"dep_iata\": \"BEY\",\n",
123+
" \"arr_iata\": \"BEY\",\n",
125124
" \"limit\": \"100\",\n",
126125
" # To get the next 100 flights we need to change the offset\n",
127126
" \"offset\": \"100\",\n",
@@ -221,9 +220,8 @@
221220
" HoverTool,\n",
222221
" Label,\n",
223222
" Span,\n",
224-
" Panel,\n",
225223
" Tabs,\n",
226-
" TabPanel\n",
224+
" TabPanel,\n",
227225
")\n",
228226
"from bokeh.palettes import Spectral6\n",
229227
"\n",
@@ -242,7 +240,7 @@
242240
" df_reindexed = df_reindexed.reset_index().rename(columns={\"index\": \"flight_date\"})\n",
243241
"\n",
244242
" df[\"total_flights\"] = df.groupby(\"flight_date\")[\"iata_arr\"].transform(\"sum\")\n",
245-
" if acled_events_daily['nrEvents'].max()<500:\n",
243+
" if acled_events_daily[\"nrEvents\"].max() < 500:\n",
246244
" max_flight = acled_events_daily[\"nrEvents\"].max() + 50\n",
247245
" else:\n",
248246
" max_flight = acled_events_daily[\"nrEvents\"].max() + 200\n",
@@ -256,7 +254,7 @@
256254
" height=600,\n",
257255
" width=800,\n",
258256
" title=title,\n",
259-
" toolbar_location='above',\n",
257+
" toolbar_location=\"above\",\n",
260258
" tools=\"pan,box_zoom,reset,save\",\n",
261259
" x_axis_label=\"Flight Date\",\n",
262260
" y_axis_label=\"Nr Flights\",\n",
@@ -346,14 +344,16 @@
346344
" span = Span(\n",
347345
" location=event_timestamp,\n",
348346
" dimension=\"height\",\n",
349-
" line_color='#C6C6C6',\n",
347+
" line_color=\"#C6C6C6\",\n",
350348
" line_width=2,\n",
351-
" line_dash=(4, 4)\n",
349+
" line_dash=(4, 4),\n",
352350
" )\n",
353351
" p.renderers.append(span)\n",
354352
"\n",
355353
" # Determine a base y position for the label\n",
356-
" base_y = max_flight - (max_flight/5) # Adjust for visibility above the plot\n",
354+
" base_y = max_flight - (\n",
355+
" max_flight / 5\n",
356+
" ) # Adjust for visibility above the plot\n",
357357
" y_position = base_y # Default position\n",
358358
"\n",
359359
" # Adjust y_position if it overlaps with previous labels\n",
@@ -398,8 +398,8 @@
398398
" pd.read_csv(\"../../data/aviation/aviationstack_bey_25082024_01012024_dep2.csv\"),\n",
399399
" pd.read_csv(\"../../data/aviation/aviationstack_bey_15082024_07102024_dep.csv\"),\n",
400400
" pd.read_csv(\"../../data/aviation/aviationstack_bey_15082024_07102024_dep2.csv\"),\n",
401-
" pd.read_csv('../../data/aviation/aviationstack_bey_07102024_23102024_dep.csv'),\n",
402-
" pd.read_csv('../../data/aviation/aviationstack_bey_07102024_23102024_dep2.csv')\n",
401+
" pd.read_csv(\"../../data/aviation/aviationstack_bey_07102024_23102024_dep.csv\"),\n",
402+
" pd.read_csv(\"../../data/aviation/aviationstack_bey_07102024_23102024_dep2.csv\"),\n",
403403
" ]\n",
404404
")\n",
405405
"departures.drop(columns=\"Unnamed: 0\", inplace=True)\n",
@@ -552,7 +552,7 @@
552552
"\n",
553553
"after = departures_exploded.shape[0]\n",
554554
"print(\n",
555-
" f\"There are {after} flights after duplication check. {before-after} flights were duplicated\"\n",
555+
" f\"There are {after} flights after duplication check. {before - after} flights were duplicated\"\n",
556556
")"
557557
]
558558
},
@@ -696,11 +696,11 @@
696696
"# '2024-06-07', '2024-06-08', '2024-06-09', '2024-09-02']\n",
697697
"\n",
698698
"events = {\n",
699-
" #\"2024-06-09\":\"Airline data\\nnot available\",\n",
700-
" \"2024-04-14\": \"Temporary shutdown of\\nLebanese airspace between\\n7AM and 1PM\",\n",
701-
" \"2024-08-25\":\"Israeli strikes in\\nSouthern Lebanon\",\n",
702-
" \"2024-09-23\":\"Start of the full blown conflict\"\n",
703-
" }"
699+
" # \"2024-06-09\":\"Airline data\\nnot available\",\n",
700+
" \"2024-04-14\": \"Temporary shutdown of\\nLebanese airspace between\\n7AM and 1PM\",\n",
701+
" \"2024-08-25\": \"Israeli strikes in\\nSouthern Lebanon\",\n",
702+
" \"2024-09-23\": \"Start of the full blown conflict\",\n",
703+
"}"
704704
]
705705
},
706706
{
@@ -1102,7 +1102,7 @@
11021102
" \"Most Changed Departures\": most_changed_departures,\n",
11031103
" \"Most Cancelled Departures\": most_cancelled_departures,\n",
11041104
" \"Most Scheduled Departures\": most_scheduled_departures,\n",
1105-
" \"Most Diverted Departures\": most_diverted_departures\n",
1105+
" \"Most Diverted Departures\": most_diverted_departures,\n",
11061106
"}\n",
11071107
"\n",
11081108
"# Initialize an empty list to store the tabs\n",
@@ -1118,25 +1118,50 @@
11181118
" source = ColumnDataSource(data)\n",
11191119
"\n",
11201120
" # Create a figure for each dataset\n",
1121-
" p = figure(y_range=data['airportcity'], width=600, height=400, title=title + \" in 2024\", tools=\"save\", toolbar_location=\"above\")\n",
1122-
" p.hbar(y='airportcity', right='count', height=0.5, color=color, alpha=0.7, source=source)\n",
1121+
" p = figure(\n",
1122+
" y_range=data[\"airportcity\"],\n",
1123+
" width=600,\n",
1124+
" height=400,\n",
1125+
" title=title + \" in 2024\",\n",
1126+
" tools=\"save\",\n",
1127+
" toolbar_location=\"above\",\n",
1128+
" )\n",
1129+
" p.hbar(\n",
1130+
" y=\"airportcity\",\n",
1131+
" right=\"count\",\n",
1132+
" height=0.5,\n",
1133+
" color=color,\n",
1134+
" alpha=0.7,\n",
1135+
" source=source,\n",
1136+
" )\n",
11231137
"\n",
11241138
" # Add text inside the bars (5 points inside the bar)\n",
1125-
" p.text(x='count', y='airportcity', text='count', source=source, \n",
1126-
" x_offset=-5, # This places the text 5 units inside the bar\n",
1127-
" y_offset=-3, # Vertical alignment\n",
1128-
" text_align='right', text_baseline='middle', text_color=\"black\", text_font_size=\"10pt\")\n",
1139+
" p.text(\n",
1140+
" x=\"count\",\n",
1141+
" y=\"airportcity\",\n",
1142+
" text=\"count\",\n",
1143+
" source=source,\n",
1144+
" x_offset=-5, # This places the text 5 units inside the bar\n",
1145+
" y_offset=-3, # Vertical alignment\n",
1146+
" text_align=\"right\",\n",
1147+
" text_baseline=\"middle\",\n",
1148+
" text_color=\"black\",\n",
1149+
" text_font_size=\"10pt\",\n",
1150+
" )\n",
11291151
"\n",
11301152
" # Customize plot (optional)\n",
11311153
" p.xaxis.visible = False\n",
11321154
" p.ygrid.visible = False\n",
11331155
" p.xgrid.visible = False\n",
11341156
" p.yaxis.major_tick_line_color = None # No major ticks\n",
11351157
" p.yaxis.minor_tick_line_color = None # No minor ticks\n",
1136-
" p.yaxis.axis_line_color = None \n",
1158+
" p.yaxis.axis_line_color = None\n",
11371159
" p.outline_line_color = None\n",
11381160
"\n",
1139-
" subtitle = Div(text=f\"<p style='font-size:12px; color:gray;'>Source: AviationStack. Acessed October 7th 2024.</p>\", width=600)\n",
1161+
" subtitle = Div(\n",
1162+
" text=\"<p style='font-size:12px; color:gray;'>Source: AviationStack. Acessed October 7th 2024.</p>\",\n",
1163+
" width=600,\n",
1164+
" )\n",
11401165
"\n",
11411166
" layout = column(p, subtitle)\n",
11421167
"\n",
@@ -1149,7 +1174,10 @@
11491174
"# Arrange the tabs in a Tabs layout\n",
11501175
"tabs_layout = Tabs(tabs=tabs)\n",
11511176
"\n",
1152-
"main_title = Div(text=\"<h2>Top 10 Destinations with Changes in Departures from BEY in 2024</h2>\", width=800)\n",
1177+
"main_title = Div(\n",
1178+
" text=\"<h2>Top 10 Destinations with Changes in Departures from BEY in 2024</h2>\",\n",
1179+
" width=800,\n",
1180+
")\n",
11531181
"\n",
11541182
"# Use column layout to stack the title on top of the tabs\n",
11551183
"layout = column(main_title, tabs_layout)\n",
@@ -1270,8 +1298,8 @@
12701298
" pd.read_csv(\"../../data/aviation/aviationstack_bey_26082024_01012024_arr.csv\"),\n",
12711299
" pd.read_csv(\"../../data/aviation/aviationstack_bey_15082024_07102024_arr.csv\"),\n",
12721300
" pd.read_csv(\"../../data/aviation/aviationstack_bey_15082024_07102024_arr2.csv\"),\n",
1273-
" pd.read_csv('../../data/aviation/aviationstack_bey_07102024_23102024_arr.csv'),\n",
1274-
" pd.read_csv('../../data/aviation/aviationstack_bey_07102024_23102024_arr2.csv')\n",
1301+
" pd.read_csv(\"../../data/aviation/aviationstack_bey_07102024_23102024_arr.csv\"),\n",
1302+
" pd.read_csv(\"../../data/aviation/aviationstack_bey_07102024_23102024_arr2.csv\"),\n",
12751303
" ]\n",
12761304
")\n",
12771305
"arrivals.drop(columns=\"Unnamed: 0\", inplace=True)\n",
@@ -1365,7 +1393,7 @@
13651393
"\n",
13661394
"after = arrivals_exploded.shape[0]\n",
13671395
"print(\n",
1368-
" f\"There are {after} flights after duplication check. {before-after} flights were duplicated\"\n",
1396+
" f\"There are {after} flights after duplication check. {before - after} flights were duplicated\"\n",
13691397
")"
13701398
]
13711399
},
@@ -1771,7 +1799,7 @@
17711799
" \"Most Changed Arrivals\": most_changed_arrivals,\n",
17721800
" \"Most Cancelled Arrivals\": most_cancelled_arrivals,\n",
17731801
" \"Most Scheduled Arrivals\": most_scheduled_arrivals,\n",
1774-
" \"Most Diverted Arrivals\": most_diverted_arrivals\n",
1802+
" \"Most Diverted Arrivals\": most_diverted_arrivals,\n",
17751803
"}\n",
17761804
"\n",
17771805
"# Initialize an empty list to store the tabs\n",
@@ -1787,38 +1815,66 @@
17871815
" source = ColumnDataSource(data)\n",
17881816
"\n",
17891817
" # Create a figure for each dataset\n",
1790-
" p = figure(y_range=data['airportcity'], width=600, height=400, title=title + \" in 2024\", tools=\"save\", toolbar_location=\"above\")\n",
1791-
" p.hbar(y='airportcity', right='count', height=0.5, color=color, alpha=0.7, source=source)\n",
1818+
" p = figure(\n",
1819+
" y_range=data[\"airportcity\"],\n",
1820+
" width=600,\n",
1821+
" height=400,\n",
1822+
" title=title + \" in 2024\",\n",
1823+
" tools=\"save\",\n",
1824+
" toolbar_location=\"above\",\n",
1825+
" )\n",
1826+
" p.hbar(\n",
1827+
" y=\"airportcity\",\n",
1828+
" right=\"count\",\n",
1829+
" height=0.5,\n",
1830+
" color=color,\n",
1831+
" alpha=0.7,\n",
1832+
" source=source,\n",
1833+
" )\n",
17921834
"\n",
17931835
" # Add text inside the bars (5 points inside the bar)\n",
1794-
" p.text(x='count', y='airportcity', text='count', source=source, \n",
1795-
" x_offset=-5, # This places the text 5 units inside the bar\n",
1796-
" y_offset=-3, # Vertical alignment\n",
1797-
" text_align='right', text_baseline='middle', text_color=\"black\", text_font_size=\"10pt\")\n",
1836+
" p.text(\n",
1837+
" x=\"count\",\n",
1838+
" y=\"airportcity\",\n",
1839+
" text=\"count\",\n",
1840+
" source=source,\n",
1841+
" x_offset=-5, # This places the text 5 units inside the bar\n",
1842+
" y_offset=-3, # Vertical alignment\n",
1843+
" text_align=\"right\",\n",
1844+
" text_baseline=\"middle\",\n",
1845+
" text_color=\"black\",\n",
1846+
" text_font_size=\"10pt\",\n",
1847+
" )\n",
17981848
"\n",
17991849
" # Customize plot (optional)\n",
18001850
" p.xaxis.visible = False\n",
18011851
" p.ygrid.visible = False\n",
18021852
" p.xgrid.visible = False\n",
18031853
" p.yaxis.major_tick_line_color = None # No major ticks\n",
18041854
" p.yaxis.minor_tick_line_color = None # No minor ticks\n",
1805-
" p.yaxis.axis_line_color = None \n",
1855+
" p.yaxis.axis_line_color = None\n",
18061856
" p.outline_line_color = None\n",
18071857
"\n",
1808-
" subtitle = Div(text=f\"<p style='font-size:12px; color:gray;'>Source: AviationStack. Acessed October 7th 2024.</p>\", width=600)\n",
1858+
" subtitle = Div(\n",
1859+
" text=\"<p style='font-size:12px; color:gray;'>Source: AviationStack. Acessed October 7th 2024.</p>\",\n",
1860+
" width=600,\n",
1861+
" )\n",
18091862
"\n",
18101863
" layout = column(p, subtitle)\n",
18111864
"\n",
18121865
" # Create a panel with the plot and the corresponding title\n",
18131866
" tab = TabPanel(child=layout, title=title)\n",
1814-
" \n",
1867+
"\n",
18151868
" # Append the panel to the list of tabs\n",
18161869
" tabs.append(tab)\n",
18171870
"\n",
18181871
"# Arrange the tabs in a Tabs layout\n",
18191872
"tabs_layout = Tabs(tabs=tabs)\n",
18201873
"\n",
1821-
"main_title = Div(text=\"<h2>Top 10 Destinations with Changes in Arrivals to BEY in 2024</h2>\", width=800)\n",
1874+
"main_title = Div(\n",
1875+
" text=\"<h2>Top 10 Destinations with Changes in Arrivals to BEY in 2024</h2>\",\n",
1876+
" width=800,\n",
1877+
")\n",
18221878
"\n",
18231879
"# Use column layout to stack the title on top of the tabs\n",
18241880
"layout = column(main_title, tabs_layout)\n",

notebooks/conflict/conflict.ipynb

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
"metadata": {},
184184
"outputs": [],
185185
"source": [
186-
"data = data[data['event_date']>'2023-10-07']"
186+
"data = data[data[\"event_date\"] > \"2023-10-07\"]"
187187
]
188188
},
189189
{
@@ -634,6 +634,7 @@
634634
" 200: \"More than 50\",\n",
635635
"}\n",
636636
"\n",
637+
"\n",
637638
"def get_size_category(item):\n",
638639
" if item < 25:\n",
639640
" return 5\n",
@@ -642,12 +643,15 @@
642643
" elif item > 50:\n",
643644
" return 200\n",
644645
"\n",
646+
"\n",
645647
"gdf = analysis.convert_to_gdf(conflict_monthly)\n",
646648
"\n",
647649
"\n",
648-
"gdf['sizeCategory'] = gdf['nrFatalities'].apply(get_size_category)\n",
650+
"gdf[\"sizeCategory\"] = gdf[\"nrFatalities\"].apply(get_size_category)\n",
649651
"\n",
650-
"beirut = gpd.read_file('../../data/shapefiles/lbn_beirut_adm4_mapaction_pcoded/lbn_beirut_adm4_MapAction_Pcoded.shp')\n",
652+
"beirut = gpd.read_file(\n",
653+
" \"../../data/shapefiles/lbn_beirut_adm4_mapaction_pcoded/lbn_beirut_adm4_MapAction_Pcoded.shp\"\n",
654+
")\n",
651655
"\n",
652656
"gdf_beirut = gdf.sjoin(beirut)"
653657
]
@@ -701,15 +705,17 @@
701705
"# country = world[world['name'] == 'Lebanon']\n",
702706
"\n",
703707
"\n",
704-
"gdf.plot(\n",
705-
" column=\"nrFatalities\",cmap=cmap, ax=ax, markersize=\"sizeCategory\", marker=\"o\"\n",
706-
")\n",
708+
"gdf.plot(column=\"nrFatalities\", cmap=cmap, ax=ax, markersize=\"sizeCategory\", marker=\"o\")\n",
707709
"lebanon_adm1.boundary.plot(ax=ax, color=\"lightgrey\", alpha=0.5, zorder=1)\n",
708710
"ax.set_title(\"Fatalities in Lebanon from 2016 to 2024\")\n",
709711
"\n",
710-
"sizes = gdf[gdf['event_date']>'2023-10-08'].sort_values(by=\"sizeCategory\")[\"sizeCategory\"].unique()\n",
712+
"sizes = (\n",
713+
" gdf[gdf[\"event_date\"] > \"2023-10-08\"]\n",
714+
" .sort_values(by=\"sizeCategory\")[\"sizeCategory\"]\n",
715+
" .unique()\n",
716+
")\n",
711717
"\n",
712-
"#country.plot(ax=ax, color='none', edgecolor='black')\n",
718+
"# country.plot(ax=ax, color='none', edgecolor='black')\n",
713719
"ctx.add_basemap(ax, crs=gdf.crs.to_string(), source=ctx.providers.CartoDB.Positron)\n",
714720
"\n",
715721
"\n",
@@ -734,7 +740,14 @@
734740
" bbox_to_anchor=(1.4, 0.2),\n",
735741
")\n",
736742
"\n",
737-
"plt.figtext(0.28, 0.09, f'Source: ACLED. Accessed {datetime.today().date().isoformat()}', ha=\"left\", fontsize=9, color=\"black\")\n",
743+
"plt.figtext(\n",
744+
" 0.28,\n",
745+
" 0.09,\n",
746+
" f\"Source: ACLED. Accessed {datetime.today().date().isoformat()}\",\n",
747+
" ha=\"left\",\n",
748+
" fontsize=9,\n",
749+
" color=\"black\",\n",
750+
")\n",
738751
"\n",
739752
"\n",
740753
"ax.spines[\"top\"].set_visible(False)\n",
@@ -745,7 +758,7 @@
745758
"ax.set_xticks([])\n",
746759
"ax.set_yticks([])\n",
747760
"\n",
748-
"plt.savefig('../../docs/images/fatalities_nov2024.png', dpi=800, bbox_inches='tight');\n"
761+
"plt.savefig(\"../../docs/images/fatalities_nov2024.png\", dpi=800, bbox_inches=\"tight\");"
749762
]
750763
},
751764
{

notebooks/ntl-analysis/01_clean_data/01_download_blackmarble.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# bearer <- file.path(ntl_dir, "blackmarble-bearer-token", "bearer_bm.csv") %>%
66
# read_csv() %>%
77
# pull("token")
8-
#
8+
#
99
# bearer <- file.path("~/Desktop", "bearer_bm.csv") %>%
1010
# read_csv() %>%
1111
# pull("token")

0 commit comments

Comments
 (0)