|
9 | 9 | import CoreFiles.DomesticHotWater as DomesticHotWater
|
10 | 10 | import CoreFiles.MUBES_pygeoj as MUBES_pygeoj
|
11 | 11 | import CoreFiles.BuildFMUs as BuildFMUs
|
| 12 | +import ReadResults.Utilities as Utilities |
12 | 13 | from openpyxl import load_workbook
|
13 | 14 | import openturns as ot
|
14 | 15 | import shutil
|
15 | 16 | import pickle
|
16 | 17 | import pyproj
|
17 | 18 | import numpy as np
|
| 19 | +import json |
18 | 20 |
|
19 | 21 | def appendBuildCase(StudiedCase,keypath,nbcase,DataBaseInput,MainPath,LogFile,PlotOnly = False, DebugMode = False):
|
20 | 22 | StudiedCase.addBuilding('Building'+str(nbcase),DataBaseInput,nbcase,MainPath,keypath,LogFile,PlotOnly, DebugMode)
|
@@ -68,21 +70,47 @@ def readPathfile(Pathways):
|
68 | 70 | keyPath[key] = os.path.normcase(line[line.find(':') + 1:-1])
|
69 | 71 | return keyPath
|
70 | 72 |
|
71 |
| -def ReadGeoJsonFile(keyPath,toBuildPool = False): |
| 73 | +def ReadGeoJsonFile(keyPath,CoordSys = '',toBuildPool = False): |
72 | 74 | #print('Reading Input files,...')
|
73 | 75 | try:
|
74 | 76 | BuildObjectDict = ReadGeojsonKeyNames(keyPath['GeojsonProperties'])
|
75 | 77 | Buildingsfile = MUBES_pygeoj.load(keyPath['Buildingsfile'])
|
76 |
| - #Shadingsfile = MUBES_pygeoj.load(keyPath['Shadingsfile']) |
77 |
| - if not toBuildPool: Buildingsfile = checkRefCoordinates(Buildingsfile) |
| 78 | + if not toBuildPool: Buildingsfile = checkRefCoordinates(Buildingsfile,CoordSys) |
| 79 | + Shadingsfile = getShadowingFile(keyPath['Buildingsfile'],CoordSys) |
78 | 80 | #if not toBuildPool: Shadingsfile = checkRefCoordinates(Shadingsfile)
|
79 |
| - return {'BuildObjDict':BuildObjectDict,'Build' :Buildingsfile}#, 'Shades': Shadingsfile} |
| 81 | + return {'BuildObjDict':BuildObjectDict,'Build' :Buildingsfile, 'Shades': Shadingsfile} |
80 | 82 | except:
|
81 | 83 | Buildingsfile = MUBES_pygeoj.load(keyPath['Buildingsfile'])
|
82 |
| - #Shadingsfile = MUBES_pygeoj.load(keyPath['Shadingsfile']) |
83 |
| - if not toBuildPool: Buildingsfile = checkRefCoordinates(Buildingsfile) |
| 84 | + if not toBuildPool: Buildingsfile = checkRefCoordinates(Buildingsfile,CoordSys) |
| 85 | + Shadingsfile = getShadowingFile(keyPath['Buildingsfile'],CoordSys) |
84 | 86 | #if not toBuildPool: Shadingsfile = checkRefCoordinates(Shadingsfile)
|
85 |
| - return {'Build': Buildingsfile}#, 'Shades': Shadingsfile} |
| 87 | + return {'Build': Buildingsfile, 'Shades': Shadingsfile} |
| 88 | + |
| 89 | +def getShadowingFile(BuildingFilePath,CoordSys): |
| 90 | + Shadingsfile = [] |
| 91 | + JSONFile = [] |
| 92 | + GeJsonFile = [] |
| 93 | + BuildingFileName = os.path.basename(BuildingFilePath) |
| 94 | + JSonTest = os.path.join(os.path.dirname(BuildingFilePath), |
| 95 | + BuildingFileName[:BuildingFileName.index('.')] + '_Walls.json') |
| 96 | + GeoJsonTest = os.path.join(os.path.dirname(BuildingFilePath), BuildingFileName.replace('Buildings', 'Walls')) |
| 97 | + GeoJsonTest1 = True if 'Walls' in GeoJsonTest else False |
| 98 | + if os.path.isfile(JSonTest): |
| 99 | + JSONFile = JSonTest |
| 100 | + elif os.path.isfile(GeoJsonTest) and GeoJsonTest1: |
| 101 | + GeJsonFile = GeoJsonTest |
| 102 | + else: |
| 103 | + msg = '[Prep. Info] No shadowing wall file found' |
| 104 | + if JSONFile: |
| 105 | + msg = '[Prep. Info] json shadowing walls file found' |
| 106 | + with open(JSONFile) as json_file: |
| 107 | + Shadingsfile = json.load(json_file) |
| 108 | + if GeJsonFile: |
| 109 | + msg = '[Prep. Info] Geojson shadowing walls file found' |
| 110 | + Shadingsfile = MUBES_pygeoj.load(GeJsonFile) |
| 111 | + Shadingsfile = checkRefCoordinates(Shadingsfile,CoordSys) |
| 112 | + print(msg) |
| 113 | + return Shadingsfile |
86 | 114 |
|
87 | 115 | def ListAvailableFiles(keyPath):
|
88 | 116 | # reading the pathfiles and the geojsonfile
|
@@ -112,30 +140,42 @@ def ReadGeoJsonDir(keyPath):
|
112 | 140 | BuildingFiles.append(file)
|
113 | 141 | return BuildingFiles
|
114 | 142 |
|
115 |
| -def checkRefCoordinates(GeojsonFile): |
| 143 | +def checkRefCoordinates(GeojsonFile,CoordSys): |
116 | 144 | if not GeojsonFile:
|
117 | 145 | return GeojsonFile
|
118 |
| - if 'EPSG' in GeojsonFile.crs['properties']['name']: |
119 |
| - return GeojsonFile |
120 |
| - ##The coordinate system depends on the input file, thus, if specific filter or conversion from one to another, |
121 |
| - # it should be done here |
122 |
| - if "CRS84" in GeojsonFile.crs['properties']['name']: |
123 |
| - print('Projecting coordinates of Input file,...') |
124 |
| - transformer = pyproj.Transformer.from_crs("CRS84", "epsg:3950") #this transformation if done for the France's reference |
125 |
| - for idx,obj in enumerate(GeojsonFile): |
126 |
| - newCoord = [] |
127 |
| - for poly in obj.geometry.coordinates: |
128 |
| - newpoly = [] |
129 |
| - for vertex in poly: |
130 |
| - newpoly.append(list(transformer.transform(vertex[0], vertex[1]))) |
131 |
| - newCoord.append(newpoly) |
132 |
| - obj.geometry.coordinates = newCoord |
133 |
| - return GeojsonFile |
| 146 | + # if 'EPSG' in GeojsonFile.crs['properties']['name']: |
| 147 | + # return GeojsonFile |
| 148 | + # ##The coordinate system depends on the input file, thus, if specific filter or conversion from one to another, |
| 149 | + # # it should be done here |
| 150 | + if type(CoordSys)==int: |
| 151 | + GeojsonFile = MakeCoordConversion(GeojsonFile, CoordSys) |
| 152 | + #GeojsonFile = MakeCoordConversion(GeojsonFile, CoordSys) |
134 | 153 | return GeojsonFile
|
135 | 154 |
|
| 155 | +def MakeCoordConversion(GeojsonFile,CoordSys): |
| 156 | + print('Projecting coordinates of Input file,...') |
| 157 | + transformer = pyproj.Transformer.from_crs("CRS84", "epsg:" + str( |
| 158 | + CoordSys)) # this transformation if done for the France's reference |
| 159 | + for idx, obj in enumerate(GeojsonFile): |
| 160 | + newCoord = [] |
| 161 | + for poly in obj.geometry.coordinates: |
| 162 | + newpoly = [] |
| 163 | + for vertex in poly: |
| 164 | + newvertex = list(transformer.transform(vertex[0], vertex[1])) |
| 165 | + newpoly.append( |
| 166 | + newvertex) # the reversed list and this signe were added after looking at google map and the plot for boston city |
| 167 | + newCoord.append(newpoly) |
| 168 | + obj.geometry.coordinates = newCoord |
| 169 | + obj.geometry.update_centroid() |
| 170 | + return GeojsonFile |
| 171 | + |
| 172 | + |
136 | 173 | def ComputeDistance(v1,v2):
|
137 | 174 | return ((v2[0]-v1[0])**2+(v2[1]-v1[1])**2)**0.5
|
138 | 175 |
|
| 176 | +def MakePolygonPlots(CaseChoices,Pool2Launch): |
| 177 | + Utilities.makePolyPlots(CaseChoices,Pool2Launch) |
| 178 | + |
139 | 179 | def MakeAbsoluteCoord(building,idf = [],roundfactor = 8):
|
140 | 180 | # we need to convert change the reference coordinate because precision is needed for boundary conditions definition:
|
141 | 181 | newfoot = []
|
@@ -388,7 +428,7 @@ def AppendLogFiles(MainPath,BldIDKey):
|
388 | 428 | os.remove(os.path.join(MainPath, file2del))
|
389 | 429 |
|
390 | 430 | #def setChangedParam(building,ParamVal,VarName2Change,MainPath,Buildingsfile,Shadingsfile,nbcase,LogFile=[]):
|
391 |
| -def setChangedParam(building, ParamVal, VarName2Change, MainPath, Buildingsfile, nbcase, LogFile=[]): |
| 431 | +def setChangedParam(building, ParamVal, VarName2Change, MainPath, DataBaseInput, nbcase, LogFile=[]): |
392 | 432 | #there is a loop file along the variable name to change and if specific ation are required it should be define here
|
393 | 433 | # if the variable to change are embedded into several layer of dictionnaries than there is a need to make checks and change accordingly to the correct element
|
394 | 434 | # here are examples for InternalMass impact using 'InternalMass' keyword in the VarName2Change list to play with the 'WeightperZoneArea' parameter
|
@@ -417,8 +457,6 @@ def setChangedParam(building, ParamVal, VarName2Change, MainPath, Buildingsfile,
|
417 | 457 | setattr(building, var, exttmass)
|
418 | 458 | elif 'MaxShadingDist' in var:
|
419 | 459 | building.MaxShadingDist = round(ParamVal[varnum], roundVal)
|
420 |
| - #building.shades = building.getshade(Buildingsfile[nbcase], Shadingsfile, Buildingsfile,LogFile,PlotOnly = False) |
421 |
| - building.shades = building.getshade(nbcase, Buildingsfile, LogFile,PlotOnly=False) |
422 | 460 | elif 'IntLoadCurveShape' in var:
|
423 | 461 | building.IntLoadCurveShape = max(round(ParamVal[varnum], roundVal),1e-6)
|
424 | 462 | building.IntLoad = building.getIntLoad(MainPath, LogFile)
|
@@ -545,8 +583,6 @@ def ManageGlobalPlots(BldObj,IdfObj,FigCenter,WindSize, PlotBldOnly,nbcase = [],
|
545 | 583 | adiabsurf.append(s.Name[:s.Name.index('_')])
|
546 | 584 | nbadiab += 1
|
547 | 585 | RoofSpecialColor = "firebrick"
|
548 |
| - if nbcase in [39]: |
549 |
| - RoofSpecialColor = 'limegreen' |
550 | 586 | IdfObj.view_model(test= True if PlotBldOnly+LastBld>0 else False, FigCenter=FigCentroid, WindSize=2 * WindSize,
|
551 | 587 | RoofSpecialColor=RoofSpecialColor)
|
552 | 588 | return FigCenter,WindSize
|
|
0 commit comments