Skip to content

Commit

Permalink
Merge pull request #3 from Vizzuality/data/sky30-35_coverage
Browse files Browse the repository at this point in the history
coverage calculations wdpa
  • Loading branch information
aagm authored Oct 26, 2023
2 parents 21d1aa4 + 578f453 commit 323279c
Show file tree
Hide file tree
Showing 8 changed files with 4,769 additions and 1,643 deletions.
717 changes: 0 additions & 717 deletions data/notebooks/MPAtlas_table.ipynb

This file was deleted.

2,003 changes: 2,003 additions & 0 deletions data/notebooks/habitats.ipynb

Large diffs are not rendered by default.

1,364 changes: 862 additions & 502 deletions data/notebooks/layers.ipynb

Large diffs are not rendered by default.

574 changes: 574 additions & 0 deletions data/notebooks/location_areas.ipynb

Large diffs are not rendered by default.

143 changes: 143 additions & 0 deletions data/notebooks/mpas_table.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Set up"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import geopandas as gpd\n",
"import pandas as pd\n",
"from datetime import datetime"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"path_in = \"/Users/sofia/Documents/Repos/skytruth-30x30/data/data/raw\"\n",
"path_out = \"/Users/sofia/Documents/Repos/skytruth-30x30/data/data/processed\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Read relevant datasets: MPAtlas, WDPA, and ProtectedSeas"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Read mpatlas data\n",
"mpatlas = gpd.read_file(path_out + \"/mpatlas/mpatlas_assess_zone_cleaned.geojson\")\n",
"mpatlas = mpatlas.drop_duplicates(subset=['wdpa_id', 'designation','location_id','establishment_stage', 'protection_level','year'], keep='first')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"ps = gpd.read_file(path_out + \"/protectedseas/protectedseas.shp\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"wdpa = gpd.read_file(path_out + \"/wdpa/merged_wdpa_all.shp\")\n",
"wdpa = wdpa[['WDPA_PID', 'NAME','PA_DEF', 'GIS_M_AREA','PARENT_ISO']].rename(columns={'WDPA_PID': 'wdpa_id', 'NAME': 'name', 'PA_DEF':'protection_type', 'GIS_M_AREA': 'area', 'PARENT_ISO': 'location_id'})\n",
"wdpa['protection_type'] = wdpa['protection_type'].astype(int).replace({1: 'mpa', 0: 'oecm'})"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Combine information from different tables"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# Add protected_level info from mpatlas and protectedseas to wdpa df\n",
"table_prot = wdpa.merge(mpatlas[['wdpa_id','area_km2','protection_level']], on='wdpa_id', how='left').rename(columns={'area_km2':'area_mpatlas','protection_level': 'mpatlas_prot_lvl'})\n",
"table_prot = table_prot.merge(ps[['wdpa_id','FPS_cat', 'total_area']], on='wdpa_id', how='left').rename(columns={'FPS_cat': 'fpl', 'total_area': 'area_ps'})"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"table_prot['area'] = table_prot['area_mpatlas'].combine_first(table_prot['area_ps']).combine_first(table_prot['area'])\n",
"table_prot = table_prot.drop(columns=['area_mpatlas', 'area_ps'])\n",
"table_prot = table_prot.drop(columns={'name', 'protection_type'})"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# Add establishment info to wdpa df\n",
"table_est = wdpa.merge(mpatlas[['wdpa_id','establishment_stage', 'year']], on='wdpa_id', how='left')\n",
"table_est = table_est.drop(columns={'area', 'location_id'})"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# Save tables as csv\n",
"table_prot.to_csv(path_out + \"/tables/mpas_table.csv\", index=False)\n",
"table_est.to_csv(path_out + \"/tables/mpas_table_establishment.csv\", index=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "skytruth",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 323279c

Please sign in to comment.