Skip to content

Commit

Permalink
use pvlive 1.4.0 and fix nighttime zeros (#96)
Browse files Browse the repository at this point in the history
* use pvlive 1.4.0 ad use correct url

* round start

* tidy up docker

* fix tests

* add import

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
peterdudfield and pre-commit-ci[bot] authored Dec 18, 2024
1 parent 6134af8 commit 0844305
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
1 change: 0 additions & 1 deletion infrastructure/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ COPY requirements.txt app/requirements.txt

# install requirements
RUN pip install -r app/requirements.txt
Run pip install git+https://github.com/SheffieldSolar/PV_Live-API#pvlive_api

# copy library files
COPY pvliveconsumer/ app/pvliveconsumer/
Expand Down
5 changes: 2 additions & 3 deletions pvliveconsumer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import pvliveconsumer
from pvliveconsumer.backup import make_gsp_yields_from_national
from pvliveconsumer.gsps import filter_gsps_which_have_new_data, get_gsps
from pvliveconsumer.nitghtime import make_night_time_zeros
from pvliveconsumer.nightime import make_night_time_zeros
from pvliveconsumer.time import check_uk_london_hour

logging.basicConfig(
Expand Down Expand Up @@ -147,8 +147,7 @@ def pull_data_and_save(
:param datetime_utc: datetime now, this is optional
"""

pvlive = PVLive()
pvlive.base_url = "https://api.pvlive.uk/pvlive/api/v4/"
pvlive = PVLive(domain_url="api.pvlive.uk")

if datetime_utc is None:
datetime_utc = datetime.utcnow().replace(tzinfo=timezone.utc) # add timezone
Expand Down
11 changes: 10 additions & 1 deletion pvliveconsumer/nitghtime.py → pvliveconsumer/nightime.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" Add zeros to nightime """
import logging
import os
from datetime import datetime
from datetime import datetime, timedelta

import pandas as pd
import pvlib
Expand Down Expand Up @@ -45,6 +45,15 @@ def make_night_time_zeros(
longitude = gsp_location["longitude"]
latitude = gsp_location["latitude"]

# round start up to the nearest half hour
start = start.replace(microsecond=0)
if start.minute == 0 and start.second == 0:
pass
elif start.minute < 30 or (start.minute == 30 and start.second == 0):
start = start.replace(minute=30, second=0, microsecond=0)
else:
start = start.replace(minute=0, second=0, microsecond=0) + timedelta(hours=1)

times = pd.date_range(start=start, end=end, freq="30min")
# check if it is nighttime, and if so, set generation values to zero
solpos = pvlib.solarposition.get_solarposition(
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ urllib3
requests
nowcasting_datamodel==1.5.46
sentry-sdk==2.13.0
#git+https://github.com/SheffieldSolar/PV_Live-API#pvlive_api
click
pvlib
pvlive-api==1.4.0
2 changes: 1 addition & 1 deletion tests/test_nighttime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pvliveconsumer.nitghtime import make_night_time_zeros
from pvliveconsumer.nightime import make_night_time_zeros
from datetime import datetime
from nowcasting_datamodel.models.gsp import LocationSQL, GSPYieldSQL
import pandas as pd
Expand Down

0 comments on commit 0844305

Please sign in to comment.