Skip to content

Commit

Permalink
Merge pull request #258 from MAYANK12SHARMA/main
Browse files Browse the repository at this point in the history
Upgrade Python Version and Update Dependencies for Compatibility and Deprecation Fixes
  • Loading branch information
peterdudfield authored Jan 16, 2025
2 parents 5a0d085 + 458a060 commit b3b32c6
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 54 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ name: Python package tests
on:
push:
pull_request:
types: [opened, synchronize, reopened]
types: [opened, synchronize, reopened]
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review]
types: [opened, synchronize, reopened, ready_for_review]
schedule:
- cron: "0 12 * * 1"

jobs:
call-run-python-tests:
uses: openclimatefix/.github/.github/workflows/python-test.yml@v1.8.4
with:
python-version: "['3.11']"
python-version: "['3.12']"
pytest_cov_dir: "src"
os_list: '["ubuntu-latest"]'
30 changes: 18 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# code from a streamlit app Peter made. the commands should be relevant to what I'm doing but stuff inside
# Use Python 3.12 slim image
FROM python:3.12-slim

FROM python:3.11-slim

# install unzip
RUN apt-get update && apt-get install -y unzip libpq-dev gcc
# Install necessary system packages
RUN apt-get update && apt-get install -y --no-install-recommends \
unzip \
libpq-dev \
gcc \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app
# copy everything in to the app folder (which we're already in)

COPY requirements.txt requirements.txt
# start building the environment that the app will run in
RUN pip3 install -r requirements.txt
# Copy requirements.txt and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application source code
COPY src .
# this the port that will be used in the container like here locally

# Expose the necessary ports
EXPOSE 8501

EXPOSE 5433
#runs the command I'd run to start the app -- these are called "flags" and they're like arguments but they're not
CMD ["streamlit", "run", "main.py", "--server.port=8501", "--browser.serverAddress=0.0.0.0", "--server.address=0.0.0.0", "–server.enableCORS False"]

# Run the Streamlit app
CMD ["streamlit", "run", "main.py", "--server.port=8501", "--server.address=0.0.0.0", "--browser.serverAddress=0.0.0.0", "--server.enableCORS=False"]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ services:
"--server.port=8501",
"--browser.serverAddress=0.0.0.0",
"--server.address=0.0.0.0",
"--server.enableCORS=False",
"--server.enableCORS=False"
]
networks:
- analysis-net
Expand Down
42 changes: 20 additions & 22 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
altair==4.2.2
requests<2.32.0
nowcasting_datamodel==1.5.42
pvsite-datamodel==1.0.45
numpy==1.24.1
pandas==1.5.3
plotly==5.10.0
psycopg2-binary==2.9.5
SQLAlchemy==2.0.29
streamlit==1.27.2
testcontainers==3.2.0
uvicorn==0.23.2
geopandas==0.14.2
altair==5.5.0
requests==2.32.3
nowcasting_datamodel==1.5.56
pvsite-datamodel==1.0.47
numpy==2.0.0
pandas==2.2.3
plotly==5.24.1
psycopg2-binary==2.9.10
SQLAlchemy==2.0.36
streamlit==1.41.1
testcontainers==4.9.0
uvicorn==0.34.0
geopandas==1.0.1
garrett-streamlit-auth0==0.9
pydantic==2.5.3
xarray==2023.5.0
fsspec==2024.2.0
s3fs==2024.2.0
ocf_blosc2==0.0.4
zarr==2.14.2
elexonpy
fiona==1.9.6
psycopg2-binary
herbie-data
xarray==2025.1.0
fsspec==2024.12.0
s3fs==2024.12.0
ocf_blosc2==0.0.11
zarr==2.18.4
elexonpy==1.0.15
fiona==1.10.1
19 changes: 10 additions & 9 deletions src/pvsite_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import plotly.graph_objects as go
import pytz
from zoneinfo import ZoneInfo

# Penalty Calculator
def calculate_penalty(df, region, asset_type, capacity_kw):
Expand Down Expand Up @@ -114,7 +115,7 @@ def pvsite_forecast_page():
][0]

