Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

nbarbier-s2
Copy link
Contributor

@nbarbier-s2 nbarbier-s2 commented Dec 24, 2024

refs #28

@nbarbier-s2 nbarbier-s2 changed the title Nbarbier solarintensity Add solar intensity based on declination angle (single parameter "latitude") Dec 24, 2024
solar_intensity = pl.col("latitude")
.map_batches(
lambda batch: get_solar_intensity_batch(batch),
return_dtype=pl.Float64
Copy link
Contributor Author

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?

Copy link
Owner

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.

Copy link
Owner

@dhimmel dhimmel left a 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.

Comment on lines +390 to +394
reactable.Column(
id="solar_intensity",
name=f"Solar",
**_column_kwargs_location_str,
),
Copy link
Owner

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",
Copy link
Owner

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%?

Copy link
Owner

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)
Copy link
Owner

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.

Comment on lines +373 to +379
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"
Copy link
Owner

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:
Copy link
Owner

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

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",
),
)
Copy link
Owner

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)

@dhimmel
Copy link
Owner

dhimmel commented Dec 26, 2024

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"
Copy link
Owner

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.

@dhimmel
Copy link
Owner

dhimmel commented Jan 7, 2025

Closing as this PR is largely superseded by #36 and dd58ef6, which use pvlib for the heavy lifting.

@dhimmel dhimmel closed this Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants