Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new notebook about gliderpy GSoC 2024 #216

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A Plotting interface to acess data GLIDERS from servers ERDAPP"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Created: 2024-08-29\n",
"\n",
"Updated: 2024-08-29\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook walk you through donwloading glider data and demonstrating all the functionalities of the plotting interface gliderpy. Information about gliderpy can be found in the GiThub repository [here](https://github.com/ioos/gliderpy)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
" First we will load a glider dataset as a pandas DataFrame."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"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": [
"Now let's see how the plotting functions work in gliderpy\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": [
"\n",
"The `plot_ctd` 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. In the cell below, you can see an example of the first usage of plot_ctd."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = df.plot_cast(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_cast(profile_number=0, var=\"temperature\", color=\"blue\")\n",
"\n",
"ax1 = ax0.twiny()\n",
"df.plot_cast(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": [
"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": "GLIDERPY",
"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
}
Loading