|
6 | 6 | import io
|
7 | 7 | import re
|
8 | 8 | from urllib.request import urlopen, Request
|
| 9 | +import numpy as np |
9 | 10 | import pandas as pd
|
10 | 11 |
|
11 | 12 |
|
@@ -139,8 +140,15 @@ def read_tmy3(filename=None, coerce_year=None, recolumn=True):
|
139 | 140 | TMYData.PresWthUncertainty Present weather code uncertainty, see [2]_.
|
140 | 141 | ============================= ======================================================================================================================================================
|
141 | 142 |
|
142 |
| - .. warning:: when coercing the year, the last index in the dataframe will |
143 |
| - actually be the first hour of the year |
| 143 | + .. warning:: TMY3 irradiance data corresponds to the previous hour, so the |
| 144 | + first hour is 1AM, corresponding to the net irradiance from midnite to |
| 145 | + 1AM, and the last hour is midnite of the *next* year, unless the year |
| 146 | + has been coerced. EG: if TMY3 was 1988-12-31 24:00:00 this becomes |
| 147 | + 1989-01-01 00:00:00 |
| 148 | +
|
| 149 | + .. warning:: When coercing the year, the last index in the dataframe will |
| 150 | + be the first hour of the same year, EG: if TMY3 was 1988-12-31 24:00:00 |
| 151 | + and year is coerced to 1990 this becomes 1990-01-01 |
144 | 152 |
|
145 | 153 | References
|
146 | 154 | ----------
|
@@ -191,9 +199,22 @@ def read_tmy3(filename=None, coerce_year=None, recolumn=True):
|
191 | 199 | # header is actually the second line in file, but tell pandas to look for
|
192 | 200 | # header information on the 1st line (0 indexing) because we've already
|
193 | 201 | # advanced past the true first line with the readline call above.
|
194 |
| - data = pd.read_csv(csvdata, header=0, index_col='Date (MM/DD/YYYY)') |
195 |
| - data.index = pd.to_datetime(data.index, format='%m/%d/%Y') |
196 |
| - shifted_hour = data['Time (HH:MM)'].str[:2].astype(int) - 1 |
| 202 | + data = pd.read_csv(csvdata, header=0) |
| 203 | + # get the date column as a pd.Series of numpy datetime64 |
| 204 | + data_ymd = pd.to_datetime(data['Date (MM/DD/YYYY)'], format='%m/%d/%Y') |
| 205 | + # shift the time column so that midnite is 00:00 instead of 24:00 |
| 206 | + shifted_hour = data['Time (HH:MM)'].str[:2].astype(int) % 24 |
| 207 | + # shift the dates at midnite so they correspond to the next day |
| 208 | + data_ymd[shifted_hour == 0] += datetime.timedelta(days=1) |
| 209 | + # NOTE: as of pandas>=0.24 the pd.Series.array has a month attribute, but |
| 210 | + # in pandas-0.18.1, only DatetimeIndex has month, but indices are immutable |
| 211 | + # so we need to continue to work with the panda series of dates `data_ymd` |
| 212 | + data_index = pd.DatetimeIndex(data_ymd) |
| 213 | + # use indices to check for a leap day and advance it to March 1st |
| 214 | + leapday = (data_index.month == 2) & (data_index.day == 29) |
| 215 | + data_ymd[leapday] += datetime.timedelta(days=1) |
| 216 | + # is this necessary? convert the series to DatetimeIndex |
| 217 | + data.index = pd.DatetimeIndex(data_ymd) |
197 | 218 | # shifted_hour is a pd.Series, so use pd.to_timedelta to get a pd.Series of
|
198 | 219 | # timedeltas
|
199 | 220 | # NOTE: as of pvlib-0.6.3, min req is pandas-0.18.1, so pd.to_timedelta
|
|
0 commit comments