Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 14 additions & 1 deletion wavey/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@

LOG = logging.getLogger(__name__)

# Location of San Carlos Beach (aka Breakwater)
# Location of Breakwater (aka San Carlos Beach)
BREAKWATER_LAT = 36.6125
BREAKWATER_LON = 238.1049
# Closest grid point with forecast data
BREAKWATER_LAT_IDX = 91 # 36.61132
BREAKWATER_LON_IDX = 55 # 238.10899

# Location of Monastery Beach
MONASTERY_LAT = 36.5260
MONASTERY_LON = 238.0722
# Closest grid point with forecast data
MONASTERY_LAT_IDX = 72 # 36.52544
MONASTERY_LON_IDX = 48 # 238.06966

# Location of Point Lobos
LOBOS_LAT = 36.5228
LOBOS_LON = 238.0598

DPI = 100
"""Matplotlib figure dpi."""

Expand Down Expand Up @@ -211,6 +221,7 @@ def main(
draw_arrows_length=DEFAULT_ARROW_LENGTH / 3,
draw_arrows_stride=1,
)
ax_bw.plot(BREAKWATER_LON, BREAKWATER_LAT, "ro")
ax_bw.set_title("Breakwater")

LOG.info("Drawing Monastery map")
Expand All @@ -229,6 +240,8 @@ def main(
draw_arrows_length=DEFAULT_ARROW_LENGTH / 3,
draw_arrows_stride=1,
)
ax_mon.plot(MONASTERY_LON, MONASTERY_LAT, "ro")
# ax_mon.plot(LOBOS_LON, LOBOS_LAT, "ro")
ax_mon.set_title("Monastery")

plt.tight_layout()
Expand Down
32 changes: 22 additions & 10 deletions wavey/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from typing import Iterable, Literal, NamedTuple

import matplotlib
import matplotlib.colors as mcolors
import matplotlib.patches as mpatches
import matplotlib.axes
import matplotlib.colors
import matplotlib.image
import matplotlib.patches
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.basemap import Basemap
Expand All @@ -20,7 +22,7 @@
class _Arrow(NamedTuple):
"""Container for data associated to an arrow on the figure."""

arrow: mpatches.FancyArrow
arrow: matplotlib.patches.FancyArrow
"""matplotlib `FancyArrow` instance."""
length: float
"""Length of arrow."""
Expand Down Expand Up @@ -129,6 +131,12 @@ def _update_arrows(


class Map:
wave_height_ft: np.ma.MaskedArray | None
wave_direction_rad: np.ma.MaskedArray | None
map: Basemap
img: matplotlib.image.AxesImage | None
arrows: list[_Arrow]

def __init__(
self,
ax: matplotlib.axes.Axes,
Expand Down Expand Up @@ -191,7 +199,7 @@ def __init__(
lats = lats[lat_min_idx:lat_max_idx, lon_min_idx:lon_max_idx]
lons = lons[lat_min_idx:lat_max_idx, lon_min_idx:lon_max_idx]

map = Basemap(
self.map = Basemap(
projection="cyl",
llcrnrlat=lat_min,
llcrnrlon=lon_min,
Expand All @@ -200,19 +208,21 @@ def __init__(
resolution=resolution,
ax=ax,
)
map.drawcoastlines()
self.map.drawcoastlines()

if water_color is not None:
map.drawmapboundary(fill_color=water_color)
self.map.drawmapboundary(fill_color=water_color)
if land_color is not None:
map.fillcontinents(color=land_color)
self.map.fillcontinents(color=land_color)

if self.wave_height_ft is not None:
self.img = map.imshow(
self.img = self.map.imshow(
self.wave_height_ft[0],
cmap="jet",
norm=mcolors.Normalize(vmin=0, vmax=MAX_WAVE_HEIGHT_FT),
norm=matplotlib.colors.Normalize(vmin=0, vmax=MAX_WAVE_HEIGHT_FT),
)
else:
self.img = None

if self.arrow_heading_rad is not None:
self.arrows = _draw_arrows(
Expand All @@ -222,11 +232,13 @@ def __init__(
length=draw_arrows_length,
stride=draw_arrows_stride,
)
else:
self.arrows = []

def update(self, hour_i: int) -> None:
"""Update map to the given hour (index)."""

if self.wave_height_ft is not None:
if self.wave_height_ft is not None and self.img is not None:
self.img.set_data(self.wave_height_ft[hour_i])

if self.arrow_heading_rad is not None:
Expand Down