diff --git a/data/notebooks/MPAtlas_table.ipynb b/data/notebooks/MPAtlas_table.ipynb deleted file mode 100644 index 40a2613b..00000000 --- a/data/notebooks/MPAtlas_table.ipynb +++ /dev/null @@ -1,717 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Set up" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "import geopandas as gpd\n", - "import pandas as pd" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "path_in = \"/Users/sofia/Documents/Repos/skytruth_30x30/data/raw\"\n", - "path_out = \"/Users/sofia/Documents/Repos/skytruth_30x30/data/processed/mpatlas\"" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### MPAtlas" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "# Read data\n", - "mpatlas = gpd.read_file(path_in + \"/MPAtlas_largest100.shp\")" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['OBJECTID', 'WDPAID', 'WDPA_PID', 'NAME', 'English_De', 'PARENT_ISO',\n", - " 'ISO3', 'MPA_Marine', 'mpa_id', 'Zone_Marin', 'IUCN_Cat', 'Stage_of_E',\n", - " 'Distant_MP', 'Level_of_P', 'Most_Impac', 'Descrip_Im', 'Vertically',\n", - " 'SHAPE_Leng', 'SHAPE_Area', 'geometry'],\n", - " dtype='object')" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mpatlas.columns" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array(['Incompatible', 'Highly', 'TBD', 'Fully', 'Lightly', 'Unknown'],\n", - " dtype=object)" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mpatlas.Level_of_P.unique()" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
OBJECTIDWDPAIDWDPA_PIDNAMEEnglish_DePARENT_ISOISO3MPA_Marinempa_idZone_Marin...Stage_of_EDistant_MPLevel_of_PMost_ImpacDescrip_ImVerticallySHAPE_LengSHAPE_AreageometryP_LEVEL
01.0478053.0478053Hikurangi DeepBenthic Protection AreaNZLNZL54022.1525854022.1...ImplementedNaNIncompatibleMining, FishingBenthic protections only. Deep sea mining allo...X12.3329525.833001POLYGON ((-175.00000 -42.16661, -175.00000 -42...Less Protected / Unknown
12.0555512062.0555512062KermadecBenthic Protection AreaNZLNZL619146.05428458540.5...ImplementedNaNIncompatibleMining, FishingBenthic protections only. Deep sea mining allo...NaN25.62935242.963159POLYGON ((-174.02370 -29.22191, -174.02370 -29...Less Protected / Unknown
\n", - "

2 rows × 21 columns

\n", - "
" - ], - "text/plain": [ - " OBJECTID WDPAID WDPA_PID NAME English_De \\\n", - "0 1.0 478053.0 478053 Hikurangi Deep Benthic Protection Area \n", - "1 2.0 555512062.0 555512062 Kermadec Benthic Protection Area \n", - "\n", - " PARENT_ISO ISO3 MPA_Marine mpa_id Zone_Marin ... Stage_of_E Distant_MP \\\n", - "0 NZL NZL 54022.1 5258 54022.1 ... Implemented NaN \n", - "1 NZL NZL 619146.0 5428 458540.5 ... Implemented NaN \n", - "\n", - " Level_of_P Most_Impac \\\n", - "0 Incompatible Mining, Fishing \n", - "1 Incompatible Mining, Fishing \n", - "\n", - " Descrip_Im Vertically SHAPE_Leng \\\n", - "0 Benthic protections only. Deep sea mining allo... X 12.332952 \n", - "1 Benthic protections only. Deep sea mining allo... NaN 25.629352 \n", - "\n", - " SHAPE_Area geometry \\\n", - "0 5.833001 POLYGON ((-175.00000 -42.16661, -175.00000 -42... \n", - "1 42.963159 POLYGON ((-174.02370 -29.22191, -174.02370 -29... \n", - "\n", - " P_LEVEL \n", - "0 Less Protected / Unknown \n", - "1 Less Protected / Unknown \n", - "\n", - "[2 rows x 21 columns]" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Create new column with protection level reclassified\n", - "def map_protection_level(value):\n", - " if value in [\"Fully\", \"Highly\"]:\n", - " return \"Fully / Highly Protected\"\n", - " else:\n", - " return \"Less Protected / Unknown\"\n", - "\n", - "# Create a new column based on column1\n", - "mpatlas['P_LEVEL'] = mpatlas['Level_of_P'].apply(map_protection_level)\n", - "mpatlas.head(2)" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [], - "source": [ - "# List of dictionaries for data in Region_ISO3_PP.txt (list of regions used in the Protected Planet database)\n", - "regions_data = [\n", - " {\n", - " 'region_iso': 'AS',\n", - " 'region_name': 'Asia & Pacific',\n", - " 'country_iso_3s': [\n", - " \"AFG\", \"ASM\", \"AUS\", \"BGD\", \"BRN\", \"BTN\", \"CCK\", \"CHN\", \"COK\", \"CXR\", \"FJI\", \"FSM\", \"GUM\", \"HKG\", \"IDN\",\n", - " \"IND\", \"IOT\", \"IRN\", \"JPN\", \"KHM\", \"KIR\", \"KOR\", \"LAO\", \"LKA\", \"MAC\", \"MDV\", \"MHL\", \"MMR\", \"MNG\", \"MNP\",\n", - " \"MYS\", \"NCL\", \"NFK\", \"NIU\", \"NPL\", \"NRU\", \"NZL\", \"PAK\", \"PCN\", \"PHL\", \"PLW\", \"PNG\", \"PRK\", \"PYF\", \"SGP\",\n", - " \"SLB\", \"THA\", \"TKL\", \"TLS\", \"TON\", \"TUV\", \"TWN\", \"VNM\", \"VUT\", \"WLF\", \"WSM\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'AF',\n", - " 'region_name': 'Africa',\n", - " 'country_iso_3s': [\n", - " \"AGO\", \"BDI\", \"BEN\", \"BFA\", \"BWA\", \"CAF\", \"CIV\", \"CMR\", \"COD\", \"COG\", \"COM\", \"CPV\", \"DJI\", \"DZA\", \"EGY\",\n", - " \"ERI\", \"ESH\", \"ETH\", \"GAB\", \"GHA\", \"GIN\", \"GMB\", \"GNB\", \"GNQ\", \"KEN\", \"LBR\", \"LBY\", \"LSO\", \"MAR\", \"MDG\",\n", - " \"MLI\", \"MOZ\", \"MRT\", \"MUS\", \"MWI\", \"MYT\", \"NAM\", \"NER\", \"NGA\", \"REU\", \"RWA\", \"SDN\", \"SEN\", \"SHN\", \"SLE\",\n", - " \"SOM\", \"SSD\", \"STP\", \"SWZ\", \"SYC\", \"TCD\", \"TGO\", \"TUN\", \"TZA\", \"UGA\", \"ZAF\", \"ZMB\", \"ZWE\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'EU',\n", - " 'region_name': 'Europe',\n", - " 'country_iso_3s': [\n", - " \"ALA\", \"ALB\", \"AND\", \"ARM\", \"AUT\", \"AZE\", \"BEL\", \"BGR\", \"BIH\", \"BLR\", \"CHE\", \"CYP\", \"CZE\", \"DEU\", \"DNK\",\n", - " \"ESP\", \"EST\", \"FIN\", \"FRA\", \"FRO\", \"GBR\", \"GEO\", \"GGY\", \"GIB\", \"GRC\", \"HRV\", \"HUN\", \"IMN\", \"IRL\", \"ISL\",\n", - " \"ISR\", \"ITA\", \"JEY\", \"KAZ\", \"KGZ\", \"LIE\", \"LTU\", \"LUX\", \"LVA\", \"MCO\", \"MDA\", \"MKD\", \"MLT\", \"MNE\", \"NLD\",\n", - " \"NOR\", \"POL\", \"PRT\", \"ROU\", \"RUS\", \"SJM\", \"SMR\", \"SRB\", \"SVK\", \"SVN\", \"SWE\", \"TJK\", \"TKM\", \"TUR\", \"UKR\",\n", - " \"UZB\", \"VAT\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'SA',\n", - " 'region_name': 'Latin America & Caribbean',\n", - " 'country_iso_3s': [\n", - " \"ABW\", \"AIA\", \"ARG\", \"ATG\", \"BES\", \"BHS\", \"BLM\", \"BLZ\", \"BMU\", \"BOL\", \"BRA\", \"BRB\", \"CHL\", \"COL\", \"CRI\",\n", - " \"CUB\", \"CUW\", \"CYM\", \"DMA\", \"DOM\", \"ECU\", \"FLK\", \"GLP\", \"GRD\", \"GTM\", \"GUF\", \"GUY\", \"HND\", \"HTI\", \"JAM\",\n", - " \"KNA\", \"LCA\", \"MAF\", \"MEX\", \"MSR\", \"MTQ\", \"NIC\", \"PAN\", \"PER\", \"PRI\", \"PRY\", \"SLV\", \"SUR\", \"SXM\", \"TCA\",\n", - " \"TTO\", \"UMI\", \"URY\", \"VCT\", \"VEN\", \"VGB\", \"VIR\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'PO',\n", - " 'region_name': 'Polar',\n", - " 'country_iso_3s': [\n", - " \"ATF\", \"BVT\", \"GRL\", \"HMD\", \"SGS\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'NA',\n", - " 'region_name': 'North America',\n", - " 'country_iso_3s': [\n", - " \"CAN\", \"SPM\", \"USA\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'GL',\n", - " 'region_name': 'Global',\n", - " 'country_iso_3s': []\n", - " },\n", - " {\n", - " 'region_iso': 'WA',\n", - " 'region_name': 'West Asia',\n", - " 'country_iso_3s': [\n", - " \"ARE\", \"BHR\", \"IRQ\", \"JOR\", \"KWT\", \"LBN\", \"OMN\", \"PSE\", \"QAT\", \"SAU\", \"SYR\", \"YEM\"\n", - " ]\n", - " }\n", - "]\n", - "\n", - "# Convert the region data to a dictionary that maps each country to its region name\n", - "country_to_region = {}\n", - "for region in regions_data:\n", - " for country in region['country_iso_3s']:\n", - " country_to_region[country] = region['region_name']" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
OBJECTIDWDPAIDWDPA_PIDNAMEEnglish_DePARENT_ISOISO3MPA_Marinempa_idZone_Marin...Distant_MPLevel_of_PMost_ImpacDescrip_ImVerticallySHAPE_LengSHAPE_AreageometryP_LEVELREGIONS
01.0478053.0478053Hikurangi DeepBenthic Protection AreaNZLNZL54022.1525854022.1...NaNIncompatibleMining, FishingBenthic protections only. Deep sea mining allo...X12.3329525.833001POLYGON ((-175.00000 -42.16661, -175.00000 -42...Less Protected / UnknownAsia & Pacific
12.0555512062.0555512062KermadecBenthic Protection AreaNZLNZL619146.05428458540.5...NaNIncompatibleMining, FishingBenthic protections only. Deep sea mining allo...NaN25.62935242.963159POLYGON ((-174.02370 -29.22191, -174.02370 -29...Less Protected / UnknownAsia & Pacific
\n", - "

2 rows × 22 columns

\n", - "
" - ], - "text/plain": [ - " OBJECTID WDPAID WDPA_PID NAME English_De \\\n", - "0 1.0 478053.0 478053 Hikurangi Deep Benthic Protection Area \n", - "1 2.0 555512062.0 555512062 Kermadec Benthic Protection Area \n", - "\n", - " PARENT_ISO ISO3 MPA_Marine mpa_id Zone_Marin ... Distant_MP \\\n", - "0 NZL NZL 54022.1 5258 54022.1 ... NaN \n", - "1 NZL NZL 619146.0 5428 458540.5 ... NaN \n", - "\n", - " Level_of_P Most_Impac \\\n", - "0 Incompatible Mining, Fishing \n", - "1 Incompatible Mining, Fishing \n", - "\n", - " Descrip_Im Vertically SHAPE_Leng \\\n", - "0 Benthic protections only. Deep sea mining allo... X 12.332952 \n", - "1 Benthic protections only. Deep sea mining allo... NaN 25.629352 \n", - "\n", - " SHAPE_Area geometry \\\n", - "0 5.833001 POLYGON ((-175.00000 -42.16661, -175.00000 -42... \n", - "1 42.963159 POLYGON ((-174.02370 -29.22191, -174.02370 -29... \n", - "\n", - " P_LEVEL REGIONS \n", - "0 Less Protected / Unknown Asia & Pacific \n", - "1 Less Protected / Unknown Asia & Pacific \n", - "\n", - "[2 rows x 22 columns]" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mpatlas['REGIONS'] = mpatlas['ISO3'].map(country_to_region)\n", - "mpatlas.head(2)" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
WDPAIDWDPA_PIDNAMEAREA_MPATLASDESIG_ENGESTABLISHMENTIMPACTP_LEVELPARENT_ISOISO3REGIONSgeometry
0478053.0478053Hikurangi Deep54022.1Benthic Protection AreaImplementedMining, FishingLess Protected / UnknownNZLNZLAsia & PacificPOLYGON ((-175.00000 -42.16661, -175.00000 -42...
1555512062.0555512062Kermadec458540.5Benthic Protection AreaImplementedMining, FishingLess Protected / UnknownNZLNZLAsia & PacificPOLYGON ((-174.02370 -29.22191, -174.02370 -29...
\n", - "
" - ], - "text/plain": [ - " WDPAID WDPA_PID NAME AREA_MPATLAS \\\n", - "0 478053.0 478053 Hikurangi Deep 54022.1 \n", - "1 555512062.0 555512062 Kermadec 458540.5 \n", - "\n", - " DESIG_ENG ESTABLISHMENT IMPACT \\\n", - "0 Benthic Protection Area Implemented Mining, Fishing \n", - "1 Benthic Protection Area Implemented Mining, Fishing \n", - "\n", - " P_LEVEL PARENT_ISO ISO3 REGIONS \\\n", - "0 Less Protected / Unknown NZL NZL Asia & Pacific \n", - "1 Less Protected / Unknown NZL NZL Asia & Pacific \n", - "\n", - " geometry \n", - "0 POLYGON ((-175.00000 -42.16661, -175.00000 -42... \n", - "1 POLYGON ((-174.02370 -29.22191, -174.02370 -29... " - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Rename columns and keep only relevant ones. \n", - "# Note: We keep \"Zone_Marine\" (area of the geometry), instead of \"MPA_Marine\" (as MPAs can be divided in smaller pieces according to their protection levels)\n", - "\n", - "mpatlas = mpatlas.rename(columns={'English_De': 'DESIG_ENG', 'Zone_Marin': 'AREA_MPATLAS', 'Stage_of_E': 'ESTABLISHMENT', 'Most_Impac': 'IMPACT' }) \n", - "mpatlas2 = mpatlas[['WDPAID', 'WDPA_PID', 'NAME', 'AREA_MPATLAS', 'DESIG_ENG', 'ESTABLISHMENT', 'IMPACT', 'P_LEVEL', 'PARENT_ISO', 'ISO3','REGIONS', 'geometry']]\n", - "mpatlas2.head(2)" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/98/0pdnjc5s29x2pnzl293pw7hr0000gn/T/ipykernel_25742/67511564.py:1: UserWarning: Column names longer than 10 characters will be truncated when saved to ESRI Shapefile.\n", - " mpatlas2.to_file(path_out + \"/mpatlas_table.shp\")\n" - ] - } - ], - "source": [ - "mpatlas2.to_file(path_out + \"/mpatlas_table.shp\")" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
WDPAIDWDPA_PIDNAMEAREA_MPATLDESIG_ENGESTABLISHMIMPACTP_LEVELPARENT_ISOISO3REGIONSgeometry
0478053.0478053Hikurangi Deep54022.1Benthic Protection AreaImplementedMining, FishingLess Protected / UnknownNZLNZLAsia & PacificPOLYGON ((-175.00000 -42.16661, -175.00000 -42...
1555512062.0555512062Kermadec458540.5Benthic Protection AreaImplementedMining, FishingLess Protected / UnknownNZLNZLAsia & PacificPOLYGON ((-174.02370 -29.22191, -174.02370 -29...
\n", - "
" - ], - "text/plain": [ - " WDPAID WDPA_PID NAME AREA_MPATL \\\n", - "0 478053.0 478053 Hikurangi Deep 54022.1 \n", - "1 555512062.0 555512062 Kermadec 458540.5 \n", - "\n", - " DESIG_ENG ESTABLISHM IMPACT \\\n", - "0 Benthic Protection Area Implemented Mining, Fishing \n", - "1 Benthic Protection Area Implemented Mining, Fishing \n", - "\n", - " P_LEVEL PARENT_ISO ISO3 REGIONS \\\n", - "0 Less Protected / Unknown NZL NZL Asia & Pacific \n", - "1 Less Protected / Unknown NZL NZL Asia & Pacific \n", - "\n", - " geometry \n", - "0 POLYGON ((-175.00000 -42.16661, -175.00000 -42... \n", - "1 POLYGON ((-174.02370 -29.22191, -174.02370 -29... " - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mpatlas = gpd.read_file(path_out + \"/mpatlas_table.shp\")\n", - "mpatlas.head(2)" - ] - } - ], - "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 -} diff --git a/data/notebooks/habitats.ipynb b/data/notebooks/habitats.ipynb index 043a5ad6..1185d367 100644 --- a/data/notebooks/habitats.ipynb +++ b/data/notebooks/habitats.ipynb @@ -32,18 +32,19 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import geopandas as gpd\n", "import pandas as pd\n", - "import openpyxl" + "import openpyxl\n", + "from datetime import datetime" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -60,7 +61,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -73,7 +74,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -85,7 +86,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -98,7 +99,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -114,7 +115,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -128,7 +129,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -141,7 +142,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -154,7 +155,7 @@ }, { "cell_type": "code", - "execution_count": 198, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -189,16 +190,16 @@ " \n", " 0\n", " ABNJ\n", - " 421.629373\n", - " 1874.982214\n", + " 421.629372679904\n", + " 1874.98221422617\n", " cold-water corals\n", " 2023\n", " \n", " \n", " 1\n", " AGO\n", - " 0.000000\n", - " 3.395671\n", + " 0\n", + " 3.39567053773998\n", " cold-water corals\n", " 2023\n", " \n", @@ -207,12 +208,12 @@ "" ], "text/plain": [ - " location_id protected_area total_area habitat_name year\n", - "0 ABNJ 421.629373 1874.982214 cold-water corals 2023\n", - "1 AGO 0.000000 3.395671 cold-water corals 2023" + " location_id protected_area total_area habitat_name year\n", + "0 ABNJ 421.629372679904 1874.98221422617 cold-water corals 2023\n", + "1 AGO 0 3.39567053773998 cold-water corals 2023" ] }, - "execution_count": 198, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -220,13 +221,13 @@ "source": [ "# Concatenate the dataframes\n", "habitats = pd.concat([cold2_grouped, salt2_grouped, sea2_grouped, warm2_grouped])\n", - "habitats['year'] = 2023\n", + "habitats['year'] = datetime.now().year\n", "habitats.head(2)" ] }, { "cell_type": "code", - "execution_count": 199, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -260,33 +261,33 @@ " \n", " \n", " 0\n", - " cold-water corals\n", - " 4214.897203\n", - " 15057.016684\n", + " saltmarsh\n", + " 111638.252564\n", + " 224435.075094\n", " GLOB\n", " 2023\n", " \n", " \n", " 1\n", - " saltmarshes\n", - " 111540.045205\n", - " 217798.398466\n", + " seagrass\n", + " 74787.449960\n", + " 314001.940600\n", " GLOB\n", " 2023\n", " \n", " \n", " 2\n", - " seagrasses\n", - " 71543.667168\n", - " 295004.516919\n", + " warmwater-corals\n", + " 63259.499130\n", + " 149886.974126\n", " GLOB\n", " 2023\n", " \n", " \n", - " 3\n", - " warm-water corals\n", - " 62074.768550\n", - " 147100.573092\n", + " 4\n", + " coldwater-corals\n", + " 4400.140842\n", + " 15336.975280\n", " GLOB\n", " 2023\n", " \n", @@ -295,29 +296,30 @@ "" ], "text/plain": [ - " habitat_name protected_area total_area location_id year\n", - "0 cold-water corals 4214.897203 15057.016684 GLOB 2023\n", - "1 saltmarshes 111540.045205 217798.398466 GLOB 2023\n", - "2 seagrasses 71543.667168 295004.516919 GLOB 2023\n", - "3 warm-water corals 62074.768550 147100.573092 GLOB 2023" + " habitat_name protected_area total_area location_id year\n", + "0 saltmarsh 111638.252564 224435.075094 GLOB 2023\n", + "1 seagrass 74787.449960 314001.940600 GLOB 2023\n", + "2 warmwater-corals 63259.499130 149886.974126 GLOB 2023\n", + "4 coldwater-corals 4400.140842 15336.975280 GLOB 2023" ] }, - "execution_count": 199, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Calculate global stats for habitats\n", - "habitats_global = habitats.groupby(['habitat_name']).agg({'protected_area': 'sum', 'total_area': 'sum'}).reset_index()\n", + "habitats_global = glob[['habitat','protected_area', 'total_area']].rename(columns={'habitat': 'habitat_name'})\n", "habitats_global['location_id'] = 'GLOB'\n", - "habitats_global['year'] = 2023\n", + "habitats_global['year'] = datetime.now().year\n", + "habitats_global = habitats_global[habitats_global['habitat_name'] != 'mangroves'] # remove mangroves\n", "habitats_global" ] }, { "cell_type": "code", - "execution_count": 200, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -341,125 +343,88 @@ " \n", " \n", " \n", - " location_id\n", + " habitat_name\n", " protected_area\n", " total_area\n", - " habitat_name\n", + " location_id\n", " year\n", " \n", " \n", " \n", " \n", " 0\n", - " ABNJ\n", - " 421.629373\n", - " 1874.982214\n", - " cold-water corals\n", - " 2023\n", - " \n", - " \n", - " 1\n", - " AGO\n", - " 0.000000\n", - " 3.395671\n", - " cold-water corals\n", - " 2023\n", - " \n", - " \n", - " 2\n", - " ALB\n", - " 0.000000\n", - " 5.986479\n", - " cold-water corals\n", - " 2023\n", - " \n", - " \n", - " 3\n", - " ARG\n", - " 6.984226\n", - " 61.826344\n", - " cold-water corals\n", - " 2023\n", - " \n", - " \n", - " 4\n", - " ATG\n", - " 0.000000\n", - " 0.997747\n", - " cold-water corals\n", - " 2023\n", - " \n", - " \n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " \n", - " \n", - " 81\n", - " ZAF\n", - " 1.398813\n", - " 1.398813\n", - " warm-water corals\n", - " 2023\n", - " \n", - " \n", - " 0\n", + " saltmarshes\n", + " 111638.252564\n", + " 224435.075094\n", " GLOB\n", - " 4214.897203\n", - " 15057.016684\n", - " cold-water corals\n", " 2023\n", " \n", " \n", " 1\n", + " seagrasses\n", + " 74787.449960\n", + " 314001.940600\n", " GLOB\n", - " 111540.045205\n", - " 217798.398466\n", - " saltmarshes\n", " 2023\n", " \n", " \n", " 2\n", + " warm-water corals\n", + " 63259.499130\n", + " 149886.974126\n", " GLOB\n", - " 71543.667168\n", - " 295004.516919\n", - " seagrasses\n", " 2023\n", " \n", " \n", - " 3\n", + " 4\n", + " cold-water corals\n", + " 4400.140842\n", + " 15336.975280\n", " GLOB\n", - " 62074.768550\n", - " 147100.573092\n", - " warm-water corals\n", " 2023\n", " \n", " \n", "\n", - "

374 rows × 5 columns

\n", "" ], "text/plain": [ - " location_id protected_area total_area habitat_name year\n", - "0 ABNJ 421.629373 1874.982214 cold-water corals 2023\n", - "1 AGO 0.000000 3.395671 cold-water corals 2023\n", - "2 ALB 0.000000 5.986479 cold-water corals 2023\n", - "3 ARG 6.984226 61.826344 cold-water corals 2023\n", - "4 ATG 0.000000 0.997747 cold-water corals 2023\n", - ".. ... ... ... ... ...\n", - "81 ZAF 1.398813 1.398813 warm-water corals 2023\n", - "0 GLOB 4214.897203 15057.016684 cold-water corals 2023\n", - "1 GLOB 111540.045205 217798.398466 saltmarshes 2023\n", - "2 GLOB 71543.667168 295004.516919 seagrasses 2023\n", - "3 GLOB 62074.768550 147100.573092 warm-water corals 2023\n", - "\n", - "[374 rows x 5 columns]" + " habitat_name protected_area total_area location_id year\n", + "0 saltmarshes 111638.252564 224435.075094 GLOB 2023\n", + "1 seagrasses 74787.449960 314001.940600 GLOB 2023\n", + "2 warm-water corals 63259.499130 149886.974126 GLOB 2023\n", + "4 cold-water corals 4400.140842 15336.975280 GLOB 2023" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Change the name of the habitats to match the ones in the habitats dataframe\n", + "habitat_name_mapping = {\n", + " 'saltmarsh': 'saltmarshes',\n", + " 'seagrass': 'seagrasses',\n", + " 'warmwater-corals': 'warm-water corals',\n", + " 'coldwater-corals': 'cold-water corals'\n", + "}\n", + "habitats_global['habitat_name'] = habitats_global['habitat_name'].replace(habitat_name_mapping)\n", + "habitats_global" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array(['cold-water corals', 'saltmarshes', 'seagrasses',\n", + " 'warm-water corals'], dtype=object)" ] }, - "execution_count": 200, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -467,12 +432,12 @@ "source": [ "# Concatenate the global stats to the habitats dataframe\n", "habitats = pd.concat([habitats, habitats_global])\n", - "habitats" + "habitats['habitat_name'].unique()" ] }, { "cell_type": "code", - "execution_count": 201, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -559,7 +524,7 @@ }, { "cell_type": "code", - "execution_count": 202, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -627,96 +592,96 @@ " 4\n", " AS\n", " cold-water corals\n", - " 433.777100\n", - " 1733.448452\n", + " 263.251498\n", + " 1332.225080\n", " 2023\n", " \n", " \n", " 5\n", " AS\n", " saltmarshes\n", - " 11965.693910\n", - " 44696.365149\n", + " 11721.439539\n", + " 39229.888860\n", " 2023\n", " \n", " \n", " 6\n", " AS\n", " seagrasses\n", - " 29085.739962\n", - " 123207.628344\n", + " 28942.705660\n", + " 72666.482052\n", " 2023\n", " \n", " \n", " 7\n", " AS\n", " warm-water corals\n", - " 41327.715018\n", - " 100106.465948\n", + " 13895.870659\n", + " 67363.486609\n", " 2023\n", " \n", " \n", " 8\n", " EU\n", " cold-water corals\n", - " 2657.645874\n", - " 7253.054271\n", + " 2183.050266\n", + " 6179.526427\n", " 2023\n", " \n", " \n", " 9\n", " EU\n", " saltmarshes\n", - " 11397.003598\n", - " 18425.728461\n", + " 7431.043710\n", + " 13274.326478\n", " 2023\n", " \n", " \n", " 10\n", " EU\n", " seagrasses\n", - " 9767.760581\n", - " 16539.589632\n", + " 5840.372925\n", + " 10391.189911\n", " 2023\n", " \n", " \n", " 11\n", " EU\n", " warm-water corals\n", - " 4357.931018\n", - " 9459.623825\n", + " 0.605763\n", + " 0.793357\n", " 2023\n", " \n", " \n", " 12\n", " NA\n", " cold-water corals\n", - " 429.351859\n", - " 2384.316484\n", + " 22.960099\n", + " 204.280433\n", " 2023\n", " \n", " \n", " 13\n", " NA\n", " saltmarshes\n", - " 57209.603176\n", - " 87048.164494\n", + " 51092.644683\n", + " 68200.081930\n", " 2023\n", " \n", " \n", " 14\n", " NA\n", " seagrasses\n", - " 8800.520794\n", - " 15860.899757\n", + " 70.012791\n", + " 301.909141\n", " 2023\n", " \n", " \n", " 15\n", " NA\n", " warm-water corals\n", - " 3652.486628\n", - " 4545.057745\n", + " 0.000000\n", + " 0.000000\n", " 2023\n", " \n", " \n", @@ -788,52 +753,57 @@ "" ], "text/plain": [ - " location_id habitat_name protected_area total_area year\n", - "0 AF cold-water corals 37.761626 381.993234 2023\n", - "1 AF saltmarshes 6688.702879 19845.915000 2023\n", - "2 AF seagrasses 6319.099491 61939.484904 2023\n", - "3 AF warm-water corals 6591.340083 15216.393947 2023\n", - "4 AS cold-water corals 433.777100 1733.448452 2023\n", - "5 AS saltmarshes 11965.693910 44696.365149 2023\n", - "6 AS seagrasses 29085.739962 123207.628344 2023\n", - "7 AS warm-water corals 41327.715018 100106.465948 2023\n", - "8 EU cold-water corals 2657.645874 7253.054271 2023\n", - "9 EU saltmarshes 11397.003598 18425.728461 2023\n", - "10 EU seagrasses 9767.760581 16539.589632 2023\n", - "11 EU warm-water corals 4357.931018 9459.623825 2023\n", - "12 NA cold-water corals 429.351859 2384.316484 2023\n", - "13 NA saltmarshes 57209.603176 87048.164494 2023\n", - "14 NA seagrasses 8800.520794 15860.899757 2023\n", - "15 NA warm-water corals 3652.486628 4545.057745 2023\n", - "16 SA cold-water corals 234.731370 1416.251323 2023\n", - "17 SA saltmarshes 22969.815906 35983.392744 2023\n", - "18 SA seagrasses 16517.097667 45847.459412 2023\n", - "19 SA warm-water corals 5597.366845 12869.801231 2023\n", - "20 WA cold-water corals 0.000000 12.970705 2023\n", - "21 WA saltmarshes 1309.225736 11798.832619 2023\n", - "22 WA seagrasses 1053.448673 25273.727431 2023\n", - "23 WA warm-water corals 547.928957 4903.230395 2023" + " location_id habitat_name protected_area total_area year\n", + "0 AF cold-water corals 37.761626 381.993234 2023\n", + "1 AF saltmarshes 6688.702879 19845.915000 2023\n", + "2 AF seagrasses 6319.099491 61939.484904 2023\n", + "3 AF warm-water corals 6591.340083 15216.393947 2023\n", + "4 AS cold-water corals 263.251498 1332.225080 2023\n", + "5 AS saltmarshes 11721.439539 39229.888860 2023\n", + "6 AS seagrasses 28942.705660 72666.482052 2023\n", + "7 AS warm-water corals 13895.870659 67363.486609 2023\n", + "8 EU cold-water corals 2183.050266 6179.526427 2023\n", + "9 EU saltmarshes 7431.043710 13274.326478 2023\n", + "10 EU seagrasses 5840.372925 10391.189911 2023\n", + "11 EU warm-water corals 0.605763 0.793357 2023\n", + "12 NA cold-water corals 22.960099 204.280433 2023\n", + "13 NA saltmarshes 51092.644683 68200.081930 2023\n", + "14 NA seagrasses 70.012791 301.909141 2023\n", + "15 NA warm-water corals 0.000000 0.000000 2023\n", + "16 SA cold-water corals 234.731370 1416.251323 2023\n", + "17 SA saltmarshes 22969.815906 35983.392744 2023\n", + "18 SA seagrasses 16517.097667 45847.459412 2023\n", + "19 SA warm-water corals 5597.366845 12869.801231 2023\n", + "20 WA cold-water corals 0.000000 12.970705 2023\n", + "21 WA saltmarshes 1309.225736 11798.832619 2023\n", + "22 WA seagrasses 1053.448673 25273.727431 2023\n", + "23 WA warm-water corals 547.928957 4903.230395 2023" ] }, - "execution_count": 202, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "# Add regions field\n", "habitats_regions = habitats.copy()\n", "habitats_regions['region'] = habitats['location_id'].map(country_to_region)\n", "\n", + "# Convert fields to numeric\n", + "habitats_regions['protected_area'] = pd.to_numeric(habitats_regions['protected_area'], errors='coerce')\n", + "habitats_regions['total_area'] = pd.to_numeric(habitats_regions['total_area'], errors='coerce')\n", + "\n", "# Calculate stats for each region\n", "habitats_regions = habitats_regions.groupby(['region', 'habitat_name']).agg({'protected_area': 'sum', 'total_area': 'sum'}).reset_index()\n", - "habitats_regions['year'] = 2023\n", + "habitats_regions['year'] = datetime.now().year\n", "habitats_regions.rename(columns={'region': 'location_id'}, inplace=True)\n", "habitats_regions\n" ] }, { "cell_type": "code", - "execution_count": 204, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -843,7 +813,7 @@ }, { "cell_type": "code", - "execution_count": 205, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -868,7 +838,7 @@ " 'AF', 'AS', 'EU', 'NA', 'SA', 'WA'], dtype=object)" ] }, - "execution_count": 205, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -879,7 +849,7 @@ }, { "cell_type": "code", - "execution_count": 206, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -895,7 +865,7 @@ }, { "cell_type": "code", - "execution_count": 213, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ @@ -908,7 +878,7 @@ }, { "cell_type": "code", - "execution_count": 214, + "execution_count": 53, "metadata": {}, "outputs": [], "source": [ @@ -922,27 +892,19 @@ }, { "cell_type": "code", - "execution_count": 215, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ "# Join eez info to seamounts falling within eez polygons\n", - "seamounts_eez = gpd.sjoin(seamounts, eez_hs, how=\"left\", predicate=\"within\")" - ] - }, - { - "cell_type": "code", - "execution_count": 216, - "metadata": {}, - "outputs": [], - "source": [ + "seamounts_eez = gpd.sjoin(seamounts, eez_hs, how=\"left\", predicate=\"within\")\n", "# Drop those not associated with an eez or hs\n", "seamounts_eez = seamounts_eez.dropna(subset=['ISO_SOV1'])" ] }, { "cell_type": "code", - "execution_count": 217, + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ @@ -960,26 +922,28 @@ }, { "cell_type": "code", - "execution_count": 218, + "execution_count": 56, "metadata": {}, "outputs": [], "source": [ - "# Split the 'iso_code' values and create separate rows only for rows with multiple values\n", - "mask = seamounts_eez['iso'].str.contains(';', na=False)\n", - "split_rows = seamounts_eez[mask].copy()\n", - "split_rows['iso'] = split_rows['iso'].str.split(';')\n", - "split_rows = split_rows.explode('iso')\n", - "\n", - "# Keep rows with single values in 'iso_code'\n", - "single_value_rows = seamounts_eez[~mask]\n", - "\n", - "# Concatenate the exploded rows with the single value rows\n", - "seamounts_eez_new = pd.concat([single_value_rows, split_rows], ignore_index=True)" + "# Check which seamounts are protectec\n", + "seamounts_wdpa = gpd.sjoin(seamounts, protected_areas, how=\"left\", predicate=\"within\")\n", + "seamounts_wdpa['protection'] = \"no\" \n", + "seamounts_wdpa.loc[~seamounts_wdpa['index_right'].isna(), 'protection'] = \"yes\"\n", + "# Remove rows in which protection is \"no\"\n", + "seamounts_wdpa = seamounts_wdpa[seamounts_wdpa['protection'] != \"no\"]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Global stats" ] }, { "cell_type": "code", - "execution_count": 219, + "execution_count": 65, "metadata": {}, "outputs": [ { @@ -1003,187 +967,103 @@ " \n", " \n", " \n", - " location_id\n", - " total_area\n", " habitat_name\n", + " total_area\n", + " location_id\n", " year\n", " \n", " \n", " \n", " \n", " 0\n", - " ABNJ\n", - " 1.483098e+07\n", - " seamounts\n", - " 2011\n", - " \n", - " \n", - " 1\n", - " AGO\n", - " 9.556242e+03\n", - " seamounts\n", - " 2011\n", - " \n", - " \n", - " 2\n", - " ARG\n", - " 3.110730e+05\n", - " seamounts\n", - " 2011\n", - " \n", - " \n", - " 3\n", - " ATA\n", - " 3.551629e+05\n", - " seamounts\n", - " 2011\n", - " \n", - " \n", - " 4\n", - " ATG\n", - " 6.215895e+03\n", - " seamounts\n", - " 2011\n", - " \n", - " \n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " ...\n", - " \n", - " \n", - " 88\n", - " VNM\n", - " 4.421338e+04\n", - " seamounts\n", - " 2011\n", - " \n", - " \n", - " 89\n", - " VUT\n", - " 1.199475e+05\n", - " seamounts\n", - " 2011\n", - " \n", - " \n", - " 90\n", - " WSM\n", - " 4.117997e+04\n", - " seamounts\n", - " 2011\n", - " \n", - " \n", - " 91\n", - " YEM\n", - " 6.294974e+04\n", - " seamounts\n", - " 2011\n", - " \n", - " \n", - " 92\n", - " ZAF\n", - " 9.946306e+04\n", " seamounts\n", + " 2.690810e+07\n", + " GLOB\n", " 2011\n", " \n", " \n", "\n", - "

93 rows × 4 columns

\n", "" ], "text/plain": [ - " location_id total_area habitat_name year\n", - "0 ABNJ 1.483098e+07 seamounts 2011\n", - "1 AGO 9.556242e+03 seamounts 2011\n", - "2 ARG 3.110730e+05 seamounts 2011\n", - "3 ATA 3.551629e+05 seamounts 2011\n", - "4 ATG 6.215895e+03 seamounts 2011\n", - ".. ... ... ... ...\n", - "88 VNM 4.421338e+04 seamounts 2011\n", - "89 VUT 1.199475e+05 seamounts 2011\n", - "90 WSM 4.117997e+04 seamounts 2011\n", - "91 YEM 6.294974e+04 seamounts 2011\n", - "92 ZAF 9.946306e+04 seamounts 2011\n", - "\n", - "[93 rows x 4 columns]" + " habitat_name total_area location_id year\n", + "0 seamounts 2.690810e+07 GLOB 2011" ] }, - "execution_count": 219, + "execution_count": 65, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# Get area of seamounts per iso\n", - "seamounts_iso = seamounts_eez_new.groupby(['iso']).agg({'AREA2D': 'sum'}).reset_index()\n", - "seamounts_iso = seamounts_iso.rename(columns={'AREA2D': 'total_area', 'iso': 'location_id'})\n", - "seamounts_iso['habitat_name'] = 'seamounts'\n", - "seamounts_iso['year'] = 2011\n", - "seamounts_iso " - ] - }, - { - "cell_type": "code", - "execution_count": 220, - "metadata": {}, - "outputs": [], - "source": [ - "# Join protection info to seamounts\n", - "seamounts_wdpa = gpd.sjoin(seamounts, protected_areas, how=\"left\", predicate=\"within\")\n", - "seamounts_wdpa['protection'] = \"no\" \n", - "seamounts_wdpa.loc[~seamounts_wdpa['index_right'].isna(), 'protection'] = \"yes\"\n" - ] - }, - { - "cell_type": "code", - "execution_count": 221, - "metadata": {}, - "outputs": [], - "source": [ - "# Remove rows in which protection is \"no\"\n", - "seamounts_wdpa = seamounts_wdpa[seamounts_wdpa['protection'] != \"no\"]" + "# Calculate global area of seamounts\n", + "seamounts_eez['habitat_name'] = 'seamounts'\n", + "seamounts_global = seamounts_eez.groupby(['habitat_name']).agg({'AREA2D': 'sum'}).reset_index().rename(columns={'AREA2D': 'total_area'})\n", + "seamounts_global['location_id'] = 'GLOB'\n", + "seamounts_global['year'] = 2011\n", + "seamounts_global" ] }, { "cell_type": "code", - "execution_count": 222, + "execution_count": 66, "metadata": {}, "outputs": [ { "data": { - "text/plain": [ - "array(['CAN', 'ABNJ', 'FRA', 'JPN', 'USA', 'PRT', 'ESP', 'BHS', 'MEX',\n", - " 'DOM', 'HND', 'NLD', 'PHL', 'VEN', 'MHL', 'YEM', 'COL', 'PLW',\n", - " 'CRI', 'PAN', 'BRA', 'ECU', 'GNQ', 'KIR', 'GBR', 'IDN', 'SYC',\n", - " 'COK', 'AUS', 'COM', 'FJI', 'NIU', 'CHL', 'NZL', 'ZAF', 'ARG',\n", - " 'ITA', 'GRC', 'CUB', 'TUV', 'PER', 'SHN', 'NOR', 'MCO'],\n", - " dtype=object)" - ] - }, - "execution_count": 222, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Split the 'iso_code' values and create separate rows only for rows with multiple values\n", - "mask = seamounts_wdpa['PARENT_ISO'].str.contains(';', na=False)\n", - "split_rows = seamounts_wdpa[mask].copy()\n", - "split_rows['PARENT_ISO'] = split_rows['PARENT_ISO'].str.split(';')\n", - "split_rows = split_rows.explode('PARENT_ISO')\n", - "\n", - "# Keep rows with single values in 'iso_code'\n", - "single_value_rows = seamounts_wdpa[~mask]\n", - "\n", - "# Concatenate the exploded rows with the single value rows\n", - "seamounts_wdpa_new = pd.concat([single_value_rows, split_rows], ignore_index=True)\n", - "seamounts_wdpa_new['PARENT_ISO'].unique()" + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
habitat_nameprotected_area
0seamounts3.438552e+06
\n", + "
" + ], + "text/plain": [ + " habitat_name protected_area\n", + "0 seamounts 3.438552e+06" + ] + }, + "execution_count": 66, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Calculate global area of seamounts protected\n", + "seamounts_wdpa['habitat_name'] = 'seamounts'\n", + "seamounts_wdpa_global = seamounts_wdpa.groupby(['habitat_name']).agg({'AREA2D': 'sum'}).reset_index().rename(columns={'AREA2D': 'protected_area'})\n", + "seamounts_wdpa_global" ] }, { "cell_type": "code", - "execution_count": 223, + "execution_count": 67, "metadata": {}, "outputs": [ { @@ -1207,45 +1087,71 @@ " \n", " \n", " \n", + " habitat_name\n", + " total_area\n", " location_id\n", + " year\n", " protected_area\n", " \n", " \n", " \n", " \n", " 0\n", - " ABNJ\n", - " 226253.932283\n", - " \n", - " \n", - " 1\n", - " ARG\n", - " 38773.659962\n", + " seamounts\n", + " 2.690810e+07\n", + " GLOB\n", + " 2011\n", + " 3.438552e+06\n", " \n", " \n", "\n", "" ], "text/plain": [ - " location_id protected_area\n", - "0 ABNJ 226253.932283\n", - "1 ARG 38773.659962" + " habitat_name total_area location_id year protected_area\n", + "0 seamounts 2.690810e+07 GLOB 2011 3.438552e+06" ] }, - "execution_count": 223, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "seamounts_protected = seamounts_wdpa_new.groupby(['PARENT_ISO']).agg({'AREA2D': 'sum'}).reset_index()\n", - "seamounts_protected = seamounts_protected.rename(columns={'AREA2D': 'protected_area', 'PARENT_ISO': 'location_id'})\n", - "seamounts_protected.head(2)" + "# Bring 'protected_area' field from seamouts_wdpa_global to seamounts_global\n", + "seamounts_global = seamounts_global.merge(seamounts_wdpa_global[['habitat_name', 'protected_area']], how='left', on='habitat_name')\n", + "seamounts_global" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Country stats" ] }, { "cell_type": "code", - "execution_count": 224, + "execution_count": 68, + "metadata": {}, + "outputs": [], + "source": [ + "# Split the 'iso_code' values and create separate rows only for those with multiple values\n", + "mask = seamounts_eez['iso'].str.contains(';', na=False)\n", + "split_rows = seamounts_eez[mask].copy()\n", + "split_rows['iso'] = split_rows['iso'].str.split(';')\n", + "split_rows = split_rows.explode('iso')\n", + "\n", + "# Keep rows with single values in 'iso_code'\n", + "single_value_rows = seamounts_eez[~mask]\n", + "\n", + "# Concatenate the exploded rows with the single value rows\n", + "seamounts_eez_new = pd.concat([single_value_rows, split_rows], ignore_index=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 69, "metadata": {}, "outputs": [ { @@ -1273,7 +1179,6 @@ " total_area\n", " habitat_name\n", " year\n", - " protected_area\n", " \n", " \n", " \n", @@ -1283,7 +1188,6 @@ " 1.483098e+07\n", " seamounts\n", " 2011\n", - " 226253.932283\n", " \n", " \n", " 1\n", @@ -1291,7 +1195,6 @@ " 9.556242e+03\n", " seamounts\n", " 2011\n", - " NaN\n", " \n", " \n", " 2\n", @@ -1299,7 +1202,6 @@ " 3.110730e+05\n", " seamounts\n", " 2011\n", - " 38773.659962\n", " \n", " \n", " 3\n", @@ -1307,7 +1209,6 @@ " 3.551629e+05\n", " seamounts\n", " 2011\n", - " NaN\n", " \n", " \n", " 4\n", @@ -1315,35 +1216,107 @@ " 6.215895e+03\n", " seamounts\n", " 2011\n", - " NaN\n", + " \n", + " \n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " ...\n", + " \n", + " \n", + " 88\n", + " VNM\n", + " 4.421338e+04\n", + " seamounts\n", + " 2011\n", + " \n", + " \n", + " 89\n", + " VUT\n", + " 1.199475e+05\n", + " seamounts\n", + " 2011\n", + " \n", + " \n", + " 90\n", + " WSM\n", + " 4.117997e+04\n", + " seamounts\n", + " 2011\n", + " \n", + " \n", + " 91\n", + " YEM\n", + " 6.294974e+04\n", + " seamounts\n", + " 2011\n", + " \n", + " \n", + " 92\n", + " ZAF\n", + " 9.946306e+04\n", + " seamounts\n", + " 2011\n", " \n", " \n", "\n", + "

93 rows × 4 columns

\n", "" ], "text/plain": [ - " location_id total_area habitat_name year protected_area\n", - "0 ABNJ 1.483098e+07 seamounts 2011 226253.932283\n", - "1 AGO 9.556242e+03 seamounts 2011 NaN\n", - "2 ARG 3.110730e+05 seamounts 2011 38773.659962\n", - "3 ATA 3.551629e+05 seamounts 2011 NaN\n", - "4 ATG 6.215895e+03 seamounts 2011 NaN" + " location_id total_area habitat_name year\n", + "0 ABNJ 1.483098e+07 seamounts 2011\n", + "1 AGO 9.556242e+03 seamounts 2011\n", + "2 ARG 3.110730e+05 seamounts 2011\n", + "3 ATA 3.551629e+05 seamounts 2011\n", + "4 ATG 6.215895e+03 seamounts 2011\n", + ".. ... ... ... ...\n", + "88 VNM 4.421338e+04 seamounts 2011\n", + "89 VUT 1.199475e+05 seamounts 2011\n", + "90 WSM 4.117997e+04 seamounts 2011\n", + "91 YEM 6.294974e+04 seamounts 2011\n", + "92 ZAF 9.946306e+04 seamounts 2011\n", + "\n", + "[93 rows x 4 columns]" ] }, - "execution_count": 224, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# join 'protected area' field in seamounts_protected to seamounts_iso based on location_id\n", - "seamounts_iso2 = seamounts_iso.merge(seamounts_protected, left_on='location_id', right_on='location_id', how='left')\n", - "seamounts_iso2.head(5)" + "# Get area of seamounts per iso\n", + "seamounts_iso = seamounts_eez_new.groupby(['iso']).agg({'AREA2D': 'sum'}).reset_index()\n", + "seamounts_iso = seamounts_iso.rename(columns={'AREA2D': 'total_area', 'iso': 'location_id'})\n", + "seamounts_iso['habitat_name'] = 'seamounts'\n", + "seamounts_iso['year'] = 2011\n", + "seamounts_iso " + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [], + "source": [ + "# Split the 'iso_code' values in seamounts_wdpa and create separate rows only for those with multiple values\n", + "mask = seamounts_wdpa['PARENT_ISO'].str.contains(';', na=False)\n", + "split_rows = seamounts_wdpa[mask].copy()\n", + "split_rows['PARENT_ISO'] = split_rows['PARENT_ISO'].str.split(';')\n", + "split_rows = split_rows.explode('PARENT_ISO')\n", + "\n", + "# Keep rows with single values in 'iso_code'\n", + "single_value_rows = seamounts_wdpa[~mask]\n", + "\n", + "# Concatenate the exploded rows with the single value rows\n", + "seamounts_wdpa_new = pd.concat([single_value_rows, split_rows], ignore_index=True)" ] }, { "cell_type": "code", - "execution_count": 225, + "execution_count": 71, "metadata": {}, "outputs": [ { @@ -1368,9 +1341,6 @@ " \n", " \n", " location_id\n", - " total_area\n", - " habitat_name\n", - " year\n", " protected_area\n", " \n", " \n", @@ -1378,70 +1348,38 @@ " \n", " 0\n", " ABNJ\n", - " 1.483098e+07\n", - " seamounts\n", - " 2011\n", " 226253.932283\n", " \n", " \n", " 1\n", - " AGO\n", - " 9.556242e+03\n", - " seamounts\n", - " 2011\n", - " 0.000000\n", - " \n", - " \n", - " 2\n", " ARG\n", - " 3.110730e+05\n", - " seamounts\n", - " 2011\n", " 38773.659962\n", " \n", - " \n", - " 3\n", - " ATA\n", - " 3.551629e+05\n", - " seamounts\n", - " 2011\n", - " 0.000000\n", - " \n", - " \n", - " 4\n", - " ATG\n", - " 6.215895e+03\n", - " seamounts\n", - " 2011\n", - " 0.000000\n", - " \n", " \n", "\n", "" ], "text/plain": [ - " location_id total_area habitat_name year protected_area\n", - "0 ABNJ 1.483098e+07 seamounts 2011 226253.932283\n", - "1 AGO 9.556242e+03 seamounts 2011 0.000000\n", - "2 ARG 3.110730e+05 seamounts 2011 38773.659962\n", - "3 ATA 3.551629e+05 seamounts 2011 0.000000\n", - "4 ATG 6.215895e+03 seamounts 2011 0.000000" + " location_id protected_area\n", + "0 ABNJ 226253.932283\n", + "1 ARG 38773.659962" ] }, - "execution_count": 225, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# set to 0 the protected_area values that are NaN\n", - "seamounts_iso2['protected_area'] = seamounts_iso2['protected_area'].fillna(0)\n", - "seamounts_iso2.head(5)" + "# Calculate area protected per iso\n", + "seamounts_protected = seamounts_wdpa_new.groupby(['PARENT_ISO']).agg({'AREA2D': 'sum'}).reset_index()\n", + "seamounts_protected = seamounts_protected.rename(columns={'AREA2D': 'protected_area', 'PARENT_ISO': 'location_id'})\n", + "seamounts_protected.head(2)" ] }, { "cell_type": "code", - "execution_count": 226, + "execution_count": 73, "metadata": {}, "outputs": [ { @@ -1465,57 +1403,61 @@ " \n", " \n", " \n", - " habitat_name\n", - " protected_area\n", - " total_area\n", " location_id\n", + " total_area\n", + " habitat_name\n", " year\n", + " protected_area\n", " \n", " \n", " \n", " \n", " 0\n", + " ABNJ\n", + " 1.483098e+07\n", " seamounts\n", - " 3.186900e+06\n", - " 2.729113e+07\n", - " GLOB\n", " 2011\n", + " 226253.932283\n", + " \n", + " \n", + " 1\n", + " AGO\n", + " 9.556242e+03\n", + " seamounts\n", + " 2011\n", + " NaN\n", " \n", " \n", "\n", "" ], "text/plain": [ - " habitat_name protected_area total_area location_id year\n", - "0 seamounts 3.186900e+06 2.729113e+07 GLOB 2011" + " location_id total_area habitat_name year protected_area\n", + "0 ABNJ 1.483098e+07 seamounts 2011 226253.932283\n", + "1 AGO 9.556242e+03 seamounts 2011 NaN" ] }, - "execution_count": 226, + "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "# Calculate global stats for seamounts\n", - "seamounts_global = seamounts_iso2.groupby(['habitat_name']).agg({'protected_area': 'sum', 'total_area': 'sum'}).reset_index()\n", - "seamounts_global['location_id'] = 'GLOB'\n", - "seamounts_global['year'] = 2011\n", - "seamounts_global" + "# Join seamounts_iso and seamounts_protected\n", + "seamounts_iso = seamounts_iso.merge(seamounts_protected, how='left', on='location_id')\n", + "seamounts_iso.head(2)" ] }, { - "cell_type": "code", - "execution_count": 227, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "# Concatenate the global stats to the seamounts dataframe\n", - "seamounts_iso2 = pd.concat([seamounts_iso2, seamounts_global])" + "### Regions stats" ] }, { "cell_type": "code", - "execution_count": 228, + "execution_count": 74, "metadata": {}, "outputs": [ { @@ -1618,13 +1560,13 @@ "6 WA seamounts 2487.428050 9.384765e+04 2011" ] }, - "execution_count": 228, + "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "seamounts_regions = seamounts_iso2.copy()\n", + "seamounts_regions = seamounts_iso.copy()\n", "seamounts_regions['region'] = seamounts_regions['location_id'].map(country_to_region)\n", "\n", "# Calculate stats for each region\n", @@ -1636,52 +1578,21 @@ }, { "cell_type": "code", - "execution_count": 229, + "execution_count": 75, "metadata": {}, "outputs": [], "source": [ - "# Concatenate region stats to seamounts_iso2\n", - "seamounts_iso2 = pd.concat([seamounts_iso2, seamounts_regions])" - ] - }, - { - "cell_type": "code", - "execution_count": 230, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array(['ABNJ', 'AGO', 'ARG', 'ATA', 'ATG', 'AUS', 'BHS', 'BLZ', 'BRA',\n", - " 'BRB', 'BRN', 'CAN', 'CHL', 'CHN', 'CIV', 'COL', 'COM', 'CPV',\n", - " 'CRI', 'CUB', 'DMA', 'DNK', 'DOM', 'ECU', 'ESH', 'ESP', 'FJI',\n", - " 'FRA', 'FSM', 'GBR', 'GHA', 'GIN', 'GNB', 'GNQ', 'GRC', 'HND',\n", - " 'HTI', 'IDN', 'IND', 'ISL', 'ITA', 'JAM', 'JPN', 'KIR', 'KOR',\n", - " 'LBR', 'LBY', 'LKA', 'MAR', 'MDG', 'MDV', 'MEX', 'MHL', 'MLT',\n", - " 'MMR', 'MOZ', 'MUS', 'MYS', 'NAM', 'NIC', 'NLD', 'NOR', 'NRU',\n", - " 'NZL', 'OMN', 'PAK', 'PAN', 'PER', 'PHL', 'PLW', 'PNG', 'PRK',\n", - " 'PRT', 'RUS', 'SEN', 'SLB', 'SOM', 'STP', 'SYC', 'TON', 'TUR',\n", - " 'TUV', 'TWN', 'TZA', 'URY', 'USA', 'VCT', 'VEN', 'VNM', 'VUT',\n", - " 'WSM', 'YEM', 'ZAF', 'GLOB', 'AF', 'AS', 'AT', 'EU', 'NA', 'SA',\n", - " 'WA'], dtype=object)" - ] - }, - "execution_count": 230, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "seamounts_iso2['location_id'].unique()" + "# Concatenate region and global stats to seamounts_iso2\n", + "seamounts_all = pd.concat([seamounts_iso, seamounts_regions, seamounts_global])" ] }, { "cell_type": "code", - "execution_count": 231, + "execution_count": 77, "metadata": {}, "outputs": [], "source": [ - "seamounts_iso2.to_csv(path_out + \"habitats/seamounts.csv\", index=False)" + "seamounts_all.to_csv(path_out + \"habitats/seamounts.csv\", index=False)" ] }, { @@ -1693,7 +1604,7 @@ }, { "cell_type": "code", - "execution_count": 232, + "execution_count": 79, "metadata": {}, "outputs": [], "source": [ @@ -1702,7 +1613,7 @@ }, { "cell_type": "code", - "execution_count": 233, + "execution_count": 80, "metadata": {}, "outputs": [ { @@ -1751,7 +1662,7 @@ "0 mangroves 61287.20375 147358.990971 GLOB 2020" ] }, - "execution_count": 233, + "execution_count": 80, "metadata": {}, "output_type": "execute_result" } @@ -1766,7 +1677,7 @@ }, { "cell_type": "code", - "execution_count": 234, + "execution_count": 81, "metadata": {}, "outputs": [], "source": [ @@ -1776,7 +1687,7 @@ }, { "cell_type": "code", - "execution_count": 235, + "execution_count": 82, "metadata": {}, "outputs": [ { @@ -1870,7 +1781,7 @@ "5 WA mangroves 27.83000 173.620938 2020" ] }, - "execution_count": 235, + "execution_count": 82, "metadata": {}, "output_type": "execute_result" } @@ -1888,7 +1799,7 @@ }, { "cell_type": "code", - "execution_count": 236, + "execution_count": 83, "metadata": {}, "outputs": [], "source": [ @@ -1896,40 +1807,6 @@ "mangroves = pd.concat([mangroves, mangroves_regions])" ] }, - { - "cell_type": "code", - "execution_count": 237, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array(['ZAF', 'YEM', 'WSM', 'WLF', 'VUT', 'VNM', 'VIR', 'VGB', 'VEN',\n", - " 'VCT', 'USA', 'TZA', 'TWN', 'TUV', 'TTO', 'TON', 'TLS', 'THA',\n", - " 'TGO', 'TCA', 'SYC', 'SXM', 'SUR', 'STP', 'SOM', 'SLV', 'SLE',\n", - " 'SLB', 'SGP', 'SEN', 'SDN', 'SAU', 'QAT', 'PYF', 'PRI', 'PNG',\n", - " 'PLW', 'PHL', 'PER', 'PAN', 'PAK', 'OMN', 'NZL', 'NIC', 'NGA',\n", - " 'NCL', 'MYT', 'MYS', 'MUS', 'MTQ', 'MRT', 'MOZ', 'MMR', 'MHL',\n", - " 'MEX', 'MDV', 'MDG', 'MAF', 'LKA', 'LCA', 'LBR', 'KNA', 'KIR',\n", - " 'KHM', 'KEN', 'JPN', 'JAM', 'IRN', 'IND', 'IDN', 'HTI', 'HND',\n", - " 'GUY', 'GUM', 'GUF', 'GTM', 'GRD', 'GNQ', 'GNB', 'GMB', 'GLP',\n", - " 'GIN', 'GHA', 'GAB', 'FSM', 'FJI', 'ERI', 'EGY', 'ECU', 'DOM',\n", - " 'DMA', 'DJI', 'CYM', 'CUW', 'CUB', 'CRI', 'COM', 'COL', 'COK',\n", - " 'COG', 'COD', 'CMR', 'CIV', 'CHN', 'BRN', 'BRB', 'BRA', 'BMU',\n", - " 'BLZ', 'BHS', 'BHR', 'BGD', 'BES', 'BEN', 'AUS', 'ATG', 'ATF',\n", - " 'ASM', 'ARE', 'AIA', 'AGO', 'ABW', 'GLOB', 'AF', 'AS', 'NA', 'PO',\n", - " 'SA', 'WA'], dtype=object)" - ] - }, - "execution_count": 237, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "mangroves['location_id'].unique()" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -1939,7 +1816,7 @@ }, { "cell_type": "code", - "execution_count": 238, + "execution_count": 85, "metadata": {}, "outputs": [ { @@ -1974,40 +1851,40 @@ " \n", " 0\n", " ABNJ\n", - " 421.629373\n", - " 1874.982214\n", + " 421.629372679904\n", + " 1874.98221422617\n", " cold-water corals\n", " 2023\n", " \n", " \n", " 1\n", " AGO\n", - " 0.000000\n", - " 3.395671\n", + " 0\n", + " 3.39567053773998\n", " cold-water corals\n", " 2023\n", " \n", " \n", " 2\n", " ALB\n", - " 0.000000\n", - " 5.986479\n", + " 0\n", + " 5.98647948252716\n", " cold-water corals\n", " 2023\n", " \n", " \n", " 3\n", " ARG\n", - " 6.984226\n", - " 61.826344\n", + " 6.98422602063557\n", + " 61.8263440651753\n", " cold-water corals\n", " 2023\n", " \n", " \n", " 4\n", " ATG\n", - " 0.000000\n", - " 0.997747\n", + " 0\n", + " 0.997746538545076\n", " cold-water corals\n", " 2023\n", " \n", @@ -2022,7 +1899,7 @@ " \n", " 1\n", " AS\n", - " 21378.750000\n", + " 21378.75\n", " 74629.194446\n", " mangroves\n", " 2020\n", @@ -2030,7 +1907,7 @@ " \n", " 2\n", " NA\n", - " 2055.400000\n", + " 2055.4\n", " 2329.115505\n", " mangroves\n", " 2020\n", @@ -2038,7 +1915,7 @@ " \n", " 3\n", " PO\n", - " 6.720000\n", + " 6.72\n", " 6.723018\n", " mangroves\n", " 2020\n", @@ -2046,7 +1923,7 @@ " \n", " 4\n", " SA\n", - " 27811.533750\n", + " 27811.53375\n", " 40875.932666\n", " mangroves\n", " 2020\n", @@ -2054,7 +1931,7 @@ " \n", " 5\n", " WA\n", - " 27.830000\n", + " 27.83\n", " 173.620938\n", " mangroves\n", " 2020\n", @@ -2065,40 +1942,40 @@ "" ], "text/plain": [ - " location_id protected_area total_area habitat_name year\n", - "0 ABNJ 421.629373 1874.982214 cold-water corals 2023\n", - "1 AGO 0.000000 3.395671 cold-water corals 2023\n", - "2 ALB 0.000000 5.986479 cold-water corals 2023\n", - "3 ARG 6.984226 61.826344 cold-water corals 2023\n", - "4 ATG 0.000000 0.997747 cold-water corals 2023\n", - ".. ... ... ... ... ...\n", - "1 AS 21378.750000 74629.194446 mangroves 2020\n", - "2 NA 2055.400000 2329.115505 mangroves 2020\n", - "3 PO 6.720000 6.723018 mangroves 2020\n", - "4 SA 27811.533750 40875.932666 mangroves 2020\n", - "5 WA 27.830000 173.620938 mangroves 2020\n", + " location_id protected_area total_area habitat_name year\n", + "0 ABNJ 421.629372679904 1874.98221422617 cold-water corals 2023\n", + "1 AGO 0 3.39567053773998 cold-water corals 2023\n", + "2 ALB 0 5.98647948252716 cold-water corals 2023\n", + "3 ARG 6.98422602063557 61.8263440651753 cold-water corals 2023\n", + "4 ATG 0 0.997746538545076 cold-water corals 2023\n", + ".. ... ... ... ... ...\n", + "1 AS 21378.75 74629.194446 mangroves 2020\n", + "2 NA 2055.4 2329.115505 mangroves 2020\n", + "3 PO 6.72 6.723018 mangroves 2020\n", + "4 SA 27811.53375 40875.932666 mangroves 2020\n", + "5 WA 27.83 173.620938 mangroves 2020\n", "\n", "[628 rows x 5 columns]" ] }, - "execution_count": 238, + "execution_count": 85, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Concatenate the dataframes\n", - "habitats_all = pd.concat([habitats, seamounts_iso2, mangroves])\n", + "habitats_all = pd.concat([habitats, seamounts_all, mangroves])\n", "habitats_all" ] }, { "cell_type": "code", - "execution_count": 239, + "execution_count": 86, "metadata": {}, "outputs": [], "source": [ - "habitats_all.to_csv(path_out + \"habitats/habitats.csv\", index=False)" + "habitats_all.to_csv(path_out + \"tables/habitats2.csv\", index=False)" ] } ], diff --git a/data/notebooks/layers.ipynb b/data/notebooks/layers.ipynb index 27bbc7be..232b762e 100644 --- a/data/notebooks/layers.ipynb +++ b/data/notebooks/layers.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -1164,6 +1164,124 @@ "source": [ "marine_areas2['location_type'].unique()" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Clean WDPA dataset" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m/Users/sofia/Documents/Repos/skytruth-30x30/data/notebooks/layers.ipynb Cell 42\u001b[0m line \u001b[0;36m2\n\u001b[1;32m 1\u001b[0m \u001b[39m# Read WDPA data\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m poly1 \u001b[39m=\u001b[39m gpd\u001b[39m.\u001b[39;49mread_file(path_in \u001b[39m+\u001b[39;49m \u001b[39m\"\u001b[39;49m\u001b[39m/WDPA_WDOECM_Sep2023_Public_marine_shp/WDPA_WDOECM_Sep2023_Public_marine_shp_0/WDPA_WDOECM_Sep2023_Public_marine_shp-polygons.shp\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n\u001b[1;32m 3\u001b[0m point1 \u001b[39m=\u001b[39m gpd\u001b[39m.\u001b[39mread_file(path_in \u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m/WDPA_WDOECM_Sep2023_Public_marine_shp/WDPA_WDOECM_Sep2023_Public_marine_shp_0/WDPA_WDOECM_Sep2023_Public_marine_shp-points.shp\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m 4\u001b[0m poly2 \u001b[39m=\u001b[39m gpd\u001b[39m.\u001b[39mread_file(path_in \u001b[39m+\u001b[39m \u001b[39m\"\u001b[39m\u001b[39m/WDPA_WDOECM_Sep2023_Public_marine_shp/WDPA_WDOECM_Sep2023_Public_marine_shp_1/WDPA_WDOECM_Sep2023_Public_marine_shp-polygons.shp\u001b[39m\u001b[39m\"\u001b[39m)\n", + "File \u001b[0;32m~/mambaforge/envs/skytruth/lib/python3.11/site-packages/geopandas/io/file.py:281\u001b[0m, in \u001b[0;36m_read_file\u001b[0;34m(filename, bbox, mask, rows, engine, **kwargs)\u001b[0m\n\u001b[1;32m 278\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 279\u001b[0m path_or_bytes \u001b[39m=\u001b[39m filename\n\u001b[0;32m--> 281\u001b[0m \u001b[39mreturn\u001b[39;00m _read_file_fiona(\n\u001b[1;32m 282\u001b[0m path_or_bytes, from_bytes, bbox\u001b[39m=\u001b[39;49mbbox, mask\u001b[39m=\u001b[39;49mmask, rows\u001b[39m=\u001b[39;49mrows, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs\n\u001b[1;32m 283\u001b[0m )\n\u001b[1;32m 285\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 286\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39munknown engine \u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00mengine\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m\u001b[39m\"\u001b[39m)\n", + "File \u001b[0;32m~/mambaforge/envs/skytruth/lib/python3.11/site-packages/geopandas/io/file.py:379\u001b[0m, in \u001b[0;36m_read_file_fiona\u001b[0;34m(path_or_bytes, from_bytes, bbox, mask, rows, where, **kwargs)\u001b[0m\n\u001b[1;32m 375\u001b[0m df \u001b[39m=\u001b[39m pd\u001b[39m.\u001b[39mDataFrame(\n\u001b[1;32m 376\u001b[0m [record[\u001b[39m\"\u001b[39m\u001b[39mproperties\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39mfor\u001b[39;00m record \u001b[39min\u001b[39;00m f_filt], columns\u001b[39m=\u001b[39mcolumns\n\u001b[1;32m 377\u001b[0m )\n\u001b[1;32m 378\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m--> 379\u001b[0m df \u001b[39m=\u001b[39m GeoDataFrame\u001b[39m.\u001b[39;49mfrom_features(\n\u001b[1;32m 380\u001b[0m f_filt, crs\u001b[39m=\u001b[39;49mcrs, columns\u001b[39m=\u001b[39;49mcolumns \u001b[39m+\u001b[39;49m [\u001b[39m\"\u001b[39;49m\u001b[39mgeometry\u001b[39;49m\u001b[39m\"\u001b[39;49m]\n\u001b[1;32m 381\u001b[0m )\n\u001b[1;32m 382\u001b[0m \u001b[39mfor\u001b[39;00m k \u001b[39min\u001b[39;00m datetime_fields:\n\u001b[1;32m 383\u001b[0m as_dt \u001b[39m=\u001b[39m pd\u001b[39m.\u001b[39mto_datetime(df[k], errors\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mignore\u001b[39m\u001b[39m\"\u001b[39m)\n", + "File \u001b[0;32m~/mambaforge/envs/skytruth/lib/python3.11/site-packages/geopandas/geodataframe.py:635\u001b[0m, in \u001b[0;36mGeoDataFrame.from_features\u001b[0;34m(cls, features, crs, columns)\u001b[0m\n\u001b[1;32m 632\u001b[0m features_lst \u001b[39m=\u001b[39m features\n\u001b[1;32m 634\u001b[0m rows \u001b[39m=\u001b[39m []\n\u001b[0;32m--> 635\u001b[0m \u001b[39mfor\u001b[39;00m feature \u001b[39min\u001b[39;00m features_lst:\n\u001b[1;32m 636\u001b[0m \u001b[39m# load geometry\u001b[39;00m\n\u001b[1;32m 637\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mhasattr\u001b[39m(feature, \u001b[39m\"\u001b[39m\u001b[39m__geo_interface__\u001b[39m\u001b[39m\"\u001b[39m):\n\u001b[1;32m 638\u001b[0m feature \u001b[39m=\u001b[39m feature\u001b[39m.\u001b[39m__geo_interface__\n", + "File \u001b[0;32mfiona/ogrext.pyx:1739\u001b[0m, in \u001b[0;36mfiona.ogrext.Iterator.__next__\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/ogrext.pyx:389\u001b[0m, in \u001b[0;36mfiona.ogrext.FeatureBuilder.build\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/_geometry.pyx:193\u001b[0m, in \u001b[0;36mfiona._geometry.GeomBuilder.build_from_feature\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/_geometry.pyx:249\u001b[0m, in \u001b[0;36mfiona._geometry.GeomBuilder.build\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/_geometry.pyx:169\u001b[0m, in \u001b[0;36mfiona._geometry.GeomBuilder._buildMultiPolygon\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/_geometry.pyx:152\u001b[0m, in \u001b[0;36mfiona._geometry.GeomBuilder._buildParts\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/_geometry.pyx:243\u001b[0m, in \u001b[0;36mfiona._geometry.GeomBuilder.build\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/_geometry.pyx:157\u001b[0m, in \u001b[0;36mfiona._geometry.GeomBuilder._buildPolygon\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/_geometry.pyx:152\u001b[0m, in \u001b[0;36mfiona._geometry.GeomBuilder._buildParts\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32mfiona/_geometry.pyx:259\u001b[0m, in \u001b[0;36mfiona._geometry.GeomBuilder.build\u001b[0;34m()\u001b[0m\n", + "File \u001b[0;32m~/mambaforge/envs/skytruth/lib/python3.11/site-packages/fiona/model.py:201\u001b[0m, in \u001b[0;36mGeometry.from_dict\u001b[0;34m(cls, ob, **kwargs)\u001b[0m\n\u001b[1;32m 196\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_delegate \u001b[39m=\u001b[39m _Geometry(\n\u001b[1;32m 197\u001b[0m coordinates\u001b[39m=\u001b[39mcoordinates, \u001b[39mtype\u001b[39m\u001b[39m=\u001b[39m\u001b[39mtype\u001b[39m, geometries\u001b[39m=\u001b[39mgeometries\n\u001b[1;32m 198\u001b[0m )\n\u001b[1;32m 199\u001b[0m \u001b[39msuper\u001b[39m()\u001b[39m.\u001b[39m\u001b[39m__init__\u001b[39m(\u001b[39m*\u001b[39m\u001b[39m*\u001b[39mdata)\n\u001b[0;32m--> 201\u001b[0m \u001b[39m@classmethod\u001b[39m\n\u001b[1;32m 202\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mfrom_dict\u001b[39m(\u001b[39mcls\u001b[39m, ob\u001b[39m=\u001b[39m\u001b[39mNone\u001b[39;00m, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs):\n\u001b[1;32m 203\u001b[0m \u001b[39mif\u001b[39;00m ob \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 204\u001b[0m data \u001b[39m=\u001b[39m \u001b[39mdict\u001b[39m(\u001b[39mgetattr\u001b[39m(ob, \u001b[39m\"\u001b[39m\u001b[39m__geo_interface__\u001b[39m\u001b[39m\"\u001b[39m, ob))\n", + "\u001b[0;31mKeyboardInterrupt\u001b[0m: " + ] + } + ], + "source": [ + "# Read WDPA data\n", + "poly1 = gpd.read_file(path_in + \"/WDPA_WDOECM_Sep2023_Public_marine_shp/WDPA_WDOECM_Sep2023_Public_marine_shp_0/WDPA_WDOECM_Sep2023_Public_marine_shp-polygons.shp\")\n", + "point1 = gpd.read_file(path_in + \"/WDPA_WDOECM_Sep2023_Public_marine_shp/WDPA_WDOECM_Sep2023_Public_marine_shp_0/WDPA_WDOECM_Sep2023_Public_marine_shp-points.shp\")\n", + "poly2 = gpd.read_file(path_in + \"/WDPA_WDOECM_Sep2023_Public_marine_shp/WDPA_WDOECM_Sep2023_Public_marine_shp_1/WDPA_WDOECM_Sep2023_Public_marine_shp-polygons.shp\")\n", + "point2 = gpd.read_file(path_in + \"/WDPA_WDOECM_Sep2023_Public_marine_shp/WDPA_WDOECM_Sep2023_Public_marine_shp_1/WDPA_WDOECM_Sep2023_Public_marine_shp-points.shp\")\n", + "poly3 = gpd.read_file(path_in + \"/WDPA_WDOECM_Sep2023_Public_marine_shp/WDPA_WDOECM_Sep2023_Public_marine_shp_2/WDPA_WDOECM_Sep2023_Public_marine_shp-polygons.shp\")\n", + "point3 = gpd.read_file(path_in + \"/WDPA_WDOECM_Sep2023_Public_marine_shp/WDPA_WDOECM_Sep2023_Public_marine_shp_2/WDPA_WDOECM_Sep2023_Public_marine_shp-points.shp\")\n", + "dataframes = [poly1, point1, poly2, point2, poly3, point3]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Convert points to polygons and merge all wdpa in one dataset**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "18613" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# Calculate radius based on REP_AREA\n", + "def calculate_radius(rep_area):\n", + " return (rep_area / 3.14159265358979323846) ** 0.5\n", + "\n", + "# Iterate through the list and process the desired dataframes\n", + "for idx in [1, 3, 5]:\n", + " # Get the dataframe at the specified index\n", + " gdf = dataframes[idx]\n", + "\n", + " # Reproject in Mollweide\n", + " gdf = gdf.to_crs('ESRI:54009')\n", + "\n", + " # Transform the reported area from square kilometers to square meters\n", + " gdf['REP_AREA_m'] = gdf['REP_AREA'] * 1000000\n", + "\n", + " # Create the \"radius\" column by applying the calculate_radius function to the \"REP_AREA\" column\n", + " gdf['radius'] = gdf['REP_AREA_m'].apply(calculate_radius)\n", + "\n", + " # Create buffers around the points using the \"radius\" column\n", + " gdf_buffered = gdf.copy()\n", + " gdf_buffered['geometry'] = gdf.apply(lambda row: row.geometry.buffer(row['radius']), axis=1)\n", + "\n", + " # Reproject back to WGS84\n", + " gdf_buffered = gdf_buffered.to_crs('EPSG:4326')\n", + "\n", + " # Remove rows with invalid geometries\n", + " gdf_buffered = gdf_buffered[gdf_buffered['geometry'].is_valid]\n", + " \n", + " # Update the original dataframe with the buffered data\n", + " dataframes[idx] = gdf_buffered\n", + "\n", + "# Merge all dataframes\n", + "merged_mpa_all = pd.concat(dataframes)\n", + "len(merged_mpa_all)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Save the wdpa dataframe as a shapefile\n", + "merged_mpa_all.to_file(path_out + \"/wdpa/merged_wdpa_all.shp\")" + ] } ], "metadata": { diff --git a/data/notebooks/mpas_table.ipynb b/data/notebooks/mpas_table.ipynb new file mode 100644 index 00000000..b846ab4c --- /dev/null +++ b/data/notebooks/mpas_table.ipynb @@ -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 +} diff --git a/data/notebooks/mpatlas_stats.ipynb b/data/notebooks/mpatlas_stats.ipynb new file mode 100644 index 00000000..afdf6408 --- /dev/null +++ b/data/notebooks/mpatlas_stats.ipynb @@ -0,0 +1,349 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Set up" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "import geopandas as gpd\n", + "import pandas as pd\n", + "from datetime import datetime" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "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 and prepare data" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "# Read data from MPAtlas\n", + "mpatlas = gpd.read_file(path_in + \"/mpatlas_assess_zone.geojson\")" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [], + "source": [ + "# Fill missing wdpa_pid with the wdpa_id\n", + "mpatlas['wdpa_pid'] = mpatlas['wdpa_pid'].fillna(mpatlas['wdpa_id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "# Create new column with protection level reclassified\n", + "def map_protection_level(value):\n", + " if value in [\"full\", \"high\"]:\n", + " return \"fully or highly protected\"\n", + " else:\n", + " return \"less protected or unknown\"\n", + "\n", + "# Create a new column based on column1\n", + "mpatlas['protection_level'] = mpatlas['protection_mpaguide_level'].apply(map_protection_level)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [], + "source": [ + "# replace proposed/committed with proposed or committed\n", + "mpatlas['establishment_stage'] = mpatlas['establishment_stage'].replace(['proposed/committed'], 'proposed or committed')" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [], + "source": [ + "# Take only year from 'proposed_date', 'designated_date', 'implemented_date'\n", + "mpatlas['proposed_date'] = mpatlas['proposed_date'].str[:4].astype('Int64')\n", + "mpatlas['designated_date'] = mpatlas['designated_date'].str[:4].astype('Int64')\n", + "mpatlas['implemented_date'] = mpatlas['implemented_date'].str[:4].astype('Int64')\n", + "\n", + "# Create column 'year' with the most recent year from 'proposed_date', 'designated_date', 'implemented_date'\n", + "mpatlas['year'] = mpatlas[['proposed_date', 'designated_date', 'implemented_date']].max(axis=1)\n", + "\n", + "# Convert year to int to be able to save it later (Int64 not allowed)\n", + "mpatlas['year'].fillna(0, inplace=True)\n", + "mpatlas['year'] = mpatlas['year'].astype(int)\n", + "mpatlas['year'] = mpatlas['year'].replace(0, pd.NaT)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [], + "source": [ + "# Calculate area in km2\n", + "mpatlas.to_crs('ESRI:54009', inplace=True)\n", + "mpatlas['area_km2'] = mpatlas['geometry'].area / 10**6\n", + "mpatlas.to_crs('EPSG:4326', inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "# Keep relevant columns \n", + "mpatlas2 = mpatlas[['wdpa_pid', 'name', 'designation', 'sovereign', 'area_km2', 'establishment_stage', 'protection_level', 'year', 'geometry']].rename(columns={'sovereign': 'location_id', 'wdpa_pid': 'wdpa_id'})\n", + "\n", + "# Save as geojson (to keep full names)\n", + "mpatlas2.to_file(path_out + \"/mpatlas/mpatlas_assess_zone_cleaned.geojson\", driver='GeoJSON')" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [], + "source": [ + "# For those with multiple countries, split them\n", + "mpatlas_iso = mpatlas2.copy()\n", + "mpatlas_iso['location_id'] = mpatlas_iso['location_id'].str.split(';')\n", + "mpatlas_iso = mpatlas_iso.explode('location_id')\n", + "mpatlas_iso['location_id'] = mpatlas_iso['location_id'].str.split(':')\n", + "mpatlas_iso = mpatlas_iso.explode('location_id')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Global stats" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "# Calculate global area per protection level\n", + "prot_global = mpatlas2.groupby('protection_level').agg({'area_km2': 'sum'}).reset_index().rename(columns={'area_km2': 'area'})\n", + "prot_global['location_id'] = 'GLOB'\n", + "prot_global['last_updated'] = datetime.now().year" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [], + "source": [ + "# Calculate global area per establishment stage\n", + "stage_global = mpatlas2.groupby(['establishment_stage']).agg({'area_km2': 'sum'}).reset_index().rename(columns={'area_km2': 'area'})\n", + "stage_global['location_id'] = 'GLOB'\n", + "stage_global['last_updated'] = datetime.now().year" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Country stats" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "prot_iso = mpatlas_iso.groupby(['location_id', 'protection_level']).agg({'area_km2': 'sum'}).reset_index().rename(columns={'area_km2': 'area'})\n", + "prot_iso['last_updated'] = datetime.now().year" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [], + "source": [ + "stage_iso = mpatlas_iso.groupby(['location_id', 'establishment_stage']).agg({'area_km2': 'sum'}).reset_index().rename(columns={'area_km2': 'area'})\n", + "stage_iso['last_updated'] = datetime.now().year" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Region stats" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [], + "source": [ + "# List of dictionaries for data in Region_ISO3_PP.txt (list of regions used in the Protected Planet database)\n", + "regions_data = [\n", + " {\n", + " 'region_iso': 'AS',\n", + " 'region_name': 'Asia & Pacific',\n", + " 'country_iso_3s': [\n", + " \"AFG\", \"ASM\", \"AUS\", \"BGD\", \"BRN\", \"BTN\", \"CCK\", \"CHN\", \"COK\", \"CXR\", \"FJI\", \"FSM\", \"GUM\", \"HKG\", \"IDN\",\n", + " \"IND\", \"IOT\", \"IRN\", \"JPN\", \"KHM\", \"KIR\", \"KOR\", \"LAO\", \"LKA\", \"MAC\", \"MDV\", \"MHL\", \"MMR\", \"MNG\", \"MNP\",\n", + " \"MYS\", \"NCL\", \"NFK\", \"NIU\", \"NPL\", \"NRU\", \"NZL\", \"PAK\", \"PCN\", \"PHL\", \"PLW\", \"PNG\", \"PRK\", \"PYF\", \"SGP\",\n", + " \"SLB\", \"THA\", \"TKL\", \"TLS\", \"TON\", \"TUV\", \"TWN\", \"VNM\", \"VUT\", \"WLF\", \"WSM\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'AF',\n", + " 'region_name': 'Africa',\n", + " 'country_iso_3s': [\n", + " \"AGO\", \"BDI\", \"BEN\", \"BFA\", \"BWA\", \"CAF\", \"CIV\", \"CMR\", \"COD\", \"COG\", \"COM\", \"CPV\", \"DJI\", \"DZA\", \"EGY\",\n", + " \"ERI\", \"ESH\", \"ETH\", \"GAB\", \"GHA\", \"GIN\", \"GMB\", \"GNB\", \"GNQ\", \"KEN\", \"LBR\", \"LBY\", \"LSO\", \"MAR\", \"MDG\",\n", + " \"MLI\", \"MOZ\", \"MRT\", \"MUS\", \"MWI\", \"MYT\", \"NAM\", \"NER\", \"NGA\", \"REU\", \"RWA\", \"SDN\", \"SEN\", \"SHN\", \"SLE\",\n", + " \"SOM\", \"SSD\", \"STP\", \"SWZ\", \"SYC\", \"TCD\", \"TGO\", \"TUN\", \"TZA\", \"UGA\", \"ZAF\", \"ZMB\", \"ZWE\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'EU',\n", + " 'region_name': 'Europe',\n", + " 'country_iso_3s': [\n", + " \"ALA\", \"ALB\", \"AND\", \"ARM\", \"AUT\", \"AZE\", \"BEL\", \"BGR\", \"BIH\", \"BLR\", \"CHE\", \"CYP\", \"CZE\", \"DEU\", \"DNK\",\n", + " \"ESP\", \"EST\", \"FIN\", \"FRA\", \"FRO\", \"GBR\", \"GEO\", \"GGY\", \"GIB\", \"GRC\", \"HRV\", \"HUN\", \"IMN\", \"IRL\", \"ISL\",\n", + " \"ISR\", \"ITA\", \"JEY\", \"KAZ\", \"KGZ\", \"LIE\", \"LTU\", \"LUX\", \"LVA\", \"MCO\", \"MDA\", \"MKD\", \"MLT\", \"MNE\", \"NLD\",\n", + " \"NOR\", \"POL\", \"PRT\", \"ROU\", \"RUS\", \"SJM\", \"SMR\", \"SRB\", \"SVK\", \"SVN\", \"SWE\", \"TJK\", \"TKM\", \"TUR\", \"UKR\",\n", + " \"UZB\", \"VAT\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'SA',\n", + " 'region_name': 'Latin America & Caribbean',\n", + " 'country_iso_3s': [\n", + " \"ABW\", \"AIA\", \"ARG\", \"ATG\", \"BES\", \"BHS\", \"BLM\", \"BLZ\", \"BMU\", \"BOL\", \"BRA\", \"BRB\", \"CHL\", \"COL\", \"CRI\",\n", + " \"CUB\", \"CUW\", \"CYM\", \"DMA\", \"DOM\", \"ECU\", \"FLK\", \"GLP\", \"GRD\", \"GTM\", \"GUF\", \"GUY\", \"HND\", \"HTI\", \"JAM\",\n", + " \"KNA\", \"LCA\", \"MAF\", \"MEX\", \"MSR\", \"MTQ\", \"NIC\", \"PAN\", \"PER\", \"PRI\", \"PRY\", \"SLV\", \"SUR\", \"SXM\", \"TCA\",\n", + " \"TTO\", \"UMI\", \"URY\", \"VCT\", \"VEN\", \"VGB\", \"VIR\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'PO',\n", + " 'region_name': 'Polar',\n", + " 'country_iso_3s': [\n", + " \"ATF\", \"BVT\", \"GRL\", \"HMD\", \"SGS\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'NA',\n", + " 'region_name': 'North America',\n", + " 'country_iso_3s': [\n", + " \"CAN\", \"SPM\", \"USA\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'WA',\n", + " 'region_name': 'West Asia',\n", + " 'country_iso_3s': [\n", + " \"ARE\", \"BHR\", \"IRQ\", \"JOR\", \"KWT\", \"LBN\", \"OMN\", \"PSE\", \"QAT\", \"SAU\", \"SYR\", \"YEM\"\n", + " ]\n", + " }\n", + "]\n", + "\n", + "# Convert the region data to a dictionary that maps each country to its region name\n", + "country_to_region = {}\n", + "for region in regions_data:\n", + " for country in region['country_iso_3s']:\n", + " country_to_region[country] = region['region_iso']\n", + "\n", + "# Add region column to mpatlas_iso\n", + "mpatlas_iso['regions'] = mpatlas_iso['location_id'].map(country_to_region)" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "# Calculate area per protection level per region\n", + "prot_region = mpatlas_iso.groupby(['regions', 'protection_level']).agg({'area_km2': 'sum'}).reset_index().rename(columns={'area_km2': 'area', 'regions': 'location_id'})\n", + "prot_region['last_updated'] = datetime.now().year" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [], + "source": [ + "# Calculate area per establishment stage per region\n", + "stage_region = mpatlas_iso.groupby(['regions', 'establishment_stage']).agg({'area_km2': 'sum'}).reset_index().rename(columns={'area_km2': 'area', 'regions': 'location_id'})\n", + "stage_region['last_updated'] = datetime.now().year" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "# Concatenate all dataframes for protection stats and establishment stage stats\n", + "prot = pd.concat([prot_iso, prot_global, prot_region], ignore_index=True)\n", + "stage = pd.concat([stage_iso, stage_global, stage_region], ignore_index=True)\n", + "prot.to_csv(path_out + \"/tables/mpatlas_protection_level.csv\", index=False)\n", + "stage.to_csv(path_out + \"/tables/mpatlas_establishment_stage.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 +} diff --git a/data/notebooks/protectedseas.ipynb b/data/notebooks/protectedseas.ipynb index e5a3d879..54ae3293 100644 --- a/data/notebooks/protectedseas.ipynb +++ b/data/notebooks/protectedseas.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -19,7 +19,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -36,348 +36,63 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
SITE_IDSITE_NAMEgeometry
0AIAG1Antigua & Barbuda EEZ (0-200NM)POLYGON ((-58.87762 19.58008, -58.82167 19.502...
1AIAG10Low Bay SanctuaryPOLYGON ((-61.91090 17.57960, -61.91096 17.579...
\n", - "
" - ], - "text/plain": [ - " SITE_ID SITE_NAME \\\n", - "0 AIAG1 Antigua & Barbuda EEZ (0-200NM) \n", - "1 AIAG10 Low Bay Sanctuary \n", - "\n", - " geometry \n", - "0 POLYGON ((-58.87762 19.58008, -58.82167 19.502... \n", - "1 POLYGON ((-61.91090 17.57960, -61.91096 17.579... " - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# Import shp containing geometries\n", - "ps = gpd.read_file(path_in + \"ProtectedSeas/ProtectedSeas_ProtectedSeas_06142023_shp_ProtectedSeas_06142023_shp.shp\")\n", - "ps.head(2)" + "ps = gpd.read_file(path_in + \"ProtectedSeas/ProtectedSeas_ProtectedSeas_06142023_shp_ProtectedSeas_06142023_shp.shp\")" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Index(['site_id', 'site_name', 'url', 'country', 'state', 'managing_authority',\n", - " 'designation', 'purpose', 'restrictions', 'allowed', 'season',\n", - " 'effective_from', 'effective_to', 'report_violations', 'latest_updates',\n", - " 'protection_focus', 'species_of_concern',\n", - " 'removal_of_marine_life_is_prohibited', 'entry_prohibited',\n", - " 'speed_restricted', 'discharge_prohibited', 'diving_prohibited',\n", - " 'removal_of_historic_artifacts_prohibited', 'stopping_prohibited',\n", - " 'anchoring_prohibited', 'landing_prohibited', 'dragging_prohibited',\n", - " 'dredging_prohibited', 'industrial_or_mineral_exploration_prohibited',\n", - " 'construction_prohibited', 'drilling_prohibited',\n", - " 'overflight_or_drones_prohibited', 'tribal', 'bottom_trawl',\n", - " 'gillnetting', 'hook_n_line', 'trolling', 'nets', 'traps_n_pots',\n", - " 'spear_fishing', 'longlining', 'misc_gear', 'recreational_restrictions',\n", - " 'commercial_restrictions', 'wdpa_id', 'iucn_cat', 'year_est',\n", - " 'gov_level', 'inshore_only', 'coastline_match', 'boundary_source',\n", - " 'modification_level', 'total_area'],\n", - " dtype='object')" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# Import csv containing information\n", - "protectedseas = pd.read_csv(path_in + \"ProtectedSeas/ProtectedSeas_ProtectedSeas_06142023.csv\")\n", - "protectedseas.columns" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(21197, 53)" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "protectedseas.shape" + "protectedseas = pd.read_csv(path_in + \"ProtectedSeas/ProtectedSeas_ProtectedSeas_06142023.csv\")" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(10879, 53)" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# Keep only rows in which wdpa_id is not null and it's different than 0\n", "protectedseas = protectedseas[protectedseas['wdpa_id'].notna()]\n", - "protectedseas = protectedseas[protectedseas['wdpa_id']!= '0']\n", - "protectedseas.shape" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(10879, 56)" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Join csv with shapefile and keep only wdpa geometries\n", - "ps_gdf = ps.merge(protectedseas, how='inner', left_on='SITE_ID', right_on='site_id')\n", - "ps_gdf.shape" + "protectedseas = protectedseas[protectedseas['wdpa_id']!= '0']" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
site_idsite_namecountrywdpa_idFPStotal_areageometry
0AIAG10Low Bay SanctuaryAntigua and Barbuda5555871975.048.321285POLYGON ((-61.91090 17.57960, -61.91096 17.579...
1AIAG11Nelson's Dockyard National ParkAntigua and Barbuda5555871921.040.705369POLYGON ((-61.75807 17.03541, -61.73745 17.021...
2AIAG13Palastar Reef SanctuaryAntigua and Barbuda5555871955.022.754514POLYGON ((-61.73350 17.52440, -61.78360 17.497...
3AIAG14Palaster Reef Marine National ParkAntigua and Barbuda21.03.207554POLYGON ((-61.74275 17.51737, -61.77440 17.523...
4AIAG16Two Foot Bay SanctuaryAntigua and Barbuda5555871985.047.933200POLYGON ((-61.70064 17.66752, -61.70039 17.667...
\n", - "
" - ], - "text/plain": [ - " site_id site_name country wdpa_id \\\n", - "0 AIAG10 Low Bay Sanctuary Antigua and Barbuda 555587197 \n", - "1 AIAG11 Nelson's Dockyard National Park Antigua and Barbuda 555587192 \n", - "2 AIAG13 Palastar Reef Sanctuary Antigua and Barbuda 555587195 \n", - "3 AIAG14 Palaster Reef Marine National Park Antigua and Barbuda 2 \n", - "4 AIAG16 Two Foot Bay Sanctuary Antigua and Barbuda 555587198 \n", - "\n", - " FPS total_area geometry \n", - "0 5.0 48.321285 POLYGON ((-61.91090 17.57960, -61.91096 17.579... \n", - "1 1.0 40.705369 POLYGON ((-61.75807 17.03541, -61.73745 17.021... \n", - "2 5.0 22.754514 POLYGON ((-61.73350 17.52440, -61.78360 17.497... \n", - "3 1.0 3.207554 POLYGON ((-61.74275 17.51737, -61.77440 17.523... \n", - "4 5.0 47.933200 POLYGON ((-61.70064 17.66752, -61.70039 17.667... " - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "ps_gdf = ps_gdf[['site_id','site_name', 'country', 'wdpa_id', 'removal_of_marine_life_is_prohibited','total_area','geometry']]\n", - "ps_gdf = ps_gdf.rename(columns={'removal_of_marine_life_is_prohibited':'FPS'})\n", - "ps_gdf.head(5)" + "# Join csv with shapefile and keep only wdpa geometries\n", + "ps_gdf = ps.merge(protectedseas, how='inner', left_on='SITE_ID', right_on='site_id')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array(['Antigua and Barbuda', 'USA', 'Albania', 'Netherlands Antilles',\n", - " 'United Arab Emirates', 'Argentina', 'France', 'Australia',\n", - " 'Barbados', 'Belgium', 'Bangladesh', 'Bulgaria', 'Belize',\n", - " 'Brazil', 'Bahamas', 'British Virgin Islands', 'Canada', 'Chile',\n", - " 'Cameroon', 'Colombia', 'Comoros', 'Costa Rica', 'Cuba', 'Cyprus',\n", - " 'Germany', 'Djbouti', 'Dominica', 'Denmark', 'Dominican Republic',\n", - " 'Algeria', 'Ecuador', 'Egypt', 'Spain', 'Estonia', 'Finland',\n", - " 'France, Italy, Monaco', 'French Antilles', nan, 'Gabon',\n", - " 'United Kingdom', 'Grenada', 'Ghana', 'Gibraltar', 'Guinea',\n", - " 'The Gambia', 'Guinea Bissau', 'Greece', 'Guatemala',\n", - " 'French Guyana', 'Honduras', 'Croatia', 'Indonesia', 'Indonesia ',\n", - " 'India', 'Ireland', 'Iceland', 'Israel', 'Italy', 'Jamaica',\n", - " 'Jordan', 'Japan', 'Kenya', 'Cambodia', 'South Korea',\n", - " 'Cayman Islands', 'Lebanon', 'Liberia', 'Saint Lucia', 'Sri Lanka',\n", - " 'Lithuania', 'Latvia', 'Morocco', 'Monaco', 'Madagascar',\n", - " 'Republic of Maldives', 'Malta', 'Myanmar', 'Mozambique',\n", - " 'Mauritania', 'Malaysia', 'Namibia', 'New Caledonia', 'Niue',\n", - " 'The Netherlands', 'Netherlands', 'Norway', 'New Zealand',\n", - " 'Panama', 'British Overseas Territory - Pitcairn', 'Peru',\n", - " 'Philippines', 'Republic of Palau', 'Poland', 'Portugal', 'Qatar',\n", - " 'Russia', 'Senegal',\n", - " 'Saint Helena, Ascension and Tristan da Cunha Overseas Teritory of the United Kingdom of Great Britain and Northern Ireland',\n", - " 'Solomon Islands', 'El Salvador', 'São Tomé and Príncipe',\n", - " 'Suriname', 'Slovenia', 'Sweden', 'Seychelles',\n", - " 'Turks and Caicos Islands', 'Thailand', 'East Timor', 'Tonga',\n", - " 'Trinidad and Tobago', 'Tunisia', 'Tanzania', 'Uruguay',\n", - " 'Saint Vincent and the Grenadines', 'Vietnam', 'Yemen',\n", - " 'South Africa', 'USA; Haiti; Jamaica'], dtype=object)" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "# Save txt file with unique names for countries\n", - "countries = ps_gdf['country'].unique()\n", - "countries" + "# Keep only columns of interest\n", + "ps_gdf = ps_gdf[['site_id','site_name', 'country', 'wdpa_id', 'removal_of_marine_life_is_prohibited','total_area','geometry']]\n", + "ps_gdf = ps_gdf.rename(columns={'removal_of_marine_life_is_prohibited':'FPS'})" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ + "# ProtectedSeas only provides country names, not country codes. We need to add country codes to the dataframe\n", "country_iso_dict = {\n", " 'Antigua and Barbuda': 'ATG',\n", " 'USA': 'USA',\n", @@ -503,10 +218,11 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ + "# Add country code to the dataframe\n", "def get_parent_iso(country):\n", " return country_iso_dict.get(country, None)\n", "\n", @@ -516,27 +232,17 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 12, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(10879, 8)" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "ps_gdf.shape" + "# There is one row with no parent_iso so let's give it the corresponding country code\n", + "ps_gdf.loc[ps_gdf['parent_iso'].isna(), 'parent_iso'] = 'FRA'" ] }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -568,184 +274,110 @@ " total_area\n", " geometry\n", " parent_iso\n", + " FPS_cat\n", " \n", " \n", " \n", " \n", - " 3372\n", - " AIFRCAR91\n", - " pointe Pasquereau - pointe Saint-Vaast\n", - " NaN\n", - " 392107\n", - " 2.0\n", - " 1.642913\n", - " MULTIPOLYGON (((-61.59887 16.27728, -61.59861 ...\n", - " None\n", + " 0\n", + " AIAG10\n", + " Low Bay Sanctuary\n", + " Antigua and Barbuda\n", + " 555587197\n", + " 5.0\n", + " 48.321285\n", + " POLYGON ((-61.91090 17.57960, -61.91096 17.579...\n", + " ATG\n", + " highly\n", + " \n", + " \n", + " 1\n", + " AIAG11\n", + " Nelson's Dockyard National Park\n", + " Antigua and Barbuda\n", + " 555587192\n", + " 1.0\n", + " 40.705369\n", + " POLYGON ((-61.75807 17.03541, -61.73745 17.021...\n", + " ATG\n", + " less\n", " \n", " \n", "\n", "" ], "text/plain": [ - " site_id site_name country wdpa_id FPS \\\n", - "3372 AIFRCAR91 pointe Pasquereau - pointe Saint-Vaast NaN 392107 2.0 \n", + " site_id site_name country wdpa_id \\\n", + "0 AIAG10 Low Bay Sanctuary Antigua and Barbuda 555587197 \n", + "1 AIAG11 Nelson's Dockyard National Park Antigua and Barbuda 555587192 \n", + "\n", + " FPS total_area geometry \\\n", + "0 5.0 48.321285 POLYGON ((-61.91090 17.57960, -61.91096 17.579... \n", + "1 1.0 40.705369 POLYGON ((-61.75807 17.03541, -61.73745 17.021... \n", "\n", - " total_area geometry parent_iso \n", - "3372 1.642913 MULTIPOLYGON (((-61.59887 16.27728, -61.59861 ... None " + " parent_iso FPS_cat \n", + "0 ATG highly \n", + "1 ATG less " ] }, - "execution_count": 21, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "ps_gdf[ps_gdf['parent_iso'].isna()]" + "# Reclassify FPS values\n", + "fps_classes = {\n", + " 1: 'less',\n", + " 2: 'less',\n", + " 3: 'moderately',\n", + " 4: 'highly',\n", + " 5: 'highly'\n", + "}\n", + "\n", + "# Create a new column 'FPS_cat' based on the mapping\n", + "ps_gdf['FPS_cat'] = ps_gdf['FPS'].apply(lambda x: fps_classes.get(x, None))\n", + "ps_gdf.head(2)\n" ] }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 14, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/var/folders/98/0pdnjc5s29x2pnzl293pw7hr0000gn/T/ipykernel_2034/3237173437.py:1: SettingWithCopyWarning: \n", - "A value is trying to be set on a copy of a slice from a DataFrame\n", - "\n", - "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", - " ps_gdf['parent_iso'][ps_gdf['parent_iso'].isna()] = 'FRA'\n" - ] - } - ], + "outputs": [], "source": [ - "ps_gdf['parent_iso'][ps_gdf['parent_iso'].isna()] = 'FRA'" + "ps_gdf.to_file(path_out + \"protectedseas/protectedseas.shp\")" ] }, { - "cell_type": "code", - "execution_count": 23, + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "len(ps_gdf['country'][ps_gdf['parent_iso'].isna()])" + "### Global stats" ] }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "global_area = ps_gdf.groupby(['FPS_cat'], as_index=False)['total_area'].sum().rename(columns={'FPS_cat':'fishing_protection_level', 'total_area':'area'})\n", + "global_area['location_id'] = 'GLOB'" + ] + }, + { + "cell_type": "markdown", "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
site_idsite_namecountrywdpa_idFPStotal_areageometryparent_iso
3246AIFRA3Pelagos / Pelagos Sanctuary For The Conservati...France, Italy, Monaco3650151.087830.341648POLYGON ((8.76729 44.42728, 8.77066 44.42690, ...FRA;ITA;MCO
10598NWR184Navassa Island National Wildlife RefugeUSA; Haiti; Jamaica5556081205.01473.656765POLYGON ((-75.00384 18.20744, -75.01645 18.207...USA;HTI;JAM
\n", - "
" - ], - "text/plain": [ - " site_id site_name \\\n", - "3246 AIFRA3 Pelagos / Pelagos Sanctuary For The Conservati... \n", - "10598 NWR184 Navassa Island National Wildlife Refuge \n", - "\n", - " country wdpa_id FPS total_area \\\n", - "3246 France, Italy, Monaco 365015 1.0 87830.341648 \n", - "10598 USA; Haiti; Jamaica 555608120 5.0 1473.656765 \n", - "\n", - " geometry parent_iso \n", - "3246 POLYGON ((8.76729 44.42728, 8.77066 44.42690, ... FRA;ITA;MCO \n", - "10598 POLYGON ((-75.00384 18.20744, -75.01645 18.207... USA;HTI;JAM " - ] - }, - "execution_count": 24, - "metadata": {}, - "output_type": "execute_result" - } - ], "source": [ - "ps_gdf[ps_gdf['parent_iso'].str.contains(';')]" + "### Country stats" ] }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 17, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(10883, 8)" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# Create a mask for rows with multiple values in 'iso_code'\n", "mask = ps_gdf['parent_iso'].str.contains(';', na=False)\n", @@ -759,942 +391,130 @@ "single_value_rows = ps_gdf[~mask]\n", "\n", "# Concatenate the exploded rows with the single value rows\n", - "ps_new = pd.concat([single_value_rows, split_rows], ignore_index=True)\n", + "ps_iso = pd.concat([single_value_rows, split_rows], ignore_index=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "# List of dictionaries for data in Region_ISO3_PP.txt (list of regions used in the Protected Planet database)\n", + "regions_data = [\n", + " {\n", + " 'region_iso': 'AS',\n", + " 'region_name': 'Asia & Pacific',\n", + " 'country_iso_3s': [\n", + " \"AFG\", \"ASM\", \"AUS\", \"BGD\", \"BRN\", \"BTN\", \"CCK\", \"CHN\", \"COK\", \"CXR\", \"FJI\", \"FSM\", \"GUM\", \"HKG\", \"IDN\",\n", + " \"IND\", \"IOT\", \"IRN\", \"JPN\", \"KHM\", \"KIR\", \"KOR\", \"LAO\", \"LKA\", \"MAC\", \"MDV\", \"MHL\", \"MMR\", \"MNG\", \"MNP\",\n", + " \"MYS\", \"NCL\", \"NFK\", \"NIU\", \"NPL\", \"NRU\", \"NZL\", \"PAK\", \"PCN\", \"PHL\", \"PLW\", \"PNG\", \"PRK\", \"PYF\", \"SGP\",\n", + " \"SLB\", \"THA\", \"TKL\", \"TLS\", \"TON\", \"TUV\", \"TWN\", \"VNM\", \"VUT\", \"WLF\", \"WSM\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'AF',\n", + " 'region_name': 'Africa',\n", + " 'country_iso_3s': [\n", + " \"AGO\", \"BDI\", \"BEN\", \"BFA\", \"BWA\", \"CAF\", \"CIV\", \"CMR\", \"COD\", \"COG\", \"COM\", \"CPV\", \"DJI\", \"DZA\", \"EGY\",\n", + " \"ERI\", \"ESH\", \"ETH\", \"GAB\", \"GHA\", \"GIN\", \"GMB\", \"GNB\", \"GNQ\", \"KEN\", \"LBR\", \"LBY\", \"LSO\", \"MAR\", \"MDG\",\n", + " \"MLI\", \"MOZ\", \"MRT\", \"MUS\", \"MWI\", \"MYT\", \"NAM\", \"NER\", \"NGA\", \"REU\", \"RWA\", \"SDN\", \"SEN\", \"SHN\", \"SLE\",\n", + " \"SOM\", \"SSD\", \"STP\", \"SWZ\", \"SYC\", \"TCD\", \"TGO\", \"TUN\", \"TZA\", \"UGA\", \"ZAF\", \"ZMB\", \"ZWE\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'EU',\n", + " 'region_name': 'Europe',\n", + " 'country_iso_3s': [\n", + " \"ALA\", \"ALB\", \"AND\", \"ARM\", \"AUT\", \"AZE\", \"BEL\", \"BGR\", \"BIH\", \"BLR\", \"CHE\", \"CYP\", \"CZE\", \"DEU\", \"DNK\",\n", + " \"ESP\", \"EST\", \"FIN\", \"FRA\", \"FRO\", \"GBR\", \"GEO\", \"GGY\", \"GIB\", \"GRC\", \"HRV\", \"HUN\", \"IMN\", \"IRL\", \"ISL\",\n", + " \"ISR\", \"ITA\", \"JEY\", \"KAZ\", \"KGZ\", \"LIE\", \"LTU\", \"LUX\", \"LVA\", \"MCO\", \"MDA\", \"MKD\", \"MLT\", \"MNE\", \"NLD\",\n", + " \"NOR\", \"POL\", \"PRT\", \"ROU\", \"RUS\", \"SJM\", \"SMR\", \"SRB\", \"SVK\", \"SVN\", \"SWE\", \"TJK\", \"TKM\", \"TUR\", \"UKR\",\n", + " \"UZB\", \"VAT\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'SA',\n", + " 'region_name': 'Latin America & Caribbean',\n", + " 'country_iso_3s': [\n", + " \"ABW\", \"AIA\", \"ARG\", \"ATG\", \"BES\", \"BHS\", \"BLM\", \"BLZ\", \"BMU\", \"BOL\", \"BRA\", \"BRB\", \"CHL\", \"COL\", \"CRI\",\n", + " \"CUB\", \"CUW\", \"CYM\", \"DMA\", \"DOM\", \"ECU\", \"FLK\", \"GLP\", \"GRD\", \"GTM\", \"GUF\", \"GUY\", \"HND\", \"HTI\", \"JAM\",\n", + " \"KNA\", \"LCA\", \"MAF\", \"MEX\", \"MSR\", \"MTQ\", \"NIC\", \"PAN\", \"PER\", \"PRI\", \"PRY\", \"SLV\", \"SUR\", \"SXM\", \"TCA\",\n", + " \"TTO\", \"UMI\", \"URY\", \"VCT\", \"VEN\", \"VGB\", \"VIR\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'PO',\n", + " 'region_name': 'Polar',\n", + " 'country_iso_3s': [\n", + " \"ATF\", \"BVT\", \"GRL\", \"HMD\", \"SGS\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'NA',\n", + " 'region_name': 'North America',\n", + " 'country_iso_3s': [\n", + " \"CAN\", \"SPM\", \"USA\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'WA',\n", + " 'region_name': 'West Asia',\n", + " 'country_iso_3s': [\n", + " \"ARE\", \"BHR\", \"IRQ\", \"JOR\", \"KWT\", \"LBN\", \"OMN\", \"PSE\", \"QAT\", \"SAU\", \"SYR\", \"YEM\"\n", + " ]\n", + " },\n", + " {\n", + " 'region_iso': 'AT', # this region is not in the Protected Planet database\n", + " 'region_name': 'Antartica',\n", + " 'country_iso_3s': [\n", + " \"ATA\"\n", + " ]\n", + " }\n", + "]\n", + "\n", + "# Convert the region data to a dictionary that maps each country to its region name\n", + "country_to_region = {}\n", + "for region in regions_data:\n", + " for country in region['country_iso_3s']:\n", + " country_to_region[country] = region['region_iso']\n", "\n", - "ps_new.shape" + "# Create a new column 'region' based on the mapping\n", + "ps_iso['region'] = ps_iso['parent_iso'].map(country_to_region)" ] }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 20, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
site_idsite_namecountrywdpa_idFPStotal_areageometryparent_iso
\n", - "
" - ], - "text/plain": [ - "Empty GeoDataFrame\n", - "Columns: [site_id, site_name, country, wdpa_id, FPS, total_area, geometry, parent_iso]\n", - "Index: []" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "ps_new[ps_new['parent_iso'].str.contains(';')]" + "country_area = ps_iso.groupby(['parent_iso', 'FPS_cat'], as_index=False)['total_area'].sum()\n", + "country_area = country_area.rename(columns={'parent_iso':'location_id', 'FPS_cat':'fishing_protection_level', 'total_area':'area'})" ] }, { "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
site_idsite_namecountrywdpa_idFPStotal_areageometryparent_iso
10880NWR184Navassa Island National Wildlife RefugeUSA; Haiti; Jamaica5556081205.01473.656765POLYGON ((-75.00384 18.20744, -75.01645 18.207...USA
10881NWR184Navassa Island National Wildlife RefugeUSA; Haiti; Jamaica5556081205.01473.656765POLYGON ((-75.00384 18.20744, -75.01645 18.207...HTI
10882NWR184Navassa Island National Wildlife RefugeUSA; Haiti; Jamaica5556081205.01473.656765POLYGON ((-75.00384 18.20744, -75.01645 18.207...JAM
\n", - "
" - ], - "text/plain": [ - " site_id site_name country \\\n", - "10880 NWR184 Navassa Island National Wildlife Refuge USA; Haiti; Jamaica \n", - "10881 NWR184 Navassa Island National Wildlife Refuge USA; Haiti; Jamaica \n", - "10882 NWR184 Navassa Island National Wildlife Refuge USA; Haiti; Jamaica \n", - "\n", - " wdpa_id FPS total_area \\\n", - "10880 555608120 5.0 1473.656765 \n", - "10881 555608120 5.0 1473.656765 \n", - "10882 555608120 5.0 1473.656765 \n", - "\n", - " geometry parent_iso \n", - "10880 POLYGON ((-75.00384 18.20744, -75.01645 18.207... USA \n", - "10881 POLYGON ((-75.00384 18.20744, -75.01645 18.207... HTI \n", - "10882 POLYGON ((-75.00384 18.20744, -75.01645 18.207... JAM " - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ps_new[ps_new['country']=='USA; Haiti; Jamaica']" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
site_idsite_namecountrywdpa_idFPStotal_areageometryparent_isoFPS_cat
0AIAG10Low Bay SanctuaryAntigua and Barbuda5555871975.048.321285POLYGON ((-61.91090 17.57960, -61.91096 17.579...ATGHighly
1AIAG11Nelson's Dockyard National ParkAntigua and Barbuda5555871921.040.705369POLYGON ((-61.75807 17.03541, -61.73745 17.021...ATGLess
\n", - "
" - ], - "text/plain": [ - " site_id site_name country wdpa_id \\\n", - "0 AIAG10 Low Bay Sanctuary Antigua and Barbuda 555587197 \n", - "1 AIAG11 Nelson's Dockyard National Park Antigua and Barbuda 555587192 \n", - "\n", - " FPS total_area geometry \\\n", - "0 5.0 48.321285 POLYGON ((-61.91090 17.57960, -61.91096 17.579... \n", - "1 1.0 40.705369 POLYGON ((-61.75807 17.03541, -61.73745 17.021... \n", - "\n", - " parent_iso FPS_cat \n", - "0 ATG Highly \n", - "1 ATG Less " - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Reclassify FPS values\n", - "fps_classes = {\n", - " 1: 'Less',\n", - " 2: 'Less',\n", - " 3: 'Moderately',\n", - " 4: 'Highly',\n", - " 5: 'Highly'\n", - "}\n", - "\n", - "# Create a new column 'FPS_cat' based on the mapping\n", - "ps_new['FPS_cat'] = ps_new['FPS'].apply(lambda x: fps_classes.get(x, None))\n", - "ps_new.head(2)\n" - ] - }, - { - "cell_type": "code", - "execution_count": 29, - "metadata": {}, - "outputs": [], - "source": [ - "# List of dictionaries for data in Region_ISO3_PP.txt (list of regions used in the Protected Planet database)\n", - "regions_data = [\n", - " {\n", - " 'region_iso': 'AS',\n", - " 'region_name': 'Asia & Pacific',\n", - " 'country_iso_3s': [\n", - " \"AFG\", \"ASM\", \"AUS\", \"BGD\", \"BRN\", \"BTN\", \"CCK\", \"CHN\", \"COK\", \"CXR\", \"FJI\", \"FSM\", \"GUM\", \"HKG\", \"IDN\",\n", - " \"IND\", \"IOT\", \"IRN\", \"JPN\", \"KHM\", \"KIR\", \"KOR\", \"LAO\", \"LKA\", \"MAC\", \"MDV\", \"MHL\", \"MMR\", \"MNG\", \"MNP\",\n", - " \"MYS\", \"NCL\", \"NFK\", \"NIU\", \"NPL\", \"NRU\", \"NZL\", \"PAK\", \"PCN\", \"PHL\", \"PLW\", \"PNG\", \"PRK\", \"PYF\", \"SGP\",\n", - " \"SLB\", \"THA\", \"TKL\", \"TLS\", \"TON\", \"TUV\", \"TWN\", \"VNM\", \"VUT\", \"WLF\", \"WSM\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'AF',\n", - " 'region_name': 'Africa',\n", - " 'country_iso_3s': [\n", - " \"AGO\", \"BDI\", \"BEN\", \"BFA\", \"BWA\", \"CAF\", \"CIV\", \"CMR\", \"COD\", \"COG\", \"COM\", \"CPV\", \"DJI\", \"DZA\", \"EGY\",\n", - " \"ERI\", \"ESH\", \"ETH\", \"GAB\", \"GHA\", \"GIN\", \"GMB\", \"GNB\", \"GNQ\", \"KEN\", \"LBR\", \"LBY\", \"LSO\", \"MAR\", \"MDG\",\n", - " \"MLI\", \"MOZ\", \"MRT\", \"MUS\", \"MWI\", \"MYT\", \"NAM\", \"NER\", \"NGA\", \"REU\", \"RWA\", \"SDN\", \"SEN\", \"SHN\", \"SLE\",\n", - " \"SOM\", \"SSD\", \"STP\", \"SWZ\", \"SYC\", \"TCD\", \"TGO\", \"TUN\", \"TZA\", \"UGA\", \"ZAF\", \"ZMB\", \"ZWE\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'EU',\n", - " 'region_name': 'Europe',\n", - " 'country_iso_3s': [\n", - " \"ALA\", \"ALB\", \"AND\", \"ARM\", \"AUT\", \"AZE\", \"BEL\", \"BGR\", \"BIH\", \"BLR\", \"CHE\", \"CYP\", \"CZE\", \"DEU\", \"DNK\",\n", - " \"ESP\", \"EST\", \"FIN\", \"FRA\", \"FRO\", \"GBR\", \"GEO\", \"GGY\", \"GIB\", \"GRC\", \"HRV\", \"HUN\", \"IMN\", \"IRL\", \"ISL\",\n", - " \"ISR\", \"ITA\", \"JEY\", \"KAZ\", \"KGZ\", \"LIE\", \"LTU\", \"LUX\", \"LVA\", \"MCO\", \"MDA\", \"MKD\", \"MLT\", \"MNE\", \"NLD\",\n", - " \"NOR\", \"POL\", \"PRT\", \"ROU\", \"RUS\", \"SJM\", \"SMR\", \"SRB\", \"SVK\", \"SVN\", \"SWE\", \"TJK\", \"TKM\", \"TUR\", \"UKR\",\n", - " \"UZB\", \"VAT\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'SA',\n", - " 'region_name': 'Latin America & Caribbean',\n", - " 'country_iso_3s': [\n", - " \"ABW\", \"AIA\", \"ARG\", \"ATG\", \"BES\", \"BHS\", \"BLM\", \"BLZ\", \"BMU\", \"BOL\", \"BRA\", \"BRB\", \"CHL\", \"COL\", \"CRI\",\n", - " \"CUB\", \"CUW\", \"CYM\", \"DMA\", \"DOM\", \"ECU\", \"FLK\", \"GLP\", \"GRD\", \"GTM\", \"GUF\", \"GUY\", \"HND\", \"HTI\", \"JAM\",\n", - " \"KNA\", \"LCA\", \"MAF\", \"MEX\", \"MSR\", \"MTQ\", \"NIC\", \"PAN\", \"PER\", \"PRI\", \"PRY\", \"SLV\", \"SUR\", \"SXM\", \"TCA\",\n", - " \"TTO\", \"UMI\", \"URY\", \"VCT\", \"VEN\", \"VGB\", \"VIR\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'PO',\n", - " 'region_name': 'Polar',\n", - " 'country_iso_3s': [\n", - " \"ATF\", \"BVT\", \"GRL\", \"HMD\", \"SGS\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'NA',\n", - " 'region_name': 'North America',\n", - " 'country_iso_3s': [\n", - " \"CAN\", \"SPM\", \"USA\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'GL',\n", - " 'region_name': 'Global',\n", - " 'country_iso_3s': ['GLOB']\n", - " },\n", - " {\n", - " 'region_iso': 'WA',\n", - " 'region_name': 'West Asia',\n", - " 'country_iso_3s': [\n", - " \"ARE\", \"BHR\", \"IRQ\", \"JOR\", \"KWT\", \"LBN\", \"OMN\", \"PSE\", \"QAT\", \"SAU\", \"SYR\", \"YEM\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'AT', # this region is not in the Protected Planet database\n", - " 'region_name': 'Antartica',\n", - " 'country_iso_3s': [\n", - " \"ATA\"\n", - " ]\n", - " },\n", - " {\n", - " 'region_iso': 'ABNJ', # this region is not in the Protected Planet database\n", - " 'region_name': 'Areas Beyond National Jurisdiction',\n", - " 'country_iso_3s': [\n", - " \"ABNJ\"\n", - " ]\n", - " }\n", - "]\n", - "\n", - "# Convert the region data to a dictionary that maps each country to its region name\n", - "country_to_region = {}\n", - "for region in regions_data:\n", - " for country in region['country_iso_3s']:\n", - " country_to_region[country] = region['region_iso']" - ] - }, - { - "cell_type": "code", - "execution_count": 30, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(10883, 10)" - ] - }, - "execution_count": 30, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ps_new['region'] = ps_new['parent_iso'].map(country_to_region)\n", - "ps_new.shape" - ] - }, - { - "cell_type": "code", - "execution_count": 31, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
site_idsite_namecountrywdpa_idFPStotal_areageometryparent_isoFPS_catregion
0AIAG10Low Bay SanctuaryAntigua and Barbuda5555871975.048.321285POLYGON ((-61.91090 17.57960, -61.91096 17.579...ATGHighlySA
1AIAG11Nelson's Dockyard National ParkAntigua and Barbuda5555871921.040.705369POLYGON ((-61.75807 17.03541, -61.73745 17.021...ATGLessSA
\n", - "
" - ], - "text/plain": [ - " site_id site_name country wdpa_id \\\n", - "0 AIAG10 Low Bay Sanctuary Antigua and Barbuda 555587197 \n", - "1 AIAG11 Nelson's Dockyard National Park Antigua and Barbuda 555587192 \n", - "\n", - " FPS total_area geometry \\\n", - "0 5.0 48.321285 POLYGON ((-61.91090 17.57960, -61.91096 17.579... \n", - "1 1.0 40.705369 POLYGON ((-61.75807 17.03541, -61.73745 17.021... \n", - "\n", - " parent_iso FPS_cat region \n", - "0 ATG Highly SA \n", - "1 ATG Less SA " - ] - }, - "execution_count": 31, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ps_new.head(2)" - ] - }, - { - "cell_type": "code", - "execution_count": 32, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ - "ps_new.to_file(path_out + \"protectedseas/protectedseas.shp\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Calculate coverage" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
location_idfishing_protection_levelarea
0ALBLess197.296039
1ALBModerately344.028483
2AREHighly6962.497530
3ARGHighly5958.615237
4ARGLess38419.623899
5ARGModerately7546.694893
6ATGHighly168.263212
7ATGLess45.247978
8ATGModerately21.163152
9AUSHighly723824.463100
\n", - "
" - ], - "text/plain": [ - " location_id fishing_protection_level area\n", - "0 ALB Less 197.296039\n", - "1 ALB Moderately 344.028483\n", - "2 ARE Highly 6962.497530\n", - "3 ARG Highly 5958.615237\n", - "4 ARG Less 38419.623899\n", - "5 ARG Moderately 7546.694893\n", - "6 ATG Highly 168.263212\n", - "7 ATG Less 45.247978\n", - "8 ATG Moderately 21.163152\n", - "9 AUS Highly 723824.463100" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ps_country = ps_new.groupby(['parent_iso', 'FPS_cat'], as_index=False)['total_area'].sum()\n", - "ps_country = ps_country.rename(columns={'parent_iso':'location_id', 'FPS_cat':'fishing_protection_level', 'total_area':'area'})\n", - "ps_country.head(10)" - ] - }, - { - "cell_type": "code", - "execution_count": 34, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
location_idfishing_protection_levelarea
0AFHighly3.518155e+04
1AFLess2.862643e+05
2AFModerately4.253144e+04
3ASHighly8.846479e+05
4ASLess1.659106e+06
5ASModerately2.825264e+05
6EUHighly2.679297e+06
7EULess3.761438e+06
8EUModerately1.884751e+06
9NAHighly3.961031e+06
\n", - "
" - ], - "text/plain": [ - " location_id fishing_protection_level area\n", - "0 AF Highly 3.518155e+04\n", - "1 AF Less 2.862643e+05\n", - "2 AF Moderately 4.253144e+04\n", - "3 AS Highly 8.846479e+05\n", - "4 AS Less 1.659106e+06\n", - "5 AS Moderately 2.825264e+05\n", - "6 EU Highly 2.679297e+06\n", - "7 EU Less 3.761438e+06\n", - "8 EU Moderately 1.884751e+06\n", - "9 NA Highly 3.961031e+06" - ] - }, - "execution_count": 34, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ps_region = ps_new.groupby(['region', 'FPS_cat'], as_index=False)['total_area'].sum()\n", - "ps_region = ps_region.rename(columns={'region':'location_id', 'FPS_cat':'fishing_protection_level', 'total_area':'area'})\n", - "ps_region.head(10)" - ] - }, - { - "cell_type": "code", - "execution_count": 35, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
fishing_protection_levelarealocation_id
0Highly8.180599e+06GLOB
1Less9.942402e+06GLOB
2Moderately3.177137e+06GLOB
\n", - "
" - ], - "text/plain": [ - " fishing_protection_level area location_id\n", - "0 Highly 8.180599e+06 GLOB\n", - "1 Less 9.942402e+06 GLOB\n", - "2 Moderately 3.177137e+06 GLOB" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ps_global = ps_new.groupby(['FPS_cat'], as_index=False)['total_area'].sum()\n", - "ps_global['location_id'] = 'GLOB'\n", - "ps_global = ps_global.rename(columns={'FPS_cat':'fishing_protection_level', 'total_area':'area'})\n", - "ps_global" + "region_area = ps_iso.groupby(['region', 'FPS_cat'], as_index=False)['total_area'].sum()\n", + "region_area = region_area.rename(columns={'region':'location_id', 'FPS_cat':'fishing_protection_level', 'total_area':'area'})" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 22, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
location_idfishing_protection_levelarea
0ALBLess1.972960e+02
1ALBModerately3.440285e+02
2AREHighly6.962498e+03
3ARGHighly5.958615e+03
4ARGLess3.841962e+04
............
216WAHighly1.024296e+04
217WALess2.129971e+04
218GLOBHighly8.180599e+06
219GLOBLess9.942402e+06
220GLOBModerately3.177137e+06
\n", - "

221 rows × 3 columns

\n", - "
" - ], - "text/plain": [ - " location_id fishing_protection_level area\n", - "0 ALB Less 1.972960e+02\n", - "1 ALB Moderately 3.440285e+02\n", - "2 ARE Highly 6.962498e+03\n", - "3 ARG Highly 5.958615e+03\n", - "4 ARG Less 3.841962e+04\n", - ".. ... ... ...\n", - "216 WA Highly 1.024296e+04\n", - "217 WA Less 2.129971e+04\n", - "218 GLOB Highly 8.180599e+06\n", - "219 GLOB Less 9.942402e+06\n", - "220 GLOB Moderately 3.177137e+06\n", - "\n", - "[221 rows x 3 columns]" - ] - }, - "execution_count": 36, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "ps_coverage = pd.concat([ps_country, ps_region, ps_global], ignore_index=True)\n", - "ps_coverage" + "ps_coverage = pd.concat([country_area, region_area, global_area], ignore_index=True)" ] }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ diff --git a/data/notebooks/wdpa_coverage.ipynb b/data/notebooks/wdpa_coverage.ipynb index 462aec59..921a2d53 100644 --- a/data/notebooks/wdpa_coverage.ipynb +++ b/data/notebooks/wdpa_coverage.ipynb @@ -57,7 +57,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -71,9 +71,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6033\n", + "172\n", + "6033\n", + "172\n", + "6033\n", + "171\n" + ] + } + ], "source": [ "print(len(poly1))\n", "print(len(point1))\n", @@ -95,7 +108,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -114,15 +127,27 @@ " df = df[(df['REP_AREA'] != 0)]\n", " \n", " # Update the original dataframes in the list\n", - " dataframes[i] = df\n", - "\n" + " dataframes[i] = df" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5999\n", + "157\n", + "6018\n", + "123\n", + "6014\n", + "135\n" + ] + } + ], "source": [ "print(len(dataframes[0]))\n", "print(len(dataframes[1]))\n", @@ -141,7 +166,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -181,14 +206,22 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 4. Merge the 6 datasets (polygons and buffered points) in a single layer and segregate those that are \"Proposed\" and those that are OECM" + "### 4. Merge the 6 datasets (polygons and buffered points) in a single layer and segregate those that are \"Proposed\"" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "All gdf have the same crs: EPSG:4326\n" + ] + } + ], "source": [ "# Check that all of them have the same crs\n", "first_crs = dataframes[0].crs\n", @@ -199,6 +232,28 @@ " print(\"gdf have different crs\")" ] }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "18445" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Merge dataframes\n", + "merged_mpa = pd.concat(dataframes)\n", + "len(merged_mpa)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -211,7 +266,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -503,12 +558,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**Countries per PARENT_ISO**" + "### Global and country stats" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -518,315 +573,55 @@ "# Create an empty list to store the results\n", "results_list = []\n", "\n", + "# Create a DataFrame to store the global coverage\n", + "global_coverage = pd.DataFrame(columns=['year', 'protection_type', 'location_id', 'cumsum_area'])\n", + "\n", "for year in years_range:\n", " filename = f'protected_dissolved_{year}.shp'\n", " file_path = os.path.join(folder_path, filename)\n", - " \n", + "\n", " if os.path.exists(file_path):\n", " gdf = gpd.read_file(file_path)\n", - " \n", + "\n", + " # Calculate global coverage for each year and protection type\n", + " global_area = gdf['AREA'].sum()\n", + " global_row = pd.DataFrame({'year': [year], 'protection_type': ['MPA+OECM'], 'location_id': ['GLOB'], 'cumsum_area': [global_area]})\n", + " global_coverage = pd.concat([global_coverage, global_row], ignore_index=True)\n", + "\n", " # Split rows with multiple ISO codes into separate rows\n", " processed_df = gdf.copy()\n", " processed_df['PARENT_ISO'] = processed_df['PARENT_ISO'].str.split(';')\n", " processed_df = processed_df.explode('PARENT_ISO')\n", - " \n", + "\n", " # Group by 'PARENT_ISO' and aggregate area\n", - " grouped = processed_df.groupby('PARENT_ISO')['AREA'].sum().reset_index()\n", - " \n", + " iso_area = processed_df.groupby('PARENT_ISO')['AREA'].sum().reset_index()\n", + "\n", " # Create columns to match BE table\n", - " grouped['year'] = year\n", - " grouped['protection_type'] = 'MPA+OECM'\n", - " grouped.rename(columns={'PARENT_ISO': 'location_id', 'AREA': 'cumsum_area'}, inplace=True)\n", - " \n", + " iso_area['year'] = year\n", + " iso_area['protection_type'] = 'MPA+OECM'\n", + " iso_area.rename(columns={'PARENT_ISO': 'location_id', 'AREA': 'cumsum_area'}, inplace=True)\n", + "\n", " # Append the result to the list\n", - " results_list.append(grouped)\n", + " results_list.append(iso_area)\n", "\n", "# Concatenate the list of results into a single DataFrame and convert area to sq.km\n", "final_df = pd.concat(results_list, ignore_index=True)\n", - "final_df['cumsum_area'] =final_df['cumsum_area']/1000000" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Global**" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [], - "source": [ - "# Calculate global per year and append it to df\n", - "glob_df = final_df.groupby(['year', 'protection_type'])['cumsum_area'].sum().reset_index()\n", - "glob_df['location_id'] = 'GLOB'\n", + "final_df['cumsum_area'] = final_df['cumsum_area'] / 1000000\n", "\n", - "final_df = pd.concat([final_df, glob_df], ignore_index=True)" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "final_df = final_df[['location_id', 'year', 'protection_type', 'cumsum_area']]" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
location_idyearprotection_typecumsum_area
0ABNJ2000MPA+OECM5.941747e+05
130ABNJ2001MPA+OECM5.941747e+05
262ABNJ2002MPA+OECM5.941747e+05
397ABNJ2003MPA+OECM5.941747e+05
533ABNJ2004MPA+OECM5.941747e+05
669ABNJ2005MPA+OECM5.941747e+05
808ABNJ2006MPA+OECM5.941747e+05
949ABNJ2007MPA+OECM5.941747e+05
1090ABNJ2008MPA+OECM5.941747e+05
1233ABNJ2009MPA+OECM5.941747e+05
1377ABNJ2010MPA+OECM9.532081e+05
1525ABNJ2011MPA+OECM8.568056e+05
1675ABNJ2012MPA+OECM1.034105e+06
1825ABNJ2013MPA+OECM1.034105e+06
1976ABNJ2014MPA+OECM1.034105e+06
2127ABNJ2015MPA+OECM1.034105e+06
2278ABNJ2016MPA+OECM1.034105e+06
2429ABNJ2017MPA+OECM2.811452e+06
2580ABNJ2018MPA+OECM2.811452e+06
2731ABNJ2019MPA+OECM2.811452e+06
2882ABNJ2020MPA+OECM2.811452e+06
3034ABNJ2021MPA+OECM2.811452e+06
3186ABNJ2022MPA+OECM2.811452e+06
3338ABNJ2023MPA+OECM2.811452e+06
\n", - "
" - ], - "text/plain": [ - " location_id year protection_type cumsum_area\n", - "0 ABNJ 2000 MPA+OECM 5.941747e+05\n", - "130 ABNJ 2001 MPA+OECM 5.941747e+05\n", - "262 ABNJ 2002 MPA+OECM 5.941747e+05\n", - "397 ABNJ 2003 MPA+OECM 5.941747e+05\n", - "533 ABNJ 2004 MPA+OECM 5.941747e+05\n", - "669 ABNJ 2005 MPA+OECM 5.941747e+05\n", - "808 ABNJ 2006 MPA+OECM 5.941747e+05\n", - "949 ABNJ 2007 MPA+OECM 5.941747e+05\n", - "1090 ABNJ 2008 MPA+OECM 5.941747e+05\n", - "1233 ABNJ 2009 MPA+OECM 5.941747e+05\n", - "1377 ABNJ 2010 MPA+OECM 9.532081e+05\n", - "1525 ABNJ 2011 MPA+OECM 8.568056e+05\n", - "1675 ABNJ 2012 MPA+OECM 1.034105e+06\n", - "1825 ABNJ 2013 MPA+OECM 1.034105e+06\n", - "1976 ABNJ 2014 MPA+OECM 1.034105e+06\n", - "2127 ABNJ 2015 MPA+OECM 1.034105e+06\n", - "2278 ABNJ 2016 MPA+OECM 1.034105e+06\n", - "2429 ABNJ 2017 MPA+OECM 2.811452e+06\n", - "2580 ABNJ 2018 MPA+OECM 2.811452e+06\n", - "2731 ABNJ 2019 MPA+OECM 2.811452e+06\n", - "2882 ABNJ 2020 MPA+OECM 2.811452e+06\n", - "3034 ABNJ 2021 MPA+OECM 2.811452e+06\n", - "3186 ABNJ 2022 MPA+OECM 2.811452e+06\n", - "3338 ABNJ 2023 MPA+OECM 2.811452e+06" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "final_df[final_df['location_id'] == 'ABNJ']" + "# Append global coverage to the final_df\n", + "final_df = pd.concat([final_df, global_coverage], ignore_index=True)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "**Regions**" + "### Regional stats" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -888,11 +683,6 @@ " ]\n", " },\n", " {\n", - " 'region_iso': 'GL',\n", - " 'region_name': 'Global',\n", - " 'country_iso_3s': ['GLOB']\n", - " },\n", - " {\n", " 'region_iso': 'WA',\n", " 'region_name': 'West Asia',\n", " 'country_iso_3s': [\n", @@ -905,13 +695,6 @@ " 'country_iso_3s': [\n", " \"ATA\"\n", " ]\n", - " },\n", - " {\n", - " 'region_iso': 'ABNJ', # this region is not in the Protected Planet database\n", - " 'region_name': 'Areas Beyond National Jurisdiction',\n", - " 'country_iso_3s': [\n", - " \"ABNJ\"\n", - " ]\n", " }\n", "]\n", "\n", @@ -924,7 +707,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -957,38 +740,38 @@ " \n", " \n", " 0\n", - " ABNJ\n", + " AF\n", " 2000\n", " MPA+OECM\n", - " 594174.659985\n", + " 94507.122820\n", " \n", " \n", " 1\n", - " ABNJ\n", + " AF\n", " 2001\n", " MPA+OECM\n", - " 594174.659985\n", + " 94807.303100\n", " \n", " \n", " 2\n", - " ABNJ\n", + " AF\n", " 2002\n", " MPA+OECM\n", - " 594174.659985\n", + " 102859.393938\n", " \n", " \n", " 3\n", - " ABNJ\n", + " AF\n", " 2003\n", " MPA+OECM\n", - " 594174.659985\n", + " 111143.352991\n", " \n", " \n", " 4\n", - " ABNJ\n", + " AF\n", " 2004\n", " MPA+OECM\n", - " 594174.659985\n", + " 119137.635862\n", " \n", " \n", " ...\n", @@ -998,35 +781,35 @@ " ...\n", " \n", " \n", - " 211\n", + " 163\n", " WA\n", " 2019\n", " MPA+OECM\n", " 30618.254664\n", " \n", " \n", - " 212\n", + " 164\n", " WA\n", " 2020\n", " MPA+OECM\n", " 30624.636536\n", " \n", " \n", - " 213\n", + " 165\n", " WA\n", " 2021\n", " MPA+OECM\n", " 30624.636536\n", " \n", " \n", - " 214\n", + " 166\n", " WA\n", " 2022\n", " MPA+OECM\n", " 31779.597984\n", " \n", " \n", - " 215\n", + " 167\n", " WA\n", " 2023\n", " MPA+OECM\n", @@ -1034,27 +817,27 @@ " \n", " \n", "\n", - "

216 rows × 4 columns

\n", + "

168 rows × 4 columns

\n", "" ], "text/plain": [ " location_id year protection_type cumsum_area\n", - "0 ABNJ 2000 MPA+OECM 594174.659985\n", - "1 ABNJ 2001 MPA+OECM 594174.659985\n", - "2 ABNJ 2002 MPA+OECM 594174.659985\n", - "3 ABNJ 2003 MPA+OECM 594174.659985\n", - "4 ABNJ 2004 MPA+OECM 594174.659985\n", + "0 AF 2000 MPA+OECM 94507.122820\n", + "1 AF 2001 MPA+OECM 94807.303100\n", + "2 AF 2002 MPA+OECM 102859.393938\n", + "3 AF 2003 MPA+OECM 111143.352991\n", + "4 AF 2004 MPA+OECM 119137.635862\n", ".. ... ... ... ...\n", - "211 WA 2019 MPA+OECM 30618.254664\n", - "212 WA 2020 MPA+OECM 30624.636536\n", - "213 WA 2021 MPA+OECM 30624.636536\n", - "214 WA 2022 MPA+OECM 31779.597984\n", - "215 WA 2023 MPA+OECM 31779.597984\n", + "163 WA 2019 MPA+OECM 30618.254664\n", + "164 WA 2020 MPA+OECM 30624.636536\n", + "165 WA 2021 MPA+OECM 30624.636536\n", + "166 WA 2022 MPA+OECM 31779.597984\n", + "167 WA 2023 MPA+OECM 31779.597984\n", "\n", - "[216 rows x 4 columns]" + "[168 rows x 4 columns]" ] }, - "execution_count": 9, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -1065,7 +848,7 @@ "\n", "# group by region and year to get sum of cumsum_area\n", "regions = regions.groupby(['location_id', 'year', 'protection_type'])['cumsum_area'].sum().reset_index()\n", - "regions\n" + "regions" ] }, { @@ -1075,230 +858,8 @@ "outputs": [ { "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
location_idyearprotection_typecumsum_area
120GL2000MPA+OECM3.193363e+06
121GL2001MPA+OECM3.569706e+06
122GL2002MPA+OECM3.695628e+06
123GL2003MPA+OECM3.748312e+06
124GL2004MPA+OECM3.866803e+06
125GL2005MPA+OECM3.980030e+06
126GL2006MPA+OECM7.559205e+06
127GL2007MPA+OECM8.741698e+06
128GL2008MPA+OECM8.825878e+06
129GL2009MPA+OECM1.060580e+07
130GL2010MPA+OECM1.202293e+07
131GL2011MPA+OECM1.208784e+07
132GL2012MPA+OECM1.395678e+07
133GL2013MPA+OECM1.423613e+07
134GL2014MPA+OECM1.566334e+07
135GL2015MPA+OECM1.634694e+07
136GL2016MPA+OECM1.823543e+07
137GL2017MPA+OECM2.270050e+07
138GL2018MPA+OECM2.712299e+07
139GL2019MPA+OECM2.832749e+07
140GL2020MPA+OECM2.982679e+07
141GL2021MPA+OECM2.994130e+07
142GL2022MPA+OECM3.011280e+07
143GL2023MPA+OECM3.011285e+07
\n", - "
" - ], "text/plain": [ - " location_id year protection_type cumsum_area\n", - "120 GL 2000 MPA+OECM 3.193363e+06\n", - "121 GL 2001 MPA+OECM 3.569706e+06\n", - "122 GL 2002 MPA+OECM 3.695628e+06\n", - "123 GL 2003 MPA+OECM 3.748312e+06\n", - "124 GL 2004 MPA+OECM 3.866803e+06\n", - "125 GL 2005 MPA+OECM 3.980030e+06\n", - "126 GL 2006 MPA+OECM 7.559205e+06\n", - "127 GL 2007 MPA+OECM 8.741698e+06\n", - "128 GL 2008 MPA+OECM 8.825878e+06\n", - "129 GL 2009 MPA+OECM 1.060580e+07\n", - "130 GL 2010 MPA+OECM 1.202293e+07\n", - "131 GL 2011 MPA+OECM 1.208784e+07\n", - "132 GL 2012 MPA+OECM 1.395678e+07\n", - "133 GL 2013 MPA+OECM 1.423613e+07\n", - "134 GL 2014 MPA+OECM 1.566334e+07\n", - "135 GL 2015 MPA+OECM 1.634694e+07\n", - "136 GL 2016 MPA+OECM 1.823543e+07\n", - "137 GL 2017 MPA+OECM 2.270050e+07\n", - "138 GL 2018 MPA+OECM 2.712299e+07\n", - "139 GL 2019 MPA+OECM 2.832749e+07\n", - "140 GL 2020 MPA+OECM 2.982679e+07\n", - "141 GL 2021 MPA+OECM 2.994130e+07\n", - "142 GL 2022 MPA+OECM 3.011280e+07\n", - "143 GL 2023 MPA+OECM 3.011285e+07" + "array(['AF', 'AS', 'AT', 'EU', 'NA', 'SA', 'WA'], dtype=object)" ] }, "execution_count": 12, @@ -1307,24 +868,13 @@ } ], "source": [ - "regions[regions['location_id'] == 'GL']" + "regions['location_id'].unique()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [ - "# Remove rows for region GL (Global)\n", - "regions2 = regions[regions['location_id'] != 'GL']\n", - "regions2 = regions2[regions2['location_id'] != 'ABNJ']" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, "outputs": [ { "data": { @@ -1346,10 +896,10 @@ " 'VNM', 'VUT', 'WSM', 'ZAF', 'DZA', 'IOT', 'GAB', 'IND', 'SGP',\n", " 'LBR', 'CIV', 'CPV', 'SLV', 'QAT', 'STP', 'SHN', 'YEM', 'URY',\n", " 'CMR', 'COM', 'KWT', 'SJM', 'GUY', 'UMI', 'HTI', 'JOR', 'GLOB',\n", - " 'AF', 'AS', 'AT', 'EU', 'GL', 'NA', 'SA', 'WA'], dtype=object)" + " 'AF', 'AS', 'AT', 'EU', 'NA', 'SA', 'WA'], dtype=object)" ] }, - "execution_count": 15, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -1361,7 +911,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -1386,9 +936,9 @@ " \n", " \n", " location_id\n", + " cumsum_area\n", " year\n", " protection_type\n", - " cumsum_area\n", " last_updated\n", " \n", " \n", @@ -1396,42 +946,42 @@ " \n", " 0\n", " ABNJ\n", + " 594174.659985\n", " 2000\n", " MPA+OECM\n", - " 594174.659985\n", - " 2023-10-13\n", + " 2023-10-18\n", " \n", " \n", " 1\n", " AGO\n", + " 0.415240\n", " 2000\n", " MPA+OECM\n", - " 0.415240\n", - " 2023-10-13\n", + " 2023-10-18\n", " \n", " \n", " 2\n", " ALB\n", + " 103.048347\n", " 2000\n", " MPA+OECM\n", - " 103.048347\n", - " 2023-10-13\n", + " 2023-10-18\n", " \n", " \n", " 3\n", " ARE\n", + " 78.516519\n", " 2000\n", " MPA+OECM\n", - " 78.516519\n", - " 2023-10-13\n", + " 2023-10-18\n", " \n", " \n", " 4\n", " ARG\n", + " 6155.668078\n", " 2000\n", " MPA+OECM\n", - " 6155.668078\n", - " 2023-10-13\n", + " 2023-10-18\n", " \n", " \n", " ...\n", @@ -1442,68 +992,68 @@ " ...\n", " \n", " \n", - " 3725\n", + " 3677\n", " WA\n", + " 30618.254664\n", " 2019\n", " MPA+OECM\n", - " 30618.254664\n", - " 2023-10-13\n", + " 2023-10-18\n", " \n", " \n", - " 3726\n", + " 3678\n", " WA\n", + " 30624.636536\n", " 2020\n", " MPA+OECM\n", - " 30624.636536\n", - " 2023-10-13\n", + " 2023-10-18\n", " \n", " \n", - " 3727\n", + " 3679\n", " WA\n", + " 30624.636536\n", " 2021\n", " MPA+OECM\n", - " 30624.636536\n", - " 2023-10-13\n", + " 2023-10-18\n", " \n", " \n", - " 3728\n", + " 3680\n", " WA\n", + " 31779.597984\n", " 2022\n", " MPA+OECM\n", - " 31779.597984\n", - " 2023-10-13\n", + " 2023-10-18\n", " \n", " \n", - " 3729\n", + " 3681\n", " WA\n", + " 31779.597984\n", " 2023\n", " MPA+OECM\n", - " 31779.597984\n", - " 2023-10-13\n", + " 2023-10-18\n", " \n", " \n", "\n", - "

3730 rows × 5 columns

\n", + "

3682 rows × 5 columns

\n", "" ], "text/plain": [ - " location_id year protection_type cumsum_area last_updated\n", - "0 ABNJ 2000 MPA+OECM 594174.659985 2023-10-13\n", - "1 AGO 2000 MPA+OECM 0.415240 2023-10-13\n", - "2 ALB 2000 MPA+OECM 103.048347 2023-10-13\n", - "3 ARE 2000 MPA+OECM 78.516519 2023-10-13\n", - "4 ARG 2000 MPA+OECM 6155.668078 2023-10-13\n", - "... ... ... ... ... ...\n", - "3725 WA 2019 MPA+OECM 30618.254664 2023-10-13\n", - "3726 WA 2020 MPA+OECM 30624.636536 2023-10-13\n", - "3727 WA 2021 MPA+OECM 30624.636536 2023-10-13\n", - "3728 WA 2022 MPA+OECM 31779.597984 2023-10-13\n", - "3729 WA 2023 MPA+OECM 31779.597984 2023-10-13\n", + " location_id cumsum_area year protection_type last_updated\n", + "0 ABNJ 594174.659985 2000 MPA+OECM 2023-10-18\n", + "1 AGO 0.415240 2000 MPA+OECM 2023-10-18\n", + "2 ALB 103.048347 2000 MPA+OECM 2023-10-18\n", + "3 ARE 78.516519 2000 MPA+OECM 2023-10-18\n", + "4 ARG 6155.668078 2000 MPA+OECM 2023-10-18\n", + "... ... ... ... ... ...\n", + "3677 WA 30618.254664 2019 MPA+OECM 2023-10-18\n", + "3678 WA 30624.636536 2020 MPA+OECM 2023-10-18\n", + "3679 WA 30624.636536 2021 MPA+OECM 2023-10-18\n", + "3680 WA 31779.597984 2022 MPA+OECM 2023-10-18\n", + "3681 WA 31779.597984 2023 MPA+OECM 2023-10-18\n", "\n", - "[3730 rows x 5 columns]" + "[3682 rows x 5 columns]" ] }, - "execution_count": 16, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -1518,7 +1068,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [