|
24 | 24 | import requests
|
25 | 25 | from bs4 import BeautifulSoup
|
26 | 26 |
|
| 27 | +from openskistats.analyze import load_ski_areas_pl |
27 | 28 | from openskistats.utils import get_request_headers
|
28 | 29 |
|
29 | 30 | SEASON_ORIGIN_MONTH = 9
|
@@ -280,6 +281,49 @@ def nesh_timelines_season_summary_plot() -> pn.ggplot:
|
280 | 281 | )
|
281 | 282 |
|
282 | 283 |
|
| 284 | +def nesh_season_duration_vs_poleward_plot() -> pn.ggplot: |
| 285 | + """ |
| 286 | + Create a scatter plot comparing ski areas' poleward affinity versus their mean season duration. |
| 287 | + """ |
| 288 | + # Get the mean season duration for each ski area |
| 289 | + nesh_metrics = ( |
| 290 | + read_nesh_timelines() |
| 291 | + .filter(pl.col("season") > 2010) |
| 292 | + .group_by("skimap_url") |
| 293 | + .agg(*_nesh_timeline_aggregators()) |
| 294 | + ) |
| 295 | + |
| 296 | + # Load ski area metrics for poleward affinity |
| 297 | + ski_areas = ( |
| 298 | + load_ski_areas_pl() |
| 299 | + .explode("ski_area_sources") |
| 300 | + .rename({"ski_area_sources": "skimap_url"}) |
| 301 | + .select("ski_area_id", "ski_area_name", "skimap_url", "poleward_affinity") |
| 302 | + .join(nesh_metrics, on="skimap_url", how="inner") |
| 303 | + ) |
| 304 | + |
| 305 | + # Create the scatter plot |
| 306 | + return ( |
| 307 | + pn.ggplot( |
| 308 | + ski_areas, |
| 309 | + pn.aes( |
| 310 | + x="season_duration_mean", |
| 311 | + y="poleward_affinity", |
| 312 | + ), |
| 313 | + ) |
| 314 | + + pn.geom_smooth(method="lm", color="red", se=True) |
| 315 | + + pn.geom_point(alpha=0.6) |
| 316 | + + pn.scale_x_continuous(name="Mean Season Duration (days)") |
| 317 | + + pn.scale_y_continuous( |
| 318 | + name="Poleward Affinity", |
| 319 | + labels=lambda x: [f"{v:.0%}" for v in x], |
| 320 | + limits=(-1, 1), |
| 321 | + ) |
| 322 | + + pn.theme_bw() |
| 323 | + + pn.theme(figure_size=(5, 3.2)) |
| 324 | + ) |
| 325 | + |
| 326 | + |
283 | 327 | nesh_to_skimap = {
|
284 | 328 | "https://www.newenglandskihistory.com/NewHampshire/abenaki.php": "https://skimap.org/skiareas/view/4091",
|
285 | 329 | "https://www.newenglandskihistory.com/NewHampshire/arrowhead.php": "https://skimap.org/skiareas/view/2146",
|
|
0 commit comments