Skip to content

Commit 3c1a814

Browse files
committed
Imports oslg v0.3.0
1 parent a9aaf2c commit 3c1a814

File tree

2 files changed

+80
-56
lines changed

2 files changed

+80
-56
lines changed

src/osut/osut.py

Lines changed: 76 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ class _CN:
4141
WRN = oslg.CN.WARN
4242
ERR = oslg.CN.ERROR
4343
FTL = oslg.CN.FATAL
44-
NS = "nameString"
4544
TOL = 0.01 # default distance tolerance (m)
4645
TOL2 = TOL * TOL # default area tolerance (m2)
4746
CN = _CN()
@@ -233,7 +232,6 @@ def genConstruction(model=None, specs=dict()):
233232

234233
if not isinstance(model, cl):
235234
return oslg.mismatch("model", model, cl, mth, CN.DBG)
236-
237235
if not isinstance(specs, dict):
238236
return oslg.mismatch("specs", specs, dict, mth, CN.DBG)
239237

@@ -242,12 +240,12 @@ def genConstruction(model=None, specs=dict()):
242240

243241
id = oslg.trim(specs["id"])
244242

245-
if not id: id = "OSut.CON." + specs["type"]
246-
243+
if not id:
244+
id = "OSut.CON." + specs["type"]
247245
if specs["type"] not in uo():
248246
return oslg.invalid("surface type", mth, 2, CN.ERR)
249-
250-
if "uo" not in specs: specs["uo"] = uo()[ specs["type"] ]
247+
if "uo" not in specs:
248+
specs["uo"] = uo()[ specs["type"] ]
251249

252250
u = specs["uo"]
253251

@@ -617,11 +615,10 @@ def genShade(subs=None) -> bool:
617615
v = int("".join(openstudio.openStudioVersion().split(".")))
618616
cl = openstudio.model.SubSurfaceVector
619617

620-
if v < 321: return False
621-
618+
if v < 321:
619+
return False
622620
if not isinstance(subs, cl):
623621
return oslg.mismatch("subs", subs, cl, mth, CN.DBG, False)
624-
625622
if not subs:
626623
return oslg.empty("subs", mth, CN.WRN, False)
627624

