Skip to content

Commit 2c2797e

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 4dfb608 commit 2c2797e

20 files changed

Lines changed: 1458 additions & 1247 deletions

docs/_toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ parts:
4646
chapters:
4747
- file: notebooks/conflict/acled-update-october24.ipynb
4848
- file: notebooks/aviation/aviation_update.ipynb
49-
- file: notebooks/vegetation-conditions/ChangeMaps.ipynb
49+
- file: notebooks/vegetation-conditions/ChangeMaps.ipynb
5050
- file: notebooks/syria-forest-cover/2023-summer-tree-cover-loss.md
5151
sections:
5252
- file: notebooks/syria-forest-cover/syria_forest.ipynb

node_modules/dotenv/README-es.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/dotenv/README.md

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

notebooks/ais-analysis/fall-2024/01-data-extraction.ipynb

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@
3838
"import pandas as pd\n",
3939
"import folium\n",
4040
"import h3.api.numpy_int as h3int\n",
41-
"from shapely.geometry import mapping, Polygon\n",
42-
"\n",
43-
"import os\n",
44-
"import subprocess\n",
45-
"import sys"
41+
"from shapely.geometry import mapping, Polygon"
4642
]
4743
},
4844
{
@@ -249,43 +245,25 @@
249245
"outputs": [],
250246
"source": [
251247
"tartus_geojson = {\n",
252-
" \"type\": \"FeatureCollection\",\n",
253-
" \"features\": [\n",
254-
" {\n",
255-
" \"type\": \"Feature\",\n",
256-
" \"properties\": {\n",
257-
" \"Port_name\": \"Tartus\",\n",
258-
" \"Country\": \"Syria\"\n",
259-
" },\n",
260-
" \"geometry\": {\n",
261-
" \"coordinates\": [\n",
262-
" [\n",
263-
" [\n",
264-
" 35.85288336140917,\n",
265-
" 34.91038874399062\n",
266-
" ],\n",
267-
" [\n",
268-
" 35.85682749616299,\n",
269-
" 34.899312694758734\n",
270-
" ],\n",
271-
" [\n",
272-
" 35.87511294210401,\n",
273-
" 34.89617739672141\n",
274-
" ],\n",
275-
" [\n",
276-
" 35.876428488429326,\n",
277-
" 34.91891484062019\n",
278-
" ],\n",
279-
" [\n",
280-
" 35.85288336140917,\n",
281-
" 34.91038874399062\n",
282-
" ]\n",
283-
" ]\n",
284-
" ],\n",
285-
" \"type\": \"Polygon\"\n",
286-
" }\n",
287-
" }\n",
288-
" ]\n",
248+
" \"type\": \"FeatureCollection\",\n",
249+
" \"features\": [\n",
250+
" {\n",
251+
" \"type\": \"Feature\",\n",
252+
" \"properties\": {\"Port_name\": \"Tartus\", \"Country\": \"Syria\"},\n",
253+
" \"geometry\": {\n",
254+
" \"coordinates\": [\n",
255+
" [\n",
256+
" [35.85288336140917, 34.91038874399062],\n",
257+
" [35.85682749616299, 34.899312694758734],\n",
258+
" [35.87511294210401, 34.89617739672141],\n",
259+
" [35.876428488429326, 34.91891484062019],\n",
260+
" [35.85288336140917, 34.91038874399062],\n",
261+
" ]\n",
262+
" ],\n",
263+
" \"type\": \"Polygon\",\n",
264+
" },\n",
265+
" }\n",
266+
" ],\n",
289267
"}"
290268
]
291269
},
@@ -297,7 +275,7 @@
297275
"outputs": [],
298276
"source": [
299277
"tartus_df = (\n",
300-
" gpd.GeoDataFrame.from_features(tartus_geojson) # json.loads(chokepoints_str)\n",
278+
" gpd.GeoDataFrame.from_features(tartus_geojson) # json.loads(chokepoints_str)\n",
301279
" .rename(columns={\"geometry\": \"port_boundary\"})\n",
302280
" .set_geometry(\"port_boundary\")\n",
303281
" .set_crs(crs=\"epsg:4326\")\n",
@@ -613,7 +591,7 @@
613591
"# [\n",
614592
"# (port_df.loc[i][\"Port\"], mapping(port_df.loc[i].port_boundary))\n",
615593
"# for i in range(port_df.shape[0])\n",
616-
"# ] + \n",
594+
"# ] +\n",
617595
"\n",
618596
"\n",
619597
"port_df_hex = af.polygon_to_hex_df(input_polygons, h3_resolution)\n",

notebooks/ais-analysis/fall-2024/03-next-draft.ipynb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@
7474
},
7575
"outputs": [],
7676
"source": [
77-
"import pandas as pd\n",
78-
"import geopandas as gpd\n",
79-
"\n",
80-
"import json"
77+
"import pandas as pd"
8178
]
8279
},
8380
{
@@ -295,10 +292,12 @@
295292
"source": [
296293
"s3path = \"s3a://ungp-ais-data-historical-backup/user_temp/\"\n",
297294
"wb_path = f\"{s3path}worldbank/\"\n",
298-
"imf = pd.read_pickle(wb_path + \"imf_port_boundary.pkl\") \\\n",
299-
" .set_crs(crs=\"epsg:4326\") \\\n",
300-
" .rename(columns={'geometry':'port_boundary'}) \\\n",
301-
" .set_geometry('port_boundary')"
295+
"imf = (\n",
296+
" pd.read_pickle(wb_path + \"imf_port_boundary.pkl\")\n",
297+
" .set_crs(crs=\"epsg:4326\")\n",
298+
" .rename(columns={\"geometry\": \"port_boundary\"})\n",
299+
" .set_geometry(\"port_boundary\")\n",
300+
")"
302301
]
303302
},
304303
{
@@ -2604,7 +2603,7 @@
26042603
"metadata": {},
26052604
"outputs": [],
26062605
"source": [
2607-
"next_df = pd.read_pickle(portcall_path_next+\"2019_2024.pkl\")"
2606+
"next_df = pd.read_pickle(portcall_path_next + \"2019_2024.pkl\")"
26082607
]
26092608
},
26102609
{
@@ -3176,8 +3175,7 @@
31763175
}
31773176
],
31783177
"source": [
3179-
"port_calls_v2 = port_calls.merge(next_df,\n",
3180-
" how='left')\n",
3178+
"port_calls_v2 = port_calls.merge(next_df, how=\"left\")\n",
31813179
"port_calls_v2.info()"
31823180
]
31833181
},

