Skip to content

Commit

Permalink
More consistent __repr__ for different classes. more pytests
Browse files Browse the repository at this point in the history
  • Loading branch information
cdeline committed Sep 6, 2024
1 parent 28d40c0 commit c267150
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
14 changes: 7 additions & 7 deletions bifacial_radiance/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def _checkRaypath():

class SuperClass:
def __repr__(self):
return str({key: self.__dict__[key] for key in self.columns})
return str(type(self)) + ' : ' + str({key: self.__dict__[key] for key in self.columns})
#return str(self.__dict__)
@property
def columns(self):
Expand Down Expand Up @@ -359,7 +359,7 @@ class RadianceObj(SuperClass):
"""
def __repr__(self):
#return str(self.__dict__)
return str({key: self.__dict__[key] for key in self.columns if key != 'trackerdict'})
return str(type(self)) + ' : ' + str({key: self.__dict__[key] for key in self.columns if key != 'trackerdict'})
def __init__(self, name=None, path=None, hpc=False):
'''
initialize RadianceObj with path of Radiance materials and objects,
Expand Down Expand Up @@ -2636,7 +2636,7 @@ def analysis1axis(self, trackerdict=None, singleindex=None, accuracy='low',

# End RadianceObj definition

class GroundObj:
class GroundObj(SuperClass):
"""
Class to set and return details for the ground surface materials and reflectance.
If 1 albedo value is passed, it is used as default.
Expand Down Expand Up @@ -2853,8 +2853,7 @@ class SceneObj(SuperClass):
-------
'''
def __repr__(self):
return 'SceneObj:\n'+str({key: self.__dict__[key] for key in self.columns})

def __init__(self, module=None, name=None):
''' initialize SceneObj
'''
Expand Down Expand Up @@ -3175,7 +3174,8 @@ def __repr__(self):
self.tmydata.info(memory_usage=False, buf=buf)
tmyinfo = buf.getvalue()
buf.close()
return f'\nMetObj.metadata:\n {self.metadata}\nMetObj.tmydata:\n {tmyinfo}\n'
return f"<class 'bifacial_radiance.main.MetObj'>.metadata:\n"\
f"{self.metadata}\n<class 'bifacial_radiance.main.MetObj'>.tmydata:\n {tmyinfo}\n"

def __init__(self, tmydata, metadata, label = 'right'):

Expand Down Expand Up @@ -3627,7 +3627,7 @@ def __printval__(self, attr):
return getattr(self,attr)

def __repr__(self):
return 'AnalysisObj:\n' + str({key: self.__printval__(key) for key in self.columns})
return str(type(self)) + ' : ' + str({key: self.__printval__(key) for key in self.columns})
def __init__(self, octfile=None, name=None, hpc=False):
"""
Initialize AnalysisObj by pointing to the octfile. Scan information
Expand Down
2 changes: 1 addition & 1 deletion bifacial_radiance/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ModuleObj(SuperClass):
"""

def __repr__(self):
return 'ModuleObj:\n' + str(self.getDataDict())
return str(type(self)) + ' : ' + str(self.getDataDict())
def __init__(self, name=None, x=None, y=None, z=None, bifi=1, modulefile=None,
text=None, customtext='', xgap=0.01, ygap=0.0, zgap=0.1,
numpanels=1, rewriteModulefile=True, cellModule=None,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_bifacial_radiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def test_1axis_gencumSky():

demo = bifacial_radiance.RadianceObj(name) # Create a RadianceObj 'object'
demo.setGround(albedo) # input albedo number or material name like 'concrete'. To see options, run this without any input.
assert demo.ground.methods == ['printGroundMaterials']
metdata = demo.readWeatherFile(weatherFile=MET_FILENAME, starttime='01_01_01', endtime = '01_01_23', coerce_year=2001) # read in the EPW weather data from above
moduleText = '! genbox black test-module 0.98 1.95 0.02 | xform -t -0.49 -2.0 0 -a 2 -t 0 2.05 0'
module=demo.makeModule(name='test-module',x=0.984,y=1.95, numpanels = 2, ygap = 0.1, text=moduleText)
Expand Down Expand Up @@ -374,6 +375,7 @@ def test_left_label_metdata():
# right labeled MetObj
import pvlib
import pandas as pd
import unittest
(tmydata, metadata) = pvlib.iotools.epw.read_epw(MET_FILENAME, coerce_year=2001)
# rename different field parameters to match output from
# pvlib.tmy.readtmy: DNI, DHI, DryBulb, Wspd
Expand All @@ -385,6 +387,12 @@ def test_left_label_metdata():
'albedo':'Alb'
}, inplace=True)
metdata1 = bifacial_radiance.MetObj(tmydata, metadata, label='left')
columnlist = ['ghi', 'dhi', 'dni', 'albedo', 'dewpoint', 'pressure', 'temp_air','wind_speed']
assert all([col in list(metdata1.tmydata.columns) for col in columnlist])
metadatalist = ['city', 'elevation', 'label', 'latitude', 'longitude', 'timezone']
assert all([col in list(metdata1.metadata.keys()) for col in metadatalist])


demo = bifacial_radiance.RadianceObj('test')
metdata2 = demo.readWeatherFile(weatherFile=MET_FILENAME, label='right', coerce_year=2001)
pd.testing.assert_frame_equal(metdata1.solpos[:-1], metdata2.solpos[:-1])
Expand Down Expand Up @@ -417,6 +425,7 @@ def test_analyzeRow():
assert rowscan[rowscan.keys()[2]][0][0] == rowscan[rowscan.keys()[2]][1][0]
# Assert Y is different for two different modules
assert rowscan[rowscan.keys()[1]][0][0]+2 == rowscan[rowscan.keys()[1]][1][0]
assert (analysis.__printval__('x')[1] == 0) & (analysis.x[1] != 0)


def test_addMaterialGroundRad():
Expand Down

0 comments on commit c267150

Please sign in to comment.