INSTRUCTION
stringlengths
1
8.43k
RESPONSE
stringlengths
75
104k
automatically set idd and open idf file. Uses version from idf to set correct idd It will work under the following circumstances: - the IDF file should have the VERSION object. - Needs the version of EnergyPlus installed that matches the IDF version. - Energyplus should be installed in the default location.
def easyopen(fname, idd=None, epw=None): """automatically set idd and open idf file. Uses version from idf to set correct idd It will work under the following circumstances: - the IDF file should have the VERSION object. - Needs the version of EnergyPlus installed that matches the IDF version. ...
the comment is similar to that in python. any charachter after the # is treated as a comment until the end of the line astr is the string to be de - commented cphrase is the comment phrase
def removecomment(astr, cphrase): """ the comment is similar to that in python. any charachter after the # is treated as a comment until the end of the line astr is the string to be de-commented cphrase is the comment phrase""" # linesep = mylib3.getlinesep(astr) alist = astr.splitlines(...
initdict2
def initdict2(self, dictfile): """initdict2""" dt = {} dtls = [] adict = dictfile for element in adict: dt[element[0].upper()] = [] # dict keys for objects always in caps dtls.append(element[0].upper()) return dt, dtls
create a blank dictionary
def initdict(self, fname): """create a blank dictionary""" if isinstance(fname, Idd): self.dt, self.dtls = fname.dt, fname.dtls return self.dt, self.dtls astr = mylib2.readfile(fname) nocom = removecomment(astr, '!') idfst = nocom alist = idfst.sp...
stuff file data into the blank dictionary
def makedict(self, dictfile, fnamefobject): """stuff file data into the blank dictionary""" #fname = './exapmlefiles/5ZoneDD.idf' #fname = './1ZoneUncontrolled.idf' if isinstance(dictfile, Idd): localidd = copy.deepcopy(dictfile) dt, dtls = localidd.dt, localidd.d...
replace the node here with the node from othereplus
def replacenode(self, othereplus, node): """replace the node here with the node from othereplus""" node = node.upper() self.dt[node.upper()] = othereplus.dt[node.upper()]
add the node here with the node from othereplus this will potentially have duplicates
def add2node(self, othereplus, node): """add the node here with the node from othereplus this will potentially have duplicates""" node = node.upper() self.dt[node.upper()] = self.dt[node.upper()] + \ othereplus.dt[node.upper()]
add an item to the node. example: add a new zone to the element ZONE
def addinnode(self, otherplus, node, objectname): """add an item to the node. example: add a new zone to the element 'ZONE' """ # do a test for unique object here newelement = otherplus.dt[node.upper()]
reflist is got from getobjectref in parse_idd. py getobjectref returns a dictionary. reflist is an item in the dictionary getrefs gathers all the fields refered by reflist
def getrefs(self, reflist): """ reflist is got from getobjectref in parse_idd.py getobjectref returns a dictionary. reflist is an item in the dictionary getrefs gathers all the fields refered by reflist """ alist = [] for element in reflist: if...
draw a graph without the nodes
def dropnodes(edges): """draw a graph without the nodes""" newedges = [] added = False for edge in edges: if bothnodes(edge): newtup = (edge[0][0], edge[1][0]) newedges.append(newtup) added = True elif firstisnode(edge): for edge1 in edges:...
gather the nodes from the edges
def edges2nodes(edges): """gather the nodes from the edges""" nodes = [] for e1, e2 in edges: nodes.append(e1) nodes.append(e2) nodedict = dict([(n, None) for n in nodes]) justnodes = list(nodedict.keys()) # justnodes.sort() justnodes = sorted(justnodes, key=lambda x: str(x[0...
make the diagram with the edges
def makediagram(edges): """make the diagram with the edges""" graph = pydot.Dot(graph_type='digraph') nodes = edges2nodes(edges) epnodes = [(node, makeanode(node[0])) for node in nodes if nodetype(node)=="epnode"] endnodes = [(node, makeendnode(node[0])) for node in nodes if nodety...
return the edges jointing the components of a branch
def makebranchcomponents(data, commdct, anode="epnode"): """return the edges jointing the components of a branch""" alledges = [] objkey = 'BRANCH' cnamefield = "Component %s Name" inletfield = "Component %s Inlet Node Name" outletfield = "Component %s Outlet Node Name" numobjects = len(da...
make the edges for the airloop and the plantloop
def makeairplantloop(data, commdct): """make the edges for the airloop and the plantloop""" anode = "epnode" endnode = "EndNode" # in plantloop get: # demand inlet, outlet, branchlist # supply inlet, outlet, branchlist plantloops = loops.plantloopfields(data, commdct) # splitter...
return the edges of the idf file fname
def getedges(fname, iddfile): """return the edges of the idf file fname""" data, commdct, _idd_index = readidf.readdatacommdct(fname, iddfile=iddfile) edges = makeairplantloop(data, commdct) return edges
input astr which is the Energy +. idd file as a string returns ( st1 st2 lss ) st1 = with all the ! comments striped st2 = strips all comments - both the ! and \\ lss = nested list of all the variables in Energy +. idd file
def get_nocom_vars(astr): """ input 'astr' which is the Energy+.idd file as a string returns (st1, st2, lss) st1 = with all the ! comments striped st2 = strips all comments - both the '!' and '\\' lss = nested list of all the variables in Energy+.idd file """ nocom = nocomment(astr, '!')...
remove the blank lines in astr
def removeblanklines(astr): """remove the blank lines in astr""" lines = astr.splitlines() lines = [line for line in lines if line.strip() != ""] return "\n".join(lines)
copied from extractidddata below. It deals with all the types of fnames
def _readfname(fname): """copied from extractidddata below. It deals with all the types of fnames""" try: if isinstance(fname, (file, StringIO)): astr = fname.read() else: astr = open(fname, 'rb').read() except NameError: if isinstance(fname, (FileIO, Str...
generate the iddindex
def make_idd_index(extract_func, fname, debug): """generate the iddindex""" astr = _readfname(fname) # fname is exhausted by the above read # reconstitute fname as a StringIO fname = StringIO(astr) # glist = iddgroups.iddtxt2grouplist(astr.decode('ISO-8859-2')) blocklst, commlst,...
insert group info into extracted idd
def embedgroupdata(extract_func, fname, debug): """insert group info into extracted idd""" astr = _readfname(fname) # fname is exhausted by the above read # reconstitute fname as a StringIO fname = StringIO(astr) try: astr = astr.decode('ISO-8859-2') except Exception as e:...
extracts all the needed information out of the idd file if debug is True it generates a series of text files. Each text file is incrementally different. You can do a diff see what the change is - this code is from 2004. it works. I am trying not to change it ( until I rewrite the whole thing ) to add functionality to i...
def extractidddata(fname, debug=False): """ extracts all the needed information out of the idd file if debug is True, it generates a series of text files. Each text file is incrementally different. You can do a diff see what the change is - this code is from 2004. it works. I am try...
makes a dictionary of object - lists each item in the dictionary points to a list of tuples the tuple is ( objectname fieldindex )
def getobjectref(blocklst, commdct): """ makes a dictionary of object-lists each item in the dictionary points to a list of tuples the tuple is (objectname, fieldindex) """ objlst_dct = {} for eli in commdct: for elj in eli: if 'object-list' in elj: objli...
read the idf file
def readdatacommlst(idfname): """read the idf file""" # iddfile = sys.path[0] + '/EplusCode/Energy+.idd' iddfile = 'Energy+.idd' # iddfile = './EPlusInterfaceFunctions/E1.idd' # TODO : can the path name be not hard coded iddtxt = open(iddfile, 'r').read() block, commlst, commdct = parse_idd.extr...
read the idf file
def readdatacommdct(idfname, iddfile='Energy+.idd', commdct=None): """read the idf file""" if not commdct: block, commlst, commdct, idd_index = parse_idd.extractidddata(iddfile) theidd = eplusdata.Idd(block, 2) else: theidd = iddfile data = eplusdata.Eplusdata(theidd, idfname) ...
get all the objects of objkey. fieldlists will have a fieldlist for each of those objects. return the contents of those fields
def extractfields(data, commdct, objkey, fieldlists): """get all the objects of objkey. fieldlists will have a fieldlist for each of those objects. return the contents of those fields""" # TODO : this assumes that the field list identical for # each instance of the object. This is not true. # So...
return the plantloopfield list
def plantloopfieldlists(data): """return the plantloopfield list""" objkey = 'plantloop'.upper() numobjects = len(data.dt[objkey]) return [[ 'Name', 'Plant Side Inlet Node Name', 'Plant Side Outlet Node Name', 'Plant Side Branch List Name', 'Demand Side Inlet Node...
get plantloop fields to diagram it
def plantloopfields(data, commdct): """get plantloop fields to diagram it""" fieldlists = plantloopfieldlists(data) objkey = 'plantloop'.upper() return extractfields(data, commdct, objkey, fieldlists)
get branches from the branchlist
def branchlist2branches(data, commdct, branchlist): """get branches from the branchlist""" objkey = 'BranchList'.upper() theobjects = data.dt[objkey] fieldlists = [] objnames = [obj[1] for obj in theobjects] for theobject in theobjects: fieldlists.append(list(range(2, len(theobject)))) ...
return the inlet and outlet of a branch
def branch_inlet_outlet(data, commdct, branchname): """return the inlet and outlet of a branch""" objkey = 'Branch'.upper() theobjects = data.dt[objkey] theobject = [obj for obj in theobjects if obj[1] == branchname] theobject = theobject[0] inletindex = 6 outletindex = len(theobject) - 2 ...
docstring for splittermixerfieldlists
def splittermixerfieldlists(data, commdct, objkey): """docstring for splittermixerfieldlists""" objkey = objkey.upper() objindex = data.dtls.index(objkey) objcomms = commdct[objindex] theobjects = data.dt[objkey] fieldlists = [] for theobject in theobjects: fieldlist = list(range(1, ...
get splitter fields to diagram it
def splitterfields(data, commdct): """get splitter fields to diagram it""" objkey = "Connector:Splitter".upper() fieldlists = splittermixerfieldlists(data, commdct, objkey) return extractfields(data, commdct, objkey, fieldlists)
get mixer fields to diagram it
def mixerfields(data, commdct): """get mixer fields to diagram it""" objkey = "Connector:Mixer".upper() fieldlists = splittermixerfieldlists(data, commdct, objkey) return extractfields(data, commdct, objkey, fieldlists)
return a list of repeating fields fld is in format Component %s Name so flds = [ fld % ( i ) for i in range ( n ) ] does not work for fields as indicated
def repeatingfields(theidd, commdct, objkey, flds): """return a list of repeating fields fld is in format 'Component %s Name' so flds = [fld % (i, ) for i in range(n)] does not work for 'fields as indicated' """ # TODO : make it work for 'fields as indicated' if type(flds) != list: flds ...
return the count of objects of key
def objectcount(data, key): """return the count of objects of key""" objkey = key.upper() return len(data.dt[objkey])
given objkey and fieldname return its index
def getfieldindex(data, commdct, objkey, fname): """given objkey and fieldname, return its index""" objindex = data.dtls.index(objkey) objcomm = commdct[objindex] for i_index, item in enumerate(objcomm): try: if item['field'] == [fname]: break except KeyError ...
docstring for fname
def getadistus(data, commdct): """docstring for fname""" objkey = "ZoneHVAC:AirDistributionUnit".upper() objindex = data.dtls.index(objkey) objcomm = commdct[objindex] adistutypefield = "Air Terminal Object Type" ifield = getfieldindex(data, commdct, objkey, adistutypefield) adistus = objcom...
make the dict adistu_inlets
def makeadistu_inlets(data, commdct): """make the dict adistu_inlets""" adistus = getadistus(data, commdct) # assume that the inlet node has the words "Air Inlet Node Name" airinletnode = "Air Inlet Node Name" adistu_inlets = {} for adistu in adistus: objkey = adistu.upper() obji...
get the version number from the E + install folder
def folder2ver(folder): """get the version number from the E+ install folder""" ver = folder.split('EnergyPlus')[-1] ver = ver[1:] splitapp = ver.split('-') ver = '.'.join(splitapp) return ver
just like the comment in python. removes any text after the phrase com
def nocomment(astr, com='!'): """ just like the comment in python. removes any text after the phrase 'com' """ alist = astr.splitlines() for i in range(len(alist)): element = alist[i] pnt = element.find(com) if pnt != -1: alist[i] = element[:pnt] return '\...
convert the idf text to a simple text
def idf2txt(txt): """convert the idf text to a simple text""" astr = nocomment(txt) objs = astr.split(';') objs = [obj.split(',') for obj in objs] objs = [[line.strip() for line in obj] for obj in objs] objs = [[_tofloat(line) for line in obj] for obj in objs] objs = [tuple(obj) for obj in o...
given the idd file or filehandle return the version handle
def iddversiontuple(afile): """given the idd file or filehandle, return the version handle""" def versiontuple(vers): """version tuple""" return tuple([int(num) for num in vers.split(".")]) try: fhandle = open(afile, 'rb') except TypeError: fhandle = afile line1 = fha...
make a bunch from the object
def makeabunch(commdct, obj, obj_i): """make a bunch from the object""" objidd = commdct[obj_i] objfields = [comm.get('field') for comm in commdct[obj_i]] objfields[0] = ['key'] objfields = [field[0] for field in objfields] obj_fields = [bunchhelpers.makefieldname(field) for field in objfields] ...
make bunches with data
def makebunches(data, commdct): """make bunches with data""" bunchdt = {} ddtt, dtls = data.dt, data.dtls for obj_i, key in enumerate(dtls): key = key.upper() bunchdt[key] = [] objs = ddtt[key] for obj in objs: bobj = makeabunch(commdct, obj, obj_i) ...
make bunches with data
def makebunches_alter(data, commdct, theidf): """make bunches with data""" bunchdt = {} dt, dtls = data.dt, data.dtls for obj_i, key in enumerate(dtls): key = key.upper() objs = dt[key] list1 = [] for obj in objs: bobj = makeabunch(commdct, obj, obj_i) ...
convert the float and interger fields
def convertfields_old(key_comm, obj, inblock=None): """convert the float and interger fields""" convinidd = ConvInIDD() typefunc = dict(integer=convinidd.integer, real=convinidd.real) types = [] for comm in key_comm: types.append(comm.get('type', [None])[0]) convs = [typefunc.get(typ, co...
convert field based on field info in IDD
def convertafield(field_comm, field_val, field_iddname): """convert field based on field info in IDD""" convinidd = ConvInIDD() field_typ = field_comm.get('type', [None])[0] conv = convinidd.conv_dict().get(field_typ, convinidd.no_type) return conv(field_val, field_iddname)
convert based on float integer and A1 N1
def convertfields(key_comm, obj, inblock=None): """convert based on float, integer, and A1, N1""" # f_ stands for field_ convinidd = ConvInIDD() if not inblock: inblock = ['does not start with N'] * len(obj) for i, (f_comm, f_val, f_iddname) in enumerate(zip(key_comm, obj, inblock)): ...
docstring for convertallfields
def convertallfields(data, commdct, block=None): """docstring for convertallfields""" # import pdbdb; pdb.set_trace() for key in list(data.dt.keys()): objs = data.dt[key] for i, obj in enumerate(objs): key_i = data.dtls.index(key) key_comm = commdct[key_i] ...
add functions to the objects
def addfunctions(dtls, bunchdt): """add functions to the objects""" snames = [ "BuildingSurface:Detailed", "Wall:Detailed", "RoofCeiling:Detailed", "Floor:Detailed", "FenestrationSurface:Detailed", "Shading:Site:Detailed", "Shading:Building:Detailed", ...
add functions to a new bunch/ munch object
def addfunctions2new(abunch, key): """add functions to a new bunch/munch object""" snames = [ "BuildingSurface:Detailed", "Wall:Detailed", "RoofCeiling:Detailed", "Floor:Detailed", "FenestrationSurface:Detailed", "Shading:Site:Detailed", "Shading:Building:...
read idf file and return bunches
def idfreader(fname, iddfile, conv=True): """read idf file and return bunches""" data, commdct, idd_index = readidf.readdatacommdct(fname, iddfile=iddfile) if conv: convertallfields(data, commdct) # fill gaps in idd ddtt, dtls = data.dt, data.dtls # skiplist = ["TABLE:MULTIVARIABLELOOKUP...
read idf file and return bunches
def idfreader1(fname, iddfile, theidf, conv=True, commdct=None, block=None): """read idf file and return bunches""" versiontuple = iddversiontuple(iddfile) # import pdb; pdb.set_trace() block, data, commdct, idd_index = readidf.readdatacommdct1( fname, iddfile=iddfile, commdct=co...
dictionary of conversion
def conv_dict(self): """dictionary of conversion""" return dict(integer=self.integer, real=self.real, no_type=self.no_type)
Find out if idjobject is mentioned an any object anywhere
def getanymentions(idf, anidfobject): """Find out if idjobject is mentioned an any object anywhere""" name = anidfobject.obj[1] foundobjs = [] keys = idfobjectkeys(idf) idfkeyobjects = [idf.idfobjects[key.upper()] for key in keys] for idfobjects in idfkeyobjects: for idfobject in idfobje...
field = object_name prev_field = object_type. Return the object
def getobject_use_prevfield(idf, idfobject, fieldname): """field=object_name, prev_field=object_type. Return the object""" if not fieldname.endswith("Name"): return None # test if prevfieldname ends with "Object_Type" fdnames = idfobject.fieldnames ifieldname = fdnames.index(fieldname) p...
return a list of keys of idfobjects that hve None Name fields
def getidfkeyswithnodes(): """return a list of keys of idfobjects that hve 'None Name' fields""" idf = IDF(StringIO("")) keys = idfobjectkeys(idf) keysfieldnames = ((key, idf.newidfobject(key.upper()).fieldnames) for key in keys) keysnodefdnames = ((key, (name for name in fdnames ...
return all objects that mention this node name
def getobjectswithnode(idf, nodekeys, nodename): """return all objects that mention this node name""" keys = nodekeys # TODO getidfkeyswithnodes needs to be done only once. take out of here listofidfobjects = (idf.idfobjects[key.upper()] for key in keys if idf.idfobjects[key.upper()]) ...
return the object if the Name or some other field is known. send filed in ** kwargs as Name = a name Roughness = smooth Returns the first find ( field search is unordered ) objkeys - > if objkeys = [ ZONE Material ] search only those groupnames - > not yet coded
def name2idfobject(idf, groupnamess=None, objkeys=None, **kwargs): """return the object, if the Name or some other field is known. send filed in **kwargs as Name='a name', Roughness='smooth' Returns the first find (field search is unordered) objkeys -> if objkeys=['ZONE', 'Material'], search only those ...
return a list of all idfobjects in idf
def getidfobjectlist(idf): """return a list of all idfobjects in idf""" idfobjects = idf.idfobjects # idfobjlst = [idfobjects[key] for key in idfobjects if idfobjects[key]] idfobjlst = [idfobjects[key] for key in idf.model.dtls if idfobjects[key]] # `for key in idf.model.dtls` maintains the or...
copy fromidf completely into toidf
def copyidfintoidf(toidf, fromidf): """copy fromidf completely into toidf""" idfobjlst = getidfobjectlist(fromidf) for idfobj in idfobjlst: toidf.copyidfobject(idfobj)
return the diffs between the two idfs
def idfdiffs(idf1, idf2): """return the diffs between the two idfs""" thediffs = {} keys = idf1.model.dtls # undocumented variable for akey in keys: idfobjs1 = idf1.idfobjects[akey] idfobjs2 = idf2.idfobjects[akey] names = set([getobjname(i) for i in idfobjs1] + ...
return autsizeable field names in idfobject
def autosize_fieldname(idfobject): """return autsizeable field names in idfobject""" # undocumented stuff in this code return [fname for (fname, dct) in zip(idfobject.objls, idfobject['objidd']) if 'autosizable' in dct]
wrapper for iddtxt2groups
def idd2group(fhandle): """wrapper for iddtxt2groups""" try: txt = fhandle.read() return iddtxt2groups(txt) except AttributeError as e: txt = open(fhandle, 'r').read() return iddtxt2groups(txt)
wrapper for iddtxt2grouplist
def idd2grouplist(fhandle): """wrapper for iddtxt2grouplist""" try: txt = fhandle.read() return iddtxt2grouplist(txt) except AttributeError as e: txt = open(fhandle, 'r').read() return iddtxt2grouplist(txt)
extract the groups from the idd file
def iddtxt2groups(txt): """extract the groups from the idd file""" try: txt = txt.decode('ISO-8859-2') except AttributeError as e: pass # for python 3 txt = nocomment(txt, '!') txt = txt.replace("\\group", "!-group") # retains group in next line txt = nocomment(txt, '\\') # remov...
return a list of group names the list in the same order as the idf objects in idd file
def iddtxt2grouplist(txt): """return a list of group names the list in the same order as the idf objects in idd file """ def makenone(astr): if astr == 'None': return None else: return astr txt = nocomment(txt, '!') txt = txt.replace("\\group", "!-group")...
add group info to commlst
def group2commlst(commlst, glist): """add group info to commlst""" for (gname, objname), commitem in zip(glist, commlst): newitem1 = "group %s" % (gname, ) newitem2 = "idfobj %s" % (objname, ) commitem[0].insert(0, newitem1) commitem[0].insert(1, newitem2) return commlst
add group info tocomdct
def group2commdct(commdct, glist): """add group info tocomdct""" for (gname, objname), commitem in zip(glist, commdct): commitem[0]['group'] = gname commitem[0]['idfobj'] = objname return commdct
extract embedded group data from commdct. return gdict - > { g1: [ obj1 obj2 obj3 ] g2: [ obj4.. ] }
def commdct2grouplist(gcommdct): """extract embedded group data from commdct. return gdict -> {g1:[obj1, obj2, obj3], g2:[obj4, ..]}""" gdict = {} for objidd in gcommdct: group = objidd[0]['group'] objname = objidd[0]['idfobj'] if group in gdict: gdict[group].append(o...
flatten and return a copy of the list indefficient on large lists
def flattencopy(lst): """flatten and return a copy of the list indefficient on large lists""" # modified from # http://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python thelist = copy.deepcopy(lst) list_is_nested = True while list_is_nested: # outer loop ...
make a pipe component generate inlet outlet names
def makepipecomponent(idf, pname): """make a pipe component generate inlet outlet names""" apipe = idf.newidfobject("Pipe:Adiabatic".upper(), Name=pname) apipe.Inlet_Node_Name = "%s_inlet" % (pname,) apipe.Outlet_Node_Name = "%s_outlet" % (pname,) return apipe
make a duct component generate inlet outlet names
def makeductcomponent(idf, dname): """make a duct component generate inlet outlet names""" aduct = idf.newidfobject("duct".upper(), Name=dname) aduct.Inlet_Node_Name = "%s_inlet" % (dname,) aduct.Outlet_Node_Name = "%s_outlet" % (dname,) return aduct
make a branch with a pipe use standard inlet outlet names
def makepipebranch(idf, bname): """make a branch with a pipe use standard inlet outlet names""" # make the pipe component first pname = "%s_pipe" % (bname,) apipe = makepipecomponent(idf, pname) # now make the branch with the pipe in it abranch = idf.newidfobject("BRANCH", Name=bname) ab...
make a branch with a duct use standard inlet outlet names
def makeductbranch(idf, bname): """make a branch with a duct use standard inlet outlet names""" # make the duct component first pname = "%s_duct" % (bname,) aduct = makeductcomponent(idf, pname) # now make the branch with the duct in it abranch = idf.newidfobject("BRANCH", Name=bname) ab...
get the components of the branch
def getbranchcomponents(idf, branch, utest=False): """get the components of the branch""" fobjtype = 'Component_%s_Object_Type' fobjname = 'Component_%s_Name' complist = [] for i in range(1, 100000): try: objtype = branch[fobjtype % (i,)] if objtype.strip() == '': ...
rename all the changed nodes
def renamenodes(idf, fieldtype): """rename all the changed nodes""" renameds = [] for key in idf.model.dtls: for idfobject in idf.idfobjects[key]: for fieldvalue in idfobject.obj: if type(fieldvalue) is list: if fieldvalue not in renameds: ...
get the filednames for the idfobject based on endswith
def getfieldnamesendswith(idfobject, endswith): """get the filednames for the idfobject based on endswith""" objls = idfobject.objls tmp = [name for name in objls if name.endswith(endswith)] if tmp == []: pass return [name for name in objls if name.endswith(endswith)]
return the field name of the node fluid is only needed if there are air and water nodes fluid is Air or Water or. if the fluid is Steam use Water
def getnodefieldname(idfobject, endswith, fluid=None, startswith=None): """return the field name of the node fluid is only needed if there are air and water nodes fluid is Air or Water or ''. if the fluid is Steam, use Water""" if startswith is None: startswith = '' if fluid is None: ...
rename nodes so that the components get connected fluid is only needed if there are air and water nodes fluid is Air or Water or. if the fluid is Steam use Water
def connectcomponents(idf, components, fluid=None): """rename nodes so that the components get connected fluid is only needed if there are air and water nodes fluid is Air or Water or ''. if the fluid is Steam, use Water""" if fluid is None: fluid = '' if len(components) == 1: th...
initialze values for all the inlet outlet nodes for the object. if force == False it willl init only if field =
def initinletoutlet(idf, idfobject, thisnode, force=False): """initialze values for all the inlet outlet nodes for the object. if force == False, it willl init only if field = '' """ def blankfield(fieldvalue): """test for blank field""" try: if fieldvalue.strip() == '': ...
insert a list of components into a branch fluid is only needed if there are air and water nodes in same object fluid is Air or Water or. if the fluid is Steam use Water
def componentsintobranch(idf, branch, listofcomponents, fluid=None): """insert a list of components into a branch fluid is only needed if there are air and water nodes in same object fluid is Air or Water or ''. if the fluid is Steam, use Water""" if fluid is None: fluid = '' componentli...
make an airloop
def makeairloop(idf, loopname, sloop, dloop, testing=None): """make an airloop""" # -------- testing --------- testn = 0 # -------- testing --------- newairloop = idf.newidfobject("AirLoopHVAC".upper(), Name=loopname) # -------- testing --------- testn = doingtesting(testing, testn, newairlo...
make plant loop with pip components
def makeplantloop(idf, loopname, sloop, dloop, testing=None): """make plant loop with pip components""" # -------- <testing --------- testn = 0 # -------- testing> --------- newplantloop = idf.newidfobject("PLANTLOOP", Name=loopname) # -------- <testing --------- testn = doingtesting(testing...
make condenser loop with pipe components
def makecondenserloop(idf, loopname, sloop, dloop, testing=None): """make condenser loop with pipe components""" # -------- <testing --------- testn = 0 # -------- testing> --------- newcondenserloop = idf.newidfobject("CondenserLoop".upper(), Name=loopname) # -------- <testing --------- tes...
force it to be a list of tuples
def _clean_listofcomponents(listofcomponents): """force it to be a list of tuples""" def totuple(item): """return a tuple""" if isinstance(item, (tuple, list)): return item else: return (item, None) return [totuple(item) for item in listofcomponents]
force 3 items in the tuple
def _clean_listofcomponents_tuples(listofcomponents_tuples): """force 3 items in the tuple""" def to3tuple(item): """return a 3 item tuple""" if len(item) == 3: return item else: return (item[0], item[1], None) return [to3tuple(item) for item in listofcomponen...
get idfobject or make it if it does not exist
def getmakeidfobject(idf, key, name): """get idfobject or make it if it does not exist""" idfobject = idf.getobject(key, name) if not idfobject: return idf.newidfobject(key, Name=name) else: return idfobject
do I even use this ?.... yup! I do
def replacebranch1(idf, loop, branchname, listofcomponents_tuples, fluid=None, debugsave=False): """do I even use this ? .... yup! I do""" if fluid is None: fluid = '' listofcomponents_tuples = _clean_listofcomponents_tuples(listofcomponents_tuples) branch = idf.getobject('BRA...
It will replace the components in the branch with components in listofcomponents
def replacebranch(idf, loop, branch, listofcomponents, fluid=None, debugsave=False, testing=None): """It will replace the components in the branch with components in listofcomponents""" if fluid is None: fluid = '' # -------- testing --------...
the main routine
def main(): """the main routine""" from six import StringIO import eppy.iddv7 as iddv7 IDF.setiddname(StringIO(iddv7.iddtxt)) idf1 = IDF(StringIO('')) loopname = "p_loop" sloop = ['sb0', ['sb1', 'sb2', 'sb3'], 'sb4'] dloop = ['db0', ['db1', 'db2', 'db3'], 'db4'] # makeplantloop(idf1,...
Area of a polygon poly
def area(poly): """Area of a polygon poly""" if len(poly) < 3: # not a plane - no area return 0 total = [0, 0, 0] num = len(poly) for i in range(num): vi1 = poly[i] vi2 = poly[(i+1) % num] prod = np.cross(vi1, vi2) total[0] += prod[0] total[1] += prod[...
unit normal vector of plane defined by points pt_a pt_b and pt_c
def unit_normal(pt_a, pt_b, pt_c): """unit normal vector of plane defined by points pt_a, pt_b, and pt_c""" x_val = np.linalg.det([[1, pt_a[1], pt_a[2]], [1, pt_b[1], pt_b[2]], [1, pt_c[1], pt_c[2]]]) y_val = np.linalg.det([[pt_a[0], 1, pt_a[2]], [pt_b[0], 1, pt_b[2]], [pt_c[0], 1, pt_c[2]]]) z_val = np...
Width of a polygon poly
def width(poly): """Width of a polygon poly""" num = len(poly) - 1 if abs(poly[num][2] - poly[0][2]) < abs(poly[1][2] - poly[0][2]): return dist(poly[num], poly[0]) elif abs(poly[num][2] - poly[0][2]) > abs(poly[1][2] - poly[0][2]): return dist(poly[1], poly[0]) else: return max(dist...
Height of a polygon poly
def height(poly): """Height of a polygon poly""" num = len(poly) - 1 if abs(poly[num][2] - poly[0][2]) > abs(poly[1][2] - poly[0][2]): return dist(poly[num], poly[0]) elif abs(poly[num][2] - poly[0][2]) < abs(poly[1][2] - poly[0][2]): return dist(poly[1], poly[0]) else: retur...
angle between two vectors
def angle2vecs(vec1, vec2): """angle between two vectors""" # vector a * vector b = |a|*|b|* cos(angle between vector a and vector b) dot = np.dot(vec1, vec2) vec1_modulus = np.sqrt(np.multiply(vec1, vec1).sum()) vec2_modulus = np.sqrt(np.multiply(vec2, vec2).sum()) if (vec1_modulus * vec2_modul...
Azimuth of a polygon poly
def azimuth(poly): """Azimuth of a polygon poly""" num = len(poly) - 1 vec = unit_normal(poly[0], poly[1], poly[num]) vec_azi = np.array([vec[0], vec[1], 0]) vec_n = np.array([0, 1, 0]) # update by Santosh # angle2vecs gives the smallest angle between the vectors # so for a west wall ang...
Tilt of a polygon poly
def tilt(poly): """Tilt of a polygon poly""" num = len(poly) - 1 vec = unit_normal(poly[0], poly[1], poly[num]) vec_alt = np.array([vec[0], vec[1], vec[2]]) vec_z = np.array([0, 0, 1]) # return (90 - angle2vecs(vec_alt, vec_z)) # update by Santosh return angle2vecs(vec_alt, vec_z)
get all the fields that have the key field
def getfields(comm): """get all the fields that have the key 'field' """ fields = [] for field in comm: if 'field' in field: fields.append(field) return fields
get the names of the repeating fields
def repeatingfieldsnames(fields): """get the names of the repeating fields""" fnames = [field['field'][0] for field in fields] fnames = [bunchhelpers.onlylegalchar(fname) for fname in fnames] fnames = [fname for fname in fnames if bunchhelpers.intinlist(fname.split())] fnames = [(bunchhelpers.replac...
put missing keys in commdct for standard objects return a list of keys where it is unable to do so commdct is not returned but is updated
def missingkeys_standard(commdct, dtls, skiplist=None): """put missing keys in commdct for standard objects return a list of keys where it is unable to do so commdct is not returned, but is updated""" if skiplist == None: skiplist = [] # find objects where all the fields are not named gk...