├── Supplemental_Materials └── S6 Area of the Ocean that is Fished │ ├── .gitignore │ ├── fishing_raster_05_20180228.tif │ ├── calculating_area_fished_files │ └── figure-markdown_github │ │ ├── unnamed-chunk-12-1.png │ │ ├── unnamed-chunk-14-1.png │ │ ├── unnamed-chunk-16-1.png │ │ ├── unnamed-chunk-18-1.png │ │ ├── unnamed-chunk-19-1.png │ │ ├── unnamed-chunk-21-1.png │ │ └── unnamed-chunk-22-1.png │ ├── calculating_area_fished.Rmd │ ├── calculating_area_fished.md │ └── fishing_area_calc_old.Rmd ├── images ├── global_plot_squid.jpg └── 3.GlobalFishingActivity-dark.jpg ├── .idea └── vcs.xml ├── data_production ├── export_all.sh ├── config.sh ├── readme.md ├── updated-algorithm-for-squid-jiggers.md └── export_table.sh ├── Figure_1 ├── Tracking_Global_Footprint_Fisheries_Figure1_files │ └── figure-markdown_github │ │ ├── unnamed-chunk-12-1.png │ │ ├── unnamed-chunk-13-1.png │ │ ├── unnamed-chunk-14-1.png │ │ └── unnamed-chunk-15-1.png ├── Tracking_Global_Footprint_Fisheries_Figure1.Rmd └── Tracking_Global_Footprint_Fisheries_Figure1.md ├── Figure_2 ├── Tracking_Global_Footprint_Fisheries_Figure2_code_files │ └── figure-markdown_github │ │ ├── unnamed-chunk-13-1.png │ │ ├── unnamed-chunk-7-1.png │ │ └── unnamed-chunk-8-1.png ├── Tracking_Global_Footprint_Fisheries_Figure2_code.md └── Tracking_Global_Footprint_Fisheries_Figure2_code.Rmd ├── README.md ├── .gitignore └── data_documentation ├── fishing_effort_byvessel.md ├── fishing_vessels.md ├── fishing_effort.md ├── update_table_documentation.py ├── vessels.md └── update_table_documentation.ipynb /Supplemental_Materials/S6 Area of the Ocean that is Fished/.gitignore: -------------------------------------------------------------------------------- 1 | .httr-oauth 2 | -------------------------------------------------------------------------------- /images/global_plot_squid.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/images/global_plot_squid.jpg -------------------------------------------------------------------------------- /images/3.GlobalFishingActivity-dark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/images/3.GlobalFishingActivity-dark.jpg -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /data_production/export_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | EXPORT="bash ./export_table.sh" 4 | 5 | ${EXPORT} fishing_effort 6 | ${EXPORT} fishing_effort_byvessel 7 | ${EXPORT} fishing_vessels 8 | ${EXPORT} vessels 9 | 10 | -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/fishing_raster_05_20180228.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Supplemental_Materials/S6 Area of the Ocean that is Fished/fishing_raster_05_20180228.tif -------------------------------------------------------------------------------- /Figure_1/Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Figure_1/Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /Figure_1/Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Figure_1/Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /Figure_1/Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Figure_1/Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /Figure_1/Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Figure_1/Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-15-1.png -------------------------------------------------------------------------------- /Figure_2/Tracking_Global_Footprint_Fisheries_Figure2_code_files/figure-markdown_github/unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Figure_2/Tracking_Global_Footprint_Fisheries_Figure2_code_files/figure-markdown_github/unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /Figure_2/Tracking_Global_Footprint_Fisheries_Figure2_code_files/figure-markdown_github/unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Figure_2/Tracking_Global_Footprint_Fisheries_Figure2_code_files/figure-markdown_github/unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /Figure_2/Tracking_Global_Footprint_Fisheries_Figure2_code_files/figure-markdown_github/unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Figure_2/Tracking_Global_Footprint_Fisheries_Figure2_code_files/figure-markdown_github/unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-21-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-21-1.png -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-22-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GlobalFishingWatch/paper-global-footprint-of-fisheries/HEAD/Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished_files/figure-markdown_github/unnamed-chunk-22-1.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tracking the Global Footprint of Fisheries 2 | 3 | This repo contains code, analyses, and links to data for [Kroodsma, D.A., J. Mayorga, T. Hochberg, N.A. Miller, K. Boerder, F. Ferretti, A. Wilson, 7 B. Bergman, T.D. White, B.A. Block, P. Woods,B. Sullivan, C. Costello, B. Worm. "Tracking the Global Footprint of Fisheries." _Science_ Vol 361 Issue 6378.](http://science.sciencemag.org/cgi/doi/10.1126/science.aao1118) 4 | 5 | To get the fishing effort and vessel data associated with this paper, [visit Global Fishing Watch's Datasets and Code page](https://globalfishingwatch.org/datasets-and-code/). 6 | 7 | ![global fishing](images/3.GlobalFishingActivity-dark.jpg) 8 | -------------------------------------------------------------------------------- /data_production/config.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # PROJECT is the GCP project ID where the bigquery tables are stored 4 | # DATASET is the bigquery data set containing the tables 5 | # BUCKET is the GCS bucket where the export will be stored 6 | # TEMP_BUCKET is used for intermediate storage of the extract from bigquery 7 | 8 | 9 | # Sample test settings 10 | PROJECT=world-fishing-827 11 | DATASET=scratch_paul_ttl_100 12 | BUCKET=scratch-paul-ttl100 13 | TEMP_BUCKET=scratch-paul-ttl100 14 | 15 | 16 | # Production settings 17 | #PROJECT=global-fishing-watch 18 | #DATASET=global_footprint_of_fisheries 19 | #BUCKET=global_footprint_of_fisheries 20 | #TEMP_BUCKET=scratch-paul-ttl100 21 | -------------------------------------------------------------------------------- /data_production/readme.md: -------------------------------------------------------------------------------- 1 | ## Export public bigquery tables to GCS 2 | 3 | NOTE: the fishing_effort table is large, so the export takes a while. It is recommended to clone this repo on a GCE instance and run it there using `screen` 4 | 5 | 6 | To export the public tables to GCS 7 | 8 | 1. Edit the config.sh to point to the right locations (you might want to run it against a temp location the first time) 9 | 10 | 2. run export_table.sh and specify which table you want to export. Run the scritp with no argumentes to get a list of supported tables 11 | 12 | For example 13 | 14 | ```bash 15 | $ ./export_table.sh 16 | usage: export_table TARGET 17 | 18 | valid targets: 19 | fishing_effort 20 | fishing_effort_byvessel 21 | fishing_vessels 22 | vessels 23 | ``` 24 | 25 | To export the fishing_effort table 26 | ```bash 27 | $ ./export_table fishing_effort 28 | ``` 29 | 30 | -------------------------------------------------------------------------------- /data_production/updated-algorithm-for-squid-jiggers.md: -------------------------------------------------------------------------------- 1 | # Updated Algorithm for Squid Jiggers 2 | 3 | Between paper acceptance and publication of our paper, we changed how our dataset calculates fishing activity for squid jiggers, and this change is reflected in the dataset we have released. 4 | 5 | These vessels make up a small fraction of the vessels in our database; about 600 out of 70,000 mmsi are likely squid jiggers. Our fishing effort training data included all our other major geartypes, but did not include this gear type. As a result, the neural net model did a poor job at identifying when these vessles were fishing, and falsely labeled many of the transits of these vessels as fishing activty. 6 | 7 | Based on conversations with experts and a review of the activity of the squid fleet operating outside the Peruvian exclusive economic zone, we developed a heuristic to account for squid fishing activity. These vessels fish only at night and only while relatively stationary. Rather than retrain the neural net model, we applied this hueristic to all squid vessels. The heuristic labels positions as fishing if the vessel is > 10 nautical miles from shore and moving slower than 1.5 knots at night for more than four hours. We eventually plan to eventually provide training data for our model to better identify likely fishing activity by Squid Jiggers. 8 | 9 | ![squid fishing](../images/global_plot_squid.jpg) 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .httr-oauth 3 | bigquery_credentials.dat 4 | .Rhistory 5 | 6 | # Byte-compiled / optimized / DLL files 7 | __pycache__/ 8 | *.py[cod] 9 | *$py.class 10 | 11 | # C extensions 12 | *.so 13 | 14 | # Distribution / packaging 15 | .Python 16 | env/ 17 | build/ 18 | develop-eggs/ 19 | dist/ 20 | downloads/ 21 | eggs/ 22 | .eggs/ 23 | lib/ 24 | lib64/ 25 | parts/ 26 | sdist/ 27 | var/ 28 | wheels/ 29 | *.egg-info/ 30 | .installed.cfg 31 | *.egg 32 | 33 | # PyInstaller 34 | # Usually these files are written by a python script from a template 35 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 36 | *.manifest 37 | *.spec 38 | 39 | # Installer logs 40 | pip-log.txt 41 | pip-delete-this-directory.txt 42 | 43 | # Unit test / coverage reports 44 | htmlcov/ 45 | .tox/ 46 | .coverage 47 | .coverage.* 48 | .cache 49 | nosetests.xml 50 | coverage.xml 51 | *.cover 52 | .hypothesis/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | 62 | # Flask stuff: 63 | instance/ 64 | .webassets-cache 65 | 66 | # Scrapy stuff: 67 | .scrapy 68 | 69 | # Sphinx documentation 70 | docs/_build/ 71 | 72 | # PyBuilder 73 | target/ 74 | 75 | # Jupyter Notebook 76 | .ipynb_checkpoints 77 | 78 | # pyenv 79 | .python-version 80 | 81 | # celery beat schedule file 82 | celerybeat-schedule 83 | 84 | # SageMath parsed files 85 | *.sage.py 86 | 87 | # dotenv 88 | .env 89 | 90 | # virtualenv 91 | .venv 92 | venv/ 93 | ENV/ 94 | 95 | # Spyder project settings 96 | .spyderproject 97 | .spyproject 98 | 99 | # Rope project settings 100 | .ropeproject 101 | 102 | # mkdocs documentation 103 | /site 104 | 105 | # mypy 106 | .mypy_cache/ 107 | 108 | # pycharm 109 | .idea/* 110 | -------------------------------------------------------------------------------- /data_documentation/fishing_effort_byvessel.md: -------------------------------------------------------------------------------- 1 | # Fishing Effort by Vessel 2 | 3 | ## Daily Fishing Effort at 10th Degree Resolution by MMSI, 2012-2016 4 | 5 | Fishing effort and vessel presence data is avaialbe in the following formats: 6 | - BigQuery Tables 7 | - CSVs 8 | 9 | Links to these data are available at [Global Fishing Watch's community page](https://globalfishingwatch.force.com/gfw/s/data-download). 10 | 11 | For additional information about these results, see the associated journal article: [D.A. Kroodsma, J. Mayorga, T. Hochberg, N.A. Miller, K. Boerder, F. Ferretti, A. Wilson, B. Bergman, T.D. White, B.A. Block, P. Woods, B. Sullivan, C. Costello, and B. Worm. "Tracking the global footprint of fisheries." Science 361.6378 (2018).](http://science.sciencemag.org/content/359/6378/904) 12 | 13 | For updates, links to example code, and more, visit: 14 | 15 | - [Global Fishing Watch R&D Site](globalfishingwatch.io/global-footprint-of-fisheries.html) 16 | - [GitHub Repo for Tracking the Global Footprint of Fisheries](GitHub.com/globalfishingwatch/tracking-global-footprint-of-fisheries) 17 | 18 | Description: Fishing effort is binned into grid cells 0.1 degrees on a side, and measured in units of hours. The time is calculated by assigning an amount of time to each AIS detection (which is half the time to the previous plus half the time to the next AIS position). To get information on each mmsi, see Global Fishing Watch data on [fishing vessels](https://github.com/GlobalFishingWatch/global-footprint-of-fisheries/blob/master/data_documentation/fishing_vessels.md). Fishing effort for squid jiggers is not calculated through the neural network, but instead through [this heuristic](https://github.com/GlobalFishingWatch/global-footprint-of-fisheries/blob/master/data_production/updated-algorithm-for-squid-jiggers.md). 19 | 20 | ## Table Schema 21 | - date: a string in format “YYYY-MM-DD” 22 | - mmsi: unique AIS identifier 23 | - lat_bin: the southern edge of the grid cell, in 10ths of a degree -- 101 is the grid cell with a southern edge at 10.1 degrees north 24 | - lon_bin: the western edge of the grid cell, in 10ths of a degree -- 101 is the grid cell with a western edge at 10.1 degrees east 25 | - fishing_hours: hours that vessels of this geartype and flag were fishing in this gridcell on this day 26 | -------------------------------------------------------------------------------- /data_documentation/fishing_vessels.md: -------------------------------------------------------------------------------- 1 | # Fishing Vessels 2 | 3 | ## Fishing Vessels Included in Fishing Effort Data 4 | 5 | These data are available in the following formats: 6 | - BigQuery Tables 7 | - CSVs 8 | 9 | Links to these data are available at [Global Fishing Watch's community page](https://globalfishingwatch.force.com/gfw/s/data-download). 10 | 11 | For additional information about these results, see the associated journal article: [D.A. Kroodsma, J. Mayorga, T. Hochberg, N.A. Miller, K. Boerder, F. Ferretti, A. Wilson, B. Bergman, T.D. White, B.A. Block, P. Woods, B. Sullivan, C. Costello, and B. Worm. "Tracking the global footprint of fisheries." Science 361.6378 (2018).](http://science.sciencemag.org/content/359/6378/904) 12 | 13 | License: [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) 14 | 15 | For updates, links to example code, and more, visit: 16 | 17 | - [Global Fishing Watch R&D Site](globalfishingwatch.io/global-footprint-of-fisheries.html) 18 | - [GitHub Repo for Tracking the Global Footprint of Fisheries](GitHub.com/globalfishingwatch/tracking-global-footprint-of-fisheries) 19 | 20 | Description: This table includes all mmsi that are included in the [fishing effort data](https://github.com/GlobalFishingWatch/global-footprint-of-fisheries/blob/master/data_documentation/fishing_effort.md). It includes all vessels that were identified as fishing vessels by the neural network and which were not identified as non-fishing vessels by registries and manual review. If an mmsi was matched to a fishing vessel on a registry, but the neural net did not classify it as a fishing vessel, it is not included on this list. There is only one row for each mmsi. 21 | 22 | ## Table Schema 23 | - mmsi: Maritime Mobile Service Identity, the identifier for AIS 24 | - flag: An iso3 value for the flag state of the vessel. If we did not have a value from a manual review or from matching the vessels to registries, we used the MMSI mid code to identify the vessel flag state. A value of "UNK" means the flag state is unknown. 25 | - geartype: Best value for geartype. Options include: 26 | - trawlers 27 | - purse_seines 28 | - squid_jigger 29 | - fixed_gear 30 | - other_fishing 31 | - drifting_longlines 32 | - length: best value for length overall in meters 33 | - tonnage: best value for gross tonnage 34 | - engine_power: best value for main engine power, in kilowatts 35 | - active_2012: If this mmsi was active in 2012 36 | - active_2013: If this mmsi was active in 2013 37 | - active_2014: If this mmsi was active in 2014 38 | - active_2015: If this mmsi was active in 2015 39 | - active_2016: If this mmsi was active in 2016 40 | -------------------------------------------------------------------------------- /data_documentation/fishing_effort.md: -------------------------------------------------------------------------------- 1 | # Fishing Effort 2 | 3 | ## Daily Fishing Effort and Vessel Presence at 100th Degree Resolution by Flag State and GearType, 2012-2016 4 | 5 | Fishing effort and vessel presence data is avaialbe in the following formats: 6 | - BigQuery Tables 7 | - CSVs 8 | - Geotiff Rasters in Google Earth Engine 9 | 10 | Links to these data are available at [Global Fishing Watch's community page](https://globalfishingwatch.force.com/gfw/s/data-download). 11 | 12 | For additional information about these results, see the associated journal article: [D.A. Kroodsma, J. Mayorga, T. Hochberg, N.A. Miller, K. Boerder, F. Ferretti, A. Wilson, B. Bergman, T.D. White, B.A. Block, P. Woods, B. Sullivan, C. Costello, and B. Worm. "Tracking the global footprint of fisheries." Science 361.6378 (2018).](http://science.sciencemag.org/content/359/6378/904) 13 | 14 | For updates, links to example code, and more, visit: 15 | 16 | - [Global Fishing Watch R&D Site](http://globalfishingwatch.io/global-footprint-of-fisheries.html) 17 | - [GitHub Repo for Tracking the Global Footprint of Fisheries](https://github.com/GlobalFishingWatch/global-footprint-of-fisheries/tree/master/data_documentation) 18 | 19 | Description: Fishing effort and vessel presence is binned into grid cells 0.01 degrees on a side, and measured in units of hours. The time is calculated by assigning an amount of time to each AIS detection (which is half the time to the previous plus half the time to the next AIS position), and then summing all positions in each grid cell. Data is based on fishing detections of >70,000 unique AIS devices on fishing vessels. Fishing vessels are identified via a neural network classifier and vessel registry databases. Fishing effort for squid jiggers is not calculated through the neural network, but instead through [this heuristic](https://github.com/GlobalFishingWatch/global-footprint-of-fisheries/blob/master/data_production/updated-algorithm-for-squid-jiggers.md). The neural net classifies fishing vessels into six categories: 20 | 21 | - drifting_longlines: drifting longlines 22 | - purse_seines: purse seines, both pelagic and demersal 23 | - trawlers: trawlers, all types 24 | - fixed_gear: a category that includes set longlines, set gillnets, and pots and traps 25 | - squid_jigger: squid jiggers, mostly large industrial pelagic operating vessels 26 | - other_fishing: a combination of vessels of unknown fishing gear and other, less common gears such as trollers or pole and line 27 | 28 | 29 | ## Table Schema 30 | - date: a string in format “YYYY-MM-DD” 31 | - lat_bin: the southern edge of the grid cell, in 100ths of a degree -- 101 is the grid cell with a southern edge at 1.01 degrees north 32 | - lon_bin: the western edge of the grid cell, in 100ths of a degree -- 101 is the grid cell with a western edge at 1.01 degrees east 33 | - flag: the flag state of the fishing effort, in iso3 value 34 | - geartype: see our description of geartpyes 35 | - vessel_hours: hours that vessels of this geartype and flag were present in this gridcell on this day 36 | - fishing_hours: hours that vessels of this geartype and flag were fishing in this gridcell on this day 37 | - mmsi_present: number of mmsi of this flag state and geartype that visited this grid cell on this day 38 | -------------------------------------------------------------------------------- /data_production/export_table.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | THIS_SCRIPT_DIR="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )" 5 | 6 | source ${THIS_SCRIPT_DIR}/config.sh 7 | 8 | display_usage() { 9 | echo "usage: export_table TARGET" 10 | echo "" 11 | echo " valid targets:" 12 | echo " fishing_effort" 13 | echo " fishing_effort_byvessel" 14 | echo " fishing_vessels" 15 | echo " vessels" 16 | } 17 | 18 | case $1 in 19 | 20 | fishing_effort) 21 | TARGET=$1 22 | PARTITION=1 23 | ;; 24 | 25 | fishing_effort_byvessel) 26 | TARGET=$1 27 | PARTITION=1 28 | ;; 29 | 30 | fishing_vessels) 31 | TARGET=$1 32 | PARTITION= 33 | ;; 34 | 35 | vessels) 36 | TARGET=$1 37 | PARTITION= 38 | ;; 39 | 40 | *) 41 | display_usage 42 | exit 0 43 | ;; 44 | esac 45 | 46 | 47 | BQ_TABLE=${PROJECT}:${DATASET}.${TARGET} 48 | README=${THIS_SCRIPT_DIR}/../data_documentation/${TARGET}.md 49 | GCS_TEMP_BUCKET=gs://${TEMP_BUCKET} 50 | GCS_DEST_DIR=gs://${BUCKET}/${TARGET} 51 | 52 | TEMP_DIR=$(mktemp -d) 53 | 54 | LOCAL_EXTRACT_DIR=${TEMP_DIR}/extract 55 | LOCAL_PARTITION_DIR=${TEMP_DIR}/partition 56 | LOCAL_DEST_DIR=${TEMP_DIR}/${TARGET} 57 | 58 | if [ -z ${PARTITION} ]; then 59 | LOCAL_CSV_DIR=${LOCAL_DEST_DIR} 60 | else 61 | LOCAL_CSV_DIR=${LOCAL_DEST_DIR}/daily_csvs 62 | fi 63 | 64 | 65 | mkdir -p ${TEMP_DIR} 66 | mkdir -p ${LOCAL_EXTRACT_DIR} 67 | mkdir -p ${LOCAL_PARTITION_DIR} 68 | mkdir -p ${LOCAL_DEST_DIR} 69 | mkdir -p ${LOCAL_CSV_DIR} 70 | 71 | UUID=$(uuidgen) 72 | 73 | GCS_EXTRACT_DIR=${GCS_TEMP_BUCKET}/${UUID} 74 | CSV_HEADER=${TEMP_DIR}/header 75 | 76 | echo "Export Bigquery table to temp gcs location" 77 | echo "" 78 | bq extract \ 79 | --compression GZIP \ 80 | --destination_format CSV \ 81 | ${BQ_TABLE} \ 82 | ${GCS_EXTRACT_DIR}/extract*.csv.gz 83 | 84 | 85 | echo "" 86 | echo "Copy the extracted files to a local temp dir" 87 | echo "" 88 | gsutil -m cp ${GCS_EXTRACT_DIR}/* ${LOCAL_EXTRACT_DIR} 89 | 90 | echo "" 91 | echo "Get the first line from the first file (csv header)" 92 | echo "" 93 | 94 | echo $(cat $(ls -d1 ${LOCAL_EXTRACT_DIR}/* | head -1) | gunzip | head -1) > ${CSV_HEADER} 95 | 96 | echo "" 97 | echo "Parition csv files by date" 98 | echo "" 99 | #partition the csv files by date (the first field), and ignore the first line (header)" 100 | for f in ${LOCAL_EXTRACT_DIR}/* 101 | do 102 | echo $f 103 | if [ -z ${PARTITION} ]; then 104 | cat $f | gunzip | tail -n+2 >> ${LOCAL_PARTITION_DIR}/${TARGET}.csv 105 | else 106 | cat $f | gunzip | tail -n+2 | awk -F, '{print >> ("'${LOCAL_PARTITION_DIR}'/"$1".csv")}' 107 | fi 108 | done 109 | 110 | echo "" 111 | echo "Add csv headers" 112 | echo "" 113 | # combine the csv header with the partitioned data 114 | for f in ${LOCAL_PARTITION_DIR}/* 115 | do 116 | echo $f 117 | CSV_FILE=${LOCAL_CSV_DIR}/$(basename $f) 118 | cat $CSV_HEADER $f > ${CSV_FILE} 119 | done 120 | 121 | echo "" 122 | echo "Create the readme" 123 | echo "" 124 | echo "${README}" 125 | sed -E 's/[#]+[ ]?//g; s/\[//g; s/\]/ /g;' ${README} > ${LOCAL_DEST_DIR}/readme.txt 126 | 127 | echo "" 128 | echo "Combine into a single zip file" 129 | echo "" 130 | 131 | # make a single zip with all the csvs in it 132 | cd ${TEMP_DIR} 133 | zip -r ${TARGET}/${TARGET}.zip ${TARGET}/* 134 | cd .. 135 | 136 | echo "" 137 | echo "gzip individual day files" 138 | echo "" 139 | 140 | # gzip individual csv files 141 | gzip ${LOCAL_CSV_DIR}/*.csv 142 | 143 | echo "" 144 | echo "Upload everything to GCS" 145 | echo "" 146 | # upload the whole mess to GCS 147 | gsutil -m cp -r ${LOCAL_DEST_DIR}/* ${GCS_DEST_DIR}/ 148 | 149 | # clean up temp dir 150 | rm -rf ${TEMP_DIR} 151 | -------------------------------------------------------------------------------- /data_documentation/update_table_documentation.py: -------------------------------------------------------------------------------- 1 | 2 | # coding: utf-8 3 | 4 | # # Update Table Documentation 5 | # 6 | # This file takes the docs in the folder `data_documentation` and adds them to bigquery and to gcs. The markdown file in `data_documentation` must have the same name as the file in bigquery at `global-fishing-watch:global-footprint-of-fisheries.TABLE_NAME`. Also, the markdown file must have the table schema formatted at the end of the file with markdown bullet points, as follows: 7 | # 8 | # ``` 9 | # # Table Schema 10 | # - field_1: 11 | # - field_2: lots 12 | # of stuff about field 2 13 | # - you can make a list of items for field 2 14 | # - if you indent them 15 | # - field_3: it is important to have the : 16 | # 17 | # this will also be in field 3 18 | # 19 | # - field_4: this is in the 4th field 20 | # ``` 21 | 22 | # In[5]: 23 | 24 | 25 | import os 26 | import json 27 | from subprocess import check_output 28 | import sys 29 | 30 | 31 | # In[19]: 32 | 33 | 34 | def de_markdownify(text): 35 | '''this gets rid of # characters, and also [ and ]. Can be improved''' 36 | return text.replace("# ","").replace("#","").replace("[","").replace("]"," ") 37 | 38 | def push_readme_to_gcs(table): 39 | with open("{}.md".format(table),'rU') as f: 40 | lines = f.read() 41 | # getting rid of the "#", and other formatting, and push to gcs 42 | lines2 = de_markdownify(lines) 43 | with open("temp.txt", 'w') as f: 44 | f.write(lines2) 45 | command = 'gsutil cp temp.txt gs://global_footprint_of_fisheries/{}/readme.txt'.format(table) 46 | os.system(command) 47 | os.system("rm temp.txt") 48 | 49 | def add_documentation_to_bigquery(table): 50 | 51 | '''this takes a markdown file at TABLE_NAME.md and loads 52 | it into a bigquery table, with the same name, at ''' 53 | 54 | with open("{}.md".format(table),'rU') as f: 55 | lines = f.read() 56 | # getting rid of the "#", and other formatting, and push to gcs 57 | lines = de_markdownify(lines) 58 | 59 | # this assumes that the file is divided into a line that equals Schema\n 60 | table_description = lines.split("\nTable Schema\n")[0] 61 | table_schema = lines.split("\nTable Schema\n")[1] 62 | # add description 63 | table_description = table_description.replace("'","'\\''").replace('"',"""'\\"'""") # so the command works 64 | command = '''bq update --description '{table_description}' global-fishing-watch:global_footprint_of_fisheries.{table}'''.format(table_description=table_description, 65 | table=table) 66 | os.system(command) 67 | 68 | # add schema 69 | add_schema(table, table_schema) 70 | 71 | 72 | def add_schema(table, table_schema): 73 | '''takes a table, and a table_schema which is written as a list in markdown, and loads 74 | the values into the table on bigquery. The fields in the list have to match perfectly with 75 | the fields in the existing bigquery table, or this will fail.''' 76 | descriptions = {} 77 | 78 | for line in table_schema[3:].split("\n - "): 79 | if(":" in line): 80 | k = line.split(":")[0] 81 | value = "".join(line.split(":")[1:]) 82 | descriptions[k]=value 83 | 84 | # Get the existing bigquery schema 85 | command = "bq show --format=json global-fishing-watch:global_footprint_of_fisheries.{table}".format(table=table) 86 | out = check_output(command.split(" ")) 87 | 88 | # update the schema structure to include a description from the markdown file 89 | j = json.loads(out) 90 | for i, s in enumerate(j['schema']['fields']): 91 | d = descriptions[s['name']] 92 | j['schema']['fields'][i]['description'] = d 93 | 94 | # load this new schema into bigquery 95 | with open('temp.json','w') as f: 96 | f.write(json.dumps(j['schema']['fields'])) 97 | command = "bq update global-fishing-watch:global_footprint_of_fisheries.{table} temp.json".format(table=table) 98 | os.system(command) 99 | os.system("rm -f temp.json") 100 | 101 | 102 | # Run this over all the markdown files in this folder 103 | 104 | 105 | from os import listdir 106 | from os.path import isfile, join 107 | onlyfiles = [f for f in listdir("./") if isfile(join("./", f))] 108 | for o in onlyfiles: 109 | if len(o)>3 and o[-3:] == ".md": 110 | table = o[:-3] 111 | add_documentation_to_bigquery(table) 112 | push_readme_to_gcs(table) 113 | 114 | -------------------------------------------------------------------------------- /data_documentation/vessels.md: -------------------------------------------------------------------------------- 1 | # Vessels 2 | 3 | ## Results of Neural Net Classifier and MMSI Matched to Registries 4 | 5 | These data are available in the following formats: 6 | - BigQuery Tables 7 | - CSVs 8 | 9 | Links to these data are available at [Global Fishing Watch's community page](https://globalfishingwatch.force.com/gfw/s/data_download). 10 | 11 | For additional information about these results, see the associated journal article: [D.A. Kroodsma, J. Mayorga, T. Hochberg, N.A. Miller, K. Boerder, F. Ferretti, A. Wilson, B. Bergman, T.D. White, B.A. Block, P. Woods, B. Sullivan, C. Costello, and B. Worm. "Tracking the global footprint of fisheries." Science 361.6378 (2018).](http://science.sciencemag.org/content/359/6378/904) 12 | 13 | License: [Creative Commons Attribution-ShareAlike 4.0 International license](https://creativecommons.org/licenses/by-sa/4.0/) 14 | 15 | For updates, links to example code, and more, visit: 16 | 17 | - [Global Fishing Watch R&D Site](globalfishingwatch.io/global-footprint-of-fisheries.html) 18 | - [GitHub Repo for Tracking the Global Footprint of Fisheries](GitHub.com/globalfishingwatch/tracking-global-footprint-of-fisheries) 19 | 20 | Description: This table includes all mmsi that were matched to a vessel regsitry, were identified through manual review or web searchers, or were classified by the neural network. MMSI that are not included did not have enough activity during our time period (2012 to 2016) to be classified by the neural network (vessels had to have at least 500 positions over a six month period). If an mmsi matched to multiple vessels, that mmsi may be repeated in this table. 21 | 22 | ## Table Schema 23 | - mmsi: Maritime Mobile Service Identity, the identifier for AIS 24 | - shipname: If this mmsi was matched to a vessel registry, the name that matched to the registry 25 | - callsign: If this mmsi was matched to a vessel registry, the International Radio Call Sign value that was matched 26 | - flag: an iso3 value for the flag state of the vessel. Only for vessels that have been matched to registries or have known values. 27 | - imo: If this mmsi was matched to a vessel registry, the Internationa Maratime Organization number that matched to the registry 28 | - registry_geartype: If this mmsi was matched to a vessel registry, and the vessel regisgtry included geartype, the geartype from the registry 29 | - inferred_geartype: the geartpye inferred by the neural network. If this value is null, it means the vessel did not have enough activity to be classified by the neural network. Possible geartypes include: 30 | - tug 31 | - gear 32 | - trawlers 33 | - purse_seines 34 | - squid_jigger 35 | - seismic_vessel 36 | - cargo_or_tanker 37 | - passenger 38 | - fixed_gear 39 | - other_fishing 40 | - reefer 41 | - drifting_longlines 42 | - inferred_geartype_score: the "score" from the neural network. Closer to 1 means that the neural network was more confident, although this is not a probability score. 43 | - inferred_subgeartype: in subgeartype inferred by the neural network. These are the same as the geartypes, except for the following: 44 | - cargo --> cargo_or_tanker 45 | - tanker --> cargo_or_tanker 46 | - set_gillnets --> fixed_gear 47 | - set_longlines --> fixed_gear 48 | - pots_and_traps --> fixed_gear 49 | - motor_passenger --> passenger 50 | - sailing --> passenger 51 | - trollers --> other_fishing 52 | - pole_and_line --> other_fishing 53 | - other_fishing --> other_fishing (other fishing in subgeartype includes all other types of fishing vessels, and in the geartype, it includes all of these plus pole and line and trollers) 54 | - inferred_subgeartype_score: the "score" from the neural network. Closer to 1 means that the neural network was more confident, although this is not a probability score. 55 | - registry_length: Length overall in meters from regsitries, if this mmsi has been matched to a registry and has a length from the registry. 56 | - inferred_length: Length, in meters, inferred by the neural network 57 | - registry_tonnage: Gross tonnage of vessel from registries, if this mmsi has been matched to a registry and has a gross tonnage listed. 58 | - inferred_tonnage: Gross tonnage of vessel inferred from the neural network. 59 | - registry_engine_power: Engine power in kilowatts of vessel from registries, if this mmsi has been matched to a registry and has an engine power listed. 60 | - inferred_engine_power: Main engine power, in kilowatts, inferred by the neural network. 61 | - source: A list of all registries that this mmsi was matched to. These lists include: 62 | - REVIEW: all human manual review or correction values 63 | - CCAMLR, CLAV, FFA, IATTC, ISSF, ITU, IUU, NPFC, SPRFMO WCPFC: values from respective organizations 64 | - CAN, EU, ISL, KOR, NOR, RUS, USA: values from respestive countries in iso3 code (or economic blocks) national vessel registry 65 | -------------------------------------------------------------------------------- /data_documentation/update_table_documentation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Update Table Documentation\n", 8 | "\n", 9 | "This file takes the docs in the folder `data_documentation` and adds them to bigquery and to gcs. The markdown file in `data_documentation` must have the same name as the file in bigquery at `global-fishing-watch:global-footprint-of-fisheries.TABLE_NAME`. Also, the markdown file must have the table schema formatted at the end of the file with markdown bullet points, as follows:\n", 10 | "\n", 11 | "```\n", 12 | "# Table Schema\n", 13 | " - field_1: \n", 14 | " - field_2: lots\n", 15 | " of stuff about field 2\n", 16 | " - you can make a list of items for field 2\n", 17 | " - if you indent them\n", 18 | " - field_3: it is important to have the :\n", 19 | " \n", 20 | " this will also be in field 3\n", 21 | " \n", 22 | " - field_4: this is in the 4th field\n", 23 | "```" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 5, 29 | "metadata": {}, 30 | "outputs": [], 31 | "source": [ 32 | "import os\n", 33 | "import json\n", 34 | "from subprocess import check_output\n", 35 | "import sys" 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": 19, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "def de_markdownify(text):\n", 45 | " '''this gets rid of # characters, and also [ and ]. Can be improved'''\n", 46 | " return text.replace(\"# \",\"\").replace(\"#\",\"\").replace(\"[\",\"\").replace(\"]\",\" \")\n", 47 | "\n", 48 | "def push_readme_to_gcs(table):\n", 49 | " with open(\"{}.md\".format(table),'rU') as f:\n", 50 | " lines = f.read()\n", 51 | " # getting rid of the \"#\", and other formatting, and push to gcs\n", 52 | " lines2 = de_markdownify(lines)\n", 53 | " with open(\"temp.txt\", 'w') as f:\n", 54 | " f.write(lines2) \n", 55 | " command = 'gsutil cp temp.txt gs://global_footprint_of_fisheries/{}/readme.txt'.format(table)\n", 56 | " os.system(command)\n", 57 | " os.system(\"rm temp.txt\")\n", 58 | "\n", 59 | "def add_documentation_to_bigquery(table):\n", 60 | " \n", 61 | " '''this takes a markdown file at TABLE_NAME.md and loads\n", 62 | " it into a bigquery table, with the same name, at '''\n", 63 | " \n", 64 | " with open(\"{}.md\".format(table),'rU') as f:\n", 65 | " lines = f.read()\n", 66 | " # getting rid of the \"#\", and other formatting, and push to gcs\n", 67 | " lines = de_markdownify(lines)\n", 68 | " \n", 69 | " # this assumes that the file is divided into a line that equals Schema\\n\n", 70 | " table_description = lines.split(\"\\nTable Schema\\n\")[0]\n", 71 | " table_schema = lines.split(\"\\nTable Schema\\n\")[1]\n", 72 | " # add description\n", 73 | " table_description = table_description.replace(\"'\",\"'\\\\''\").replace('\"',\"\"\"'\\\\\"'\"\"\") # so the command works\n", 74 | " command = '''bq update --description '{table_description}'\\\n", 75 | " global-fishing-watch:global_footprint_of_fisheries.{table}'''.format(table_description=table_description,\n", 76 | " table=table)\n", 77 | " os.system(command)\n", 78 | " \n", 79 | " # add schema\n", 80 | " add_schema(table, table_schema)\n", 81 | "\n", 82 | " \n", 83 | "def add_schema(table, table_schema):\n", 84 | " '''takes a table, and a table_schema which is written as a list in markdown, and loads \n", 85 | " the values into the table on bigquery. The fields in the list have to match perfectly with \n", 86 | " the fields in the existing bigquery table, or this will fail.'''\n", 87 | " descriptions = {}\n", 88 | "\n", 89 | " for line in table_schema[3:].split(\"\\n - \"):\n", 90 | " if(\":\" in line): \n", 91 | " k = line.split(\":\")[0]\n", 92 | " value = \"\".join(line.split(\":\")[1:])\n", 93 | " descriptions[k]=value\n", 94 | " \n", 95 | " # Get the existing bigquery schema\n", 96 | " command = \"bq show --format=json global-fishing-watch:global_footprint_of_fisheries.{table}\".format(table=table)\n", 97 | " out = check_output(command.split(\" \"))\n", 98 | "\n", 99 | " # update the schema structure to include a description from the markdown file\n", 100 | " j = json.loads(out)\n", 101 | " for i, s in enumerate(j['schema']['fields']):\n", 102 | " d = descriptions[s['name']]\n", 103 | " j['schema']['fields'][i]['description'] = d\n", 104 | "\n", 105 | " # load this new schema into bigquery\n", 106 | " with open('temp.json','w') as f:\n", 107 | " f.write(json.dumps(j['schema']['fields']))\n", 108 | " command = \"bq update global-fishing-watch:global_footprint_of_fisheries.{table} temp.json\".format(table=table)\n", 109 | " os.system(command)\n", 110 | " os.system(\"rm -f temp.json\")" 111 | ] 112 | }, 113 | { 114 | "cell_type": "code", 115 | "execution_count": 20, 116 | "metadata": {}, 117 | "outputs": [], 118 | "source": [ 119 | "table = 'fishing_effort'\n", 120 | "add_documentation_to_bigquery(table)" 121 | ] 122 | }, 123 | { 124 | "cell_type": "code", 125 | "execution_count": 21, 126 | "metadata": {}, 127 | "outputs": [], 128 | "source": [ 129 | "push_readme_to_gcs(table)" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 23, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [ 138 | "from os import listdir\n", 139 | "from os.path import isfile, join\n", 140 | "onlyfiles = [f for f in listdir(\"./\") if isfile(join(\"./\", f))]\n", 141 | "for o in onlyfiles:\n", 142 | " if len(o)>3 and o[-3:] == \".md\": \n", 143 | " table = o[:-3]\n", 144 | " add_documentation_to_bigquery(table) \n", 145 | " push_readme_to_gcs(table)" 146 | ] 147 | }, 148 | { 149 | "cell_type": "code", 150 | "execution_count": null, 151 | "metadata": {}, 152 | "outputs": [], 153 | "source": [] 154 | } 155 | ], 156 | "metadata": { 157 | "kernelspec": { 158 | "display_name": "Python 2", 159 | "language": "python", 160 | "name": "python2" 161 | }, 162 | "language_info": { 163 | "codemirror_mode": { 164 | "name": "ipython", 165 | "version": 2 166 | }, 167 | "file_extension": ".py", 168 | "mimetype": "text/x-python", 169 | "name": "python", 170 | "nbconvert_exporter": "python", 171 | "pygments_lexer": "ipython2", 172 | "version": "2.7.14" 173 | } 174 | }, 175 | "nbformat": 4, 176 | "nbformat_minor": 2 177 | } 178 | -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Area of the Ocean that is Fished" 3 | subtitle: "The Global Footprint of Fisheries" 4 | output: github_document 5 | --- 6 | 7 | ```{r setup, include=FALSE} 8 | knitr::opts_chunk$set(echo = TRUE, warning = FALSE, comment = FALSE, message = FALSE) 9 | ``` 10 | 11 | Load packages 12 | ```{r} 13 | library(bigrquery) 14 | library(dplyr) 15 | library(raster) 16 | library(sp) 17 | library(rgdal) 18 | library(sf) 19 | library(rgeos) 20 | library(ggplot2) 21 | ``` 22 | 23 | ```{r, echo=FALSE} 24 | BQ_connection <- dbConnect(dbi_driver(), dataset = "", project = "world-fishing-827") 25 | 26 | ``` 27 | 28 | 29 | Query to get the fishing effort at 0.5 degree resolution from the GFW public Big Query 30 | table. [Fishing Effort](https://bigquery.cloud.google.com/table/global-fishing-watch:global_footprint_of_fisheries.fishing_effort?pli=1) 31 | ```{sql connection = BQ_connection, output.var = "total_fishing_effort_05"} 32 | SELECT 33 | SUM(fishing_hours)/(COS(RADIANS(lat_bin/2)) * POW(111, 2)) hours_sq_km, 34 | lat_bin, 35 | lon_bin 36 | FROM ( 37 | SELECT 38 | FLOOR((lat_bin/100)/0.5) * 0.5 lat_bin, 39 | FLOOR((lon_bin/100)/0.5) * 0.5 lon_bin, 40 | fishing_hours 41 | FROM 42 | [global-fishing-watch:global_footprint_of_fisheries.fishing_effort] 43 | WHERE 44 | _PARTITIONTIME >= "2016-01-01 00:00:00" 45 | AND _PARTITIONTIME < "2017-01-01 00:00:00" 46 | AND fishing_hours > 0) 47 | GROUP BY 48 | lat_bin, 49 | lon_bin 50 | ``` 51 | 52 | Generate a grid of points at 0.5 53 | ```{r} 54 | grid_latlon <- expand.grid(lat =seq(min(total_fishing_effort_05$lat_bin), 55 | max(total_fishing_effort_05$lat_bin), 0.5), 56 | lon = seq(min(total_fishing_effort_05$lon_bin), 57 | max(total_fishing_effort_05$lon_bin), 0.5)) 58 | ``` 59 | 60 | Join the global grid to the global fishing data. Assign locations with no fishing 61 | a fishing value of 0. 62 | ```{r} 63 | gridded_fishing = left_join(grid_latlon, total_fishing_effort_05, by = c('lat' = 'lat_bin', 'lon' = 'lon_bin')) 64 | gridded_fishing$hours = ifelse(is.na(gridded_fishing$hours), 0, gridded_fishing$hours) 65 | ``` 66 | 67 | Convert fishing effort dataframe into a spatial dataframe (specify lon and lat as x, y) 68 | ```{r} 69 | coordinates(gridded_fishing)=~lon+lat 70 | ``` 71 | 72 | Specify `EPSG:4326` as initial projection for the gridded fishing effort. 73 | ```{r} 74 | # set it to EPSG:4326 75 | proj4string(gridded_fishing)=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") 76 | 77 | #ensure fishing in on regular grid 78 | gridded(gridded_fishing) = TRUE 79 | ``` 80 | 81 | 82 | Generate the fishing effort raster. Specify original projection and extent, 83 | then project the raster into Gall-Peters equal area projection 84 | ```{r} 85 | fishing_raster_05 = rasterFromXYZ(gridded_fishing, crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") 86 | bb = extent(-180.25, 179.75, -88.25, 81.75) 87 | fishing_raster_05 = setExtent(fishing_raster_05, bb, keepres = TRUE) 88 | #this is Gall-Peters Equal Area Projection 89 | fishing_raster_05 = projectRaster(fishing_raster_05, crs = "+proj=cea +lon_0=0 +x_0=0 +y_0=0 +lat_ts=45 +datum=WGS84 +units=m +no_defs", over = TRUE) 90 | ``` 91 | 92 | Export raster 93 | ```{r, eval=FALSE} 94 | writeRaster(fishing_raster_05, '~/Documents/GlobalFishingWatch/Global_raster_paper/oceans_equal_area/fishing_raster_05_20180228.tif', format = 'GTiff', overwrite = TRUE) 95 | ``` 96 | 97 | 98 | Load a 10m Oceans shapefile from Natural Earth http://www.naturalearthdata.com/downloads/10m-physical-vectors/: 99 | This file has had polygons dissolved into single ocean polygon and has been projected into Gall-Peters Equal area projections already. 100 | ```{r} 101 | ocean_cea_sf <- read_sf('~/Documents/GlobalFishingWatch/shapefiles/oceans_CEA_equal_area/oceans_cea.shp') 102 | ``` 103 | 104 | For completeness and to ensure the appropriate projection, here we reproject the oceans 105 | shapefile using a Gall-Peters Equal Area Projection to ensure equal area at all latitudes. 106 | ```{r} 107 | ocean_cea_sf <- st_transform(ocean_cea_sf, crs = "+proj=cea +lon_0=0 +lat_ts=45 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs") 108 | ``` 109 | 110 | Check the vector file to ensure projection look appropriate 111 | ```{r} 112 | head(ocean_cea_sf) 113 | ggplot() + 114 | geom_sf(data = ocean_cea_sf, fill = 'dodgerblue') 115 | ``` 116 | 117 | For simplicity assign areas of fishing a value of 1 and those without NA. 118 | ```{r} 119 | fishing_raster_05[fishing_raster_05[] > 0] <- 1 120 | fishing_raster_05[fishing_raster_05[] <= 0] <- NA 121 | ``` 122 | 123 | A quick visual check to see if the raster looks appropriate (though it will not yet have the appropriate projection) 124 | ```{r} 125 | plot(fishing_raster_05) 126 | ``` 127 | 128 | Convert the raster to a vector file which makes it possible to compare with the oceans vector. 129 | ```{r} 130 | #raster to polygon using maximum number of vertices (n = 16) 131 | fishing_polygon <- rasterToPolygons(fishing_raster_05, dissolve = TRUE, n = 16) 132 | #convert Spatial dataframe to Simple features 133 | fishing_polygon_sf <- st_as_sf(fishing_polygon) 134 | #reproject fishing to Gall-Peters Equal area projection 135 | fishing_polygon_sf <- st_transform(fishing_polygon_sf, crs = "+proj=cea +lon_0=0 +lat_ts=45 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs") 136 | ``` 137 | 138 | ```{r} 139 | ggplot() + 140 | geom_sf(data = fishing_polygon_sf, fill = 'tomato') 141 | ``` 142 | 143 | 144 | Identify where the fishing and ocean vector files intersect. Ensures that for grid cells 145 | that overlap the coastline we only include the area that is within the ocean. 146 | In some sense, this provides a smaller grid along the coastline. 147 | ```{r} 148 | fishing_ocean_intersect <- sf::st_intersection(x = ocean_cea_sf, fishing_polygon_sf) 149 | ``` 150 | 151 | Calculate the area of the fishing/ocean intersection vector and the area of the ocean vector, both of which are in equal area projection. The units are relatively unimportant, but in m^2^. Calculate the percent of the ocean that is covered fishing. 152 | ```{r} 153 | fishing_area <- st_area(fishing_ocean_intersect) 154 | ocean_area <- st_area(ocean_cea_sf) 155 | (fishing_area/ocean_area) * 100 156 | ``` 157 | 158 | ```{r} 159 | library(ggplot2) 160 | ggplot() + 161 | geom_sf(data = fishing_ocean_intersect, fill = 'dodgerblue') 162 | ``` 163 | 164 | 165 | #### Same analysis using previous fishing raster 166 | Here we illustrate the same calculation using a fishing raster that 167 | was generated using an earlier version of the fishing effort dataset. This dataset 168 | may have overemphasized squid-jigger fishing. 169 | ```{r} 170 | fishing_raster_05_old <- raster('~/Documents/GlobalFishingWatch/Projects/Global_raster_paper/oceans_equal_area/fishing_raster_05.tif') 171 | ``` 172 | 173 | Analysis same as before: Convert grid cells with fishing to 1's and grid cells without fishing to NA. 174 | ```{r} 175 | fishing_raster_05_old[fishing_raster_05_old[] > 0] <- 1 176 | fishing_raster_05_old[fishing_raster_05_old[] <= 0] <- NA 177 | ``` 178 | 179 | A quick visual check to see if the raster looks appropriate (though it will not yet have the appropriate projection). 180 | ```{r} 181 | plot(fishing_raster_05_old) 182 | ``` 183 | 184 | Convert the raster to a vector, which makes it possible to compare with the oceans vector. 185 | ```{r} 186 | #raster to polygon using maximum number of vertices (n = 16) 187 | fishing_polygon_old <- rasterToPolygons(fishing_raster_05_old, dissolve = TRUE, n = 16) 188 | #convert Spatial dataframe to Simple features 189 | fishing_polygon_old_sf <- st_as_sf(fishing_polygon_old) 190 | #reproject fishing to Gall-Peters Equal area projection 191 | fishing_polygon_old_sf <- st_transform(fishing_polygon_old_sf, crs = "+proj=cea +lon_0=0 +lat_ts=45 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs") 192 | ``` 193 | 194 | 195 | Identify where the fishing and ocean vector files intersect. Ensures we clip the 196 | fishing raster to the ocean. 197 | ```{r} 198 | fishing_old_ocean_intersect <- sf::st_intersection(x = ocean_cea_sf, fishing_polygon_old_sf) 199 | ``` 200 | 201 | Calculate the area of the fishing/ocean intersection vector and the area of the ocean vector, both of which are in equal area projection. The units are relatively unimportant, but in m^2^. Calculate the percent of the ocean that is covered fishing. 202 | ```{r} 203 | fishing_area_old <- st_area(fishing_old_ocean_intersect) 204 | ocean_area <- st_area(ocean_cea_sf) 205 | (fishing_area_old/ocean_area) * 100 206 | ``` 207 | 208 | 209 | Note that this value is ~55% 210 | -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/calculating_area_fished.md: -------------------------------------------------------------------------------- 1 | Area of the Ocean that is Fished 2 | ================ 3 | 4 | Analysis by Nate Miller 5 | 6 | Load packages 7 | 8 | ``` r 9 | library(bigrquery) 10 | library(dplyr) 11 | library(raster) 12 | library(sp) 13 | library(rgdal) 14 | library(sf) 15 | library(rgeos) 16 | library(ggplot2) 17 | ``` 18 | 19 | Query to get the fishing effort at 0.5 degree resolution from the GFW public Big Query table. [Fishing Effort](https://bigquery.cloud.google.com/table/global-fishing-watch:global_footprint_of_fisheries.fishing_effort?pli=1) 20 | 21 | ``` sql 22 | SELECT 23 | SUM(fishing_hours)/(COS(RADIANS(lat_bin/2)) * POW(111, 2)) hours_sq_km, 24 | lat_bin, 25 | lon_bin 26 | FROM ( 27 | SELECT 28 | FLOOR((lat_bin/100)/0.5) * 0.5 lat_bin, 29 | FLOOR((lon_bin/100)/0.5) * 0.5 lon_bin, 30 | fishing_hours 31 | FROM 32 | [global-fishing-watch:global_footprint_of_fisheries.fishing_effort] 33 | WHERE 34 | _PARTITIONTIME >= "2016-01-01 00:00:00" 35 | AND _PARTITIONTIME < "2017-01-01 00:00:00" 36 | AND fishing_hours > 0) 37 | GROUP BY 38 | lat_bin, 39 | lon_bin 40 | ``` 41 | 42 | Generate a grid of points at 0.5 43 | 44 | ``` r 45 | grid_latlon <- expand.grid(lat =seq(min(total_fishing_effort_05$lat_bin), 46 | max(total_fishing_effort_05$lat_bin), 0.5), 47 | lon = seq(min(total_fishing_effort_05$lon_bin), 48 | max(total_fishing_effort_05$lon_bin), 0.5)) 49 | ``` 50 | 51 | Join the global grid to the global fishing data. Assign locations with no fishing a fishing value of 0. 52 | 53 | ``` r 54 | gridded_fishing = left_join(grid_latlon, total_fishing_effort_05, by = c('lat' = 'lat_bin', 'lon' = 'lon_bin')) 55 | gridded_fishing$hours = ifelse(is.na(gridded_fishing$hours), 0, gridded_fishing$hours) 56 | ``` 57 | 58 | Convert fishing effort dataframe into a spatial dataframe (specify lon and lat as x, y) 59 | 60 | ``` r 61 | coordinates(gridded_fishing)=~lon+lat 62 | ``` 63 | 64 | Specify `EPSG:4326` as initial projection for the gridded fishing effort. 65 | 66 | ``` r 67 | # set it to EPSG:4326 68 | proj4string(gridded_fishing)=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") 69 | 70 | #ensure fishing in on regular grid 71 | gridded(gridded_fishing) = TRUE 72 | ``` 73 | 74 | Generate the fishing effort raster. Specify original projection and extent, then project the raster into Gall-Peters equal area projection 75 | 76 | ``` r 77 | fishing_raster_05 = rasterFromXYZ(gridded_fishing, crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") 78 | bb = extent(-180.25, 179.75, -88.25, 81.75) 79 | fishing_raster_05 = setExtent(fishing_raster_05, bb, keepres = TRUE) 80 | #this is Gall-Peters Equal Area Projection 81 | fishing_raster_05 = projectRaster(fishing_raster_05, crs = "+proj=cea +lon_0=0 +x_0=0 +y_0=0 +lat_ts=45 +datum=WGS84 +units=m +no_defs", over = TRUE) 82 | ``` 83 | 84 | Export raster 85 | 86 | ``` r 87 | writeRaster(fishing_raster_05, '~/Documents/GlobalFishingWatch/Global_raster_paper/oceans_equal_area/fishing_raster_05_20180228.tif', format = 'GTiff', overwrite = TRUE) 88 | ``` 89 | 90 | Load a 10m Oceans shapefile from Natural Earth : 91 | This file has had polygons dissolved into single ocean polygon and has been projected into Gall-Peters Equal area projections already. 92 | 93 | ``` r 94 | ocean_cea_sf <- read_sf('~/Documents/GlobalFishingWatch/shapefiles/oceans_CEA_equal_area/oceans_cea.shp') 95 | ``` 96 | 97 | For completeness and to ensure the appropriate projection, here we reproject the oceans shapefile using a Gall-Peters Equal Area Projection to ensure equal area at all latitudes. 98 | 99 | ``` r 100 | ocean_cea_sf <- st_transform(ocean_cea_sf, crs = "+proj=cea +lon_0=0 +lat_ts=45 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs") 101 | ``` 102 | 103 | Check the vector file to ensure projection look appropriate 104 | 105 | ``` r 106 | head(ocean_cea_sf) 107 | ``` 108 | 109 | FALSE Simple feature collection with 1 feature and 19 fields 110 | FALSE geometry type: MULTIPOLYGON 111 | FALSE dimension: XY 112 | FALSE bbox: xmin: -14192430 ymin: -8953315 xmax: 14192430 ymax: 8984818 113 | FALSE epsg (SRID): NA 114 | FALSE proj4string: +proj=cea +lon_0=0 +lat_ts=45 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs 115 | FALSE # A tibble: 1 x 20 116 | FALSE featurecla scalerank fishingcou fishingmea not_fishin meanmean 117 | FALSE 118 | FALSE 1 Ocean 0 0.0000141 1.00 0.454 0.0733 119 | FALSE # ... with 14 more variables: overlapmea , pos20_mean , 120 | FALSE # nofish_mea , test_mean , X0725_mean , 121 | FALSE # X0725_20_me , nonfish_me , X0728mean_m , 122 | FALSE # nofish_und , nofish_05m , high_seasm , 123 | FALSE # highseas_m , highseas_1 , geometry 124 | 125 | ``` r 126 | ggplot() + 127 | geom_sf(data = ocean_cea_sf, fill = 'dodgerblue') 128 | ``` 129 | 130 | ![](calculating_area_fished_files/figure-markdown_github/unnamed-chunk-12-1.png) 131 | 132 | For simplicity assign areas of fishing a value of 1 and those without NA. 133 | 134 | ``` r 135 | fishing_raster_05[fishing_raster_05[] > 0] <- 1 136 | fishing_raster_05[fishing_raster_05[] <= 0] <- NA 137 | ``` 138 | 139 | A quick visual check to see if the raster looks appropriate (though it will not yet have the appropriate projection) 140 | 141 | ``` r 142 | plot(fishing_raster_05) 143 | ``` 144 | 145 | ![](calculating_area_fished_files/figure-markdown_github/unnamed-chunk-14-1.png) 146 | 147 | Convert the raster to a vector file which makes it possible to compare with the oceans vector. 148 | 149 | ``` r 150 | #raster to polygon using maximum number of vertices (n = 16) 151 | fishing_polygon <- rasterToPolygons(fishing_raster_05, dissolve = TRUE, n = 16) 152 | #convert Spatial dataframe to Simple features 153 | fishing_polygon_sf <- st_as_sf(fishing_polygon) 154 | #reproject fishing to Gall-Peters Equal area projection 155 | fishing_polygon_sf <- st_transform(fishing_polygon_sf, crs = "+proj=cea +lon_0=0 +lat_ts=45 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs") 156 | ``` 157 | 158 | ``` r 159 | ggplot() + 160 | geom_sf(data = fishing_polygon_sf, fill = 'tomato') 161 | ``` 162 | 163 | ![](calculating_area_fished_files/figure-markdown_github/unnamed-chunk-16-1.png) 164 | 165 | Identify where the fishing and ocean vector files intersect. Ensures that for grid cells that overlap the coastline we only include the area that is within the ocean. In some sense, this provides a smaller grid along the coastline. 166 | 167 | ``` r 168 | fishing_ocean_intersect <- sf::st_intersection(x = ocean_cea_sf, fishing_polygon_sf) 169 | ``` 170 | 171 | Calculate the area of the fishing/ocean intersection vector and the area of the ocean vector, both of which are in equal area projection. The units are relatively unimportant, but in m2. Calculate the percent of the ocean that is covered fishing. 172 | 173 | ``` r 174 | fishing_area <- st_area(fishing_ocean_intersect) 175 | ocean_area <- st_area(ocean_cea_sf) 176 | (fishing_area/ocean_area) * 100 177 | ``` 178 | 179 | FALSE 50.55793 1 180 | 181 | ``` r 182 | library(ggplot2) 183 | ggplot() + 184 | geom_sf(data = fishing_ocean_intersect, fill = 'dodgerblue') 185 | ``` 186 | 187 | ![](calculating_area_fished_files/figure-markdown_github/unnamed-chunk-19-1.png) 188 | 189 | #### Same analysis using previous fishing raster 190 | 191 | Here we illustrate the same calculation using a fishing raster that was generated using an earlier version of the fishing effort dataset. This dataset may have overemphasized squid-jigger fishing. 192 | 193 | ``` r 194 | fishing_raster_05_old <- raster('~/Documents/GlobalFishingWatch/Projects/Global_raster_paper/oceans_equal_area/fishing_raster_05.tif') 195 | ``` 196 | 197 | Analysis same as before: Convert grid cells with fishing to 1's and grid cells without fishing to NA. 198 | 199 | ``` r 200 | fishing_raster_05_old[fishing_raster_05_old[] > 0] <- 1 201 | fishing_raster_05_old[fishing_raster_05_old[] <= 0] <- NA 202 | ``` 203 | 204 | A quick visual check to see if the raster looks appropriate (though it will not yet have the appropriate projection). 205 | 206 | ``` r 207 | plot(fishing_raster_05_old) 208 | ``` 209 | 210 | ![](calculating_area_fished_files/figure-markdown_github/unnamed-chunk-22-1.png) 211 | 212 | Convert the raster to a vector, which makes it possible to compare with the oceans vector. 213 | 214 | ``` r 215 | #raster to polygon using maximum number of vertices (n = 16) 216 | fishing_polygon_old <- rasterToPolygons(fishing_raster_05_old, dissolve = TRUE, n = 16) 217 | #convert Spatial dataframe to Simple features 218 | fishing_polygon_old_sf <- st_as_sf(fishing_polygon_old) 219 | #reproject fishing to Gall-Peters Equal area projection 220 | fishing_polygon_old_sf <- st_transform(fishing_polygon_old_sf, crs = "+proj=cea +lon_0=0 +lat_ts=45 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs") 221 | ``` 222 | 223 | Identify where the fishing and ocean vector files intersect. Ensures we clip the fishing raster to the ocean. 224 | 225 | ``` r 226 | fishing_old_ocean_intersect <- sf::st_intersection(x = ocean_cea_sf, fishing_polygon_old_sf) 227 | ``` 228 | 229 | Calculate the area of the fishing/ocean intersection vector and the area of the ocean vector, both of which are in equal area projection. The units are relatively unimportant, but in m2. Calculate the percent of the ocean that is covered fishing. 230 | 231 | ``` r 232 | fishing_area_old <- st_area(fishing_old_ocean_intersect) 233 | ocean_area <- st_area(ocean_cea_sf) 234 | (fishing_area_old/ocean_area) * 100 235 | ``` 236 | 237 | FALSE 54.4856 1 238 | 239 | Note that this value is ~55% 240 | -------------------------------------------------------------------------------- /Figure_1/Tracking_Global_Footprint_Fisheries_Figure1.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Tracking the Global Footprint of Fisheries: Figure 1" 3 | output: html_document 4 | --- 5 | 6 | ```{r setup, include=FALSE} 7 | knitr::opts_chunk$set(echo = TRUE, message = FALSE, comment = FALSE, warning = FALSE) 8 | ``` 9 | 10 | ```{r echo = FALSE, message=FALSE, comment=FALSE} 11 | library(ggplot2) 12 | library(bigrquery) 13 | library(sf) 14 | BQ_connection <- dbConnect(dbi_driver(), dataset = "", project = "world-fishing-827") 15 | ``` 16 | 17 | Code for making Figure 1 from Tracking the Footprint of Global Fisheries paper from 18 | public Big Query datasets provided by Global Fishing Watch. 19 | 20 | ##### Figure prep 21 | ```{r} 22 | theme_gfw_paper <- theme(text = element_text(family="Arial", face="bold", size=12), 23 | axis.text.x = element_text(size = 12, colour = "black"), 24 | axis.text.y = element_text(size = 12, colour = "black"), 25 | axis.line.x = element_line(colour = "black", size = .5), 26 | axis.line.y = element_line(colour = "black", size = .5), 27 | legend.position = "bottom", 28 | axis.title.y = element_text(size = 12, margin=margin(0,15,0,0)), 29 | axis.title.x = element_text(size = 12, margin=margin(15,0,0,0)), 30 | panel.grid.major = element_blank(), 31 | panel.grid.minor = element_blank(), 32 | panel.background = element_blank(), 33 | axis.line = element_line(colour = "black"), 34 | plot.margin = unit(c(1,1,1,1), "cm") 35 | ) 36 | ``` 37 | 38 | 39 | Load shapefile downloaded from Natural Earth (110m resolution) 40 | ```{r} 41 | land_df <- read_sf('../data/ne_110m_land/ne_110m_land.shp', quiet = TRUE) 42 | # This shapefile is available from http://www.naturalearthdata.com/downloads/110m-physical-vectors/110m-land/ 43 | ``` 44 | 45 | 46 | #### SQL query for Total Fishing Effort (0.5 degree) 47 | ```{sql connection = BQ_connection, output.var = "total_fishing_effort_05"} 48 | SELECT 49 | SUM(fishing_hours)/(COS(RADIANS(lat_bin/2)) * POW(111, 2)) hours_sq_km, 50 | lat_bin, 51 | lon_bin 52 | FROM ( 53 | SELECT 54 | FLOOR((lat_bin/100)/0.5) * 0.5 lat_bin, 55 | FLOOR((lon_bin/100)/0.5) * 0.5 lon_bin, 56 | fishing_hours 57 | FROM 58 | [global-fishing-watch:global_footprint_of_fisheries.fishing_effort] 59 | WHERE 60 | _PARTITIONTIME >= "2016-01-01 00:00:00" 61 | AND _PARTITIONTIME < "2017-01-01 00:00:00" 62 | AND fishing_hours > 0) 63 | GROUP BY 64 | lat_bin, 65 | lon_bin 66 | ``` 67 | 68 | 69 | 70 | #### SQL Query for Fishing Effort by Geartype (0.5 degree) 71 | ```{sql connection = BQ_connection, output.var = "fishing_effort_by_type_05"} 72 | SELECT 73 | SUM(fishing_hours)/(COS(RADIANS(lat_bin/2)) * POW(111, 2)) hours_sq_km, 74 | lat_bin, 75 | lon_bin, 76 | geartype 77 | FROM ( 78 | SELECT 79 | FLOOR((lat_bin/100)/0.5) * 0.5 lat_bin, 80 | FLOOR((lon_bin/100)/0.5) * 0.5 lon_bin, 81 | fishing_hours, 82 | geartype 83 | FROM 84 | [global-fishing-watch:global_footprint_of_fisheries.fishing_effort] 85 | WHERE 86 | _PARTITIONTIME >= "2016-01-01 00:00:00" 87 | AND _PARTITIONTIME < "2017-01-01 00:00:00" 88 | AND fishing_hours > 0) 89 | GROUP BY 90 | lat_bin, 91 | lon_bin, 92 | geartype 93 | ``` 94 | 95 | 96 | ```{r} 97 | head(total_fishing_effort_05) 98 | ``` 99 | 100 | 101 | ```{r} 102 | head(fishing_effort_by_type_05) 103 | ``` 104 | 105 | #### Process data 106 | Data processing for plotting total fishing effort 107 | ```{r} 108 | total_fishing_effort_05$hours_sq_km = total_fishing_effort_05$hours_sq_km * 10000 109 | total_fishing_effort_05$logHours = log10(total_fishing_effort_05$hours_sq_km) 110 | total_fishing_effort_05$logHours = ifelse(total_fishing_effort_05$logHours >= 5, 111 | 5, 112 | total_fishing_effort_05$logHours) 113 | total_fishing_effort_05$logHours = ifelse(total_fishing_effort_05$logHours <= 1, 114 | 1, 115 | total_fishing_effort_05$logHours) 116 | 117 | total_fishing_effort_05 = total_fishing_effort_05 %>% 118 | filter(lat_bin < 85 & lat_bin > -85 & lon_bin > -180 & lon_bin < 180) 119 | ``` 120 | 121 | 122 | Data processing for plotting fishing effort by geartype 123 | ```{r} 124 | 125 | fishing_effort_by_type_05$hours_sq_km = fishing_effort_by_type_05$hours_sq_km * 10000 126 | fishing_effort_by_type_05$logHours = log10(fishing_effort_by_type_05$hours_sq_km) 127 | fishing_effort_by_type_05$logHours = ifelse(fishing_effort_by_type_05$logHours >= 5, 128 | 5, 129 | fishing_effort_by_type_05$logHours) 130 | fishing_effort_by_type_05$logHours = ifelse(fishing_effort_by_type_05$logHours <= 1, 131 | 1, 132 | fishing_effort_by_type_05$logHours) 133 | 134 | purse_seine_effort_05 = fishing_effort_by_type_05 %>% 135 | filter(geartype == 'purse_seines'& 136 | lat_bin > -90 & 137 | lat_bin < 90 & 138 | lon_bin > -180 & 139 | lon_bin < 180) 140 | 141 | 142 | longline_effort_05 = fishing_effort_by_type_05 %>% 143 | filter(geartype == 'drifting_longlines'& 144 | lat_bin > -90 & 145 | lat_bin < 85 & 146 | lon_bin > -180 & 147 | lon_bin < 180) 148 | 149 | trawler_effort_05 = fishing_effort_by_type_05 %>% 150 | filter(geartype == 'trawlers' & 151 | lat_bin > -90 & 152 | lat_bin < 90 & 153 | lon_bin > -180 & 154 | lon_bin < 180) 155 | 156 | ``` 157 | 158 | 159 | #### Generating Fishing Effort Figure Panels 160 | Color scheme 161 | ```{r, fig.height=8, fig.width=15} 162 | 163 | cont_fill = 'white'#'grey30' #'grey80' 164 | back_fill = 'white'#'#202A50' #'black' #'#1F2A4F' 165 | cont_color = 'grey60'#'grey30' 166 | #color_grad = c( "#414487", "#2A788E", "#22A884", "#7AD151","#FDE725","#FFC04C") 167 | color_grad = c("#C6DBEF", "#9ECAE1", "#6BAED6","#4292C6" ,"#2171B5", "#084594") #blues 168 | ``` 169 | 170 | ##### Total Effort 171 | ```{r} 172 | total_effort_05 <- ggplot() + 173 | geom_raster(data = total_fishing_effort_05, 174 | aes(x = lon_bin, y = lat_bin, fill = logHours), 175 | interpolate = FALSE) + 176 | geom_sf(data = land_df, 177 | color = cont_color, 178 | size = 0.5, 179 | fill = cont_fill) + 180 | scale_fill_viridis_c("Vessel Density", na.value = NA, limits = c(1, 5), 181 | breaks=c(seq(1,5,length.out = 4)), 182 | labels = c('1','10', '100','> 1000' ), 183 | direction = -1)+ 184 | coord_sf(datum = NA) + 185 | theme_gfw_paper + 186 | theme(axis.title.x = element_blank(), 187 | axis.title.y = element_blank(), 188 | axis.text.x = element_blank(), 189 | axis.text.y = element_blank(), 190 | axis.ticks = element_blank(), 191 | axis.line = element_blank(), 192 | panel.background = element_rect(color = NA,fill = back_fill), 193 | legend.position = 'none', 194 | legend.direction="horizontal", 195 | plot.margin=unit(c(0,-0.5,-0.5,-0.5), 'cm'), 196 | legend.text = element_text(size = 6, family = 'Times New Roman'), 197 | legend.title = element_text(size = 7, family = 'Times New Roman')) 198 | total_effort_05 199 | ``` 200 | 201 | ##### Purse Seine Effort 202 | 203 | ```{r} 204 | purse_seine_05 <- ggplot() + 205 | geom_raster(data = purse_seine_effort_05, 206 | aes(x = lon_bin, y = lat_bin, fill = logHours), 207 | interpolate = TRUE) + 208 | geom_sf(data = land_df, 209 | color = cont_color, 210 | size = 0.5, 211 | fill = cont_fill) + 212 | scale_fill_viridis_c("Vessel Density", na.value = NA, limits = c(1, 5), 213 | breaks=c(seq(1,5,length.out = 4)), 214 | labels = c('1','10', '100','> 1000' ), 215 | direction = -1) + 216 | coord_sf(datum = NA) + 217 | theme_gfw_paper + 218 | theme(axis.title.x = element_blank(), 219 | axis.title.y = element_blank(), 220 | axis.text.x = element_blank(), 221 | axis.text.y = element_blank(), 222 | axis.ticks = element_blank(), 223 | axis.line = element_blank(), 224 | panel.border = element_blank(), 225 | panel.background = element_rect(color = NA,fill = back_fill), 226 | legend.position = 'none', 227 | plot.margin=unit(c(0,-0.5,-0.5,-0.5), 'cm')) 228 | purse_seine_05 229 | ``` 230 | 231 | ##### Drifting Longline Effort 232 | 233 | ```{r} 234 | 235 | longline_05 <- ggplot() + 236 | geom_raster(data = longline_effort_05, 237 | aes(x = lon_bin, y = lat_bin, fill = logHours), 238 | interpolate = TRUE) + 239 | geom_sf(data = land_df, 240 | color = cont_color, 241 | size = 0.5, 242 | fill = cont_fill) + 243 | scale_fill_viridis_c("Vessel Density", na.value = NA, limits = c(1, 5), 244 | breaks=c(seq(1,5,length.out = 4)), 245 | labels = c('1','10', '100','> 1000' ), 246 | direction = -1) + 247 | coord_sf(datum = NA) + 248 | theme_gfw_paper + 249 | theme(axis.title.x = element_blank(), 250 | axis.title.y = element_blank(), 251 | axis.text.x = element_blank(), 252 | axis.text.y = element_blank(), 253 | axis.ticks = element_blank(), 254 | axis.line = element_blank(), 255 | panel.background = element_rect(color = NA,fill = back_fill), 256 | legend.position = 'none', 257 | plot.margin=unit(c(0,-0.5,-0.5,-0.5), "cm")) 258 | longline_05 259 | ``` 260 | 261 | ##### Trawler Effort 262 | 263 | ```{r} 264 | trawling_05 <- ggplot() + 265 | geom_raster(data = trawler_effort_05, 266 | aes(x = lon_bin, y = lat_bin, fill = logHours), 267 | interpolate = TRUE) + 268 | geom_sf(data = land_df, 269 | color = cont_color, 270 | size = 0.5, 271 | fill = cont_fill) + 272 | scale_fill_viridis_c("Vessel Density", na.value = NA, limits = c(1, 5), 273 | breaks=c(seq(1,5,length.out = 4)), 274 | labels = c('1','10', '100','> 1000' ), 275 | direction = -1) + 276 | coord_sf(datum = NA) + 277 | theme_gfw_paper + 278 | theme(axis.title.x = element_blank(), 279 | axis.title.y = element_blank(), 280 | axis.text.x = element_blank(), 281 | axis.text.y = element_blank(), 282 | axis.ticks = element_blank(), 283 | axis.line = element_blank(), 284 | panel.background = element_rect(color = NA,fill = back_fill), 285 | legend.position = 'none', 286 | plot.margin=unit(c(-0.5,-0.5,-0.5,-0.5), "cm")) 287 | trawling_05 288 | ``` 289 | 290 | 291 | 292 | #### Generating Legends 293 | Code for generating legend to a a set of gridded fishing plots. 294 | Requires making a plot with a legend and then extracting the legend using get_legend 295 | First for the fishing effort and the for the NPP 296 | 297 | ```{r, eval=FALSE} 298 | library(cowplot) 299 | #plot with legend 300 | #color_grad = c( "#414487", "#2A788E", "#22A884", "#7AD151","#FDE725","#FFC04C") 301 | 302 | legend_plot_05 = ggplot() + 303 | geom_raster(data = total_fishing_effort_05, 304 | aes(x = lon_bin, y = lat_bin, fill = logHours), 305 | interpolate = FALSE) + 306 | geom_polygon(data = land_df, 307 | fill = cont_fill) + 308 | scale_fill_viridis_c("Vessel Density", 309 | na.value = NA, 310 | limits = c(1, 5), 311 | breaks=c(seq(1,5,length.out = 5)), 312 | direction = -1) + 313 | guides(fill = guide_colorbar(barwidth = 12, 314 | barheight = 0.3, 315 | title.hjust = 0.5, 316 | title.position = 'bottom')) 317 | 318 | effort_legend_05 <- get_legend(legend_plot_05 + 319 | theme(legend.position="bottom")) 320 | 321 | 322 | ``` 323 | -------------------------------------------------------------------------------- /Figure_1/Tracking_Global_Footprint_Fisheries_Figure1.md: -------------------------------------------------------------------------------- 1 | Tracking the Global Footprint of Fisheries: Figure 1 2 | ================ 3 | 4 | Code for making Figure 1 from Tracking the Footprint of Global Fisheries paper from public Big Query datasets provided by Global Fishing Watch. 5 | 6 | ##### Figure prep 7 | 8 | ``` r 9 | library(ggplot2) 10 | library(sf) 11 | library(bigrquery) 12 | 13 | theme_gfw_paper <- theme(text = element_text(family="Arial", face="bold", size=12), 14 | axis.text.x = element_text(size = 12, colour = "black"), 15 | axis.text.y = element_text(size = 12, colour = "black"), 16 | axis.line.x = element_line(colour = "black", size = .5), 17 | axis.line.y = element_line(colour = "black", size = .5), 18 | legend.position = "bottom", 19 | axis.title.y = element_text(size = 12, margin=margin(0,15,0,0)), 20 | axis.title.x = element_text(size = 12, margin=margin(15,0,0,0)), 21 | panel.grid.major = element_blank(), 22 | panel.grid.minor = element_blank(), 23 | panel.background = element_blank(), 24 | axis.line = element_line(colour = "black"), 25 | plot.margin = unit(c(1,1,1,1), "cm") 26 | ) 27 | ``` 28 | 29 | Load shapefile downloaded from Natural Earth (110m resolution) 30 | 31 | ``` r 32 | land_df <- read_sf('../data/ne_110m_land/ne_110m_land.shp', quiet = TRUE) 33 | # This shapefile is available from http://www.naturalearthdata.com/downloads/110m-physical-vectors/110m-land/ 34 | ``` 35 | 36 | #### SQL query for Total Fishing Effort (0.5 degree) 37 | 38 | ``` sql 39 | SELECT 40 | SUM(fishing_hours)/(COS(RADIANS(lat_bin/2)) * POW(111, 2)) hours_sq_km, 41 | lat_bin, 42 | lon_bin 43 | FROM ( 44 | SELECT 45 | FLOOR((lat_bin/100)/0.5) * 0.5 lat_bin, 46 | FLOOR((lon_bin/100)/0.5) * 0.5 lon_bin, 47 | fishing_hours 48 | FROM 49 | [global-fishing-watch:global_footprint_of_fisheries.fishing_effort] 50 | WHERE 51 | _PARTITIONTIME >= "2016-01-01 00:00:00" 52 | AND _PARTITIONTIME < "2017-01-01 00:00:00" 53 | AND fishing_hours > 0) 54 | GROUP BY 55 | lat_bin, 56 | lon_bin 57 | ``` 58 | 59 | #### SQL Query for Fishing Effort by Geartype (0.5 degree) 60 | 61 | ``` sql 62 | SELECT 63 | SUM(fishing_hours)/(COS(RADIANS(lat_bin/2)) * POW(111, 2)) hours_sq_km, 64 | lat_bin, 65 | lon_bin, 66 | geartype 67 | FROM ( 68 | SELECT 69 | FLOOR((lat_bin/100)/0.5) * 0.5 lat_bin, 70 | FLOOR((lon_bin/100)/0.5) * 0.5 lon_bin, 71 | fishing_hours, 72 | geartype 73 | FROM 74 | [global-fishing-watch:global_footprint_of_fisheries.fishing_effort] 75 | WHERE 76 | _PARTITIONTIME >= "2016-01-01 00:00:00" 77 | AND _PARTITIONTIME < "2017-01-01 00:00:00" 78 | AND fishing_hours > 0) 79 | GROUP BY 80 | lat_bin, 81 | lon_bin, 82 | geartype 83 | ``` 84 | 85 | ``` r 86 | head(total_fishing_effort_05) 87 | ``` 88 | 89 | FALSE hours_sq_km lat_bin lon_bin 90 | FALSE 1 0.006005120 -13.0 12.5 91 | FALSE 2 0.006339496 -42.0 -59.5 92 | FALSE 3 0.109134825 -41.5 -62.0 93 | FALSE 4 0.462021867 43.5 -50.0 94 | FALSE 5 0.034238645 49.0 -124.0 95 | FALSE 6 0.265192376 49.5 -125.0 96 | 97 | ``` r 98 | head(fishing_effort_by_type_05) 99 | ``` 100 | 101 | FALSE hours_sq_km lat_bin lon_bin geartype 102 | FALSE 1 0.59905824 -10.5 12.5 trawlers 103 | FALSE 2 0.21807976 48.5 -3.0 trawlers 104 | FALSE 3 0.18707084 48.5 -10.5 trawlers 105 | FALSE 4 0.52536166 61.5 -5.5 trawlers 106 | FALSE 5 0.07882448 69.5 -59.5 trawlers 107 | FALSE 6 0.07506287 69.5 42.0 trawlers 108 | 109 | #### Process data 110 | 111 | Data processing for plotting total fishing effort 112 | 113 | ``` r 114 | total_fishing_effort_05$hours_sq_km = total_fishing_effort_05$hours_sq_km * 10000 115 | total_fishing_effort_05$logHours = log10(total_fishing_effort_05$hours_sq_km) 116 | total_fishing_effort_05$logHours = ifelse(total_fishing_effort_05$logHours >= 5, 117 | 5, 118 | total_fishing_effort_05$logHours) 119 | total_fishing_effort_05$logHours = ifelse(total_fishing_effort_05$logHours <= 1, 120 | 1, 121 | total_fishing_effort_05$logHours) 122 | 123 | total_fishing_effort_05 = total_fishing_effort_05 %>% 124 | filter(lat_bin < 85 & lat_bin > -85 & lon_bin > -180 & lon_bin < 180) 125 | ``` 126 | 127 | Data processing for plotting fishing effort by geartype 128 | 129 | ``` r 130 | fishing_effort_by_type_05$hours_sq_km = fishing_effort_by_type_05$hours_sq_km * 10000 131 | fishing_effort_by_type_05$logHours = log10(fishing_effort_by_type_05$hours_sq_km) 132 | fishing_effort_by_type_05$logHours = ifelse(fishing_effort_by_type_05$logHours >= 5, 133 | 5, 134 | fishing_effort_by_type_05$logHours) 135 | fishing_effort_by_type_05$logHours = ifelse(fishing_effort_by_type_05$logHours <= 1, 136 | 1, 137 | fishing_effort_by_type_05$logHours) 138 | 139 | purse_seine_effort_05 = fishing_effort_by_type_05 %>% 140 | filter(geartype == 'purse_seines'& 141 | lat_bin > -90 & 142 | lat_bin < 90 & 143 | lon_bin > -180 & 144 | lon_bin < 180) 145 | 146 | 147 | longline_effort_05 = fishing_effort_by_type_05 %>% 148 | filter(geartype == 'drifting_longlines'& 149 | lat_bin > -90 & 150 | lat_bin < 85 & 151 | lon_bin > -180 & 152 | lon_bin < 180) 153 | 154 | trawler_effort_05 = fishing_effort_by_type_05 %>% 155 | filter(geartype == 'trawlers' & 156 | lat_bin > -90 & 157 | lat_bin < 90 & 158 | lon_bin > -180 & 159 | lon_bin < 180) 160 | ``` 161 | 162 | 163 | #### Generating Fishing Effort Figure Panels 164 | 165 | ``` r 166 | cont_fill = 'white'#'grey30' #'grey80' 167 | back_fill = 'white'#'#202A50' #'black' #'#1F2A4F' 168 | cont_color = 'grey60'#'grey30' 169 | #color_grad = c( "#414487", "#2A788E", "#22A884", "#7AD151","#FDE725","#FFC04C") 170 | color_grad = c("#C6DBEF", "#9ECAE1", "#6BAED6","#4292C6" ,"#2171B5", "#084594") #blues 171 | ``` 172 | 173 | ##### Total Effort 174 | 175 | ``` r 176 | total_effort_05 <- ggplot() + 177 | geom_raster(data = total_fishing_effort_05, 178 | aes(x = lon_bin, y = lat_bin, fill = logHours), 179 | interpolate = FALSE) + 180 | geom_sf(data = land_df, 181 | color = cont_color, 182 | size = 0.5, 183 | fill = cont_fill) + 184 | scale_fill_viridis("Vessel Density", na.value = NA, limits = c(1, 5), 185 | breaks=c(seq(1,5,length.out = 4)), 186 | labels = c('1','10', '100','> 1000' ), 187 | direction = -1)+ 188 | coord_sf(datum = NA) + 189 | theme_gfw_paper + 190 | theme(axis.title.x = element_blank(), 191 | axis.title.y = element_blank(), 192 | axis.text.x = element_blank(), 193 | axis.text.y = element_blank(), 194 | axis.ticks = element_blank(), 195 | axis.line = element_blank(), 196 | panel.background = element_rect(color = NA,fill = back_fill), 197 | legend.position = 'none', 198 | legend.direction="horizontal", 199 | plot.margin=unit(c(0,-0.5,-0.5,-0.5), 'cm'), 200 | legend.text = element_text(size = 6, family = 'Times New Roman'), 201 | legend.title = element_text(size = 7, family = 'Times New Roman')) 202 | total_effort_05 203 | ``` 204 | 205 | ![](Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-12-1.png) 206 | 207 | ##### Purse Seine Effort 208 | 209 | ``` r 210 | purse_seine_05 <- ggplot() + 211 | geom_raster(data = purse_seine_effort_05, 212 | aes(x = lon_bin, y = lat_bin, fill = logHours), 213 | interpolate = TRUE) + 214 | geom_sf(data = land_df, 215 | color = cont_color, 216 | size = 0.5, 217 | fill = cont_fill) + 218 | scale_fill_viridis("Vessel Density", na.value = NA, limits = c(1, 5), 219 | breaks=c(seq(1,5,length.out = 4)), 220 | labels = c('1','10', '100','> 1000' ), 221 | direction = -1) + 222 | coord_sf(datum = NA) + 223 | theme_gfw_paper + 224 | theme(axis.title.x = element_blank(), 225 | axis.title.y = element_blank(), 226 | axis.text.x = element_blank(), 227 | axis.text.y = element_blank(), 228 | axis.ticks = element_blank(), 229 | axis.line = element_blank(), 230 | panel.border = element_blank(), 231 | panel.background = element_rect(color = NA,fill = back_fill), 232 | legend.position = 'none', 233 | plot.margin=unit(c(0,-0.5,-0.5,-0.5), 'cm')) 234 | purse_seine_05 235 | ``` 236 | 237 | ![](Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-13-1.png) 238 | 239 | ##### Drifting Longline Effort 240 | 241 | ``` r 242 | longline_05 <- ggplot() + 243 | geom_raster(data = longline_effort_05, 244 | aes(x = lon_bin, y = lat_bin, fill = logHours), 245 | interpolate = TRUE) + 246 | geom_sf(data = land_df, 247 | color = cont_color, 248 | size = 0.5, 249 | fill = cont_fill) + 250 | scale_fill_viridis("Vessel Density", na.value = NA, limits = c(1, 5), 251 | breaks=c(seq(1,5,length.out = 4)), 252 | labels = c('1','10', '100','> 1000' ), 253 | direction = -1) + 254 | coord_sf(datum = NA) + 255 | theme_gfw_paper + 256 | theme(axis.title.x = element_blank(), 257 | axis.title.y = element_blank(), 258 | axis.text.x = element_blank(), 259 | axis.text.y = element_blank(), 260 | axis.ticks = element_blank(), 261 | axis.line = element_blank(), 262 | panel.background = element_rect(color = NA,fill = back_fill), 263 | legend.position = 'none', 264 | plot.margin=unit(c(0,-0.5,-0.5,-0.5), "cm")) 265 | longline_05 266 | ``` 267 | 268 | ![](Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-14-1.png) 269 | 270 | ##### Trawler Effort 271 | 272 | ``` r 273 | trawling_05 <- ggplot() + 274 | geom_raster(data = trawler_effort_05, 275 | aes(x = lon_bin, y = lat_bin, fill = logHours), 276 | interpolate = TRUE) + 277 | geom_sf(data = land_df, 278 | color = cont_color, 279 | size = 0.5, 280 | fill = cont_fill) + 281 | scale_fill_viridis("Vessel Density", na.value = NA, limits = c(1, 5), 282 | breaks=c(seq(1,5,length.out = 4)), 283 | labels = c('1','10', '100','> 1000' ), 284 | direction = -1) + 285 | coord_sf(datum = NA) + 286 | theme_gfw_paper + 287 | theme(axis.title.x = element_blank(), 288 | axis.title.y = element_blank(), 289 | axis.text.x = element_blank(), 290 | axis.text.y = element_blank(), 291 | axis.ticks = element_blank(), 292 | axis.line = element_blank(), 293 | panel.background = element_rect(color = NA,fill = back_fill), 294 | legend.position = 'none', 295 | plot.margin=unit(c(-0.5,-0.5,-0.5,-0.5), "cm")) 296 | trawling_05 297 | ``` 298 | 299 | ![](Tracking_Global_Footprint_Fisheries_Figure1_files/figure-markdown_github/unnamed-chunk-15-1.png) 300 | 301 | 302 | 303 | #### Generating Legends 304 | 305 | Code for generating legend to a a set of gridded fishing plots. Requires making a plot with a legend and then extracting the legend using get\_legend First for the fishing effort and the for the NPP 306 | 307 | ``` r 308 | library(cowplot) 309 | #plot with legend 310 | #color_grad = c( "#414487", "#2A788E", "#22A884", "#7AD151","#FDE725","#FFC04C") 311 | 312 | legend_plot_05 = ggplot() + 313 | geom_raster(data = total_fishing_effort_05, 314 | aes(x = lon_bin, y = lat_bin, fill = logHours), 315 | interpolate = FALSE) + 316 | geom_polygon(data = land_df, 317 | fill = cont_fill) + 318 | scale_fill_viridis("Vessel Density", 319 | na.value = NA, 320 | limits = c(1, 5), 321 | breaks=c(seq(1,5,length.out = 5)), 322 | direction = -1) + 323 | guides(fill = guide_colorbar(barwidth = 12, 324 | barheight = 0.3, 325 | title.hjust = 0.5, 326 | title.position = 'bottom')) 327 | 328 | effort_legend_05 <- get_legend(legend_plot_05 + 329 | theme(legend.position="bottom")) 330 | ``` 331 | 332 | -------------------------------------------------------------------------------- /Figure_2/Tracking_Global_Footprint_Fisheries_Figure2_code.md: -------------------------------------------------------------------------------- 1 | Tracking the Global Footprint of Fisheries: Figure 2 2 | ================ 3 | 4 | This code replicates Figure 2, Panels A and B from the paper Tracking the Global Footprint of Fisheries using the publicly available Big Query tables provided by Global Fishing Watch. 5 | 6 | ``` r 7 | library(tidyverse) 8 | library(sf) 9 | library(bigrquery) 10 | library(lubridate) 11 | library(fuzzyjoin) 12 | ``` 13 | 14 | #### Figure Prep 15 | 16 | ``` r 17 | theme_gfw_paper <- theme(text = element_text(family="Arial", face="bold", size=10), 18 | axis.text.x = element_text(size = 12, colour = "black"), 19 | axis.text.y = element_text(size = 12, colour = "black"), 20 | axis.line.x = element_line(colour = "black", size = .5), 21 | axis.line.y = element_line(colour = "black", size = .5), 22 | legend.position = "bottom", 23 | axis.title.y = element_text(size = 12, margin=margin(0,15,0,0)), 24 | axis.title.x = element_text(size = 12, margin=margin(15,0,0,0)), 25 | panel.grid.major = element_blank(), 26 | panel.grid.minor = element_blank(), 27 | panel.background = element_blank(), 28 | axis.line = element_line(colour = "black"), 29 | plot.margin = unit(c(1,1,1,1), "cm") 30 | ) 31 | ``` 32 | 33 | ### Panel A: Global Patterns Panel 34 | 35 | Query to generate the total fishing hours group by latitude, day and year. The original plot provided finer resolution of grouping by 12 hours (0.5 day), but a similar plot is possible using day aggregated data. 36 | 37 | ``` sql 38 | SELECT 39 | SUM(fishing_hours) total_fishing_hours, 40 | FLOOR((lat_bin/100)*4)/4 lat_bin, 41 | integer(DAYOFYEAR(date)) day, 42 | integer(YEAR(date)) year, 43 | FROM 44 | [global-fishing-watch:global_footprint_of_fisheries.fishing_effort] 45 | WHERE 46 | _PARTITIONTIME >= "2013-01-01 00:00:00" 47 | AND _PARTITIONTIME < "2017-01-01 00:00:00" 48 | AND fishing_hours > 0 49 | GROUP BY 50 | lat_bin, 51 | day, 52 | year 53 | ``` 54 | 55 | ``` r 56 | head(global_fish_patterns) 57 | ``` 58 | 59 | FALSE total_fishing_hours lat_bin day year 60 | FALSE 1 34.556944 -38.25 313 2013 61 | FALSE 2 41.818472 -43.25 313 2013 62 | FALSE 3 25.221111 -38.00 313 2013 63 | FALSE 4 423.063333 50.00 313 2013 64 | FALSE 5 8.852639 -44.25 313 2013 65 | FALSE 6 21.907639 -10.25 313 2013 66 | 67 | #### Data Processing 68 | 69 | Here we processes the dates and replace a date that is irrecoverably missing (2013-05-31). The values for that date are imputed as the mean fishing hours for the preceeding and following day at each latitude. 70 | 71 | ``` r 72 | global_fish_patterns$date = format(as.Date(paste(global_fish_patterns$year, 73 | global_fish_patterns$day, 74 | sep='-'),"%Y-%j"), "%Y-%m-%d") 75 | 76 | #get May 30, 2013 and June 1, 2013 and average to substitute for the missing May 31, 2013 77 | may_31_estimate = global_fish_patterns %>% 78 | filter(date == as.Date('2013-05-30') | date == as.Date('2013-06-01')) %>% 79 | group_by(lat_bin) %>% 80 | summarize(total_fishing_hours = mean(total_fishing_hours, na.rm = TRUE)) 81 | may_31_estimate$day = c(rep(151, nrow(may_31_estimate))) 82 | may_31_estimate$year = c(rep(2013, nrow(may_31_estimate))) 83 | may_31_estimate$date = c(rep('2013-05-31', nrow(may_31_estimate))) 84 | global_fish_patterns = rbind(global_fish_patterns, may_31_estimate) 85 | ``` 86 | 87 | Additional processing for generating appropriate color scale 88 | 89 | ``` r 90 | global_fish_patterns$maxxed_hours = ifelse(global_fish_patterns$total_fishing_hours >= 1000, 91 | 1000, 92 | global_fish_patterns$total_fishing_hours) #originally 10000 93 | global_fish_patterns$maxxed_hours = ifelse(global_fish_patterns$total_fishing_hours <=1, 94 | 1, 95 | global_fish_patterns$total_fishing_hours) 96 | global_fish_patterns$maxxed_hours = ifelse(global_fish_patterns$lat_bin < -85, 97 | 0, 98 | global_fish_patterns$maxxed_hours) #just to clean up a few odd points 99 | ``` 100 | 101 | ### Making Plot 102 | 103 | ``` r 104 | color_grad = c( "#414487", "#2A788E", "#22A884", "#7AD151","#FDE725","#FFC04C") 105 | back_fill = 'black' 106 | 107 | global_patterns_plot <- ggplot2::ggplot() + 108 | ggplot2::geom_raster(data = global_fish_patterns, 109 | aes(as.Date(date),lat_bin, 110 | fill = log10(maxxed_hours*4)), 111 | interpolate = TRUE)+ 112 | ggplot2::scale_fill_gradientn("Fishing Effort \n", 113 | colors = color_grad, 114 | na.value = NA, 115 | breaks = c(0.60206,1.60206, 2.60206, 3.60206, 4.60206), 116 | limits = c(0.60206,4.60206), 117 | labels = c('0', '0.4','4','40','>400') #, 118 | #guide = 'none' 119 | ) + 120 | ggplot2::scale_x_date('Year', date_breaks = 'year', date_labels = '%Y', 121 | expand = c(0,0), 122 | limits = c(as.Date('2013-01-01'), as.Date('2017-01-01'))) + 123 | ggplot2::scale_y_continuous('Latitude', 124 | limits = c(-90, 90), 125 | breaks = c(seq(-90,90, 45)), 126 | expand = c(0,0)) + 127 | theme_gfw_paper + 128 | theme(text = element_text(family="Arial", face="bold", size=10), 129 | axis.text.x = element_text(size = 12, colour = "black"), 130 | axis.text.y = element_text(size = 12, colour = "black"), 131 | axis.line.x = element_line(colour = "black", size = .5), 132 | axis.line.y = element_line(colour = "black", size = .5), 133 | axis.title.y = element_text(size = 12, margin=margin(0,15,0,0)), 134 | axis.title.x = element_text(size = 12, margin=margin(15,0,0,0)), 135 | panel.grid.major = element_blank(), 136 | panel.grid.minor = element_blank(), 137 | axis.line = element_line(colour = "black"), 138 | # legend.position = 'bottom', 139 | # legend.direction = 'horizontal', 140 | # legend.key.height = unit(.2, 'cm'), 141 | # legend.key.width = unit(1,'cm'), 142 | # legend.title.align = 0, 143 | legend.position = 'none', 144 | panel.background = element_rect(fill = back_fill ), 145 | plot.margin = unit(c(1, 1,1,1), 'cm')) 146 | global_patterns_plot 147 | ``` 148 | 149 | ![](Tracking_Global_Footprint_Fisheries_Figure2_code_files/figure-markdown_github/unnamed-chunk-8-1.png) 150 | 151 | ##### Making Legend 152 | 153 | Generating a separate legend for the plot for flexibility and convenience. 154 | 155 | ``` r 156 | library(cowplot) 157 | global_patterns_legend <- ggplot2::ggplot() + 158 | ggplot2::geom_raster(data = global_fish_patterns, 159 | aes(as.Date(date),lat_bin, 160 | fill = log10(maxxed_hours*4)), 161 | interpolate = TRUE)+ 162 | ggplot2::scale_fill_gradientn("Fishing Effort \n", 163 | colors = color_grad, 164 | na.value = NA, 165 | breaks = c(0.60206,1.60206, 2.60206, 3.60206, 4.60206), 166 | limits = c(0.60206,4.60206), 167 | labels = c('0', '0.4','4','40','>400') #, 168 | #guide = 'none' 169 | ) + 170 | theme_gfw_paper + 171 | theme(legend.position = 'bottom', 172 | legend.direction = 'horizontal', 173 | legend.key.height = unit(.2, 'cm'), 174 | legend.key.width = unit(1,'cm'), 175 | legend.title.align = 0, 176 | panel.background = element_rect(fill = back_fill ), 177 | plot.margin = unit(c(1, 1,1,1), 'cm')) 178 | 179 | global_legend <- get_legend(global_patterns_legend) 180 | ``` 181 | 182 | ### Panel C: Fishing Hours Chinese Vessels 183 | 184 | The following code is not identical to that used to generate the original Panel C, of Figure 2, but demonstrates how, with a bit of wrangling, a similar figure can be generated using publically available data. 185 | 186 | #### Query Date 187 | 188 | Query to identify fishing hours by Chinese vessels, grouped by date and year, NEAR the Chinese EEZ. This will be restricted to just be that fishing which takes place within the Chinese EEZ later. 189 | 190 | ``` sql 191 | SELECT 192 | YEAR(date) year, 193 | date, 194 | FLOOR((lat_bin/100)*10) / 10 AS lat_bin, 195 | FLOOR((lon_bin/100)*10) / 10 AS lon_bin, 196 | SUM(fishing_hours) fishing_hours 197 | FROM 198 | [global-fishing-watch:global_footprint_of_fisheries.fishing_effort] 199 | WHERE 200 | _PARTITIONTIME >= "2013-01-01 00:00:00" 201 | AND _PARTITIONTIME < "2017-01-01 00:00:00" 202 | AND flag == "CHN" 203 | AND lat_bin/100 < 47 204 | AND lon_bin/100 > 101 205 | AND lat_bin/100 > 12 206 | AND lon_bin/100 < 136 207 | AND fishing_hours > 0 208 | GROUP BY 209 | date, 210 | lat_bin, 211 | lon_bin, 212 | year 213 | ``` 214 | 215 | #### Identify Fishing Hours within Chinese EEZ 216 | 217 | ``` r 218 | #read in EEZ shapefile available from Marine Regions http://www.marineregions.org/downloads.php 219 | eez_sp <- sf::read_sf('~/shapefiles/World_EEZ_v10.shp') 220 | 221 | #reduce the shapefile to just the Chinese EEZ 222 | eez_chn_sp <- eez_sp %>% 223 | filter(ISO_3digit == 'CHN') 224 | 225 | #convert dataframe of gridded values to sf class 226 | chn_sf = sf::st_as_sf(chinese_active_vessels_all_years, 227 | coords = c('lon_bin', 'lat_bin'), crs = 4326, agr = "constant") 228 | 229 | #spatial left join, functions as a point in polygon to identify those fishing hours 230 | #that take place within the Chinese EEZ. 231 | event_in_shp <- sf::st_join(chn_sf, eez_sp, join = sf::st_intersects, left = TRUE) 232 | chinese_active_vessels_inside_eez <- event_in_shp %>% 233 | dplyr::filter(!is.na(ISO_3digit)) %>% 234 | dplyr::select(year, date, fishing_hours) 235 | chinese_active_vessels_inside_eez <- as.data.frame(chinese_active_vessels_inside_eez) 236 | ``` 237 | 238 | ### Further Processing for Chinese Moratoria and New Year 239 | 240 | ``` r 241 | chinese_active_vessels_inside_eez <- chinese_active_vessels_inside_eez %>% 242 | mutate(date = lubridate::ymd(date)) %>% 243 | group_by(year, date) %>% 244 | summarise(fishing_hours = sum(fishing_hours)) %>% 245 | ungroup() %>% 246 | dplyr::select(-year) 247 | 248 | 249 | moratoria_dates1 <- tibble(year = c(2013:2016)) %>% 250 | mutate(start_date = lubridate::ymd(paste(year,"-06-01",sep = "")), 251 | end_date = lubridate::ymd(paste(year,"-08-01",sep = ""))) 252 | moratoria_dates2 <- tibble(year = c(2013:2016)) %>% 253 | mutate(start_date = lubridate::ymd(paste(year,"-05-16",sep = "")), 254 | end_date = lubridate::ymd(paste(year,"-09-16",sep = ""))) 255 | 256 | new_year_dates <- tibble(year = c(2013:2016), 257 | start_date = c(lubridate::ymd("2013-02-07"), 258 | lubridate::ymd("2014-01-28"), 259 | lubridate::ymd("2015-02-16"), 260 | lubridate::ymd("2016-02-05")), 261 | end_date = c(lubridate::ymd("2013-02-07") + days(23), 262 | lubridate::ymd("2014-01-28") + days(23), 263 | lubridate::ymd("2015-02-16") + days(23), 264 | lubridate::ymd("2016-02-05") + days(23))) 265 | 266 | chinese_active_vessels_inside_eez <- chinese_active_vessels_inside_eez %>% 267 | fuzzyjoin::fuzzy_left_join(new_year_dates, 268 | by = c("date" = "start_date", "date" = "end_date"), 269 | match_fun = list(`>=`, `<=`)) %>% 270 | mutate(new_year = ifelse(!is.na(year), TRUE, FALSE)) %>% 271 | dplyr::select(-start_date, -end_date, -year ) %>% 272 | distinct() %>% 273 | fuzzyjoin::fuzzy_left_join(moratoria_dates1, 274 | by = c("date" = "start_date", "date" = "end_date"), 275 | match_fun = list(`>=`, `<=`)) %>% 276 | mutate(moratoria1 = ifelse(!is.na(year), TRUE, FALSE)) %>% 277 | dplyr::select(-start_date, -end_date, -year ) %>% 278 | distinct() %>% 279 | fuzzyjoin::fuzzy_left_join(moratoria_dates2, 280 | by = c("date" = "start_date", "date" = "end_date"), 281 | match_fun = list(`>=`, `<=`)) %>% 282 | mutate(moratoria2 = ifelse(!is.na(year), TRUE, FALSE)) %>% 283 | dplyr::select(-start_date, -end_date, -year ) %>% 284 | distinct() 285 | 286 | new_year_rows <- which(chinese_active_vessels_inside_eez$new_year == T) 287 | 288 | new_year_counterfactual_rows <- unique(sort(new_year_rows + rep(-5:5, each = length(new_year_rows)))) 289 | 290 | new_year_counterfactual_rows <- new_year_counterfactual_rows[!new_year_counterfactual_rows %in% new_year_rows] 291 | 292 | chinese_active_vessels_inside_eez <- chinese_active_vessels_inside_eez %>% 293 | mutate(new_year_counterfactual = ifelse(row_number() %in% new_year_counterfactual_rows, T, F)) 294 | 295 | theme_gfw_paper <- theme(text = element_text(family="Arial", face="bold", size=14), 296 | axis.text.x = element_text(size = 12, colour = "black"), 297 | axis.text.y = element_text(size = 12, colour = "black"), 298 | axis.line.x = element_line(colour = "black", size = .5), 299 | axis.line.y = element_line(colour = "black", size = .5), 300 | legend.position = "right", 301 | axis.title.y = element_text(margin=margin(0,15,0,0)), 302 | axis.title.x = element_text(margin=margin(15,0,0,0)), 303 | panel.grid.major = element_blank(), 304 | panel.grid.minor = element_blank(), 305 | panel.background = element_blank(), 306 | axis.line = element_line(colour = "black") 307 | ) 308 | ``` 309 | 310 | #### Making Panel C 311 | 312 | ``` r 313 | chinese_moratoria_plot_fishing_hours <- ggplot() + 314 | geom_rect(data = moratoria_dates1, 315 | aes(xmin = start_date, 316 | xmax = end_date, 317 | ymin = 0, 318 | ymax = Inf, 319 | fill = "tomato"), 320 | alpha = 0.5, 321 | show.legend = TRUE) + 322 | geom_rect(data = moratoria_dates2, 323 | aes(xmin = start_date, 324 | xmax = end_date, 325 | ymin = 0, 326 | ymax = Inf, 327 | fill = "tomato"), 328 | alpha = 0.15, 329 | show.legend = TRUE) + 330 | geom_rect(data = new_year_dates, 331 | aes(xmin = start_date, 332 | xmax = end_date, 333 | ymin = 0, 334 | ymax = Inf, 335 | fill = "#f7e456"), 336 | alpha = 1, 337 | show.legend = TRUE) + 338 | geom_line(data = chinese_active_vessels_inside_eez, 339 | aes(x = date, y = fishing_hours/1000), 340 | size = 0.3) + 341 | theme_minimal() + 342 | scale_x_date(date_breaks = "1 year", 343 | date_labels = "%Y ", 344 | limits = c(as.Date("2013-01-01"), as.Date('2017-01-01')), 345 | expand = c(0,0)) + 346 | xlab("") + 347 | scale_y_continuous(breaks = c(0,20,40,60), 348 | expand = c(0, 0), 349 | labels = scales::comma, 350 | limits = c(0,60) ) + 351 | ylab("Fishing Hours (x1000)")+ 352 | scale_fill_manual(values = c("#f7d694", "tomato"), 353 | name = " ", 354 | labels = c("Chinese New Year", "Moratoria")) + 355 | theme_gfw_paper + 356 | theme(axis.ticks = element_line(size = 0.5), 357 | panel.grid.major = element_blank(), 358 | panel.grid.minor = element_blank(), 359 | panel.background = element_blank(), 360 | axis.line = element_line(colour = "black"), 361 | axis.text.y = element_text(size = 10), 362 | 363 | legend.justification = "top", 364 | legend.position = 'none', 365 | legend.text = element_text(size = 6), 366 | plot.margin = unit(margin(1,1,1,1),'cm') 367 | ) 368 | chinese_moratoria_plot_fishing_hours 369 | ``` 370 | 371 | ![](Tracking_Global_Footprint_Fisheries_Figure2_code_files/figure-markdown_github/unnamed-chunk-13-1.png) 372 | -------------------------------------------------------------------------------- /Figure_2/Tracking_Global_Footprint_Fisheries_Figure2_code.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Tracking the Global Footprint of Fisheries: Figure 2" 3 | output: github_document 4 | --- 5 | 6 | 7 | ```{r setup, include=FALSE, message=FALSE, comment=FALSE, warning=FALSE} 8 | knitr::opts_chunk$set(echo = TRUE, comment = FALSE, warning = FALSE, message = FALSE) 9 | ``` 10 | 11 | This code replicates Figure 2, Panels A and B from the paper Tracking the Global Footprint of 12 | Fisheries using the publicly available Big Query tables provided by Global Fishing Watch. 13 | 14 | ```{r, message=FALSE, comment=FALSE, warning=FALSE} 15 | library(tidyverse) 16 | library(sf) 17 | library(bigrquery) 18 | library(lubridate) 19 | library(fuzzyjoin) 20 | ``` 21 | 22 | 23 | ```{r echo = FALSE, message=FALSE, comment=FALSE, warning=FALSE} 24 | BQ_connection <- dbConnect(dbi_driver(), dataset = "", project = "world-fishing-827") 25 | ``` 26 | 27 | 28 | #### Figure Prep 29 | ```{r, message=FALSE, comment=FALSE, warning=FALSE} 30 | theme_gfw_paper <- theme(text = element_text(family="Arial", face="bold", size=10), 31 | axis.text.x = element_text(size = 12, colour = "black"), 32 | axis.text.y = element_text(size = 12, colour = "black"), 33 | axis.line.x = element_line(colour = "black", size = .5), 34 | axis.line.y = element_line(colour = "black", size = .5), 35 | legend.position = "bottom", 36 | axis.title.y = element_text(size = 12, margin=margin(0,15,0,0)), 37 | axis.title.x = element_text(size = 12, margin=margin(15,0,0,0)), 38 | panel.grid.major = element_blank(), 39 | panel.grid.minor = element_blank(), 40 | panel.background = element_blank(), 41 | axis.line = element_line(colour = "black"), 42 | plot.margin = unit(c(1,1,1,1), "cm") 43 | ) 44 | ``` 45 | 46 | 47 | ### Panel A: Global Patterns Panel 48 | 49 | Query to generate the total fishing hours group by latitude, day and year. The original 50 | plot provided finer resolution of grouping by 12 hours (0.5 day), but a similar 51 | plot is possible using day aggregated data. 52 | ```{sql connection = BQ_connection, output.var = "global_fish_patterns"} 53 | SELECT 54 | SUM(fishing_hours) total_fishing_hours, 55 | FLOOR((lat_bin/100)*4)/4 lat_bin, 56 | integer(DAYOFYEAR(date)) day, 57 | integer(YEAR(date)) year, 58 | FROM 59 | [global-fishing-watch:global_footprint_of_fisheries.fishing_effort] 60 | WHERE 61 | _PARTITIONTIME >= "2013-01-01 00:00:00" 62 | AND _PARTITIONTIME < "2017-01-01 00:00:00" 63 | AND fishing_hours > 0 64 | GROUP BY 65 | lat_bin, 66 | day, 67 | year 68 | ``` 69 | 70 | 71 | 72 | ```{r} 73 | head(global_fish_patterns) 74 | ``` 75 | 76 | #### Data Processing 77 | Here we processes the dates and replace a date that is irrecoverably missing (2013-05-31). 78 | The values for that date are imputed as the mean fishing hours for the preceeding and 79 | following day at each latitude. 80 | ```{r} 81 | global_fish_patterns$date = format(as.Date(paste(global_fish_patterns$year, 82 | global_fish_patterns$day, 83 | sep='-'),"%Y-%j"), "%Y-%m-%d") 84 | 85 | #get May 30, 2013 and June 1, 2013 and average to substitute for the missing May 31, 2013 86 | may_31_estimate = global_fish_patterns %>% 87 | filter(date == as.Date('2013-05-30') | date == as.Date('2013-06-01')) %>% 88 | group_by(lat_bin) %>% 89 | summarize(total_fishing_hours = mean(total_fishing_hours, na.rm = TRUE)) 90 | may_31_estimate$day = c(rep(151, nrow(may_31_estimate))) 91 | may_31_estimate$year = c(rep(2013, nrow(may_31_estimate))) 92 | may_31_estimate$date = c(rep('2013-05-31', nrow(may_31_estimate))) 93 | global_fish_patterns = rbind(global_fish_patterns, may_31_estimate) 94 | ``` 95 | 96 | Additional processing for generating appropriate color scale 97 | ```{r} 98 | global_fish_patterns$maxxed_hours = ifelse(global_fish_patterns$total_fishing_hours >= 1000, 99 | 1000, 100 | global_fish_patterns$total_fishing_hours) #originally 10000 101 | global_fish_patterns$maxxed_hours = ifelse(global_fish_patterns$total_fishing_hours <=1, 102 | 1, 103 | global_fish_patterns$total_fishing_hours) 104 | global_fish_patterns$maxxed_hours = ifelse(global_fish_patterns$lat_bin < -85, 105 | 0, 106 | global_fish_patterns$maxxed_hours) #just to clean up a few odd points 107 | ``` 108 | 109 | ### Making Plot 110 | 111 | ```{r} 112 | color_grad = c( "#414487", "#2A788E", "#22A884", "#7AD151","#FDE725","#FFC04C") 113 | back_fill = 'black' 114 | 115 | global_patterns_plot <- ggplot2::ggplot() + 116 | ggplot2::geom_raster(data = global_fish_patterns, 117 | aes(as.Date(date),lat_bin, 118 | fill = log10(maxxed_hours*4)), 119 | interpolate = TRUE)+ 120 | ggplot2::scale_fill_gradientn("Fishing Effort \n", 121 | colors = color_grad, 122 | na.value = NA, 123 | breaks = c(0.60206,1.60206, 2.60206, 3.60206, 4.60206), 124 | limits = c(0.60206,4.60206), 125 | labels = c('0', '0.4','4','40','>400') #, 126 | #guide = 'none' 127 | ) + 128 | ggplot2::scale_x_date('Year', date_breaks = 'year', date_labels = '%Y', 129 | expand = c(0,0), 130 | limits = c(as.Date('2013-01-01'), as.Date('2017-01-01'))) + 131 | ggplot2::scale_y_continuous('Latitude', 132 | limits = c(-90, 90), 133 | breaks = c(seq(-90,90, 45)), 134 | expand = c(0,0)) + 135 | theme_gfw_paper + 136 | theme(text = element_text(family="Arial", face="bold", size=10), 137 | axis.text.x = element_text(size = 12, colour = "black"), 138 | axis.text.y = element_text(size = 12, colour = "black"), 139 | axis.line.x = element_line(colour = "black", size = .5), 140 | axis.line.y = element_line(colour = "black", size = .5), 141 | axis.title.y = element_text(size = 12, margin=margin(0,15,0,0)), 142 | axis.title.x = element_text(size = 12, margin=margin(15,0,0,0)), 143 | panel.grid.major = element_blank(), 144 | panel.grid.minor = element_blank(), 145 | axis.line = element_line(colour = "black"), 146 | # legend.position = 'bottom', 147 | # legend.direction = 'horizontal', 148 | # legend.key.height = unit(.2, 'cm'), 149 | # legend.key.width = unit(1,'cm'), 150 | # legend.title.align = 0, 151 | legend.position = 'none', 152 | panel.background = element_rect(fill = back_fill ), 153 | plot.margin = unit(c(1, 1,1,1), 'cm')) 154 | global_patterns_plot 155 | ``` 156 | 157 | ##### Making Legend 158 | Generating a separate legend for the plot for flexibility and convenience. 159 | ```{r} 160 | library(cowplot) 161 | global_patterns_legend <- ggplot2::ggplot() + 162 | ggplot2::geom_raster(data = global_fish_patterns, 163 | aes(as.Date(date),lat_bin, 164 | fill = log10(maxxed_hours*4)), 165 | interpolate = TRUE)+ 166 | ggplot2::scale_fill_gradientn("Fishing Effort \n", 167 | colors = color_grad, 168 | na.value = NA, 169 | breaks = c(0.60206,1.60206, 2.60206, 3.60206, 4.60206), 170 | limits = c(0.60206,4.60206), 171 | labels = c('0', '0.4','4','40','>400') #, 172 | #guide = 'none' 173 | ) + 174 | theme_gfw_paper + 175 | theme(legend.position = 'bottom', 176 | legend.direction = 'horizontal', 177 | legend.key.height = unit(.2, 'cm'), 178 | legend.key.width = unit(1,'cm'), 179 | legend.title.align = 0, 180 | panel.background = element_rect(fill = back_fill ), 181 | plot.margin = unit(c(1, 1,1,1), 'cm')) 182 | 183 | global_legend <- get_legend(global_patterns_legend) 184 | ``` 185 | 186 | 187 | 188 | ### Panel B: Fishing Hours Chinese Vessels 189 | 190 | The following code is not identical to that used to generate the original Panel B, 191 | of Figure 2, but demonstrates how, with a bit of wrangling, a similar figure can 192 | be generated using publically available data. 193 | 194 | #### Query Date 195 | Query to identify fishing hours by Chinese vessels, grouped by date and year, 196 | NEAR the Chinese EEZ. This will be restricted to just be that fishing which takes 197 | place within the Chinese EEZ later. 198 | ```{sql connection = BQ_connection, output.var = "chinese_active_vessels_all_years"} 199 | SELECT 200 | YEAR(date) year, 201 | date, 202 | FLOOR((lat_bin/100)*10) / 10 AS lat_bin, 203 | FLOOR((lon_bin/100)*10) / 10 AS lon_bin, 204 | SUM(fishing_hours) fishing_hours 205 | FROM 206 | [global-fishing-watch:global_footprint_of_fisheries.fishing_effort] 207 | WHERE 208 | _PARTITIONTIME >= "2013-01-01 00:00:00" 209 | AND _PARTITIONTIME < "2017-01-01 00:00:00" 210 | AND flag == "CHN" 211 | AND lat_bin/100 < 47 212 | AND lon_bin/100 > 101 213 | AND lat_bin/100 > 12 214 | AND lon_bin/100 < 136 215 | AND fishing_hours > 0 216 | GROUP BY 217 | date, 218 | lat_bin, 219 | lon_bin, 220 | year 221 | ``` 222 | 223 | #### Identify Fishing Hours within Chinese EEZ 224 | ```{r} 225 | #read in EEZ shapefile available from Marine Regions http://www.marineregions.org/downloads.php 226 | eez_sp <- sf::read_sf('~/Documents/GlobalFishingWatch/shapefiles/World_EEZ_v8_20140228_LR/World_EEZ_v8_2014.shp') 227 | 228 | #reduce the shapefile to just the Chinese EEZ 229 | eez_chn_sp <- eez_sp %>% 230 | filter(ISO_3digit == 'CHN') 231 | 232 | #convert dataframe of gridded values to sf class 233 | chn_sf = sf::st_as_sf(chinese_active_vessels_all_years, 234 | coords = c('lon_bin', 'lat_bin'), crs = 4326, agr = "constant") 235 | 236 | #spatial left join, functions as a point in polygon to identify those fishing hours 237 | #that take place within the Chinese EEZ. 238 | event_in_shp <- sf::st_join(chn_sf, eez_sp, join = sf::st_intersects, left = TRUE) 239 | chinese_active_vessels_inside_eez <- event_in_shp %>% 240 | dplyr::filter(!is.na(ISO_3digit)) %>% 241 | dplyr::select(year, date, fishing_hours) 242 | chinese_active_vessels_inside_eez <- as.data.frame(chinese_active_vessels_inside_eez) 243 | 244 | ``` 245 | 246 | 247 | ### Further Processing for Chinese Moratoria and New Year 248 | ```{r} 249 | chinese_active_vessels_inside_eez <- chinese_active_vessels_inside_eez %>% 250 | mutate(date = lubridate::ymd(date)) %>% 251 | group_by(year, date) %>% 252 | summarise(fishing_hours = sum(fishing_hours)) %>% 253 | ungroup() %>% 254 | dplyr::select(-year) 255 | 256 | 257 | moratoria_dates1 <- tibble(year = c(2013:2016)) %>% 258 | mutate(start_date = lubridate::ymd(paste(year,"-06-01",sep = "")), 259 | end_date = lubridate::ymd(paste(year,"-08-01",sep = ""))) 260 | moratoria_dates2 <- tibble(year = c(2013:2016)) %>% 261 | mutate(start_date = lubridate::ymd(paste(year,"-05-16",sep = "")), 262 | end_date = lubridate::ymd(paste(year,"-09-16",sep = ""))) 263 | 264 | new_year_dates <- tibble(year = c(2013:2016), 265 | start_date = c(lubridate::ymd("2013-02-07"), 266 | lubridate::ymd("2014-01-28"), 267 | lubridate::ymd("2015-02-16"), 268 | lubridate::ymd("2016-02-05")), 269 | end_date = c(lubridate::ymd("2013-02-07") + days(23), 270 | lubridate::ymd("2014-01-28") + days(23), 271 | lubridate::ymd("2015-02-16") + days(23), 272 | lubridate::ymd("2016-02-05") + days(23))) 273 | 274 | chinese_active_vessels_inside_eez <- chinese_active_vessels_inside_eez %>% 275 | fuzzyjoin::fuzzy_left_join(new_year_dates, 276 | by = c("date" = "start_date", "date" = "end_date"), 277 | match_fun = list(`>=`, `<=`)) %>% 278 | mutate(new_year = ifelse(!is.na(year), TRUE, FALSE)) %>% 279 | dplyr::select(-start_date, -end_date, -year ) %>% 280 | distinct() %>% 281 | fuzzyjoin::fuzzy_left_join(moratoria_dates1, 282 | by = c("date" = "start_date", "date" = "end_date"), 283 | match_fun = list(`>=`, `<=`)) %>% 284 | mutate(moratoria1 = ifelse(!is.na(year), TRUE, FALSE)) %>% 285 | dplyr::select(-start_date, -end_date, -year ) %>% 286 | distinct() %>% 287 | fuzzyjoin::fuzzy_left_join(moratoria_dates2, 288 | by = c("date" = "start_date", "date" = "end_date"), 289 | match_fun = list(`>=`, `<=`)) %>% 290 | mutate(moratoria2 = ifelse(!is.na(year), TRUE, FALSE)) %>% 291 | dplyr::select(-start_date, -end_date, -year ) %>% 292 | distinct() 293 | 294 | new_year_rows <- which(chinese_active_vessels_inside_eez$new_year == T) 295 | 296 | new_year_counterfactual_rows <- unique(sort(new_year_rows + rep(-5:5, each = length(new_year_rows)))) 297 | 298 | new_year_counterfactual_rows <- new_year_counterfactual_rows[!new_year_counterfactual_rows %in% new_year_rows] 299 | 300 | chinese_active_vessels_inside_eez <- chinese_active_vessels_inside_eez %>% 301 | mutate(new_year_counterfactual = ifelse(row_number() %in% new_year_counterfactual_rows, T, F)) 302 | 303 | theme_gfw_paper <- theme(text = element_text(family="Arial", face="bold", size=14), 304 | axis.text.x = element_text(size = 12, colour = "black"), 305 | axis.text.y = element_text(size = 12, colour = "black"), 306 | axis.line.x = element_line(colour = "black", size = .5), 307 | axis.line.y = element_line(colour = "black", size = .5), 308 | legend.position = "right", 309 | axis.title.y = element_text(margin=margin(0,15,0,0)), 310 | axis.title.x = element_text(margin=margin(15,0,0,0)), 311 | panel.grid.major = element_blank(), 312 | panel.grid.minor = element_blank(), 313 | panel.background = element_blank(), 314 | axis.line = element_line(colour = "black") 315 | ) 316 | ``` 317 | 318 | 319 | #### Making Panel B 320 | ```{r, fig.height=3.5, fig.width=8} 321 | chinese_moratoria_plot_fishing_hours <- ggplot() + 322 | geom_rect(data = moratoria_dates1, 323 | aes(xmin = start_date, 324 | xmax = end_date, 325 | ymin = 0, 326 | ymax = Inf, 327 | fill = "tomato"), 328 | alpha = 0.5, 329 | show.legend = TRUE) + 330 | geom_rect(data = moratoria_dates2, 331 | aes(xmin = start_date, 332 | xmax = end_date, 333 | ymin = 0, 334 | ymax = Inf, 335 | fill = "tomato"), 336 | alpha = 0.15, 337 | show.legend = TRUE) + 338 | geom_rect(data = new_year_dates, 339 | aes(xmin = start_date, 340 | xmax = end_date, 341 | ymin = 0, 342 | ymax = Inf, 343 | fill = "#f7e456"), 344 | alpha = 1, 345 | show.legend = TRUE) + 346 | geom_line(data = chinese_active_vessels_inside_eez, 347 | aes(x = date, y = fishing_hours/1000), 348 | size = 0.3) + 349 | theme_minimal() + 350 | scale_x_date(date_breaks = "1 year", 351 | date_labels = "%Y ", 352 | limits = c(as.Date("2013-01-01"), as.Date('2017-01-01')), 353 | expand = c(0,0)) + 354 | xlab("") + 355 | scale_y_continuous(breaks = c(0,20,40,60), 356 | expand = c(0, 0), 357 | labels = scales::comma, 358 | limits = c(0,60) ) + 359 | ylab("Fishing Hours (x1000)")+ 360 | scale_fill_manual(values = c("#f7d694", "tomato"), 361 | name = " ", 362 | labels = c("Chinese New Year", "Moratoria")) + 363 | theme_gfw_paper + 364 | theme(axis.ticks = element_line(size = 0.5), 365 | panel.grid.major = element_blank(), 366 | panel.grid.minor = element_blank(), 367 | panel.background = element_blank(), 368 | axis.line = element_line(colour = "black"), 369 | axis.text.y = element_text(size = 10), 370 | 371 | legend.justification = "top", 372 | legend.position = 'none', 373 | legend.text = element_text(size = 6), 374 | plot.margin = unit(margin(1,1,1,1),'cm') 375 | ) 376 | chinese_moratoria_plot_fishing_hours 377 | ``` 378 | 379 | 380 | 381 | -------------------------------------------------------------------------------- /Supplemental_Materials/S6 Area of the Ocean that is Fished/fishing_area_calc_old.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Fishing Coverage- Equal Area Projection" 3 | output: html_document 4 | --- 5 | 6 | ```{r setup, include=FALSE} 7 | knitr::opts_chunk$set(echo = TRUE) 8 | ``` 9 | 10 | 11 | ```{r echo = FALSE, message=FALSE, comment=FALSE} 12 | library(tidyverse) 13 | library(viridis) 14 | library(extrafont) 15 | library(bigrquery) 16 | library(rgdal) 17 | library(rgeos) 18 | library(ggalt) 19 | library(printr) 20 | loadfonts() 21 | BQ_connection <- dbConnect(dbi_driver(), dataset = "", project = "world-fishing-827") 22 | ``` 23 | 24 | This notebook calculates the area of the ocean over which fishing by all gear 25 | types takes place, as well as fishing by the three (3) primary geartypes described 26 | in the manuscript (drifting longlines, trawlers, purse seines). 27 | 28 | The code starts with an example using all fishing and is then followed by 29 | individual analyses for each gear type. 30 | 31 | Query to generate total fishing raster at 0.5 degree resolution. 32 | ```{sql connection = BQ_connection, output.var = "total_fishing_effort_05"} 33 | SELECT 34 | SUM(hours) hours, 35 | FLOOR(lat/0.5)*0.5 lat_bin, 36 | FLOOR(lon/0.5)*0.5 lon_bin 37 | FROM ( 38 | SELECT 39 | * 40 | FROM ( 41 | SELECT 42 | mmsi, 43 | hours, 44 | seg_id, 45 | lat, 46 | lon 47 | FROM 48 | [gfw_research.nn] 49 | /*[gfw_research.FAO] */ 50 | WHERE 51 | _PARTITIONTIME BETWEEN TIMESTAMP('2016-01-01') AND TIMESTAMP('2016-12-31') 52 | AND 53 | nnet_score >.5 ) /*measure_new_score */ 54 | WHERE 55 | seg_id IN ( 56 | SELECT seg_id FROM [world-fishing-827:gfw_research.segments2] 57 | WHERE point_count > 20 58 | AND max_lat - min_lat > .01 59 | AND max_lon - min_lon > .01 60 | AND NOT (point_count<10 61 | AND terrestrial_positions = point_count) 62 | AND NOT ((min_lon >= 0 /* these are almost definitely noise*/ 63 | AND max_lon <= 0.109225) 64 | OR (min_lat >= 0 65 | AND max_lat <= 0.109225) OR 66 | (min_lat <= -0.109225 AND 67 | max_lat <= 0))) /*must move 100 meters in lat and lon*/ 68 | AND mmsi IN (SELECT mmsi from [gfw_research.vessel_info_20170522] WHERE on_fishing_list_nn) 69 | AND mmsi not in (SELECT mmsi from [world-fishing-827:gfw_research.vessel_info_20170522] WHERE offsetting) 70 | AND mmsi not in (725000332, 71 | 725000910, 72 | 725000335, 73 | 725000410) /*trawlers off chile classified as PS*/ 74 | AND mmsi not in (224084620, 224107670) /* trawlers South Atlantic as PS*/ 75 | AND mmsi not in (431560000, 431757000, 432846000) /*Western Pacific research as PS*/ 76 | AND mmsi not in (431704470, 431267000, 431800050) /*north west pacific, squid jiggers as PS, and research vessel FRA */ 77 | AND mmsi not in (416000002) /* south atlantic */ 78 | ANd mmsi not in (431700260, 431797000,431704490) /* offsetting longliners, Panama */ 79 | and mmsi not in (412421007) /* DL track in EEZ north Pacific */ 80 | And mmsi not in (413322690,413322770) /*DL track in EEZ near NZ, good longliners, odd fishing */ 81 | AND mmsi not in (412420971, 412420973) /* odd squid jiggers tracking across Pacific */ 82 | AND mmsi not in (416121800) /*south Pacific track across EEZ */ 83 | AND mmsi NOT IN (412421005) /*squid jigger appears to be fishing across southern Atlantic during transit */ 84 | AND mmsi NOT IN (441051000,412420001) /*trawler, transitting south Atlantic */ 85 | AND mmsi NOT IN (432288000) /* research vessel, track across West Pacific EEZ, listed as drifting longliner */ ) a 86 | INNER JOIN 87 | (SELECT 88 | mmsi 89 | FROM 90 | [scratch_david_mmsi_lists.nn_labels_20170516] 91 | where label IN ("fixed_gear", 92 | "drifting_longlines", 93 | "other_fishing", 94 | "trawlers", 95 | "purse_seines", 96 | "squid_jigger") 97 | and mmsi in (SELECT mmsi from [scratch_david_mmsi_lists.nn_labels_2016_20170516] 98 | WHERE label IN ("fixed_gear", 99 | "drifting_longlines", 100 | "other_fishing", 101 | "trawlers", 102 | "purse_seines", 103 | "squid_jigger") 104 | )) b 105 | ON 106 | a.mmsi = b.mmsi 107 | GROUP BY 108 | lat_bin, 109 | lon_bin) 110 | ``` 111 | 112 | Generate a grid of points at 0.5 113 | ```{r} 114 | #nrow(total_fishing_effort_05) 115 | 116 | grid_latlon <- expand.grid(lat =seq(min(total_fishing_effort_05$lat_bin), 117 | max(total_fishing_effort_05$lat_bin), 0.5), 118 | lon = seq(min(total_fishing_effort_05$lon_bin), 119 | max(total_fishing_effort_05$lon_bin), 0.5)) 120 | 121 | ``` 122 | 123 | Join the global grid to the global fishing data. Assign locations with no fishing 124 | a fishing value of 0. 125 | ```{r} 126 | gridded_fishing = left_join(grid_latlon, total_fishing_effort_05, by = c('lat' = 'lat_bin', 'lon' = 'lon_bin')) 127 | gridded_fishing$hours = ifelse(is.na(gridded_fishing$hours), 0, gridded_fishing$hours) 128 | #gridded_fishing %>% filter(hours == 0) %>% summarize(n()) 129 | #nrow(gridded_fishing) - gridded_fishing %>% filter(hours == 0) %>% summarize(n()) 130 | ``` 131 | 132 | Convert fishing effort dataframe into a spatial dataframe (specify lon and lat as x, y) 133 | ```{r} 134 | library(sp) 135 | library(rgdal) 136 | coordinates(gridded_fishing)=~lon+lat 137 | ``` 138 | 139 | Assign a projection to the gridded fishing effort 140 | ```{r} 141 | proj4string(gridded_fishing)=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") # set it to lat-long 142 | #gridded_fishing = spTransform(gridded_fishing,CRS("+proj=cea +lon_0=0 +x_0=0 +y_0=0 +lat_ts=45 +datum=WGS84 +units=m +no_defs")) 143 | 144 | #ensure fishing in on regular grid 145 | gridded(gridded_fishing) = TRUE 146 | ``` 147 | 148 | 149 | Generate the fishing effort raster. Specify original projection and extent, 150 | then project the raster into Gall-Peters equal area 151 | ```{r} 152 | library(raster) 153 | fishing_raster_05 = rasterFromXYZ(gridded_fishing, crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") 154 | bb = extent(-180, 180, -78.8, 81.8) 155 | fishing_raster_05 = setExtent(fishing_raster_05, bb, keepres = TRUE) 156 | fishing_raster_05 = projectRaster(fishing_raster_05, crs = "+proj=cea +lon_0=0 +x_0=0 +y_0=0 +lat_ts=45 +datum=WGS84 +units=m +no_defs", over = TRUE) #this is Gall-Peters Equal Area Projection 157 | ``` 158 | 159 | 160 | Export raster which is then analyzed in QGIS (See outline below). 161 | ```{r, eval=FALSE} 162 | writeRaster(fishing_raster_05, '~/Documents/GlobalFishingWatch/Global_raster_paper/oceans_equal_area/fishing_raster_05_round2.tif', format = 'GTiff', overwrite = TRUE) 163 | ``` 164 | 165 | ### Loading the oceans shapefile 166 | ```{r} 167 | setwd("~/Documents/GlobalFishingWatch/oceans_equal_area/") 168 | oceans <- readOGR('.', "oceans_gallpeters") 169 | oceans_df = fortify(oceans) 170 | ``` 171 | 172 | 173 | 174 | 175 | Building upon this post: 176 | https://gis.stackexchange.com/questions/147158/how-to-calculate-the-area-of-a-raster-within-a-polygon-which-is-greater-than-a-s 177 | 178 | Then in QGIS: 179 | *1 Import both the raster and the gall_peters projected oceans shapefile (oceans 180 | shapefile from natural earth http://www.naturalearthdata.com/downloads/10m-physical-vectors/). 181 | *2 Within raster tools, use Raster Calculator to calculate where the fishing value is greater than 0. 182 | fishing_raster_05@1 > 0, this is a Boolean that gives 1 if true, 0 if false and generates a new raster of 0/1. 183 | *3 Then use the Zonal Statistics (under Raster) to generate the mean value for this 0/1 raster within the oceans polygon. 184 | * This represents the percentage of the ocean that is fished. Knowing the areas of the polygon one could calculate the actual area fished. 185 | 186 | For the total effort raster = 56.4% 187 | 188 | ## For each gear type % of total ocean (% of total area fished) 189 | These data arise from analysis below 190 | 191 | longline = 45.7% or (81%) 192 | trawler = 9.7% or (17.2%) 193 | purse = 17.1% or (30.3%) 194 | 195 | 196 | Using the field calculator and the Gall-Peters projected oceans shapefile I calculated an area of the shapefile 197 | Attributes Table -> Field Calculator -> area($geometry) in square meters. 363223868892795 m2 198 | Converting to square kilometers the value agrees with values reported online: #363223868 km2 199 | 200 | Total area fished = 0.56 * 363223868 = 203,405,366 km2 or 2.03 x 10^8 km2 201 | 202 | 203 | ```{r} 204 | # % of whole ocean 205 | total_fishing_percent = 0.564 206 | longliner_percent = 0.457 207 | trawler_percent = 0.097 208 | purse_seine_percent = 0.171 209 | 210 | 211 | #for the total ocean 212 | total_ocean_area_km2 = 363223868 213 | 214 | total_fished_area = total_fishing_percent * total_ocean_area_km2 215 | longliner_ocean = longliner_percent * total_ocean_area_km2 216 | trawler_ocean = trawler_percent * total_ocean_area_km2 217 | purse_seine_ocean = purse_seine_percent * total_ocean_area_km2 218 | 219 | 220 | df = data.frame(gear_type = c('total','longliner', 'trawler', 'purse_seine'), 221 | area_of_ocean_fished = c(total_fished_area, longliner_ocean, trawler_ocean, purse_seine_ocean)) 222 | df 223 | 224 | ``` 225 | 226 | ANALYSIS/DATA for individual gear types following methods outlines in detail 227 | above. 228 | 229 | ### Run the query to get the fishing effort by type so that individual rasters 230 | can be created for each gear type 231 | 232 | ```{sql connection = BQ_connection, output.var = "fishing_effort_by_type_05"} 233 | SELECT 234 | SUM(hours) hours, 235 | FLOOR(lat/0.5)*0.5 lat_bin, 236 | FLOOR(lon/0.5)*0.5 lon_bin, 237 | label 238 | FROM ( 239 | SELECT 240 | * 241 | FROM ( 242 | SELECT 243 | mmsi, 244 | hours, 245 | seg_id, 246 | lat, 247 | lon 248 | FROM 249 | [gfw_research.nn] 250 | WHERE 251 | _PARTITIONTIME BETWEEN TIMESTAMP('2016-01-01') AND TIMESTAMP('2016-12-31') 252 | AND 253 | nnet_score >.5 ) 254 | WHERE 255 | seg_id IN ( 256 | SELECT seg_id FROM [world-fishing-827:gfw_research.segments2] 257 | WHERE point_count > 20 258 | AND max_lat - min_lat > .01 259 | AND max_lon - min_lon > .01 260 | AND NOT (point_count<10 261 | AND terrestrial_positions = point_count) 262 | AND NOT ((min_lon >= 0 /* these are almost definitely noise*/ 263 | AND max_lon <= 0.109225) 264 | OR (min_lat >= 0 265 | AND max_lat <= 0.109225) OR 266 | (min_lat <= -0.109225 AND 267 | max_lat <= 0))) /*must move 100 meters in lat and lon*/ 268 | AND mmsi IN (SELECT mmsi from [gfw_research.vessel_info_20170522] WHERE on_fishing_list_nn) 269 | AND mmsi not in (SELECT mmsi from [world-fishing-827:gfw_research.vessel_info_20170522] WHERE offsetting) 270 | AND mmsi not in (725000332, 271 | 725000910, 272 | 725000335, 273 | 725000410) /*trawlers off chile classified as PS*/ 274 | AND mmsi not in (224084620, 224107670) /* trawlers South Atlantic as PS*/ 275 | AND mmsi not in (431560000, 431757000, 432846000) /*Western Pacific research as PS*/ 276 | AND mmsi not in (431704470, 431267000, 431800050) /*north west pacific, squid jiggers as PS, and research vessel FRA */ 277 | AND mmsi not in (416000002) /* south atlantic */ 278 | ANd mmsi not in (431700260, 431797000,431704490) /* offsetting longliners, Panama */ 279 | and mmsi not in (412421007) /* DL track in EEZ north Pacific */ 280 | And mmsi not in (413322690,413322770) /*DL track in EEZ near NZ, good longliners, odd fishing */ 281 | AND mmsi not in (412420971, 412420973) /* odd squid jiggers tracking across Pacific */ 282 | AND mmsi not in (416121800) /*south Pacific track across EEZ */ 283 | AND mmsi NOT IN (760000650) /*oil products tanker, off Peru, labeled as trawler */ 284 | AND mmsi NOT IN (412421005) /*squid jigger appears to be fishing across southern Atlantic during transit */ 285 | AND mmsi NOT IN (413201110) /*longliner, currently classified as a trawler (mid-Atlantic) */ 286 | AND mmsi NOT IN (432288000) /* research vessel, track across West Pacific EEZ, listed as drifting longliner */ 287 | /*mmsi NOT IN (432621000,431028000,431494000, 432850000,9102213,112420884,150200144,150200148,150200162,150200250,150200252,150200389,150200783,150200893,150200895,150200974,150201019,150201073,150201423,150201498,150201517,150201536,150201550,150201552,150201776,150202857,150202858,150202904,150203018,150203019,150203020,150203021,150203022,158888888,200000590,200000596,200000598,200000599,411041802,412071033,412200146,412200991,412207532,412207533,412207535,412207536,412207537,412207538,412207539,412207541,412207542,412207545,412207546,412209011,412209092,412209093,412209097,412209098,412209099,412209101,412209102,412209105,412209106,412209132,412209133,412209136,412209139,412209141,412209168,412209171,412209172,412211196,412211691,412322329,412322547,412322587,412322866,412322952,412322953,412322984,412323207,412326016,412327269,412327285,412327422,412327493,412328279,412328794,412329642,412329643,412329644,412331106,412331107,412331109,412331111,412331112,412333121,412364066,412364739,412401220,412402610,412411514,412411515,412411519,412411529,412412981,412418059,412419955,412419958,412420248,412420276,412420421,412420453,412420502,412420503,412420561,412420573,412420574,412420575,412420576,412420684,412420787,412420789,412420805,412420833,412420871,412420878,412420879,412420881,412420882,412420883,412420885,412420886,412425706,412437961,412437962,412440077,412440078,412440104,412440105,412440106,412440113,412440255,412440256,412440257,412440258,412440259,412440261,412440377,412447093,412480433,412480434,412661896,412693030,412699340,413035015,413066568,413322650,413685698,414203586,415000005,441301074,462801187,800011282,800016350,800017747,800017800,800018712,800019446,800030681,812411524,900007134,900007138,900007140,900007148,900007154,900023867,900025166,900025206,900025236,900025344,900025350,900025357,900025393,900025395,910060382) vessels with offset positions 288 | AND mmsi NOT IN (SELECT mmsi FROM [world-fishing-827:scratch_david_mmsi_lists.research_20170522] research/training vessels) 289 | and mmsi not in (987357573,987357579,987357559,986737000,983712160,987357529,987357559,987357579) helicopters */) a 290 | INNER JOIN 291 | (SELECT 292 | mmsi, 293 | label 294 | FROM 295 | [scratch_david_mmsi_lists.nn_labels_20170516] 296 | where label IN ("fixed_gear", 297 | "drifting_longlines", 298 | "other_fishing", 299 | "trawlers", 300 | "purse_seines", 301 | "squid_jigger") 302 | and mmsi in (SELECT mmsi from [scratch_david_mmsi_lists.nn_labels_2016_20170516] 303 | WHERE label IN ("fixed_gear", 304 | "drifting_longlines", 305 | "other_fishing", 306 | "trawlers", 307 | "purse_seines", 308 | "squid_jigger") 309 | )) b 310 | ON 311 | a.mmsi = b.mmsi 312 | GROUP BY 313 | lat_bin, 314 | lon_bin, 315 | label) 316 | ``` 317 | 318 | Separate out the different gear types 319 | 320 | ```{r} 321 | purse_seine_effort_05 = fishing_effort_by_type_05 %>% 322 | filter(inferred_label == 'purse_seines'& lat_bin > -90 & lat_bin < 90) 323 | 324 | 325 | longline_effort_05 = fishing_effort_by_type_05 %>% 326 | filter(inferred_label == 'drifting_longlines'& lat_bin > -90 & lat_bin < 85) 327 | 328 | trawler_effort_05 = fishing_effort_by_type_05 %>% 329 | filter(inferred_label == 'trawlers' & lat_bin > -90 & lat_bin < 90) 330 | ``` 331 | 332 | 333 | ### Longliners 334 | Apply the gridded lat lon and replace the NA values with 0 335 | 336 | ```{r} 337 | gridded_fishing_longliner = left_join(grid_latlon, longline_effort_05, by = c('lat' = 'lat_bin', 'lon' = 'lon_bin')) 338 | gridded_fishing_longliner$hours = ifelse(is.na(gridded_fishing_longliner$hours), 0, gridded_fishing_longliner$hours) 339 | ``` 340 | 341 | Same as above, generate a spatial dataframe and then a raster with the Gall-Peters projections 342 | ```{r} 343 | coordinates(gridded_fishing_longliner)=~lon+lat 344 | ``` 345 | 346 | 347 | 348 | ```{r} 349 | gridded_raster_longliner = rasterFromXYZ(gridded_fishing_longliner, crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") #specify original projections as longlat 350 | bb = extent(-180, 180, -90, 90) #specify the extent 351 | gridded_raster_longliner = setExtent(gridded_raster_longliner, bb, keepres = TRUE) #apply extent 352 | gridded_raster_longliner = projectRaster(gridded_raster_longliner, crs = "+proj=cea +lon_0=0 +x_0=0 +y_0=0 +lat_ts=45 +datum=WGS84 +units=m +no_defs", over = TRUE) #project the raster into the Gall-Peters Equal Area Projection 353 | ``` 354 | 355 | 356 | ```{r, eval = FALSE} 357 | writeRaster(gridded_raster_longliner, '~/Documents/GlobalFishingWatch/oceans_equal_area/fishing_raster_05_longliner.tif', format = 'GTiff', overwrite = TRUE) 358 | ``` 359 | 360 | ### Trawlers 361 | 362 | ```{r} 363 | gridded_fishing_trawler = left_join(grid_latlon, trawler_effort_05, by = c('lat' = 'lat_bin', 'lon' = 'lon_bin')) 364 | gridded_fishing_trawler$hours = ifelse(is.na(gridded_fishing_trawler$hours), 0, gridded_fishing_trawler$hours) 365 | ``` 366 | 367 | 368 | ```{r} 369 | coordinates(gridded_fishing_trawler)=~lon+lat 370 | ``` 371 | 372 | 373 | 374 | ```{r} 375 | gridded_raster_trawler = rasterFromXYZ(gridded_fishing_trawler, crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") #specify original projections as longlat 376 | bb = extent(-180, 180, -90, 90) #specify the extent 377 | gridded_raster_trawler = setExtent(gridded_raster_trawler, bb, keepres = TRUE) #apply extent 378 | gridded_raster_trawler = projectRaster(gridded_raster_trawler, crs = "+proj=cea +lon_0=0 +x_0=0 +y_0=0 +lat_ts=45 +datum=WGS84 +units=m +no_defs", over = TRUE) #project the raster into the Gall-Peters Equal Area Projection 379 | ``` 380 | 381 | 382 | ```{r, eval = FALSE} 383 | writeRaster(gridded_raster_trawler, '~/Documents/GlobalFishingWatch/oceans_equal_area/fishing_raster_05_trawler.tif', format = 'GTiff', overwrite = TRUE) 384 | ``` 385 | 386 | 387 | 388 | ### Purse seines 389 | 390 | ```{r} 391 | gridded_fishing_purseseine = left_join(grid_latlon, purse_seine_effort_05, by = c('lat' = 'lat_bin', 'lon' = 'lon_bin')) 392 | gridded_fishing_purseseine$hours = ifelse(is.na(gridded_fishing_purseseine$hours), 0, gridded_fishing_purseseine$hours) 393 | ``` 394 | 395 | 396 | ```{r} 397 | coordinates(gridded_fishing_purseseine)=~lon+lat 398 | ``` 399 | 400 | 401 | 402 | ```{r} 403 | gridded_raster_purseseine = rasterFromXYZ(gridded_fishing_purseseine, crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs") #specify original projections as longlat 404 | bb = extent(-180, 180, -90, 90) #specify the extent 405 | gridded_raster_purseseine = setExtent(gridded_raster_purseseine, bb, keepres = TRUE) #apply extent 406 | gridded_raster_purseseine = projectRaster(gridded_raster_purseseine, crs = "+proj=cea +lon_0=0 +x_0=0 +y_0=0 +lat_ts=45 +datum=WGS84 +units=m +no_defs", over = TRUE) #project the raster into the Gall-Peters Equal Area Projection 407 | ``` 408 | 409 | 410 | ```{r, eval=FALSE} 411 | writeRaster(gridded_raster_purseseine, '~/Documents/GlobalFishingWatch/oceans_equal_area/fishing_raster_05_purseseine.tif', format = 'GTiff', overwrite = TRUE) 412 | ``` 413 | 414 | --------------------------------------------------------------------------------