Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 16, 2024
1 parent 13d1224 commit a99aefc
Show file tree
Hide file tree
Showing 20 changed files with 1,458 additions and 1,247 deletions.
2 changes: 1 addition & 1 deletion docs/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ parts:
chapters:
- file: notebooks/conflict/acled-update-october24.ipynb
- file: notebooks/aviation/aviation_update.ipynb
- file: notebooks/vegetation-conditions/ChangeMaps.ipynb
- file: notebooks/vegetation-conditions/ChangeMaps.ipynb
- file: notebooks/syria-forest-cover/2023-summer-tree-cover-loss.md
sections:
- file: notebooks/syria-forest-cover/syria_forest.ipynb
Expand Down
2 changes: 1 addition & 1 deletion node_modules/dotenv/README-es.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions node_modules/dotenv/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 22 additions & 44 deletions notebooks/ais-analysis/fall-2024/01-data-extraction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@
"import pandas as pd\n",
"import folium\n",
"import h3.api.numpy_int as h3int\n",
"from shapely.geometry import mapping, Polygon\n",
"\n",
"import os\n",
"import subprocess\n",
"import sys"
"from shapely.geometry import mapping, Polygon"
]
},
{
Expand Down Expand Up @@ -249,43 +245,25 @@
"outputs": [],
"source": [
"tartus_geojson = {\n",
" \"type\": \"FeatureCollection\",\n",
" \"features\": [\n",
" {\n",
" \"type\": \"Feature\",\n",
" \"properties\": {\n",
" \"Port_name\": \"Tartus\",\n",
" \"Country\": \"Syria\"\n",
" },\n",
" \"geometry\": {\n",
" \"coordinates\": [\n",
" [\n",
" [\n",
" 35.85288336140917,\n",
" 34.91038874399062\n",
" ],\n",
" [\n",
" 35.85682749616299,\n",
" 34.899312694758734\n",
" ],\n",
" [\n",
" 35.87511294210401,\n",
" 34.89617739672141\n",
" ],\n",
" [\n",
" 35.876428488429326,\n",
" 34.91891484062019\n",
" ],\n",
" [\n",
" 35.85288336140917,\n",
" 34.91038874399062\n",
" ]\n",
" ]\n",
" ],\n",
" \"type\": \"Polygon\"\n",
" }\n",
" }\n",
" ]\n",
" \"type\": \"FeatureCollection\",\n",
" \"features\": [\n",
" {\n",
" \"type\": \"Feature\",\n",
" \"properties\": {\"Port_name\": \"Tartus\", \"Country\": \"Syria\"},\n",
" \"geometry\": {\n",
" \"coordinates\": [\n",
" [\n",
" [35.85288336140917, 34.91038874399062],\n",
" [35.85682749616299, 34.899312694758734],\n",
" [35.87511294210401, 34.89617739672141],\n",
" [35.876428488429326, 34.91891484062019],\n",
" [35.85288336140917, 34.91038874399062],\n",
" ]\n",
" ],\n",
" \"type\": \"Polygon\",\n",
" },\n",
" }\n",
" ],\n",
"}"
]
},
Expand All @@ -297,7 +275,7 @@
"outputs": [],
"source": [
"tartus_df = (\n",
" gpd.GeoDataFrame.from_features(tartus_geojson) # json.loads(chokepoints_str)\n",
" gpd.GeoDataFrame.from_features(tartus_geojson) # json.loads(chokepoints_str)\n",
" .rename(columns={\"geometry\": \"port_boundary\"})\n",
" .set_geometry(\"port_boundary\")\n",
" .set_crs(crs=\"epsg:4326\")\n",
Expand Down Expand Up @@ -613,7 +591,7 @@
"# [\n",
"# (port_df.loc[i][\"Port\"], mapping(port_df.loc[i].port_boundary))\n",
"# for i in range(port_df.shape[0])\n",
"# ] + \n",
"# ] +\n",
"\n",
"\n",
"port_df_hex = af.polygon_to_hex_df(input_polygons, h3_resolution)\n",
Expand Down
20 changes: 9 additions & 11 deletions notebooks/ais-analysis/fall-2024/03-next-draft.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import geopandas as gpd\n",
"\n",
"import json"
"import pandas as pd"
]
},
{
Expand Down Expand Up @@ -295,10 +292,12 @@
"source": [
"s3path = \"s3a://ungp-ais-data-historical-backup/user_temp/\"\n",
"wb_path = f\"{s3path}worldbank/\"\n",
"imf = pd.read_pickle(wb_path + \"imf_port_boundary.pkl\") \\\n",
" .set_crs(crs=\"epsg:4326\") \\\n",
" .rename(columns={'geometry':'port_boundary'}) \\\n",
" .set_geometry('port_boundary')"
"imf = (\n",
" pd.read_pickle(wb_path + \"imf_port_boundary.pkl\")\n",
" .set_crs(crs=\"epsg:4326\")\n",
" .rename(columns={\"geometry\": \"port_boundary\"})\n",
" .set_geometry(\"port_boundary\")\n",
")"
]
},
{
Expand Down Expand Up @@ -2604,7 +2603,7 @@
"metadata": {},
"outputs": [],
"source": [
"next_df = pd.read_pickle(portcall_path_next+\"2019_2024.pkl\")"
"next_df = pd.read_pickle(portcall_path_next + \"2019_2024.pkl\")"
]
},
{
Expand Down Expand Up @@ -3176,8 +3175,7 @@
}
],
"source": [
"port_calls_v2 = port_calls.merge(next_df,\n",
" how='left')\n",
"port_calls_v2 = port_calls.merge(next_df, how=\"left\")\n",
"port_calls_v2.info()"
]
},
Expand Down
64 changes: 49 additions & 15 deletions notebooks/ais-analysis/fall-2024/04-trade-estimation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@
"id": "84792c7f",
"metadata": {},
"outputs": [],
"source": [
"from os.path import join, expanduser"
]
"source": []
},
{
"cell_type": "code",
Expand Down Expand Up @@ -1990,8 +1988,8 @@
"metadata": {},
"outputs": [],
"source": [
"group_cols = [\"Country\", \"Port\", \"year\", \"month\", \"ym\", \"Type\"] # \"ShipTypeLevel2\"\n",
"data_cols = ['trade_flow_final_abs']"
"group_cols = [\"Country\", \"Port\", \"year\", \"month\", \"ym\", \"Type\"] # \"ShipTypeLevel2\"\n",
"data_cols = [\"trade_flow_final_abs\"]"
]
},
{
Expand All @@ -2011,7 +2009,12 @@
"metadata": {},
"outputs": [],
"source": [
"df_all = df.groupby([\"Country\", \"year\", \"month\", \"ym\", \"Type\"])[data_cols].sum().reset_index().assign(Port=\"Syria\")"
"df_all = (\n",
" df.groupby([\"Country\", \"year\", \"month\", \"ym\", \"Type\"])[data_cols]\n",
" .sum()\n",
" .reset_index()\n",
" .assign(Port=\"Syria\")\n",
")"
]
},
{
Expand All @@ -2031,7 +2034,15 @@
"metadata": {},
"outputs": [],
"source": [
"df_all = df_all.pivot_table(index=[\"Country\", \"Port\", \"year\", \"month\", \"ym\"], columns='Type', values='trade_flow_final_abs').reset_index().fillna(0)\n",
"df_all = (\n",
" df_all.pivot_table(\n",
" index=[\"Country\", \"Port\", \"year\", \"month\", \"ym\"],\n",
" columns=\"Type\",\n",
" values=\"trade_flow_final_abs\",\n",
" )\n",
" .reset_index()\n",
" .fillna(0)\n",
")\n",
"# .to_csv(\"./Trade_Estimation_Syria_Monthly.csv\", index=False)"
]
},
Expand Down Expand Up @@ -2073,7 +2084,18 @@
"outputs": [],
"source": [
"# count unique mmsi per year and ship type\n",
"df_count = df.groupby(['year', 'ShipTypeLevel2', 'ShiptypeLevel5', ])[['mmsi']].nunique().reset_index().rename(columns={'mmsi':'unique_mmsi'})"
"df_count = (\n",
" df.groupby(\n",
" [\n",
" \"year\",\n",
" \"ShipTypeLevel2\",\n",
" \"ShiptypeLevel5\",\n",
" ]\n",
" )[[\"mmsi\"]]\n",
" .nunique()\n",
" .reset_index()\n",
" .rename(columns={\"mmsi\": \"unique_mmsi\"})\n",
")"
]
},
{
Expand All @@ -2083,12 +2105,15 @@
"metadata": {},
"outputs": [],
"source": [
"df_count.rename(columns={\n",
" 'year':'Year',\n",
" 'ShipTypeLevel2':'Ship Type Level 2',\n",
" 'ShiptypeLevel5':'Ship Type Level 5',\n",
" 'unique_mmsi':'No. of vessels'\n",
"}, inplace=True)"
"df_count.rename(\n",
" columns={\n",
" \"year\": \"Year\",\n",
" \"ShipTypeLevel2\": \"Ship Type Level 2\",\n",
" \"ShiptypeLevel5\": \"Ship Type Level 5\",\n",
" \"unique_mmsi\": \"No. of vessels\",\n",
" },\n",
" inplace=True,\n",
")"
]
},
{
Expand All @@ -2098,7 +2123,16 @@
"metadata": {},
"outputs": [],
"source": [
"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)"
"table = (\n",
" df_count.pivot(\n",
" index=[\"Ship Type Level 2\", \"Ship Type Level 5\"],\n",
" columns=\"Year\",\n",
" values=\"No. of vessels\",\n",
" )\n",
" .fillna(0)\n",
" .reset_index()\n",
" .to_markdown(tablefmt=\"github\", index=False)\n",
")"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion notebooks/ais-analysis/fall-2024/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ The vessel-level data can be accessed via this [link](https://worldbankgroup.sha
## References

```{bibliography}
```
```
Loading

0 comments on commit a99aefc

Please sign in to comment.