timezone_selected = st.sidebar.selectbox("Select timezone", ["UTC", "Asia/Calcutta"])
timezone_selected = pytz.timezone(timezone_selected)
timezone_selected = ZoneInfo(timezone_selected)

day_after_tomorrow = datetime.today() + timedelta(days=3)
starttime = st.sidebar.date_input(
Expand Down Expand Up @@ -205,16 +206,16 @@ def pvsite_forecast_page():
endtime = datetime.combine(endtime, time.min)

# change to the correct timezone
starttime = timezone_selected.localize(starttime)
endtime = timezone_selected.localize(endtime)
starttime = starttime.replace(tzinfo=timezone_selected)
endtime = endtime.replace(tzinfo=timezone_selected)

# change to utc
starttime = starttime.astimezone(pytz.utc)
endtime = endtime.astimezone(pytz.utc)
starttime = starttime.astimezone(ZoneInfo("UTC"))
endtime = endtime.astimezone(ZoneInfo("UTC"))

if created is not None:
created = timezone_selected.localize(created)
created = created.astimezone(pytz.utc)
created = created.replace(tzinfo=timezone_selected) # Add timezone information to created
created = created.astimezone(ZoneInfo("UTC"))

# great ml model names for this site

Expand Down Expand Up @@ -256,7 +257,7 @@ class Models:
y = [i.forecast_power_kw for i in forecast]

# convert to timezone
x = [i.replace(tzinfo=pytz.utc) for i in x]
x = [i.replace(tzinfo=ZoneInfo("UTC")) for i in x]
x = [i.astimezone(timezone_selected) for i in x]

ys[model.name] = y
Expand All @@ -277,7 +278,7 @@ class Models:
xx = [generation.start_utc for generation in generations if generation is not None]

# convert to timezone
xx = [i.replace(tzinfo=pytz.utc) for i in xx]
xx = [i.replace(tzinfo=ZoneInfo("UTC")) for i in xx]
xx = [i.astimezone(timezone_selected) for i in xx]

df_forecast = []
Expand Down
2 changes: 1 addition & 1 deletion src/site_toolbox/get_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_site_details(session, site_uuid: str):
site = get_site_by_uuid(session=session, site_uuid=site_uuid)

if isinstance(site.asset_type, SiteAssetType):
asset_type_value = site.asset_type.name.lower() # 'pv' or 'wind'
asset_type_value = str(site.asset_type.name.lower()) # 'pv' or 'wind'
else:
asset_type_value = str(site.asset_type)

Expand Down
10 changes: 4 additions & 6 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import requests
from datetime import datetime
import pytz
from zoneinfo import ZoneInfo # Replacing pytz with zoneinfo

def load_css(css_file):
"""Load CSS from a file."""
Expand All @@ -14,7 +14,6 @@ def load_css(css_file):




def parse_timestamp(status):
"""Parse the timestamp from the status object and return local time"""
timestamp = str(status.created_utc)
Expand All @@ -25,19 +24,18 @@ def parse_timestamp(status):
raise ValueError(f"Invalid timestamp format: {e}")

if parsed_time.tzinfo is not None:
utc_time = parsed_time.astimezone(pytz.utc)
utc_time = parsed_time.astimezone(ZoneInfo("UTC"))
else:
# If no timezone is specified, assume it's UTC
utc_time = parsed_time.replace(tzinfo=pytz.utc)
utc_time = parsed_time.replace(tzinfo=ZoneInfo("UTC"))

# Convert to specific timezone (Asia/Kolkata)
local_timezone = pytz.timezone("Asia/Kolkata")
local_timezone = ZoneInfo("Asia/Kolkata")
local_time = parsed_time.astimezone(local_timezone)

return local_time



def format_time(local_time):
"""Format date and time"""
formatted_date = local_time.strftime("%Y-%m-%d")
Expand Down

0 comments on commit b3b32c6

Please sign in to comment.