-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add solar intensity based on declination angle (single parameter "latitude") #24
Conversation
… can suppress this font not found warning in matplotlib, and preparing to calculate solar intensity as a column
solar_intensity = pl.col("latitude") | ||
.map_batches( | ||
lambda batch: get_solar_intensity_batch(batch), | ||
return_dtype=pl.Float64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the type here is wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return_dtype=pl.Float64
That looks correct to me, but you may need returns_scalar=True
. Not entirely sure. The polars.Expr.map_batches
docs are kinda confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool. Sunlight intensity or some type of scaled insolation will be an amazing feature to have, although it will be critical to incorporate trail orientation and slope for the table MVP.
reactable.Column( | ||
id="solar_intensity", | ||
name=f"Solar", | ||
**_column_kwargs_location_str, | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not add to table yet until we have refined and tested this metric.
@@ -252,6 +252,11 @@ class SkiAreaModel(Model): # type: ignore [misc] | |||
hemisphere: Literal["north", "south"] | None = Field( | |||
description="Hemisphere of the ski area.", | |||
) | |||
solar_intensity: float | None = Field( | |||
description="Solar intensity of the ski resort calculated by the declination at that latitude at the solstice", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify which solstice.
What does solar intensity mean? Is it insolation scaled in some way? E.g. how does one interpret solar_intensity of 60%?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additions should go in a new sunlight.py
module
|
||
HOURS_IN_DAY = 24 | ||
HOURS_START = 9 # Start time (9 AM) | ||
HOURS_END = 16 # End time (4 PM) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you evaluate existing libraries like:
For whether they could do these calculations and were suitable dependencies? For calculations like these that are highly technical, I think it's best if we start with existing tooling and only switch to a homegrown implementation if third party libs don't do what we want.
Code looks nice and methods appear correct to me, but also I know very little here and there are no references provided for which we can verify the methods.
def get_hemisphere(latitude: float) -> Literal["north", "south"] | None: | ||
if latitude is None: | ||
return None | ||
elif latitude >= 0: | ||
return "north" | ||
elif latitude < 0: | ||
return "south" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to utils
def get_hemisphere(latitude: float) -> Literal["north", "south"] | None: | ||
if latitude is None: | ||
return None | ||
elif latitude >= 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
latitude 0 should return None as per
openskistats/openskistats/utils.py
Lines 41 to 47 in 3d0e496
def pl_hemisphere(latitude_col: str = "latitude") -> pl.Expr: | |
return ( | |
pl.when(pl.col(latitude_col).gt(0)) | |
.then(pl.lit("north")) | |
.when(pl.col(latitude_col).lt(0)) | |
.then(pl.lit("south")) | |
) |
and my past research into which hemisphere the equator is in. This will never arise in the data.
@@ -511,7 +518,7 @@ def _ski_area_metric_style(ci: reactable.CellInfo) -> dict[str, Any] | None: | |||
cell=reactable.JS("cellRose"), | |||
# max_width=45, | |||
class_="border-left", | |||
), | |||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the pre-commit formatter would not allow this (and will fix it once enabled)
I opened #28, where we can discuss methods and large implementation details. |
@@ -204,6 +205,7 @@ def _percent_diverging_style(ci: reactable.CellInfo) -> dict[str, Any] | None: | |||
# add custom descriptions including overwriting SkiAreaModel descriptions | |||
"latitude": "Hemisphere where the ski area is located, either ℕ for north or 𝕊 for south, " | |||
"as well as the latitude (φ) in decimal degrees.", | |||
"solar_intensity" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax issue, should be a key: value pair.
refs #28