{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [ "remove-cell" ] }, "outputs": [], "source": [ "import subprocess\n", "import sys\n", "\n", "COLAB = \"google.colab\" in sys.modules\n", "\n", "\n", "def _install(package):\n", " if COLAB:\n", " ans = input(f\"Install { package }? [y/n]:\")\n", " if ans.lower() in [\"y\", \"yes\"]:\n", " subprocess.check_call(\n", " [sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", package]\n", " )\n", " print(f\"{ package } installed!\")\n", "\n", "\n", "def _colab_install_missing_deps(deps):\n", " import importlib\n", "\n", " for dep in deps:\n", " if importlib.util.find_spec(dep) is None:\n", " if dep == \"iris\":\n", " dep = \"scitools-iris\"\n", " _install(dep)\n", "\n", "\n", "deps = [\"erddapy\"]\n", "_colab_install_missing_deps(deps)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Fetching data from CO-OPS ERDDAP with Python tools\n", "\n", "Created: 2016-10-12\n", "\n", "Updated: 2022-05-26\n", "\n", "In this post we will use `erddapy` to find and download data from the\n", "[Center for Operational Oceanographic Products and Services (CO-OPS)](https://opendap.co-ops.nos.noaa.gov/erddap/index.html) ERDDAP server.\n", "\n", "Here we will fetch data during the [hurricane Matthew](https://en.wikipedia.org/wiki/Hurricane_Matthew) passage over the southeast states from 2016-10-05 to 2016-10-12. The first step is to instantiate the server object and then add the constraints for our query." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "jupyter": { "outputs_hidden": true } }, "outputs": [], "source": [ "from erddapy import ERDDAP\n", "\n", "e = ERDDAP(\n", " server=\"https://opendap.co-ops.nos.noaa.gov/erddap\",\n", " protocol=\"tabledap\",\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The geographical bounding box includes all the states in the [SECOORA](https://secoora.org/) region: Florida, Georgia, South and North Carolina." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "min_lat, max_lat = 24.25, 36.70\n", "min_lon, max_lon = -87.40, -74.70" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Row Type | \n", "Variable Name | \n", "Attribute Name | \n", "Data Type | \n", "Value | \n", "
---|---|---|---|---|---|
15 | \n", "variable | \n", "STATION_ID | \n", "NaN | \n", "String | \n", "NaN | \n", "
16 | \n", "attribute | \n", "STATION_ID | \n", "cf_role | \n", "String | \n", "timeseries_id | \n", "
17 | \n", "attribute | \n", "STATION_ID | \n", "comment | \n", "String | \n", "To view the station id listing go to: https://... | \n", "
18 | \n", "attribute | \n", "STATION_ID | \n", "ioos_category | \n", "String | \n", "Identifier | \n", "
19 | \n", "attribute | \n", "STATION_ID | \n", "long_name | \n", "String | \n", "REQUIRED 7-character Station ID surrounded in ... | \n", "