Skip to content

Commit

Permalink
Merge pull request #122 from FloraSauerbronn/new-doc-notebook
Browse files Browse the repository at this point in the history
New notebook
  • Loading branch information
ocefpaf committed Aug 7, 2024
2 parents c9df903 + 5ad1d61 commit 3963902
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
run: |
set -e
jupyter nbconvert --to notebook --execute notebooks/00-quick_intro.ipynb --output=00-quick_intro-output.ipynb
jupyter nbconvert --to notebook --execute notebooks/01-plotting_intro.ipynb --output=01-plotting_intro-output.ipynb
mv notebooks/*output.ipynb docs/source/
pushd docs
make clean html linkcheck
Expand Down
4 changes: 1 addition & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@
#
from gliderpy import __version__

version = __version__
# The full version, including alpha/beta/rc tags.
release = __version__
version = release = __version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ functionality to browse, fetch, and plot glider data.
:caption: Contents:

00-quick_intro-output.ipynb
01-plotting_intro-output.ipynb
gliderpy

Indices and tables
Expand Down
24 changes: 12 additions & 12 deletions gliderpy/fetchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ def standardise_df(glider_df: pd.DataFrame, dataset_url: str) -> pd.DataFrame:
class GliderDataFetcher:
"""Instantiate the glider fetcher.
Args:
----
server: A glider ERDDAP server URL.
Attributes:
Attributes
----------
dataset_id: A dataset unique id.
constraints: Download constraints, defaults same as query.
dataset_id : str
A dataset unique id.
constraints : dict
Download constraints, defaults same as query.
"""

Expand Down Expand Up @@ -192,9 +190,9 @@ class DatasetList:
Attributes
----------
e: an ERDDAP server instance
TODO -> search_terms: A list of terms to search the server for.
Multiple terms will be combined as "AND."
e : an ERDDAP server instance
TODO -> search_terms: A list of terms to search the server for.
Multiple terms will be combined as "AND."
"""

Expand All @@ -203,8 +201,10 @@ def __init__(self: "DatasetList", server: OptionalStr = _server) -> None:
Attributes
----------
server: the server URL.
protocol: ERDDAP's protocol (tabledap/griddap)
server : str
the server URL.
protocol : str
ERDDAP's protocol (tabledap/griddap)
"""
self.e = ERDDAP(
Expand Down
149 changes: 149 additions & 0 deletions notebooks/01-plotting_intro.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plotting Intro\n",
"\n",
"\n",
"Gliderpy has a plotting interface for quick simple diagnostic figures they are: `plot_ track`, `plot_ctd`, and `plot_transect` for plotting the glider track, a vertical transect for a specific variable, or a single cast (glider dive). Let's take a look on how to use them. First we will load a glider dataset as a pandas DataFrame."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### plot_track\n",
"\n",
"The `plot_track` method will returns a map with the glider's track."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = df.plot_track()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### plot_ctd\n",
"\n",
"This method groups all the casts by their position (latitude and longitude) giving the user access to each individual cast using the index (`profile_number`) of the grouped DataFrame."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = df.plot_ctd(profile_number=0, var=\"temperature\", color=\"blue\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All the methods accept and `ax` argument and more complex figures can be create. For example, let's add a second variable to the cast above."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax0 = df.plot_ctd(profile_number=0, var=\"temperature\", color=\"blue\")\n",
"\n",
"ax1 = ax0.twiny()\n",
"df.plot_ctd(profile_number=0, var=\"salinity\", color=\"red\", ax=ax1)\n",
"\n",
"ax0.legend()\n",
"ax1.legend()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can check a whole transec with the `plot_transect` method."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = df.plot_transect(var=\"temperature\", cmap=\"viridis\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using a given matplotlib we can create a fancier version with two variables in a subplot."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"fig, (ax0, ax1) = plt.subplots(\n",
" figsize=(15, 9),\n",
" nrows=2,\n",
" sharex=True,\n",
" sharey=True,\n",
")\n",
"\n",
"df.plot_transect(var=\"temperature\", ax=ax0, cmap=\"viridis\")\n",
"df.plot_transect(var=\"salinity\", ax=ax1, cmap=\"cividis\")"
]
}
],
"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.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 3963902

Please sign in to comment.