notebooks/ais-analysis/fall-2024/04-trade-estimation.ipynb

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@
146146
"id": "84792c7f",
147147
"metadata": {},
148148
"outputs": [],
149-
"source": [
150-
"from os.path import join, expanduser"
151-
]
149+
"source": []
152150
},
153151
{
154152
"cell_type": "code",
@@ -1990,8 +1988,8 @@
19901988
"metadata": {},
19911989
"outputs": [],
19921990
"source": [
1993-
"group_cols = [\"Country\", \"Port\", \"year\", \"month\", \"ym\", \"Type\"] # \"ShipTypeLevel2\"\n",
1994-
"data_cols = ['trade_flow_final_abs']"
1991+
"group_cols = [\"Country\", \"Port\", \"year\", \"month\", \"ym\", \"Type\"] # \"ShipTypeLevel2\"\n",
1992+
"data_cols = [\"trade_flow_final_abs\"]"
19951993
]
19961994
},
19971995
{
@@ -2011,7 +2009,12 @@
20112009
"metadata": {},
20122010
"outputs": [],
20132011
"source": [
2014-
"df_all = df.groupby([\"Country\", \"year\", \"month\", \"ym\", \"Type\"])[data_cols].sum().reset_index().assign(Port=\"Syria\")"
2012+
"df_all = (\n",
2013+
" df.groupby([\"Country\", \"year\", \"month\", \"ym\", \"Type\"])[data_cols]\n",
2014+
" .sum()\n",
2015+
" .reset_index()\n",
2016+
" .assign(Port=\"Syria\")\n",
2017+
")"
20152018
]
20162019
},
20172020
{
@@ -2031,7 +2034,15 @@
20312034
"metadata": {},
20322035
"outputs": [],
20332036
"source": [
2034-
"df_all = df_all.pivot_table(index=[\"Country\", \"Port\", \"year\", \"month\", \"ym\"], columns='Type', values='trade_flow_final_abs').reset_index().fillna(0)\n",
2037+
"df_all = (\n",
2038+
" df_all.pivot_table(\n",
2039+
" index=[\"Country\", \"Port\", \"year\", \"month\", \"ym\"],\n",
2040+
" columns=\"Type\",\n",
2041+
" values=\"trade_flow_final_abs\",\n",
2042+
" )\n",
2043+
" .reset_index()\n",
2044+
" .fillna(0)\n",
2045+
")\n",
20352046
"# .to_csv(\"./Trade_Estimation_Syria_Monthly.csv\", index=False)"
20362047
]
20372048
},
@@ -2073,7 +2084,18 @@
20732084
"outputs": [],
20742085
"source": [
20752086
"# count unique mmsi per year and ship type\n",
2076-
"df_count = df.groupby(['year', 'ShipTypeLevel2', 'ShiptypeLevel5', ])[['mmsi']].nunique().reset_index().rename(columns={'mmsi':'unique_mmsi'})"
2087+
"df_count = (\n",
2088+
" df.groupby(\n",
2089+
" [\n",
2090+
" \"year\",\n",
2091+
" \"ShipTypeLevel2\",\n",
2092+
" \"ShiptypeLevel5\",\n",
2093+
" ]\n",
2094+
" )[[\"mmsi\"]]\n",
2095+
" .nunique()\n",
2096+
" .reset_index()\n",
2097+
" .rename(columns={\"mmsi\": \"unique_mmsi\"})\n",
2098+
")"
20772099
]
20782100
},
20792101
{
@@ -2083,12 +2105,15 @@
20832105
"metadata": {},
20842106
"outputs": [],
20852107
"source": [
2086-
"df_count.rename(columns={\n",
2087-
" 'year':'Year',\n",
2088-
" 'ShipTypeLevel2':'Ship Type Level 2',\n",
2089-
" 'ShiptypeLevel5':'Ship Type Level 5',\n",
2090-
" 'unique_mmsi':'No. of vessels'\n",
2091-
"}, inplace=True)"
2108+
"df_count.rename(\n",
2109+
" columns={\n",
2110+
" \"year\": \"Year\",\n",
2111+
" \"ShipTypeLevel2\": \"Ship Type Level 2\",\n",
2112+
" \"ShiptypeLevel5\": \"Ship Type Level 5\",\n",
2113+
" \"unique_mmsi\": \"No. of vessels\",\n",
2114+
" },\n",
2115+
" inplace=True,\n",
2116+
")"
20922117
]
20932118
},
20942119
{
@@ -2098,7 +2123,16 @@
20982123
"metadata": {},
20992124
"outputs": [],
21002125
"source": [
2101-
"table = df_count.pivot(index=['Ship Type Level 2', 'Ship Type Level 5'], columns='Year', values='No. of vessels').fillna(0).reset_index().to_markdown(tablefmt=\"github\", index=False)"
2126+
"table = (\n",
2127+
" df_count.pivot(\n",
2128+
" index=[\"Ship Type Level 2\", \"Ship Type Level 5\"],\n",
2129+
" columns=\"Year\",\n",
2130+
" values=\"No. of vessels\",\n",
2131+
" )\n",
2132+
" .fillna(0)\n",
2133+
" .reset_index()\n",
2134+
" .to_markdown(tablefmt=\"github\", index=False)\n",
2135+
")"
21022136
]
21032137
},
21042138
{

notebooks/ais-analysis/fall-2024/update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ The vessel-level data can be accessed via this [link](https://worldbankgroup.sha
9292
## References
9393

9494
```{bibliography}
95-
```
95+
```

0 commit comments

Comments
 (0)