Skip to content

Feature/add nighttime zeros issue #104#110

Open
Sagarpillai wants to merge 34 commits intoopenclimatefix:mainfrom
Sagarpillai:feature/add-nighttime-zeros-issue-104
Open

Feature/add nighttime zeros issue #104#110
Sagarpillai wants to merge 34 commits intoopenclimatefix:mainfrom
Sagarpillai:feature/add-nighttime-zeros-issue-104

Conversation

@Sagarpillai
Copy link
Contributor

Pull Request

Changes made:

Added import for make_night_time_zeros from pvliveconsumer.nightime
Added function call in the PVLive data processing loop to fill nighttime gaps
Added pvliveconsumer dependency to pyproject.toml
Fixes #104

@Sagarpillai Sagarpillai marked this pull request as draft November 3, 2025 13:56
@Sagarpillai Sagarpillai marked this pull request as ready for review November 3, 2025 17:18
@Sagarpillai
Copy link
Contributor Author

Hi @peterdudfield
quick note: I originally tried to call the function directly from pvlive-consumer, but CI fails because that package isn’t on PyPI. So I’ve just added a small local helper file for the nighttime-zero logic (same function, just vendored here).

If you’d prefer this to live in a different folder or a different name, let me know and I’ll move it.

@@ -0,0 +1,43 @@
# solar_consumer/pvlive/nighttime.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if possible, could you put this under the data folder

at_night = (df["target_time_utc"] < df["sunrise_utc"]) | (df["target_time_utc"] >= df["sunset_utc"])
df.loc[at_night, "generation_mw"] = 0.0

return df
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also copy any tests across from PVLive consumer?

@peterdudfield
Copy link
Contributor

Thank you btw for doing this

@Sagarpillai
Copy link
Contributor Author

@peterdudfield, sure, I've made the changes, please let me know if everything's okay


# Build mask: night is before sunrise OR at/after sunset
at_night = (df[ts_col] < df[sunrise_col]) | (df[ts_col] >= df[sunset_col])
df.loc[at_night, mw_col] = 0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont remeber these sunrise and sunset columns? How was this done in PVLive-Consumer?

@Sagarpillai
Copy link
Contributor Author

@peterdudfield ,
I switched to pvlib solar elevation threshold (<5°) which removes the sunrise/sunset columns entirely and keeps the logic simpler. Test added. All feedback addressed, and CI is green. Ready for re-review.

# Prefer loading locations from the canonical datamodel; fall back to empty frame
try:
from nowcasting_datamodel.read.gsp import get_all_locations # type: ignore
_GSP_LOCATIONS = get_all_locations().set_index("gsp_id")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, could we not use nowcasting_datamodel, i think copying in a csv of the centeroid of the gsps would be fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure I'll change that

Copy of df with nighttime rows set to zero in `mw_col`.
"""
try:
import pvlib # lazy import
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have this try and except? I would just import it at the opt

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'll change this as well, I'll update the PR soon, is there an issue with anything else?

@Sagarpillai
Copy link
Contributor Author

@peterdudfield yep, made the changes. Hope everything's good now, please let me know if im missing anything, thank you.

@Sagarpillai
Copy link
Contributor Author

@peterdudfield, For the CSV with gsp_id + lat/lon which repo/source would you like me to take the centroid values from?

Once I know the preferred source, I’ll copy those values into solar_consumer/data/uk_gsp_locations_20250109.csv and push it, for now ive just added

gsp_id,latitude,longitude
0,52.355518,-1.17432

@peterdudfield
Copy link
Contributor

@peterdudfield, For the CSV with gsp_id + lat/lon which repo/source would you like me to take the centroid values from?

Once I know the preferred source, I’ll copy those values into solar_consumer/data/uk_gsp_locations_20250109.csv and push it, for now ive just added

gsp_id,latitude,longitude 0,52.355518,-1.17432

where does it get them from in PVLive-consumer?

@Sagarpillai
Copy link
Contributor Author

Sagarpillai commented Nov 5, 2025

@peterdudfield, For the CSV with gsp_id + lat/lon which repo/source would you like me to take the centroid values from?
Once I know the preferred source, I’ll copy those values into solar_consumer/data/uk_gsp_locations_20250109.csv and push it, for now ive just added
gsp_id,latitude,longitude 0,52.355518,-1.17432

where does it get them from in PVLive-consumer?

@peterdudfield yep, got it was confused on copying .csv files, hope this is the one.

# Load GSP lat/lon for night-time zeroing from CSV (no datamodel dependency)
DIR = os.path.dirname(__file__)

def _load_gsp_locations() -> pd.DataFrame | None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could this be moved to nighttime, as a specific to that?

Copy link
Contributor

@peterdudfield peterdudfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

I think with one more test, we would be good to go

@Sagarpillai
Copy link
Contributor Author

This looks great!

I think with one more test, we would be good to go

sure, I've added the test to check whether it loads data

def test_load_gsp_locations():
"""Verify the bundled GSP locations CSV loads and contains expected columns."""
if GSP_LOCATIONS is None:
pytest.skip("GSP locations CSV not present in this environment")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this please

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to make sure the test run

def test_make_night_time_zeros_uses_gsp_id_fallback():
"""Ensure make_night_time_zeros can look up coords using gsp_id and run."""
if GSP_LOCATIONS is None:
pytest.skip("GSP locations CSV not present in this environment")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this too

@Sagarpillai
Copy link
Contributor Author

@peterdudfield Ive removed the skipping tests part, please review it when you get a moment

@Sagarpillai
Copy link
Contributor Author

@peterdudfield any update on this?

…builds start/end time index and includes capacity columns (fix reviewer request)
@Sagarpillai
Copy link
Contributor Author

@peterdudfield
Just pushed the requested changes, nighttime zeroing now only triggers when PVLive returns no rows, and the helper builds the correct time index + capacity columns.
Let me know if you want any more tweaks!

- `Datetime_GMT`: Combined date and time in UTC.
- `solar_forecast_kw`: Estimated solar forecast in kW.
"""
meta_url = "https://api.neso.energy/api/3/action/datapackage_show?id=embedded-wind-and-solar-forecasts"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why has this changed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont really understand why any of this function has been changed?
(aprt from adding nighttime in)

@Sagarpillai
Copy link
Contributor Author

@peterdudfield , sorry about the mess, I've reverted back to the original code. Please check if everything's okay, thank you

@Sagarpillai
Copy link
Contributor Author

Hey @peterdudfield any updates on this?

@peterdudfield
Copy link
Contributor

Sorry for my slow reply. I think im getting a bit confused. Looking back at the issue, #104, this function should add night time zeros, if there is no data provded by PVLive. However looking at this PR, it looks like it changes results. I think we might need to change this.

Sorry i should have said this when you first submiited it

@Sagarpillai
Copy link
Contributor Author

Sorry for my slow reply. I think im getting a bit confused. Looking back at the issue, #104, this function should add night time zeros, if there is no data provded by PVLive. However looking at this PR, it looks like it changes results. I think we might need to change this.

Sorry i should have said this when you first submiited it

Apologies for the misunderstanding, I'll redo it and put up a PR soon.

@Sagarpillai
Copy link
Contributor Author

Hi, I've been travelling and I'm a little sick, I'll make the changes as soon as I can :)

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.

PVLive: add nighttime zeros

2 participants