@@ -868,6 +865,60 @@ def defaultConstructionSet(s=None):
868865
869866
"""
870867
mth = "osut.defaultConstructionSet"
868+
cl = openstudio.model.Surface
869+
870+
if not isinstance(s, cl):
871+
return oslg.mismatch("surface", s, cl, mth)
872+
if not s.isConstructionDefaulted():
873+
oslg.log(CN.WRN, "construction not defaulted (%s)" % mth)
874+
return None
875+
if s.construction():
876+
return oslg.empty("construction", mth, CN.WRN)
877+
if not s.space():
878+
return oslg.empty("space", mth, CN.WRN)
879+
880+
mdl = s.model()
881+
base = s.construction().get()
882+
space = s.space().get()
883+
type = s.surfaceType()
884+
bnd = s.outsideBoundaryCondition().downcase()
885+
886+
ground = True if s.isGroundSurface() else False
887+
exterior = True if bnd == "outdoors" else False
888+
889+
if space.defaultConstructionSet():
890+
set = space.defaultConstructionSet().get()
891+
892+
if holdsConstruction(set, base, ground, exterior, type): return set
893+
894+
if space.spaceType():
895+
spacetype = space.spaceType().get()
896+
897+
if spacetype.defaultConstructionSet():
898+
set = spacetype.defaultConstructionSet().get()
899+
900+
if holdsConstruction(set, base, ground, exterior, type):
901+
return set
902+
903+
if space.buildingStory():
904+
story = space.buildingStory().get()
905+
906+
if story.defaultConstructionSet():
907+
set = story.defaultConstructionSet().get()
908+
909+
if holdsConstruction(set, base, ground, exterior, type):
910+
return set
911+
912+
913+
building = mdl.getBuilding()
914+
915+
if building.defaultConstructionSet():
916+
set = building.defaultConstructionSet().get()
917+
918+
if holdsConstruction(set, base, ground, exterior, type):
919+
return set
920+
921+
return None
871922

872923

873924
def are_standardOpaqueLayers(lc=None) -> bool:
@@ -885,13 +936,8 @@ def are_standardOpaqueLayers(lc=None) -> bool:
885936
mth = "osut.are_standardOpaqueLayers"
886937
cl = openstudio.model.LayeredConstruction
887938

888-
if not hasattr(lc, CN.NS):
889-
return oslg.invalid("layered construction", mth, 1, DBG, 0.0)
890-
891-
id = oslg.trim(lc.nameString())
892-
893939
if not isinstance(lc, cl):
894-
return oslg.mismatch(id, lc, cl, mth, CN.DBG, 0.0)
940+
return oslg.mismatch("lc", lc, cl, mth, CN.DBG, 0.0)
895941

896942
for m in lc.layers():
897943
if not m.to_StandardOpaqueMaterial(): return False
@@ -915,16 +961,10 @@ def thickness(lc=None) -> float:
915961
cl = openstudio.model.LayeredConstruction
916962
d = 0.0
917963

918-
if not hasattr(lc, CN.NS):
919-
return oslg.invalid("layered construction", mth, 1, DBG, 0.0)
920-
921-
id = oslg.trim(lc.nameString())
922-
923964
if not isinstance(lc, cl):
924-
return oslg.mismatch(id, lc, cl, mth, CN.DBG, 0.0)
925-
965+
return oslg.mismatch("lc", lc, cl, mth, CN.DBG, 0.0)
926966
if not are_standardOpaqueLayers(lc):
927-
oslg.log(CN.ERR, "%s holds non-StandardOpaqueMaterial(s) %s" % (id, mth))
967+
oslg.log(CN.ERR, "holding non-StandardOpaqueMaterial(s) %s" % mth)
928968
return d
929969

930970
for m in lc.layers(): d += m.thickness()
@@ -1005,33 +1045,27 @@ def rsi(lc=None, film=0.0, t=0.0) -> float:
10051045
10061046
"""
10071047
mth = "osut.rsi"
1008-
cl1 = openstudio.model.LayeredConstruction
1009-
1010-
if not hasattr(lc, CN.NS):
1011-
return oslg.invalid("layered construction", mth, 1, DBG, 0.0)
1012-
1013-
id = lc.nameString()
1048+
cl = openstudio.model.LayeredConstruction
10141049

1015-
if not isinstance(lc, cl1):
1016-
return oslg.mismatch(id, lc, cl1, mth, CN.DBG, 0.0)
1050+
if not isinstance(lc, cl):
1051+
return oslg.mismatch("lc", lc, cl, mth, CN.DBG, 0.0)
10171052

10181053
try:
10191054
film = float(film)
10201055
except ValueError as e:
1021-
return oslg.mismatch(id + " film", film, float, mth, CN.DBG, 0.0)
1056+
return oslg.mismatch("film", film, float, mth, CN.DBG, 0.0)
10221057

10231058
try:
10241059
t = float(t)
10251060
except ValueError as e:
1026-
return oslg.mismatch(id + " temp K", t, float, mth, CN.DBG, 0.0)
1061+
return oslg.mismatch("temp K", t, float, mth, CN.DBG, 0.0)
10271062

10281063
t += 273.0 # °C to K
10291064

10301065
if t < 0:
1031-
return oslg.negative(id + " temp K", mth, CN.ERR, 0.0)
1032-
1066+
return oslg.negative("temp K", mth, CN.ERR, 0.0)
10331067
if film < 0:
1034-
return oslg.negative(id + " film", mth, ERR, 0.0)
1068+
return oslg.negative("film", mth, ERR, 0.0)
10351069

10361070
rsi = film
10371071

@@ -1083,13 +1117,8 @@ def insulatingLayer(lc=None) -> dict:
10831117
res = dict(index=None, type=None, r=0.0)
10841118
i = 0 # iterator
10851119

1086-
if not hasattr(lc, CN.NS):
1087-
return oslg.invalid("lc", mth, 1, CN.DBG, res)
1088-
1089-
id = lc.nameString()
1090-
10911120
if not isinstance(lc, cl):
1092-
return oslg.mismatch(id, lc, cl, mth, CN.DBG, res)
1121+
return oslg.mismatch("lc", lc, cl, mth, CN.DBG, res)
10931122

10941123
for m in lc.layers():
10951124
if m.to_MasslessOpaqueMaterial():
@@ -1209,15 +1238,11 @@ def transforms(group=None) -> dict:
12091238
res = dict(t=None, r=None)
12101239
cl = openstudio.model.PlanarSurfaceGroup
12111240

1212-
if not hasattr(group, CN.NS):
1213-
return oslg.invalid("group", mth, 0, CN.DBG, res)
1241+
if isinstance(group, cl):
1242+
return oslg.mismatch("group", group, cl, mth, CN.DBG, res)
12141243

1215-
id = group.nameString()
12161244
mdl = group.model()
12171245

1218-
if isinstance(group, cl):
1219-
return oslg.mismatch(id, group, cl, mth, CN.DBG, res)
1220-
12211246
res["t"] = group.siteTransformation()
12221247
res["r"] = group.directionofRelativeNorth() + mdl.getBuilding().northAxis()
12231248

@@ -1342,8 +1367,8 @@ def is_same_vtx(s1=None, s2=None, indexed=True) -> bool:
13421367
False: If invalid input (see logs).
13431368
13441369
"""
1345-
s1 = list(to_p3Dv(s1))
1346-
s2 = list(to_p3Dv(s2))
1370+
s1 = list(to_p3Dv(s1))
1371+
s2 = list(to_p3Dv(s2))
13471372
if not s1: return False
13481373
if not s2: return False
13491374
if len(s1) != len(s2): return False
@@ -1360,7 +1385,7 @@ def is_same_vtx(s1=None, s2=None, indexed=True) -> bool:
13601385
indx = None
13611386

13621387
for i, pt in enumerate(s2):
1363-
if indx: break
1388+
if indx: continue
13641389

13651390
xOK = abs(s1[0].x() - s2[i].x()) < CN.TOL
13661391
yOK = abs(s1[0].y() - s2[i].y()) < CN.TOL

tests/test_osut.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
WRN = osut.CN.WRN
4141
ERR = osut.CN.ERR
4242
FTL = osut.CN.FTL
43-
NS = osut.CN.NS
4443
TOL = osut.CN.TOL
4544
TOL2 = osut.CN.TOL2
4645

@@ -229,7 +228,7 @@ def test06_insulatingLayer(self):
229228
self.assertTrue(model)
230229
model = model.get()
231230

232-
m0 = "Invalid 'lc' arg #1 (osut.insulatingLayer)"
231+
m0 = " expecting LayeredConstruction (osut.insulatingLayer)"
233232

234233
for lc in model.getLayeredConstructions():
235234
id = lc.nameString()
@@ -279,7 +278,7 @@ def test06_insulatingLayer(self):
279278
self.assertFalse(lyr["type"])
280279
self.assertEqual(round(lyr["r"], 2), 0.00)
281280
self.assertEqual(len(o.logs()), 1)
282-
self.assertEqual(o.logs()[0]["message"], m0)
281+
self.assertTrue(m0 in o.logs()[0]["message"])
283282
self.assertEqual(o.clean(), DBG)
284283

285284
lyr = osut.insulatingLayer("")
@@ -288,7 +287,7 @@ def test06_insulatingLayer(self):
288287
self.assertFalse(lyr["type"])
289288
self.assertEqual(round(lyr["r"], 2), 0.00)
290289
self.assertTrue(len(o.logs()), 1)
291-
self.assertEqual(o.logs()[0]["message"], m0)
290+
self.assertTrue(m0 in o.logs()[0]["message"])
292291
self.assertEqual(o.clean(), DBG)
293292

294293
lyr = osut.insulatingLayer(model)
@@ -297,7 +296,7 @@ def test06_insulatingLayer(self):
297296
self.assertFalse(lyr["type"])
298297
self.assertEqual(round(lyr["r"], 2), 0.00)
299298
self.assertTrue(len(o.logs()), 1)
300-
self.assertEqual(o.logs()[0]["message"], m0)
299+
self.assertTrue(m0 in o.logs()[0]["message"])
301300
self.assertEqual(o.clean(), DBG)
302301

303302
def test07_genConstruction(self):

0 commit comments

Comments
 (0)