diff --git a/openskistats/plot.py b/openskistats/plot.py index 1aa71a7514..3210d17d3e 100644 --- a/openskistats/plot.py +++ b/openskistats/plot.py @@ -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. @@ -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, diff --git a/openskistats/sunlight.py b/openskistats/sunlight.py index 20be414c3d..42c03a1ee9 100644 --- a/openskistats/sunlight.py +++ b/openskistats/sunlight.py @@ -24,6 +24,7 @@ from openskistats.utils import ( get_data_directory, get_hemisphere, + get_images_directory, running_in_ci, running_in_test, ) @@ -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, @@ -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( @@ -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: @@ -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, @@ -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, @@ -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