Skip to content

Commit

Permalink
Merge pull request #553 from NREL/552_epwfile_error
Browse files Browse the repository at this point in the history
Fix leap day bug in readWeatherFile.  fixes #552.
  • Loading branch information
cdeline authored Oct 2, 2024
2 parents ea37681 + 680f880 commit 75aae25
Show file tree
Hide file tree
Showing 12 changed files with 9,031 additions and 693 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
2 changes: 1 addition & 1 deletion docs/sphinx/source/user_guide/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Linux/Mac OSX:
4. Make directories where you want to install radiance, for example ``~/.local/opt/radiance``. Some users have reported that the installer for MacOS isn't descriptive about where it installs, and they have an easier time just choosing a location by pressing the "Change Install Location..." button in the "Installation Type" stage of the install. Then they source it in the bash/zsh_profile like so::

export PATH=$HOME/bin/radiance/bin:$PATH
export RAYPATH=$HOME/bin/radiance/lib
export RAYPATH=.:$HOME/bin/radiance/lib
export MANPATH=$HOME/bin/radiance/man
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/bin/radiance/lib
export MDIR=$HOME/bin/radiance/lib
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 @@ -24,6 +24,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`)
* :py:func:`bifacial_radiance.load.readconfigurationinputfile` now properly handles loading moduleObj parameters from .ini files: `glass`, `glassEdge`, `frameParamsDict`, `omegaParamsDict` (:pull:`551`)
* 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
507 changes: 24 additions & 483 deletions docs/tutorials/18 - AgriPV - Coffee Plantation with Tree Modeling.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#
# While we have HPC scripts to do the below simulation, this journals runs all of the above so it might take some time, as there are 109 combinations of parameters explored

# In[7]:
# In[ ]:


import bifacial_radiance
Expand All @@ -64,7 +64,7 @@
import pandas as pd


# In[8]:
# In[ ]:


testfolder = str(Path().resolve().parent.parent / 'bifacial_radiance' / 'TEMP' / 'Tutorial_18')
Expand All @@ -76,7 +76,7 @@

# ## General Parameters and Variables

# In[9]:
# In[ ]:


lat = 18.202142
Expand All @@ -99,12 +99,12 @@
nMods = 20
nRows = 7
numpanels = 1
moduletype = 'test-module'
module_name = 'test-module'
hpc = False
sim_general_name = 'tutorial_18'


# In[10]:
# In[ ]:


if not os.path.exists(os.path.join(testfolder, 'EPWs')):
Expand All @@ -118,7 +118,7 @@

# ## 1. Loop to Raytrace and sample irradiance at where Three would be located

# In[15]:
# In[ ]:


demo = bifacial_radiance.RadianceObj(sim_general_name,str(testfolder))
Expand Down Expand Up @@ -152,9 +152,10 @@
coffeeplant_x = (x+xgap)/2
coffeeplant_y = pitch/2

demo.makeModule(name=moduletype, x=x, y=y, xgap = xgap)
sceneDict = {'tilt':tilt,'pitch':pitch,'clearance_height':clearance_height,'azimuth':azimuth, 'nMods': nMods, 'nRows': nRows}
scene = demo.makeScene(moduletype=moduletype,sceneDict=sceneDict, radname = sim_name)
demo.makeModule(name=module_name, x=x, y=y, xgap = xgap)
sceneDict = {'tilt':tilt, 'pitch':pitch, 'clearance_height':clearance_height, 'azimuth':azimuth,
'nMods': nMods, 'nRows':nRows}
scene = demo.makeScene(module=module_name, sceneDict=sceneDict, radname=sim_name)
octfile = demo.makeOct(octname = demo.basename )
analysis = bifacial_radiance.AnalysisObj(octfile=octfile, name=sim_name)

Expand All @@ -180,13 +181,13 @@

# ### Option 1: Raytrace of Empty Field

# In[13]:
# In[ ]:


sim_name = 'EMPTY'
demo.makeModule(name=moduletype, x=0.001, y=0.001, xgap = 0)
demo.makeModule(name=module_name, x=0.001, y=0.001, xgap = 0)
sceneDict = {'tilt':0,'pitch':2,'clearance_height':0.005,'azimuth':180, 'nMods': 1, 'nRows': 1}
scene = demo.makeScene(moduletype=moduletype,sceneDict=sceneDict, radname = sim_name)
scene = demo.makeScene(module=module_name,sceneDict=sceneDict, radname = sim_name)
octfile = demo.makeOct(octname = demo.basename)
analysis = bifacial_radiance.AnalysisObj(octfile=octfile, name=sim_name)
frontscan, backscan = analysis.moduleAnalysis(scene=scene, sensorsy=1)
Expand All @@ -205,12 +206,11 @@
print("YEARLY TOTAL Wh/m2:", puerto_rico_Year)



# <a id='step2b'></a>

# ### Option 2: Weather File

# In[14]:
# In[ ]:


# Indexes for start of each month of interest in TMY3 8760 hours file
Expand Down Expand Up @@ -410,9 +410,9 @@
coffeeplant_x = (x+xgap)/2
coffeeplant_y = pitch

demo.makeModule(name=moduletype, x=x, y=y, xgap = xgap)
demo.makeModule(name=module_name, x=x, y=y, xgap = xgap)
sceneDict = {'tilt':tilt,'pitch':pitch,'clearance_height':clearance_height,'azimuth':azimuth, 'nMods': nMods, 'nRows': nRows}
scene = demo.makeScene(moduletype=moduletype,sceneDict=sceneDict, radname = sim_name)
scene = demo.makeScene(module=module_name,sceneDict=sceneDict, radname = sim_name)

# Appending the Trees here
text = ''
Expand Down Expand Up @@ -511,9 +511,9 @@
coffeeplant_y = pitch

demo.gendaylit(4020)
demo.makeModule(name=moduletype, x=x, y=y, xgap = xgap)
demo.makeModule(name=module_name, x=x, y=y, xgap = xgap)
sceneDict = {'tilt':tilt,'pitch':pitch,'clearance_height':clearance_height,'azimuth':azimuth, 'nMods': nMods, 'nRows': nRows}
scene = demo.makeScene(moduletype=moduletype,sceneDict=sceneDict, radname = sim_name)
scene = demo.makeScene(module=module_name,sceneDict=sceneDict, radname = sim_name)


for ii in range(0,3):
Expand Down
Loading

0 comments on commit 75aae25

Please sign in to comment.