Closed PKMendes closed 3 years ago
Hi @PKMendes,
Maybe it is a problem with the dataframe (weather_data) index, Modelchain expects that the index is the date time column but in this dataframe the index I think it is just the row number.
Can you try this?
mc.run_model(times=weather_data['DateTime'], weather=weather_data)
But first, do not rename the date time column name, so change it for something like this.
weather_data = df.rename(columns={
"GHI": "ghi",
"DNI": "dni",
"DHI": "dhi",
"Tamb": "temp_air",
"WS": "wind_speed"})
Let me know if this helps.
I have just seen, that the times
argument it not used by run_model
and it is only included for compatibility reasons.
def run_model(self, weather, times=None):
"""
Run the model.
Parameters
----------
weather : DataFrame
Column names must be ``'dni'``, ``'ghi'``, ``'dhi'``,
``'wind_speed'``, ``'temp_air'``. All irradiance components
are required. Air temperature of 20 C and wind speed
of 0 m/s will be added to the DataFrame if not provided.
times : None, deprecated
Deprecated argument included for API compatibility, but not
used internally. The index of the weather DataFrame is used
for times.
So you have to make the DateTime column the dataframe index.
weather_data.set_index('DateTime')
Still with the same warnings. My weather_data looks ok:
DateTime ghi dni dhi TAmb Ws wind_speed temp_air 0 2014-01-01 00:55:00 0.0 0.0 0.0 6.56 2.14 0 20 1 2014-01-01 01:55:00 0.0 0.0 0.0 6.55 2.26 0 20 2 2014-01-01 02:55:00 0.0 0.0 0.0 6.55 2.38 0 20 .....
But the print(mc.aoi) shows data from 1970! 1970-01-01 00:00:00.000000000 162.427726 1970-01-01 00:00:00.000000001 162.427726 .... Name: aoi, Length: 8760, dtype: float64
Length:8760 is ok too.
This is my code:
from datetime import datetime from PvGis import PvGis import plotly.offline as py import plotly.graph_objs as go
import pandas as pd import numpy as np
import pvlib from pvlib.pvsystem import PVSystem from pvlib.location import Location from pvlib.modelchain import ModelChain from pvlib.temperature import TEMPERATURE_MODEL_PARAMETERS
pvGis = PvGis() pvGis.latitude = 40.8991793 pvGis.longitude = -8.3698031 pvGis.start_date = datetime(2014, 1, 1, 00, 00, 00) pvGis.end_date = datetime(2015, 1, 1, 00, 00, 00)
pvGis.rad_database = 'PVGIS-CMSAF'
pvGis.request_hourly_time_series()
pvGis.save_csv('weather_data.csv')
df = pvGis.pandas_data_frame()
temperature_model_parameters = TEMPERATURE_MODEL_PARAMETERS['sapm']['open_rack_glass_glass']
sandia_modules = pvlib.pvsystem.retrieve_sam('SandiaMod')
cec_inverters = pvlib.pvsystem.retrieve_sam('cecinverter') sandia_module = sandia_modules['Canadian_Solar_CS5P_220M2009'] cec_inverter = cec_inverters['ABBMICRO_0_25_I_OUTD_US_208_208V']
location = Location(pvGis.latitude, pvGis.longitude)
system = PVSystem(surface_tilt=20, surface_azimuth=200, module_parameters=sandia_module, inverter_parameters=cec_inverter, temperature_model_parameters=temperature_model_parameters)
mc = ModelChain(system, location)
weather_data = df.rename(columns={ "GHI": "ghi", "DNI": "dni", "DHI": "dhi", "Tamb": "temp_air", "WS": "wind_speed"})
weather_data.set_index('DateTime')
mc.run_model(times=weather_data['DateTime'], weather=weather_data)
print(mc.aoi)
I forgot to mention this warning, I believe that is related with what you commented:
...venv\lib\site-packages\pvlib\modelchain.py:956: pvlibDeprecationWarning:
times keyword argument is deprecated and will be removed in 0.8. The index of the weather DataFrame is used for times.
Hi @PKMendes,
Sorry, I think the index is not being updated in your dataframe, try this.
weather_data = weather_data.set_index('DateTime')
Or alternatively, you can also do this:
weather_data.set_index('DateTime', inplace=True)
Hi Javi,
It is working, the solution is what you suggested. Thank you very much for your help!
Hi Javi,
Thank you for your code, it was exactly what I was looking. Nevertheless, I am trying to use your code, on: https://pvlib-python.readthedocs.io/en/stable/modelchain.html
I got the first part, which I need to change your columns to the following names:
weather_data = df.rename(columns={"DateTime": "", "GHI": "ghi", "DNI": "dni", "DHI": "dhi", "Tamb": "temp_air", "WS": "wind_speed"})
afterwards, when I run modelchain:
mc.run_model(weather_data)
I got the following warnings, and inspecting the results I conclude that the result is wrong:
" ..\lib\site-packages\pandas\core\indexes\base.py:3331: RuntimeWarning: '<' not supported between instances of 'int' and 'Timestamp', sort order is undefined for incomparable objects
..core\indexes\api.py:205: RuntimeWarning: '<' not supported between instances of 'int' and 'Timestamp', sort order is undefined for incomparable objects
..\indexes\base.py:2192: RuntimeWarning: '<' not supported between instances of 'int' and 'Timestamp', sort order is undefined for incomparable objects
I suspect that Modelchain is expecting integers on panda file, but there are other type on your file. Could you help me overcoming this issue?