Skip to content

Feat/add pvlive nighttime zeros#160

Open
AdityaShome wants to merge 2 commits intoopenclimatefix:mainfrom
AdityaShome:feature/pvlive-nighttime-zeros
Open

Feat/add pvlive nighttime zeros#160
AdityaShome wants to merge 2 commits intoopenclimatefix:mainfrom
AdityaShome:feature/pvlive-nighttime-zeros

Conversation

@AdityaShome
Copy link

Description

This PR implements nighttime zeros for PVLive data when no generation data is available.

Changes:

  • Added nighttime.py module with make_night_time_zeros() function that uses pvlib to calculate solar elevation
  • When solar elevation < 5°, synthetic zero-generation rows are created for 30-minute intervals
  • Added uk_gsp_locations.csv with latitude/longitude data for 333 GSPs
  • Integrated into fetch_gb_data_historic() - only triggers when PVLive returns empty results
  • Added pvlib dependency to pyproject.toml
  • Includes 5 comprehensive unit tests

Approach:
This implementation addresses all feedback from PR #110:

  • Uses local CSV for GSP locations (no external dependency on nowcasting_datamodel)
  • Minimal changes to existing code, only adds zeros when PVLive returns no data
  • Uses pvlib solar elevation calculation (same as pvlive-consumer)
  • Only active for regime="in-day"

Fixes #104

How Has This Been Tested?

Unit Tests:

  • Winter midnight returns zeros (nighttime)
  • Summer midday returns empty (daytime)
  • Non "in-day" regime returns empty
  • Invalid GSP ID handled gracefully
  • DataFrame schema validation (correct columns, 30min intervals)

All 5 tests pass:

uv run pytest tests/unit/test_nighttime.py -v
# all 5 passed 

If your changes affect data processing, have you plotted any changes? i.e. have you done a quick sanity check?

  • Yes

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

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

1 participant