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

plots negative power too #130

Open
aryanbhosale opened this issue Jun 6, 2024 · 19 comments
Open

plots negative power too #130

aryanbhosale opened this issue Jun 6, 2024 · 19 comments
Assignees
Labels
bug Something isn't working

Comments

@aryanbhosale
Copy link
Member

aryanbhosale commented Jun 6, 2024

Describe the bug

I plotted the live enphase data at 9:06pm IST against the fake data and i can see negative power in the curve
image
image

To Reproduce

Steps to reproduce the behavior:

  1. Run the inverter_example.py file

Expected behavior

No negative power should be plotted

Additional context

Should the negative part be taken 0 or modded?

@aryanbhosale aryanbhosale added the bug Something isn't working label Jun 6, 2024
@peterdudfield
Copy link
Contributor

Is this still an issue, or did we sovle this?

@aryanbhosale
Copy link
Member Author

Is this still an issue, or did we sovle this?

I think this is solved after taking 7day data

@peterdudfield
Copy link
Contributor

Shall we close this then?

@aryanbhosale
Copy link
Member Author

Shall we close this then?

Yes this could be closed

@aryanbhosale aryanbhosale self-assigned this Jul 16, 2024
@iRonin
Copy link

iRonin commented Sep 15, 2024

Negative production still occurs for me when I run the script for a site in the Caribbean using the GFS model, example output:

Hourly Production (kWh):
2024-09-14 01:00:00: 0.00
2024-09-14 02:00:00: 0.00
2024-09-14 03:00:00: 0.00
2024-09-14 04:00:00: 0.00
2024-09-14 05:00:00: 0.00
2024-09-14 06:00:00: 0.99
2024-09-14 07:00:00: 7.25
2024-09-14 08:00:00: 8.76
2024-09-14 09:00:00: 1.04
2024-09-14 10:00:00: -1.35    <-----
2024-09-14 11:00:00: -1.47    <-----
2024-09-14 12:00:00: 0.63
2024-09-14 13:00:00: 3.66
2024-09-14 14:00:00: 4.09
2024-09-14 15:00:00: 1.59
2024-09-14 16:00:00: 3.03
2024-09-14 17:00:00: 1.63

ICON gives more negatives:

...
2024-09-14 08:00:00: 7.42
2024-09-14 09:00:00: 3.19
2024-09-14 10:00:00: -1.07    <-----
2024-09-14 11:00:00: 0.38
2024-09-14 12:00:00: 0.38
...
2024-09-15 05:00:00: 0.00
2024-09-15 06:00:00: 0.64
2024-09-15 07:00:00: 2.86
2024-09-15 08:00:00: 2.98
2024-09-15 09:00:00: -0.67    <-----
2024-09-15 10:00:00: -2.90    <-----
2024-09-15 11:00:00: -3.05    <-----
2024-09-15 12:00:00: -3.06    <-----
2024-09-15 13:00:00: -2.84    <-----
2024-09-15 14:00:00: -2.32    <-----
2024-09-15 15:00:00: -1.39    <-----
2024-09-15 16:00:00: 0.60
2024-09-15 17:00:00: 0.56
2024-09-15 18:00:00: 0.00

@aryanbhosale
Copy link
Member Author

Negative production still occurs for me when I run the script for a site in the Caribbean using the GFS model, example output:

Hourly Production (kWh):
2024-09-14 01:00:00: 0.00
2024-09-14 02:00:00: 0.00
2024-09-14 03:00:00: 0.00
2024-09-14 04:00:00: 0.00
2024-09-14 05:00:00: 0.00
2024-09-14 06:00:00: 0.99
2024-09-14 07:00:00: 7.25
2024-09-14 08:00:00: 8.76
2024-09-14 09:00:00: 1.04
2024-09-14 10:00:00: -1.35    <-----
2024-09-14 11:00:00: -1.47    <-----
2024-09-14 12:00:00: 0.63
2024-09-14 13:00:00: 3.66
2024-09-14 14:00:00: 4.09
2024-09-14 15:00:00: 1.59
2024-09-14 16:00:00: 3.03
2024-09-14 17:00:00: 1.63

ICON gives more negatives:

...
2024-09-14 08:00:00: 7.42
2024-09-14 09:00:00: 3.19
2024-09-14 10:00:00: -1.07    <-----
2024-09-14 11:00:00: 0.38
2024-09-14 12:00:00: 0.38
...
2024-09-15 05:00:00: 0.00
2024-09-15 06:00:00: 0.64
2024-09-15 07:00:00: 2.86
2024-09-15 08:00:00: 2.98
2024-09-15 09:00:00: -0.67    <-----
2024-09-15 10:00:00: -2.90    <-----
2024-09-15 11:00:00: -3.05    <-----
2024-09-15 12:00:00: -3.06    <-----
2024-09-15 13:00:00: -2.84    <-----
2024-09-15 14:00:00: -2.32    <-----
2024-09-15 15:00:00: -1.39    <-----
2024-09-15 16:00:00: 0.60
2024-09-15 17:00:00: 0.56
2024-09-15 18:00:00: 0.00

@peterdudfield guess we'll have to reopen this? Can perhaps cap the values at 0 so that they don't go below

@aryanbhosale aryanbhosale reopened this Sep 15, 2024
@iRonin
Copy link

iRonin commented Sep 15, 2024

@aryanbhosale is your project / data / models trained only for the UK? The forecast of this lib for my system is completely off.

@aryanbhosale
Copy link
Member Author

@aryanbhosale is your project / data / models trained only for the UK? The forecast of this lib for my system is completely off.

