Skip to content

Commit

Permalink
Merge pull request #494 from NREL/493_pytests
Browse files Browse the repository at this point in the history
493 pytests
  • Loading branch information
cdeline authored Nov 29, 2023
2 parents 4ae5f3a + d69b5f3 commit 967e848
Show file tree
Hide file tree
Showing 9 changed files with 8,832 additions and 20 deletions.
6 changes: 3 additions & 3 deletions bifacial_radiance/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def _exportTrackerDict(trackerdict, savefile, reindex=False, monthlyyearly=False
# So we get average hourly irradiance as well as Wh on
# results of power.
D2b = D2.copy()
D2b = D2b.groupby(pd.PeriodIndex(D2b.index, freq="H")).mean().reset_index()
D2b = D2b.groupby(pd.PeriodIndex(D2b.index, freq="H")).mean(numeric_only=True).reset_index()
D2b['BGG'] = D2b['Grear_mean']*100/D2b['Gfront_mean']
D2b['BGE'] = (D2b['Pout']-D2b['Pout_Gfront'])*100/D2b['Pout']
D2b['Mismatch'] = (D2b['Pout_raw']-D2b['Pout'])*100/D2b['Pout_raw']
Expand All @@ -388,7 +388,7 @@ def _exportTrackerDict(trackerdict, savefile, reindex=False, monthlyyearly=False
D3['Mismatch'] = (D3['Pout_raw']-D3['Pout'])*100/D3['Pout_raw']
D3['rowWanted'] = rownum
D3['modWanted'] = modnum
D3m = D2.groupby(pd.PeriodIndex(D2.index, freq="M")).mean().reset_index()
D3m = D2.groupby(pd.PeriodIndex(D2.index, freq="M")).mean(numeric_only=True).reset_index()
D3['temp_air'] = D3m['temp_air']
D3['wind_speed'] = D3m['wind_speed']
D3.drop(columns=['theta', 'surf_tilt', 'surf_azm'], inplace=True)
Expand All @@ -399,7 +399,7 @@ def _exportTrackerDict(trackerdict, savefile, reindex=False, monthlyyearly=False
D4['Mismatch'] = (D4['Pout_raw']-D4['Pout'])*100/D4['Pout_raw']
D4['rowWanted'] = rownum
D4['modWanted'] = modnum
D4m = D2.groupby(pd.PeriodIndex(D2.index, freq="Y")).mean().reset_index()
D4m = D2.groupby(pd.PeriodIndex(D2.index, freq="Y")).mean(numeric_only=True).reset_index()
D4['temp_air'] = D4m['temp_air']
D4['wind_speed'] = D4m['wind_speed']
D4.drop(columns=['theta', 'surf_tilt', 'surf_azm'], inplace=True)
Expand Down
34 changes: 25 additions & 9 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
def _findme(lst, a): #find string match in a list. script from stackexchange
return [i for i, x in enumerate(lst) if x == a]

def _firstlist(l): #find first not-none value in a list. useful for checking multiple keys in dict
try:
return next(item for item in l if item is not None)
except StopIteration:
return None

def _missingKeyWarning(dictype, missingkey, newvalue): # prints warnings
if type(newvalue) is bool:
valueunit = ''
Expand Down Expand Up @@ -1053,13 +1059,22 @@ def _parseTimes(t, hour, coerce_year):
return t_out, coerce_year
# end _parseTimes

def _parseMetadataNSRDB(m):
# put correct keys on m = metadata dict

m['altitude'] = _firstlist([m.get('altitude'), m.get('elevation')])
m['TZ'] = _firstlist([m.get('TZ'), m.get('Time Zone'), m.get('timezone')])
m['Name'] = _firstlist([m.get('county'), f"nsrdb_{m.get('Location ID')}"])

try:
m['city'] = (m['county'] + ',' + m['state'] +
',' + m['country'])
except KeyError:
m['city'] = '-'

return m

metadata['TZ'] = metadata['timezone']
metadata['Name'] = metadata['county']
metadata['altitude'] = metadata['elevation']
metadata['city'] = (metadata['county'] + ',' + metadata['state'] +
',' + metadata['country'])
metadata = _parseMetadataNSRDB(metadata)

metdata.rename(columns={'dni': 'DNI',
'dhi': 'DHI',
Expand Down Expand Up @@ -2302,6 +2317,7 @@ def printModules(self):
def addPiles(self, spacingPiles=6, pile_lenx=0.2, pile_leny=0.2, pile_height=None):
'''
Function to add support piles at determined intervals throughout the rows.
TODO: enable functionality or check for scenes using 'clearance_height' ?
Parameters
----------
Expand Down Expand Up @@ -3645,6 +3661,7 @@ def __init__(self, tmydata, metadata, label = 'right'):
self.longitude = metadata['longitude']; lon=self.longitude
self.elevation = metadata['altitude']; elev=self.elevation
self.timezone = metadata['TZ']

try:
self.city = metadata['Name'] # readepw version
except KeyError:
Expand All @@ -3654,10 +3671,9 @@ def __init__(self, tmydata, metadata, label = 'right'):
self.ghi = np.array(tmydata.GHI)
self.dhi = np.array(tmydata.DHI)
self.dni = np.array(tmydata.DNI)
try:
self.albedo = np.array(tmydata.Alb)
except AttributeError: # no TMY albedo data
self.albedo = None
self.albedo = np.array(_firstlist([tmydata.get('Alb'), tmydata.get('albedo'),
tmydata.get('Albedo')]) )
if pd.isnull(self.albedo).all(): self.albedo = None

# Try and retrieve dewpoint and pressure
try:
Expand Down
1 change: 1 addition & 0 deletions docs/sphinx/source/manualapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Weather

RadianceObj.getEPW
RadianceObj.readWeatherFile
RadianceObj.NSRDBWeatherData

Sky Dome
--------
Expand Down
9 changes: 5 additions & 4 deletions docs/sphinx/source/whatsnew/pending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Release of new version including ...

API Changes
~~~~~~~~~~~~
*A new function can now be called to compile results and report out final irradiance and performance data: :py:class:`~bifacial_radiance.RadianceObj.compileResults`.
* A new function can now be called to compile results and report out final irradiance and performance data: :py:class:`~bifacial_radiance.RadianceObj.compileResults`.
* Results generated with the above can be saved with the :py:class:`~bifacial_radiance.RadianceObj.exportTrackerDict`, which saves an Hourly, Monthly and Yearly .csvs in the results folder.
*Multiple modules and rows can now be selected in a single analysis scan. ``modWanted`` and ``rowWanted`` inputs in :py:class:`~bifacial_radiance.RadianceObj.analysis1axis` can now be a list, to select multiple rows and modules for scans. (:issue:`405`)(:pull:`408`)
*To support multiple modules and row scans for 1axis simulations, outputs like Wm2Front are now stored in ``trackerdict``.``Results`` (:issue:`405`)(:pull:`408`)
* ``mismatch.mad_fn`` has new functionality and input parameter `axis`. If a 2D matrix or dataframe is passed in as data, MAD is calculated along the row (default) or along the columns by passing 'axis=1'
* Multiple modules and rows can now be selected in a single analysis scan. ``modWanted`` and ``rowWanted`` inputs in :py:class:`~bifacial_radiance.RadianceObj.analysis1axis` can now be a list, to select multiple rows and modules for scans. (:issue:`405`)(:pull:`408`)
* To support multiple modules and row scans for 1axis simulations, outputs like Wm2Front are now stored in ``trackerdict``.``Results`` (:issue:`405`)(:pull:`408`)
* ``mismatch.mad_fn`` has new functionality and input parameter `axis`. If a 2D matrix or dataframe is passed in as data, MAD is calculated along the row (default) or along the columns by passing 'axis=1' (:issue:`449`)(:pull:`485`)
* NSRDB weather data can now be loaded using :py:class:`~bifacial_radiance.RadianceObj.NSRDBWeatherData`.

Enhancements
~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
install_requires=[
'pandas',
'pandas >= 1.3.0',
'pvlib >= 0.8.0',
'pvmismatch',
'configparser',
Expand Down
1 change: 1 addition & 0 deletions tests/nsrdb_boulder_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Source": "NSRDB", "Location ID": "149190", "City": "-", "State": "-", "Country": "-", "Time Zone": -7, "Local Time Zone": -7, "Dew Point Units": "c", "DHI Units": "w/m2", "DNI Units": "w/m2", "GHI Units": "w/m2", "Temperature Units": "c", "Pressure Units": "mbar", "Wind Direction Units": "Degrees", "Wind Speed Units": "m/s", "Surface Albedo Units": "N/A", "Version": "3.2.0", "latitude": 40.01, "longitude": -105.26, "altitude": 1636}
Loading

0 comments on commit 967e848

Please sign in to comment.