Skip to content

Commit

Permalink
export polar simulations to png
Browse files Browse the repository at this point in the history
  • Loading branch information
dhimmel committed Jan 21, 2025
1 parent 8c91c5c commit 2ae9d5c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion openskistats/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def _add_polar_y_ticks(
arc_width: float = 10.0,
arc_color: str = "white",
title: str | None = None,
label_ticks_at: tuple[int, ...] = (0, 90),
) -> None:
"""Add radial ticks and optional title to polar plot.
Expand All @@ -341,7 +342,7 @@ def _add_polar_y_ticks(
y_ticks = np.arange(0, 91, 10)
ax.set_yticks(y_ticks)
ax.set_yticklabels(
[f"{r}°" if r in {0, 90} else "" for r in y_ticks],
[f"{r}°" if r in label_ticks_at else "" for r in y_ticks],
rotation=0,
fontsize=7,
color=arc_color,
Expand Down
23 changes: 16 additions & 7 deletions openskistats/sunlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from openskistats.utils import (
get_data_directory,
get_hemisphere,
get_images_directory,
running_in_ci,
running_in_test,
)
Expand Down Expand Up @@ -389,6 +390,12 @@ class SolarPolarPlot:
# If datetime is not None, plot the solar irradiance at that date and time.
date_time: datetime | None = None

def get_bearings_range(self) -> npt.NDArray[np.float64]:
return np.arange(0, 360, 4, dtype=np.float64)

def get_y_range(self) -> npt.NDArray[np.float64]:
return np.arange(0, 90, 2, dtype=np.float64)

def plot(
self,
fig: plt.Figure | None = None,
Expand All @@ -415,7 +422,6 @@ def _setup_polar_plot(self, ax: plt.Axes, colorbar: bool = True) -> Colorbar | N
ax.set_xticks(ax.get_xticks())
ax.set_xticklabels(labels=["N", "", "E", "", "S", "", "W", ""])
ax.tick_params(axis="x", which="major", pad=-2)

from openskistats.plot import _add_polar_y_ticks

_add_polar_y_ticks(
Expand All @@ -424,7 +430,9 @@ def _setup_polar_plot(self, ax: plt.Axes, colorbar: bool = True) -> Colorbar | N
arc_width=10,
arc_color="white",
title="Slope" if isinstance(self, SlopeByBearingPlots) else "Latitude",
label_ticks_at=(0, 40, 80),
)
ax.set_rlabel_position(320)

cb = None
if colorbar:
Expand Down Expand Up @@ -479,10 +487,7 @@ def get_clearsky(self) -> pl.DataFrame:
return df

def get_slopes_range(self) -> npt.NDArray[np.float64]:
return np.arange(0, 90, 5, dtype=np.float64)

def get_bearings_range(self) -> npt.NDArray[np.float64]:
return np.arange(0, 360, 10, dtype=np.float64)
return self.get_y_range()

def _get_grids_season(
self,
Expand Down Expand Up @@ -588,8 +593,8 @@ def get_grids(
) -> tuple[
npt.NDArray[np.float64], npt.NDArray[np.float64], npt.NDArray[np.float64]
]:
latitudes = np.arange(0, 90, 5)
bearings = np.arange(0, 360, 10)
bearings = self.get_bearings_range()
latitudes = self.get_y_range()
bearing_grid, latitude_grid = np.meshgrid(
bearings,
latitudes,
Expand Down Expand Up @@ -686,4 +691,8 @@ def create_combined_solar_plots() -> plt.Figure:
aspect=40,
)

path = get_images_directory().joinpath("solar_irradiance_simulation_grids.png")
logging.info(f"Saving figure to {path}.")
fig.savefig(path, dpi=300, bbox_inches="tight")

return fig

0 comments on commit 2ae9d5c

Please sign in to comment.