It's not exactly my project, I've only worked with integrating solar inverters to get live data,
@peterdudfield would you like to comment on this?

@peterdudfield
Copy link
Contributor

Yea we train on uk systems, but we would be very interested in testing it and possibly expanding it. In principle we should be able to make a global model.

Can you share any plots and code you used? Any comparisons with real data would be great

There could be a chance there are some timezone issues

@iRonin
Copy link

iRonin commented Sep 16, 2024

Here is the code I used @peterdudfield

from quartz_solar_forecast.forecast import run_forecast
from quartz_solar_forecast.pydantic_models import PVSite
from datetime import datetime, timedelta
import json
import pandas as pd
from pv_params import LATITUDE, LONGITUDE, TOTAL_WATT_PEAK, TILT, AZIMUTH

# make a pv site object
site = PVSite(latitude=LATITUDE, longitude=LONGITUDE, capacity_kwp=TOTAL_WATT_PEAK / 1000, tilt=TILT, orientation=AZIMUTH)
# site = PVSite(latitude=51.75, longitude=-1.25, capacity_kwp=1.25)

# Set the timestamp to 5 AM on the previous day
ts = (datetime.now() - timedelta(days=1)).replace(hour=5, minute=0, second=0, microsecond=0)
# ts = datetime.today()
predictions_df = run_forecast(site=site, ts=ts, nwp_source="gfs")

# Save the original predictions to JSON
predictions_df.to_json("qsf.json")

# Load the JSON data
with open("qsf.json", "r") as f:
    data = json.load(f)

# Convert timestamps to datetime objects and power values to a pandas Series
timestamps = [datetime.fromtimestamp(int(ts) / 1000) for ts in data["power_kw"].keys()]
power_values = pd.Series(list(data["power_kw"].values()), index=timestamps)

# Calculate total production per day
daily_production = power_values.resample('D').sum()

# Calculate total production per hour
hourly_production = power_values.resample('H').sum()

# Output results
print("Daily Production (kWh):")
for date, production in daily_production.items():
    print(f"{date.date()}: {production:.2f}")

print("\nHourly Production (kWh):")
for datetime, production in hourly_production.items():
    print(f"{datetime}: {production:.2f}")

# Optionally, save the results to a file
with open("production_summary.txt", "w") as f:
    f.write("Daily Production (kWh):\n")
    for date, production in daily_production.items():
        f.write(f"{date.date()}: {production:.2f}\n")

    f.write("\nHourly Production (kWh):\n")
    for datetime, production in hourly_production.items():
        f.write(f"{datetime}: {production:.2f}\n")

It's kind of weird that a PV production forecast would ever return a negative value 🙃

@peterdudfield
Copy link
Contributor

peterdudfield commented Sep 17, 2024

Thanks. Yea negative numbers are odd.

What are the constant like lat and lon you used? Just so we can reproduce.

Also you can round your lat and lons, if you want to keep the location slightly more prviate

@iRonin
Copy link

iRonin commented Sep 17, 2024

@peterdudfield I was checking it for Antigua.

@peterdudfield
Copy link
Contributor

Thanks. I'll have to test out there.

Ultimately the ML model is trained on UK sites, but it should work globally. We only trained on UK sites, as we have UK data

@peterdudfield
Copy link
Contributor

Hi @iRonin, I just ran a forecast for Antigua, I got some results like this. Is this what you get?

Screenshot 2024-09-20 at 08 10 52
""" Example code to run the forecast"""
from quartz_solar_forecast.forecast import run_forecast
from quartz_solar_forecast.pydantic_models import PVSite
from datetime import datetime, timedelta
import plotly.express as px

def main():
    # make input data
    site = PVSite(latitude=17, longitude=-61, capacity_kwp=1.0)
    
    ts = datetime.now()

    # User has three options for the 'nwp_source': 'icon', 'gfs', or 'ukmo'.
    predictions_df = run_forecast(site=site, ts=ts, nwp_source="icon")

    print(predictions_df)
    print(f"Max: {predictions_df['power_kw'].max()}")

    fig = px.line(predictions_df.reset_index().rename(columns={"index": "date"}),
                  x="date", y="power_kw",
                  labels={"power_kw": "Power (kw)"},
                  title="Solar Energy Prediction")
    fig.show()

if __name__ == "__main__":
    main()

@iRonin
Copy link

iRonin commented Sep 20, 2024

I'll email you my coordinates as these seem to still produce negative forecast values.

@peterdudfield
Copy link
Contributor

I'll email you my coordinates as these seem to still produce negative forecast values.

Thanks, and what about for the coordiantes above, does it work for you?

@iRonin
Copy link

iRonin commented Sep 20, 2024

Thanks, and what about for the coordiantes above, does it work for you?

No negative values but your coordinates are somewhere close to St. Lucia.

It seems the negative values start happening once you add capacity. Try this:

site = PVSite(latitude=17.0742, longitude=-61.8869, capacity_kwp=15.48)

@peterdudfield
Copy link
Contributor

Ah interesting, out training set was using capacities from 1 - 4 is kwp, so could you try it with a smaller number?

We could also scale the results if the capacity is above 5. I.e

  • installed capacity need is 20
  • run forecast model with 4kwp and then
  • add warning, "The ML model was trained with system no larger than 4kwp, therefore we have run the model with 4 kwp and scaled up the results"
  • then scale the forecast from 4 kwp to 20

@zakwatts I'd be interested in your opinion on this?

@iRonin
Copy link

iRonin commented Sep 20, 2024

Default 1kW works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants