Skip to content

read_epw data shifted 1 hour back #1156

Open
@shirubana

Description

@shirubana

Describe the bug
It seems that the EPW data being read is being shifted one hour back.

To Reproduce

epwfile = 'USA_AZ_Tucson.Intl.AP.722740_TMY3.epw'
tmyfile = '722740TYA.CSV'                           # TMY file for Tucson

import pvlib
(epwdata, metadata) = pvlib.iotools.epw.read_epw(epwfile, coerce_year=2002) #pvlib>0.6.1
(tmydata, metadata) = pvlib.iotools.tmy.read_tmy3(tmyfile, coerce_year=2002) #pvlib>0.6.1

fig, ax = plt.subplots()
ax.plot(tmydata.index[0:24], tmydata.DNI[0:24], label='TMY data read with pvlib')
ax.plot(epwdata.index[0:24], epwdata.dni[0:24], label='EPW read with pvlib')
ax.set_ylabel('DNI [W/m$^2$]')
ax.legend()
fig.autofmt_xdate()

Expected behavior
The EPW weather files follow IWEC Manual’s conventions, where the data is aggregated hourly as an average from t-1 to t, just like Typical Meteorological Year Data (TMY). From example, from IWEC Manual:

DNI: This is the Direct Normal Radiation in Wh/m2. (Amount of solar radiation in Wh/m2 received directly from the solar disk on a surface perpendicular to the sun’s rays, during the number of minutes preceding the time indicated.)

Screenshots
If applicable, add screenshots to help explain your problem.
image

Versions:

  • pvlib.__version__: '0.9.0-alpha.1+4.g750b1fa'
  • pandas.__version__: '0.24.2'
  • python: 3.7.3

Additional context
Suggested fix:

epwdata_fix = epwdata.copy()
epwdata_fix .index = epwdata_fix .index+pd.Timedelta(hours=1) 

fig, ax = plt.subplots()
ax.plot(tmydata.index[0:24], tmydata.DNI[0:24], label='TMY data read with pvlib')
ax.plot(epwdata.index[0:24], epwdata.dni[0:24], label='EPW read with pvlib ')
ax.plot(epwdata_fix.index[0:24], epwdata_fix .dni[0:24], '*', label='EPW read with pvlib (with suggested shift)')
ax.set_ylabel('DNI [W/m$^2$]')
ax.legend()
fig.autofmt_xdate()

image

However --- this creates one entry for the first day of the next year at the end of the dataframe which can cause trouble; not sure what to suggest for that, for our use of this we're going to go with deleting the last line.
epwdata_fix = epwdata_fix[:-1]

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions