{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Quick introduction\n", "\n", "gliderpy can be installed with conda\n", "\n", "```\n", "conda install --channel conda-forge gliderpy\n", "```\n", "\n", "or pip\n", "\n", "```\n", "pip install gliderpy\n", "```\n", "\n", "gliderpy aims to make querying and downloading glider data easier.\n", "Here is how one would build a query using erddapy:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-04-08T19:26:04.834415Z", "iopub.status.busy": "2024-04-08T19:26:04.834036Z", "iopub.status.idle": "2024-04-08T19:26:07.447359Z", "shell.execute_reply": "2024-04-08T19:26:07.446803Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
depth (m)latitude (degrees_north)longitude (degrees_east)salinity (1)temperature (Celsius)profile_id
time (UTC)
2016-09-02 17:05:38+00:006.4341.120018-71.01711832.07925820.54071
2016-09-02 17:05:38+00:007.8241.120018-71.01711832.09540620.50711
2016-09-02 17:05:38+00:008.6941.120018-71.01711832.11192020.49041
2016-09-02 17:05:38+00:009.5441.120018-71.01711832.12658720.48971
2016-09-02 17:05:38+00:0010.3241.120018-71.01711832.14071720.49091
\n", "
" ], "text/plain": [ " depth (m) latitude (degrees_north) \\\n", "time (UTC) \n", "2016-09-02 17:05:38+00:00 6.43 41.120018 \n", "2016-09-02 17:05:38+00:00 7.82 41.120018 \n", "2016-09-02 17:05:38+00:00 8.69 41.120018 \n", "2016-09-02 17:05:38+00:00 9.54 41.120018 \n", "2016-09-02 17:05:38+00:00 10.32 41.120018 \n", "\n", " longitude (degrees_east) salinity (1) \\\n", "time (UTC) \n", "2016-09-02 17:05:38+00:00 -71.017118 32.079258 \n", "2016-09-02 17:05:38+00:00 -71.017118 32.095406 \n", "2016-09-02 17:05:38+00:00 -71.017118 32.111920 \n", "2016-09-02 17:05:38+00:00 -71.017118 32.126587 \n", "2016-09-02 17:05:38+00:00 -71.017118 32.140717 \n", "\n", " temperature (Celsius) profile_id \n", "time (UTC) \n", "2016-09-02 17:05:38+00:00 20.5407 1 \n", "2016-09-02 17:05:38+00:00 20.5071 1 \n", "2016-09-02 17:05:38+00:00 20.4904 1 \n", "2016-09-02 17:05:38+00:00 20.4897 1 \n", "2016-09-02 17:05:38+00:00 20.4909 1 " ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from erddapy import ERDDAP\n", "\n", "e = ERDDAP(\n", " server=\"https://gliders.ioos.us/erddap\",\n", " protocol=\"tabledap\",\n", " response=\"csv\",\n", ")\n", "e.dataset_id = \"whoi_406-20160902T1700\"\n", "\n", "e.variables = [\n", " \"depth\",\n", " \"latitude\",\n", " \"longitude\",\n", " \"salinity\",\n", " \"temperature\",\n", " \"profile_id\",\n", " \"time\",\n", "]\n", "\n", "df = e.to_pandas(\n", " index_col=\"time (UTC)\",\n", " parse_dates=True,\n", ")\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And here is how to use gliderpy to obtain the same results but with fewer lines and a cleaner code:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-04-08T19:26:07.475898Z", "iopub.status.busy": "2024-04-08T19:26:07.475687Z", "iopub.status.idle": "2024-04-08T19:26:09.594254Z", "shell.execute_reply": "2024-04-08T19:26:09.593755Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
latitudelongitudepressureprofile_idsalinitytemperaturedataset_url
time (utc)
2016-09-02 17:05:3841.120018-71.0171186.43132.07925820.5407https://gliders.ioos.us/erddap/tabledap/whoi_4...
2016-09-02 17:05:3841.120018-71.0171187.82132.09540620.5071https://gliders.ioos.us/erddap/tabledap/whoi_4...
2016-09-02 17:05:3841.120018-71.0171188.69132.11192020.4904https://gliders.ioos.us/erddap/tabledap/whoi_4...
2016-09-02 17:05:3841.120018-71.0171189.54132.12658720.4897https://gliders.ioos.us/erddap/tabledap/whoi_4...
2016-09-02 17:05:3841.120018-71.01711810.32132.14071720.4909https://gliders.ioos.us/erddap/tabledap/whoi_4...
\n", "
" ], "text/plain": [ " latitude longitude pressure profile_id salinity \\\n", "time (utc) \n", "2016-09-02 17:05:38 41.120018 -71.017118 6.43 1 32.079258 \n", "2016-09-02 17:05:38 41.120018 -71.017118 7.82 1 32.095406 \n", "2016-09-02 17:05:38 41.120018 -71.017118 8.69 1 32.111920 \n", "2016-09-02 17:05:38 41.120018 -71.017118 9.54 1 32.126587 \n", "2016-09-02 17:05:38 41.120018 -71.017118 10.32 1 32.140717 \n", "\n", " temperature \\\n", "time (utc) \n", "2016-09-02 17:05:38 20.5407 \n", "2016-09-02 17:05:38 20.5071 \n", "2016-09-02 17:05:38 20.4904 \n", "2016-09-02 17:05:38 20.4897 \n", "2016-09-02 17:05:38 20.4909 \n", "\n", " dataset_url \n", "time (utc) \n", "2016-09-02 17:05:38 https://gliders.ioos.us/erddap/tabledap/whoi_4... \n", "2016-09-02 17:05:38 https://gliders.ioos.us/erddap/tabledap/whoi_4... \n", "2016-09-02 17:05:38 https://gliders.ioos.us/erddap/tabledap/whoi_4... \n", "2016-09-02 17:05:38 https://gliders.ioos.us/erddap/tabledap/whoi_4... \n", "2016-09-02 17:05:38 https://gliders.ioos.us/erddap/tabledap/whoi_4... " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from gliderpy.fetchers import GliderDataFetcher\n", "\n", "glider_grab = GliderDataFetcher()\n", "\n", "glider_grab.fetcher.dataset_id = \"whoi_406-20160902T1700\"\n", "df = glider_grab.to_pandas()\n", "df.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Much easier, right?\n", "The variable names are standardized by gliderpy,\n", "making it easier to fetch from different data sources and comparing the results.\n", "\n", "The gliderpy library can subset the data on the server side by passing a geographic bounding box and time interval." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Querying multiple datasets\n", "\n", "The most common use is to search all datasets for data that falls within the certain space-time bounds." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-04-08T19:26:09.596464Z", "iopub.status.busy": "2024-04-08T19:26:09.596137Z", "iopub.status.idle": "2024-04-08T19:26:09.671047Z", "shell.execute_reply": "2024-04-08T19:26:09.670560Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
TitleInstitutionDataset IDinfo_url
0ru23-20130305T2004Rutgers Universityru23-20130305T2004https://gliders.ioos.us/erddap/info/ru23-20130...
1ru23-20121025T1944Rutgers Universityru23-20121025T1944https://gliders.ioos.us/erddap/info/ru23-20121...
\n", "
" ], "text/plain": [ " Title Institution Dataset ID \\\n", "0 ru23-20130305T2004 Rutgers University ru23-20130305T2004 \n", "1 ru23-20121025T1944 Rutgers University ru23-20121025T1944 \n", "\n", " info_url \n", "0 https://gliders.ioos.us/erddap/info/ru23-20130... \n", "1 https://gliders.ioos.us/erddap/info/ru23-20121... " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "glider_grab = GliderDataFetcher()\n", "\n", "df = glider_grab.query(\n", " min_lat=10,\n", " max_lat=40,\n", " min_lon=-90,\n", " max_lon=8,\n", " min_time=\"2010-01-01\",\n", " max_time=\"2013-06-02\",\n", ")\n", "df" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-04-08T19:26:09.673026Z", "iopub.status.busy": "2024-04-08T19:26:09.672704Z", "iopub.status.idle": "2024-04-08T19:26:27.341326Z", "shell.execute_reply": "2024-04-08T19:26:27.340855Z" } }, "outputs": [ { "data": { "text/plain": [ "dict_keys(['ru23-20130305T2004', 'ru23-20121025T1944'])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "datasets = glider_grab.to_pandas()\n", "datasets.keys()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2024-04-08T19:26:27.343492Z", "iopub.status.busy": "2024-04-08T19:26:27.343117Z", "iopub.status.idle": "2024-04-08T19:26:27.350154Z", "shell.execute_reply": "2024-04-08T19:26:27.349722Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
latitudelongitudepressureprofile_idsalinity (1e-3)temperaturedataset_url
time (utc)
2012-10-27 18:20:2539.999821-73.5105661.6728931.97303016.9787https://gliders.ioos.us/erddap/tabledap/ru23-2...
2012-10-27 18:20:2539.999821-73.5105661.6828931.97380616.9775https://gliders.ioos.us/erddap/tabledap/ru23-2...
2012-10-27 18:20:2539.999821-73.510566NaN289NaNNaNhttps://gliders.ioos.us/erddap/tabledap/ru23-2...
2012-10-27 18:20:2539.999821-73.5105661.8228931.97308716.9778https://gliders.ioos.us/erddap/tabledap/ru23-2...
2012-10-27 18:20:2539.999821-73.510566NaN289NaNNaNhttps://gliders.ioos.us/erddap/tabledap/ru23-2...
\n", "
" ], "text/plain": [ " latitude longitude pressure profile_id \\\n", "time (utc) \n", "2012-10-27 18:20:25 39.999821 -73.510566 1.67 289 \n", "2012-10-27 18:20:25 39.999821 -73.510566 1.68 289 \n", "2012-10-27 18:20:25 39.999821 -73.510566 NaN 289 \n", "2012-10-27 18:20:25 39.999821 -73.510566 1.82 289 \n", "2012-10-27 18:20:25 39.999821 -73.510566 NaN 289 \n", "\n", " salinity (1e-3) temperature \\\n", "time (utc) \n", "2012-10-27 18:20:25 31.973030 16.9787 \n", "2012-10-27 18:20:25 31.973806 16.9775 \n", "2012-10-27 18:20:25 NaN NaN \n", "2012-10-27 18:20:25 31.973087 16.9778 \n", "2012-10-27 18:20:25 NaN NaN \n", "\n", " dataset_url \n", "time (utc) \n", "2012-10-27 18:20:25 https://gliders.ioos.us/erddap/tabledap/ru23-2... \n", "2012-10-27 18:20:25 https://gliders.ioos.us/erddap/tabledap/ru23-2... \n", "2012-10-27 18:20:25 https://gliders.ioos.us/erddap/tabledap/ru23-2... \n", "2012-10-27 18:20:25 https://gliders.ioos.us/erddap/tabledap/ru23-2... \n", "2012-10-27 18:20:25 https://gliders.ioos.us/erddap/tabledap/ru23-2... " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "datasets[\"ru23-20121025T1944\"].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dataset search\n", "\n", "One can query all dataset_ids available in the server." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2024-04-08T19:26:27.352044Z", "iopub.status.busy": "2024-04-08T19:26:27.351729Z", "iopub.status.idle": "2024-04-08T19:26:27.563936Z", "shell.execute_reply": "2024-04-08T19:26:27.563429Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "found 1807 glider datasets on https://gliders.ioos.us/erddap.\n" ] } ], "source": [ "from gliderpy.fetchers import DatasetList\n", "\n", "datasets = DatasetList()\n", "ds_ids = datasets.get_ids()\n", "\n", "print(f\"found {len(ds_ids)} glider datasets on {datasets.e.server}.\")" ] } ], "metadata": { "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.12.2" } }, "nbformat": 4, "nbformat_minor": 4 }