Skip to content

Commit

Permalink
Merge pull request #108 from FloraSauerbronn/plot-track
Browse files Browse the repository at this point in the history
Updating plot_track from gliderpy
  • Loading branch information
ocefpaf authored Jun 12, 2024
2 parents 8de0bec + 2fa38ca commit 819a911
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion gliderpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
__version__ = "unknown"

from .fetchers import GliderDataFetcher
from .plotting import plot_transect
from .plotting import plot_track, plot_transect

__all__ = [
"GliderDataFetcher",
"plot_track",
"plot_transect",
]
21 changes: 21 additions & 0 deletions gliderpy/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import TYPE_CHECKING

try:
import cartopy.crs as ccrs
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
except ModuleNotFoundError:
Expand All @@ -22,6 +23,26 @@
from pandas_flavor import register_dataframe_method


@register_dataframe_method
def plot_track(df: pd.DataFrame) -> tuple(plt.Figure, plt.Axes):
"""Plot a track of glider path coloured by temperature.
:return: figures, axes
"""
x = df["longitude"]
y = df["latitude"]
dx, dy = 2, 4

fig, ax = plt.subplots(
figsize=(9, 9),
subplot_kw={"projection": ccrs.PlateCarree()},
)
ax.scatter(x, y, c=None, s=25, alpha=0.25, edgecolor="none")
ax.coastlines("10m")
ax.set_extent([x.min() - dx, x.max() + dx, y.min() - dy, y.max() + dy])
return fig, ax


@register_dataframe_method
def plot_transect(
df: pd.DataFrame,
Expand Down
Binary file added tests/baseline/test_plot_track.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,28 @@
import pytest

from gliderpy.fetchers import GliderDataFetcher
from gliderpy.plotting import plot_transect
from gliderpy.plotting import plot_track, plot_transect

root = Path(__file__).parent


@pytest.mark.mpl_image_compare(baseline_dir=root.joinpath("baseline/"))
def test_plot_track():
"""Image comparison test for plot_track."""
glider_grab = GliderDataFetcher()

glider_grab.fetcher.dataset_id = "whoi_406-20160902T1700"
df = glider_grab.to_pandas()
# Generate the plot
fig, ax = plot_track(df)

# Return the figure for pytest-mpl to compare
return fig


@pytest.mark.mpl_image_compare(baseline_dir=root.joinpath("baseline/"))
def test_plot_transect():
"""Image comparison test for plot_transect."""
glider_grab = GliderDataFetcher()

glider_grab.fetcher.dataset_id = "whoi_406-20160902T1700"
Expand Down

0 comments on commit 819a911

Please sign in to comment.