File indexing completed on 2025-01-30 09:14:59
0001
0002
0003
0004
0005
0006
0007
0008
0009 import json
0010 import sys
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 def getSurfaceMaterial(mat):
0021 outputmat = {}
0022 value = {}
0023 material = {}
0024 bound = {}
0025 outputmat["volume"] = mat["volume"]
0026 if "boundary" in mat:
0027 outputmat["boundary"] = mat["boundary"]
0028 if "layer" in mat:
0029 if "approach" not in entry:
0030 if "sensitive" not in entry:
0031 outputmat["layer"] = "X"
0032 if "approach" in mat:
0033 outputmat["approach"] = mat["approach"]
0034 if "sensitive" in mat:
0035 outputmat["layer"] = mat["layer"]
0036 outputmat["sensitive"] = "X"
0037 material["binUtility"] = mat["value"]["material"]["binUtility"]
0038 material["mapMaterial"] = False
0039 material["mappingType"] = mat["value"]["material"]["mappingType"]
0040 bound["type"] = mat["value"]["bounds"]["type"]
0041 value["material"] = material
0042 value["bounds"] = bound
0043 outputmat["value"] = value
0044 return outputmat
0045
0046
0047 if sys.version_info[0] < 3:
0048 print("Using Python 2")
0049 print("To obtain the proper ordering in the Json files Python 3 is recommended")
0050
0051 if len(sys.argv) < 2:
0052 inFileName = "geometry-map.json"
0053 else:
0054 inFileName = sys.argv[1]
0055
0056
0057 with open(inFileName, "r") as json_file:
0058 config = {}
0059 config["Surfaces"] = {}
0060 data = json.load(json_file)
0061 lastVol = -1
0062 for entry in data["Surfaces"]["entries"]:
0063 if lastVol != entry["volume"]:
0064 if lastVol != -1:
0065 config["Surfaces"][lastVol] = vconfig
0066 vconfig = []
0067 lastVol = entry["volume"]
0068 typeLayer = []
0069 createdApproach1 = False
0070 createdApproach2 = False
0071 typeSensitive = {}
0072
0073 if "type" not in entry["value"]["bounds"]:
0074 entry["value"]["bounds"]["type"] = ""
0075
0076 if "layer" in entry:
0077 if "approach" not in entry:
0078 if "sensitive" not in entry:
0079 if entry["value"]["bounds"]["type"] not in typeLayer:
0080 typeLayer.append(entry["value"]["bounds"]["type"])
0081 surface = getSurfaceMaterial(entry)
0082 vconfig.append(surface)
0083 continue
0084
0085 if "boundary" in entry:
0086 if "layer" not in entry:
0087 surface = getSurfaceMaterial(entry)
0088 vconfig.append(surface)
0089 continue
0090
0091 if "approach" in entry:
0092 if "sensitive" not in entry:
0093 if entry["approach"] == 1 and createdApproach1 == False:
0094 createdApproach1 = True
0095 surface = getSurfaceMaterial(entry)
0096 vconfig.append(surface)
0097 continue
0098 if entry["approach"] == 2 and createdApproach2 == False:
0099 createdApproach2 = True
0100 surface = getSurfaceMaterial(entry)
0101 vconfig.append(surface)
0102 continue
0103
0104 if "sensitive" in entry:
0105 if "approach" not in entry:
0106 if entry["value"]["material"]["binUtility"]["binningdata"] != None:
0107 if not entry["layer"] in typeSensitive:
0108 typeSensitive[entry["layer"]] = []
0109 if (
0110 entry["value"]["bounds"]["type"]
0111 not in typeSensitive[entry["layer"]]
0112 ):
0113 typeSensitive[entry["layer"]].append(
0114 entry["value"]["bounds"]["type"]
0115 )
0116 surface = getSurfaceMaterial(entry)
0117 vconfig.append(surface)
0118 continue
0119
0120 if lastVol != -1:
0121 config["Surfaces"][lastVol] = vconfig
0122 config["Volumes"] = data["Volumes"]
0123
0124 if len(sys.argv) < 3:
0125 outFileName = "config-map.json"
0126 else:
0127 outFileName = sys.argv[2]
0128
0129 with open(outFileName, "w") as outfile:
0130 json.dump(config, outfile, indent=4)