{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Quick introduction\n",
"\n",
"erddapy is a pure python package and can be installed with conda\n",
"\n",
"```shell\n",
"conda install --channel conda-forge erddapy\n",
"```\n",
"\n",
"or pip\n",
"\n",
"```shell\n",
"pip install erddapy\n",
"```\n",
"\n",
"\n",
"First we need to instantiate the ERDDAP URL constructor for a server.\n",
"In these examples we will use\n",
"[https://standards.sensors.ioos.us/erddap/index.html](https://standards.sensors.ioos.us/erddap/index.html) and [https://erddap.ioos.us/erddap/index.html](https://erddap.ioos.us/erddap/index.html)."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2023-08-09T14:28:34.647736Z",
"iopub.status.busy": "2023-08-09T14:28:34.647471Z",
"iopub.status.idle": "2023-08-09T14:28:35.190289Z",
"shell.execute_reply": "2023-08-09T14:28:35.189637Z"
}
},
"outputs": [],
"source": [
"from erddapy import ERDDAP\n",
"\n",
"\n",
"server = \"https://standards.sensors.ioos.us/erddap\"\n",
"e = ERDDAP(\n",
" server=server,\n",
" protocol=\"tabledap\",\n",
" response=\"csv\",\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can populate the object a dataset id, variables of interest, and its\n",
"constraints (last week gliders). Use the method `to_pandas` to download the\n",
"csv(p) response, a comma separated values with units and explore the Dataframe.\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2023-08-09T14:28:35.193760Z",
"iopub.status.busy": "2023-08-09T14:28:35.193288Z",
"iopub.status.idle": "2023-08-09T14:28:35.785462Z",
"shell.execute_reply": "2023-08-09T14:28:35.784463Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" latitude (degrees_north) | \n",
" longitude (degrees_east) | \n",
" sea_water_temperature (degree_Celsius) | \n",
" air_temperature (degree_Celsius) | \n",
"
\n",
" \n",
" time (UTC) | \n",
" | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 2000-01-01 00:08:00+00:00 | \n",
" 32.8032 | \n",
" -79.6204 | \n",
" 14.01 | \n",
" 14.42 | \n",
"
\n",
" \n",
" 2000-01-01 01:08:00+00:00 | \n",
" 32.8032 | \n",
" -79.6204 | \n",
" 13.92 | \n",
" 13.91 | \n",
"
\n",
" \n",
" 2000-01-01 02:08:00+00:00 | \n",
" 32.8032 | \n",
" -79.6204 | \n",
" 13.90 | \n",
" 13.60 | \n",
"
\n",
" \n",
" 2000-01-01 03:08:00+00:00 | \n",
" 32.8032 | \n",
" -79.6204 | \n",
" 13.92 | \n",
" 13.47 | \n",
"
\n",
" \n",
" 2000-01-01 04:08:00+00:00 | \n",
" 32.8032 | \n",
" -79.6204 | \n",
" 13.93 | \n",
" 13.28 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" latitude (degrees_north) longitude (degrees_east) \\\n",
"time (UTC) \n",
"2000-01-01 00:08:00+00:00 32.8032 -79.6204 \n",
"2000-01-01 01:08:00+00:00 32.8032 -79.6204 \n",
"2000-01-01 02:08:00+00:00 32.8032 -79.6204 \n",
"2000-01-01 03:08:00+00:00 32.8032 -79.6204 \n",
"2000-01-01 04:08:00+00:00 32.8032 -79.6204 \n",
"\n",
" sea_water_temperature (degree_Celsius) \\\n",
"time (UTC) \n",
"2000-01-01 00:08:00+00:00 14.01 \n",
"2000-01-01 01:08:00+00:00 13.92 \n",
"2000-01-01 02:08:00+00:00 13.90 \n",
"2000-01-01 03:08:00+00:00 13.92 \n",
"2000-01-01 04:08:00+00:00 13.93 \n",
"\n",
" air_temperature (degree_Celsius) \n",
"time (UTC) \n",
"2000-01-01 00:08:00+00:00 14.42 \n",
"2000-01-01 01:08:00+00:00 13.91 \n",
"2000-01-01 02:08:00+00:00 13.60 \n",
"2000-01-01 03:08:00+00:00 13.47 \n",
"2000-01-01 04:08:00+00:00 13.28 "
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e.dataset_id = \"org_cormp_cap2\"\n",
"\n",
"e.variables = [\n",
" \"time\",\n",
" \"latitude\",\n",
" \"longitude\",\n",
" \"sea_water_temperature\",\n",
" \"air_temperature\"\n",
"]\n",
"\n",
"e.constraints = {\n",
" \"time>=\": \"2000-01-01\",\n",
"}\n",
"\n",
"\n",
"df = e.to_pandas(\n",
" index_col=\"time (UTC)\",\n",
" parse_dates=True,\n",
").dropna()\n",
"\n",
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can constraint the in time and space with relative constraints like in the\n",
"example below. For more ways to access the data please check the \"Longer\n",
"introduction.\"\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2023-08-09T14:28:35.823344Z",
"iopub.status.busy": "2023-08-09T14:28:35.822544Z",
"iopub.status.idle": "2023-08-09T14:28:35.828418Z",
"shell.execute_reply": "2023-08-09T14:28:35.827614Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://erddap.ioos.us/erddap/tabledap/processed_asset_inventory.htmlTable?&longitude<=min(longitude)+10&longitude>=min(longitude)&latitude<=min(latitude)+10&latitude>=min(latitude)\n"
]
}
],
"source": [
"server = \"https://erddap.ioos.us/erddap\"\n",
"e = ERDDAP(\n",
" server=server,\n",
" protocol=\"tabledap\",\n",
" response=\"csv\",\n",
")\n",
"\n",
"e.dataset_id = \"processed_asset_inventory\"\n",
"\n",
"# Get the box of the first 10 degrees bbox.\n",
"constraints = {\n",
" \"longitude<=\": \"min(longitude)+10\",\n",
" \"longitude>=\": \"min(longitude)\",\n",
" \"latitude<=\": \"min(latitude)+10\",\n",
" \"latitude>=\": \"min(latitude)\",\n",
"}\n",
"\n",
"\n",
"url = e.get_download_url(\n",
" response=\"htmlTable\",\n",
" constraints=constraints,\n",
")\n",
"\n",
"print(url)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can search all datasets with a set of constraints by setting `dataset_id` to `\"allDatasets\"`. Note that these variables are different than the ones available at the individual dataset level. For a reference of the possible variables to query all datasets see the `/erddap//allDatasets.html` page, like [this one](https://erddap.ifremer.fr/erddap/tabledap/allDatasets.html) for the Ifremer ERDDAP server."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"execution": {
"iopub.execute_input": "2023-08-09T14:28:35.830993Z",
"iopub.status.busy": "2023-08-09T14:28:35.830559Z",
"iopub.status.idle": "2023-08-09T14:28:36.045282Z",
"shell.execute_reply": "2023-08-09T14:28:36.044581Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"https://erddap.ioos.us/erddap/tabledap/allDatasets.html?datasetID,institution\n"
]
},
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" institution | \n",
"
\n",
" \n",
" datasetID | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" allDatasets | \n",
" Axiom Docker Install | \n",
"
\n",
" \n",
" OBIS | \n",
" ??? | \n",
"
\n",
" \n",
" ra_regional_boundaries | \n",
" NOAA/NOS/IOOS | \n",
"
\n",
" \n",
" processed_asset_inventory | \n",
" NOAA/NOS/IOOS | \n",
"
\n",
" \n",
" raw_asset_inventory | \n",
" NOAA/NOS/IOOS | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" institution\n",
"datasetID \n",
"allDatasets Axiom Docker Install\n",
"OBIS ???\n",
"ra_regional_boundaries NOAA/NOS/IOOS\n",
"processed_asset_inventory NOAA/NOS/IOOS\n",
"raw_asset_inventory NOAA/NOS/IOOS"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e.dataset_id = \"allDatasets\"\n",
"\n",
"e.variables = [\n",
" \"datasetID\",\n",
" \"institution\",\n",
"]\n",
"\n",
"\n",
"url = e.get_download_url(response=\"html\")\n",
"print(url)\n",
"\n",
"df = e.to_pandas(\n",
" index_col=\"datasetID\",\n",
").dropna()\n",
"\n",
"\n",
"df.head()"
]
}
],
"metadata": {
"_draft": {
"nbviewer_url": "https://gist.github.com/7e5eab16282538d11fdab7de5bd0c474"
},
"gist": {
"data": {
"description": "ERDDAP_advanced_glider_search.ipynb",
"public": true
},
"id": "7e5eab16282538d11fdab7de5bd0c474"
},
"gist_id": "3f0f25b13ade0c64c84607bd92903d1b",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 1
}