Skip to content

Commit

Permalink
Fix leap day bug in readWeatherFile. fixes #552.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeline committed Sep 25, 2024
1 parent 9486645 commit e667a7c
Show file tree
Hide file tree
Showing 4 changed files with 8,785 additions and 3 deletions.
11 changes: 9 additions & 2 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,10 +961,10 @@ def _tz_convert(metdata, metadata, tz_convert_val):
metdata, metadata = self._readSOLARGIS(weatherFile, label=label)

if source.lower() =='epw':
metdata, metadata = self._readEPW(weatherFile, label=label)
metdata, metadata = self._readEPW(weatherFile, label=label, coerce_year=coerce_year)

if source.lower() =='tmy3':
metdata, metadata = self._readTMY(weatherFile, label=label)
metdata, metadata = self._readTMY(weatherFile, label=label, coerce_year=coerce_year)

metdata, metadata = _tz_convert(metdata, metadata, tz_convert_val)
tzinfo = metdata.index.tzinfo
Expand Down Expand Up @@ -1270,7 +1270,14 @@ def _readEPW(self, epwfile=None, label = 'right', coerce_year=None):
coerce_year=coerce_year) #pvlib>0.6.1
#pvlib uses -1hr offset that needs to be un-done.
tmydata.index = tmydata.index+pd.Timedelta(hours=1)
# need to check for leap year here and add a day just in case
# use indices to check for a leap day and advance it to March 1st
leapday = (tmydata.index.month == 2) & (tmydata.index.day == 29)
index2 = tmydata.index.to_series()
index2.loc[leapday] += datetime.timedelta(days=1)
tmydata.set_index(index2, inplace=True)


# rename different field parameters to match output from
# pvlib.tmy.readtmy: DNI, DHI, DryBulb, Wspd
tmydata.rename(columns={'dni':'DNI',
Expand Down
1 change: 1 addition & 0 deletions docs/sphinx/source/whatsnew/pending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Bug fixes
~~~~~~~~~
* Fixed a major error with indexing the irradiance conditions with :py:func:`~bifacial_radiance.RadianceObj.gendaylit1axis`. This could result in the trackerdict entry being mismatched from the metdata resource. (:issue:`441`)
* versioning with setuptools_scm- set fallback_version to bifirad v0.4.3 to prevent crashes if git is not present (:issue:`535`)(:pull:`539`)
* Fixed a leap year bug in :py:func:`~bifacial_radiance.RadianceObj.readWeatherFile` that crashed if epwfiles are loaded that include leap year data (like Feb. 28 2020). (:issue:`552`)

Documentation
~~~~~~~~~~~~~~
Expand Down
Loading

0 comments on commit e667a7c

Please sign in to comment.