Visual analytics web application for AFSC GAP data that can be used without writing code. It uses the afscgap
library underneath and enables users to continue in code or through a spreadsheet export.
No install required! The application is hosted for the public at https://app.pyafscgap.org but may be run locally as described below as well.
This application can be self-hosted or run locally. Due to the high disk usage required for this tool to operate efficiently (about 1GB local disk storage), it is not installed by default when running pip install afscgap
. To install:
$ git clone https://github.com/SchmidtDSE/afscgap.git
$ cd afscgap/afscgapviz
$ pip install -r requirements.txt
$ bash load_deps.sh
Note that this application still requires a dataset as described below. For ease of development, webpack is not required.
This application is a Flask application that requires access to a database in order to work correctly.
The default usage leverages a sqlite database which is read only when used by the application. A pre-built database can be downloaded into the afscgap/afscgapviz
directory like so:
$ cd afscgap/afscgapviz
$ wget https://pyafscgap.org/community/geohashes.zip
$ unzip geohashes.zip
$ rm geohashes.zip
If you want to build the dataset yourself, run the build_database
script like so:
$ cd afscgap/afscgapviz
$ bash build_database.sh
Once the database is in place, one can start the web application with python afscgapviz.py
. If you need to create a Flask app manually, it can be done like so:
import flask
import afscgapviz
app = flask.Flask(__name__)
afscgapviz.build_app(app)
This may be useful when running outside a development server.
Any DB API 2.0 compliant database library may be used. For example, pg8000 can be used to leverage Postgres instead of sqlite like so:
import contextlib
import threading
import flask
import pg8000
import afscgapviz
pg8000.dbapi.paramstyle = 'qmark'
app = flask.Flask(__name__)
def get_connection_no_cache():
return pg8000.dbapi.connect()
def build_get_connection():
lock = threading.Lock()
cache = {'cache': None}
def get_connection():
connection = cache['cache']
# Test connection
if connection:
try:
cursor = connection.cursor()
cursor.execute('SELECT 1')
cursor.fetchone()
cursor.close()
except:
connection = None
# Make connection if needed
if connection is None:
connection = get_connection_no_cache()
# Save for next time
cache['cache'] = connection
return connection
@contextlib.contextmanager
def get_connection_wrapped():
lock.acquire()
try:
yield get_connection()
finally:
lock.release()
return get_connection_wrapped
afscgapviz.build_app(
app,
conn_generator_builder=build_get_connection
)
Note that the development of the tool is focused on sqlite. Pull requests are welcome for fixes for other backends but changes to SQL must be compatible with sqlite.
Invalid data are excluded and only data with area swept in hectares, catch (count and weight in kg), and temperatures (both bottom and surface) are retained. No effort is made to try to "fix" records with incorrect data. Information is used as provided by the AFSC GAP API service. Furthermore, aggregation uses a single latitude / longitude point for a record and it remains possible that a haul may spill out of a geohash causing some approximation in catch per unit effort (CPUE) calculation. For more details on the "zero catch" inference methods used, see main README.
Like the rest of the the project, we are happy to make this library available under the BSD 3-Clause license. See LICENSE for more details. (c) 2023 Regents of University of California. See the Eric and Wendy Schmidt Center for Data Science and the Environment at UC Berkeley.
After installing dev dependencies (pip install -r requirements.txt
), we recommend the following local checks:
$ nose2
$ mypy *.py
$ pyflakes *.py
$ pycodestyle *.py
Note these checks are run by CI / CD. Furthermore, JS tests can be run via grunt from the root directory or by:
$ python -m http.server
Then, direct your browser to http://0.0.0.0:8000/static/test/test.html.
We invite contributions via our project Github. Please read the CONTRIBUTING.md file for more information.
In addition to using the afscgap
library elsewhere in this repository, the following open source tools are used:
- D3.js under the ISC License from Mike Bostock.
- Flask under the BSD License from Pallets.
- Geolib under the MIT License from Anu Joy.
- Papa Parse under the MIT License from Matthew Holt.
- Toolz under the BSD License from Matthew Rocklin.
In CI / CD, this project also uses QUnit under the MIT License from OpenJS Foundation and other contributors as well as Grunt under an MIT-like License from jQuery Foundation and other contributors.
Thank you to all of these projects for their contribution. Note that CDNs are not used for privacy reasons.
The following are citations specifically for the visual analytics tool not covered in the open source section:
- "AFSC Groundfish and Crab Assessment Program Bottom Trawl Surveys." AFSC Gap Survey, NOAA Fisheries, https://www.fisheries.noaa.gov/foss/f?p=215%3A28.
- Brewer, Cynthia, and Mark Harrower. "Colorbrewer 2.0." ColorBrewer, The Pennsylvania State University, 3 May 2021, https://colorbrewer2.org/#type=sequential&scheme=BuGn&n=3.
- Brown, Mark. "Super Mario 3D World's 4 Step Level Design." Game Maker's Toolkit, YouTube, 16 Mar. 2015, https://www.youtube.com/watch?v=dBmIkEvEBtA.
- George, Kavitha. "Alaska Cod Fishery Closes and Industry Braces for Ripple Effect." NPR, NPR, 8 Dec. 2019, https://www.npr.org/2019/12/08/785634169/alaska-cod-fishery-closes-and-industry-braces-for-ripple-effect.
- Laurel, Benjamin J., and Lauren A. Rogers. "Loss of Spawning Habitat and Prerecruits of Pacific Cod during a Gulf of Alaska Heatwave." Canadian Journal of Fisheries and Aquatic Sciences, vol. 77, no. 4, 23 Jan. 2020, pp. 644–650., https://doi.org/10.1139/cjfas-2019-0238.
- Nutt, Christian. "The Structure of Fun: Learning from Super Mario 3D Land's Director." Game Developer, Informa PLC Informa UK, 13 Apr. 2012, https://www.gamedeveloper.com/design/the-structure-of-fun-learning-from-i-super-mario-3d-land-i-s-director.
- Yang, Qiong, et al. "How 'The Blob' Affected Groundfish Distributions in the Gulf of Alaska." Fisheries Oceanography, 6 Feb. 2019, https://doi.org/10.1111/fog.12422.