diff --git a/notebooks/01-plotting_intro.ipynb b/notebooks/01-plotting_intro.ipynb new file mode 100644 index 0000000..e11c8e8 --- /dev/null +++ b/notebooks/01-plotting_intro.ipynb @@ -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", + "