-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e7eb20
commit 73755af
Showing
1 changed file
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Plotting Intro" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Gliderpy has a plotting interface where you can call different functions and receive images from the glider of your choice.\n", | ||
"Each function in plotting returns an image; some functions have more parameters than others. Here, we will explain each function with all the details.\n", | ||
"This documentation uses the dataset 'whoi_406-20160902T1700' as an example, as previously presented in the notebook 00-quick_intro.ipynb." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"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": [ | ||
"This DataFrame will be the key data source for generating all the images with the functions from plotting.py." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# plot_track" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"plot_track will return an image with a simple map showing the contour of the coast and the glider's track in blue during the period it was adrift. Below is an example image." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from gliderpy.plotting import plot_track\n", | ||
"\n", | ||
"fig, ax = plot_track(df)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# plot_transect" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The plot_transect function returns images of the transect with pressure and the variable of your choice (temperature or salinity). The variables that affect the function for one subplot are the DataFrame (df), the chosen variable, and the color palette (cmap), with the default being 'viridis'.\n", | ||
"\n", | ||
"The function creates a plot on the specified axis (ax) using the data provided in the DataFrame (df) and applies the chosen colormap (cmap). Assertions are used to ensure the consistency of the plots and the colormaps.\n", | ||
"\n", | ||
"See the example below:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# importing function\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"\n", | ||
"from gliderpy.plotting import plot_transect\n", | ||
"\n", | ||
"# Function in defoult form\n", | ||
"plot_transect(df, var=\"temperature\", cmap=\"viridis\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"It is possible to add subplots in this function, if you want to see the transect of more then one variable.\n", | ||
"\n", | ||
"The figure with subplots is created using plt.subplots with two subplots arranged in two rows.\n", | ||
"The plot_transect function is called to plot temperature and salinity on each subplot using different colormaps (viridis and cividis).\n", | ||
"Assertions are used to ensure that the axes share the same limits and that the labels of the axes and colorbars are correct." | ||
] | ||
}, | ||
{ | ||
"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", | ||
"plot_transect(df, var=\"temperature\", ax=ax0, cmap=\"viridis\")\n", | ||
"plot_transect(df, var=\"salinity\", ax=ax1, cmap=\"cividis\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# plot_ctd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The plot_ctd function groups the latitude and longitude where the glider has collected data, allowing you to access all of these profiles using the index of the DataFrame. The function has three main parameters: df, index, and variable. 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": [ | ||
"# Import function\n", | ||
"from gliderpy.plotting import plot_ctd\n", | ||
"\n", | ||
"# Function defoult of CTD plot\n", | ||
"plot_ctd(df, 0, var=\"temperature\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Let's see how we can access all the index of the positions" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from IPython.display import HTML, display\n", | ||
"\n", | ||
"# Group by latitude and longitude\n", | ||
"grouped = df.groupby([\"latitude\", \"longitude\"]).size().reset_index().drop(columns=0)\n", | ||
"\n", | ||
"# Display unique latitude and longitude pairs in a scrollable table\n", | ||
"unique_pairs = grouped[[\"latitude\", \"longitude\"]]\n", | ||
"\n", | ||
"# Reset index to include it in the DataFrame\n", | ||
"unique_pairs = unique_pairs.reset_index()\n", | ||
"\n", | ||
"# Convert the DataFrame to an HTML table with a scrollable div\n", | ||
"html = unique_pairs.to_html(index=False)\n", | ||
"scrollable_table = f\"\"\"\n", | ||
"<div style=\"height:400px;overflow:auto;\">\n", | ||
"{html}\n", | ||
"</div>\n", | ||
"\"\"\"\n", | ||
"display(HTML(scrollable_table))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"It is possible to add a new variable to the plot and visualize two properties in one image. See the example below." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Primeiro plot para Temperatura x Profundidade\n", | ||
"fig, ax = df.plot_ctd(idx=0, var=\"temperature\", color=\"blue\")\n", | ||
"\n", | ||
"# Segundo plot para Salinidade x Profundidade usando o mesmo eixo\n", | ||
"fig, ax = df.plot_ctd(idx=0, var=\"salinity\", ax=ax, color=\"red\")" | ||
] | ||
} | ||
], | ||
"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 | ||
} |