Skip to content

Commit 16507cb

Browse files
committed
ski roses with local difficulty colors
1 parent fb83c66 commit 16507cb

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

openskistats/analyze.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,19 @@ def aggregate_ski_areas_pl(
399399
vertical_drop=pl.max("max_elevation") - pl.min("min_elevation"),
400400
latitude=pl.mean("latitude"),
401401
longitude=pl.mean("longitude"),
402+
osm_run_convention=pl.col("osm_run_convention").unique().drop_nulls(),
402403
_bearing_stats=pl.struct(
403404
pl.col("bearing_mean").alias("bearing"),
404405
"bearing_magnitude_cum",
405406
"bearing_alignment",
406407
"hemisphere",
407408
).map_batches(_get_bearing_summary_stats_pl, returns_scalar=True),
408409
)
410+
.with_columns(
411+
osm_run_convention=pl.when(pl.col("osm_run_convention").list.len() == 1)
412+
.then(pl.col("osm_run_convention").list.first())
413+
.otherwise(None)
414+
)
409415
.unnest("_bearing_stats")
410416
.join(bearings_pl, on=group_by)
411417
.sort(*group_by)
@@ -700,6 +706,7 @@ def _create_ski_area_rose(
700706
"""Create a preview and a full rose for a ski area."""
701707
ski_area_id = info["ski_area_id"]
702708
ski_area_name = info["ski_area_name"]
709+
color_convention = info["osm_run_convention"]
703710

704711
# plot and save preview rose
705712
bearing_preview_pl = bearing_pl.filter(pl.col("num_bins") == 8)
@@ -736,7 +743,9 @@ def _create_ski_area_rose(
736743
fig, ax = plot_orientation(
737744
bin_counts=bearing_full_pl.get_column("bin_count").to_numpy(),
738745
bin_centers=bearing_full_pl.get_column("bin_center").to_numpy(),
739-
color_to_bin_counts=get_difficulty_color_to_bearing_bin_counts(bearing_full_pl),
746+
color_to_bin_counts=get_difficulty_color_to_bearing_bin_counts(
747+
bearing_full_pl, convention=color_convention
748+
),
740749
title=ski_area_name,
741750
title_font_size=16,
742751
margin_text=_generate_margin_text(info),

openskistats/bearing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from openskistats.models import (
1010
BearingStatsModel,
1111
SkiAreaBearingDistributionModel,
12+
SkiRunConvention,
1213
SkiRunDifficulty,
1314
)
1415

@@ -279,6 +280,7 @@ def get_bearing_histogram(
279280

280281
def get_difficulty_color_to_bearing_bin_counts(
281282
bearing_pl: pl.DataFrame,
283+
convention: SkiRunConvention = SkiRunConvention.north_america,
282284
) -> dict[str, pl.Series]:
283285
return ( # type: ignore [no-any-return]
284286
bearing_pl.select(
@@ -290,7 +292,8 @@ def get_difficulty_color_to_bearing_bin_counts(
290292
.select(
291293
pl.all().name.map(
292294
lambda x: SkiRunDifficulty(x.removeprefix("bin_count_")).color(
293-
subtle=True
295+
subtle=True,
296+
convention=convention,
294297
)
295298
)
296299
)

openskistats/plot.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from osmnx.plot import _get_fig_ax
1616

1717
from openskistats.bearing import get_difficulty_color_to_bearing_bin_counts
18+
from openskistats.models import SkiRunConvention
1819
from openskistats.sunlight import get_solar_location_band
1920

2021
SUBPLOT_FIGSIZE = 4.0
@@ -385,6 +386,7 @@ def subplot_orientations(
385386
suptitle: str | None = None,
386387
sort_groups: bool = True,
387388
plot_solar_band: bool = False,
389+
color_convention: SkiRunConvention | None = SkiRunConvention.north_america,
388390
) -> plt.Figure:
389391
"""
390392
Plot orientations from multiple graphs in a grid.
@@ -406,6 +408,9 @@ def subplot_orientations(
406408
This value must exist in the input groups_pl bearings.num_bins column.
407409
suptitle
408410
The figure's super title.
411+
color_convention
412+
The convention to use for color-coding the polar histogram by run difficulty.
413+
If None, use the group specific conventions provided in groups_pl.
409414
"""
410415
assert not groups_pl.select(grouping_col).is_duplicated().any()
411416
names = groups_pl.get_column(grouping_col).to_list()
@@ -443,7 +448,10 @@ def subplot_orientations(
443448
bin_counts=group_dist_pl.get_column("bin_count").to_numpy(),
444449
bin_centers=group_dist_pl.get_column("bin_center").to_numpy(),
445450
color_to_bin_counts=get_difficulty_color_to_bearing_bin_counts(
446-
group_dist_pl
451+
group_dist_pl,
452+
convention=color_convention
453+
or group_info["osm_run_convention"]
454+
or SkiRunConvention.north_america,
447455
),
448456
ax=ax,
449457
max_bin_count=max_bin_count,

0 commit comments

Comments
 (0)