def getProperty(self, propID, time, objectID=0): """ Returns property identified by its ID evaluated at given time. :param PropertyID propID: property ID :param float time: Time when property should to be evaluated :param int objectID: Identifies object/submesh on which property is evaluated (optional, default 0) :return: Returns representation of requested property :rtype: Property """ key = (propID, objectID, time) if propID not in self.properties.index: raise APIError.APIError('Unknown property ID') if time not in self.properties.index: prop = interP.interpolateProperty(self.properties, time=time, propertyID=propID, objectID=objectID, method='linear') else: prop = self.properties[key] # Check pyro registering if applicaple if hasattr(self, '_pyroDaemon') and not hasattr(prop, '_PyroURI'): uri = self._pyroDaemon.register(prop) prop._PyroURI = uri return (prop)
def getField(self, fieldID, time): """ Returns the requested field at given time. Field is identified by fieldID. :param FieldID fieldID: Identifier of the field :param float time: Target time :return: Returns requested field. :rtype: Field """ key = (fieldID, time) field = 0 if fieldID not in self.fields.index: raise APIError.APIError('Unknown field ID') if time not in self.fields.index: field = interP.interpolateFields(self.fields, time, fieldID, method='linear') else: field = self.fields[key] # Check if object is registered to Pyro # if hasattr(self, '_pyroDaemon') and not hasattr(field, '_PyroURI'): # uri = self._pyroDaemon.register(field) # field._PyroURI = uri return(field)
def getProperty(self, propID, time, objectID=0): if (propID == PropertyID.PID_Demo_Value): return Property.ConstantProperty(self.count, PropertyID.PID_Demo_Value, ValueType.Scalar, PQ.getDimensionlessUnit()) else: raise APIError.APIError('Unknown property ID')
def computeCellVolumeOrArea(cell): ''' Computes the volume or area of given Cell. Volume is returned for 3d solids and area for surface cells e.g. Triangle. Parameters ---------- cell : mupif.Cell Cell to calculate the area or volume Returns ------- area or volume : double Area or volume of the cell. ''' vol = 0 if cell.getGeometryType() == CellGeometryType.CGT_TETRA: # Get vertices and create points as np.array verts = cell.getVertices() p0 = np.array(verts[0].getCoordinates()) p1 = np.array(verts[1].getCoordinates()) p2 = np.array(verts[2].getCoordinates()) p3 = np.array(verts[3].getCoordinates()) # Creat three polyhedron edge vectors a, b, and c a = p1 - p0 b = p2 - p0 c = p3 - p0 # Calculate volume vol = 1 / 6.0 * np.abs(np.dot(a, np.cross(b, c))) elif cell.getGeometryType() == CellGeometryType.CGT_TRIANGLE_1: # Get vertices and create points as np.array verts = cell.getVertices() p0 = np.array(verts[0].getCoordinates()) p1 = np.array(verts[1].getCoordinates()) p2 = np.array(verts[2].getCoordinates()) # Creat edge vectors a, b a = p1 - p0 b = p2 - p0 # Calculate volume vol = np.linalg.norm(np.cross(a, b)) / 2.0 else: raise APIError.APIError("Volume/Area calculation for %s\ not supported" % str(cell)) return (vol)
def checkRequiredFields(fields, fID=FieldID): """ Checks that all relevant fields for the simulation are present. """ # TODO: Check! found = True if fID.FID_Thermal_absorption_volume not in fields.index: print("Thermal_absorption_volume not found!") #found = False if not found: print("not all relevant fields found!") raise APIError.APIError("not all relevant fields found!")
def checkRequiredParameters(props, pID=PropertyID): """ Checks that all relevant parameters for the simulation are present. """ # TODO: Check! """ PropertyID.PID_RefractiveIndex = 22 PropertyID.PID_NumberOfRays = 23 PropertyID.PID_LEDSpectrum = 24 PropertyID.PID_ParticleNumberDensity = 25 PropertyID.PID_ParticleRefractiveIndex = 26 """ #print("Property keys:") # for key in props.index: # print(key) found = True if pID.PID_RefractiveIndex not in props.index: print("RefractiveIndex not found!") found = False if pID.PID_NumberOfRays not in props.index: print("NumberOfRays not found!") found = False if pID.PID_LEDSpectrum not in props.index: print("LEDSpectrum not found!") found = False if pID.PID_ParticleNumberDensity not in props.index: print("ParticleNumberDensity not found!") #found = False #if pID.PID_ParticleRefractiveIndex not in props.index: # print("ParticleRefractiveIndex not found!") # #found = False if pID.PID_InverseCumulativeDist not in props.index: print("InverseCumulativeDist not found!") #found = False if pID.PID_ScatteringCrossSections not in props.index: print("ScatteringCrossSections not found!") #found = False if found is False: print("not all relevant parameters found!") raise APIError.APIError("not all relevant properties found!")
def setProperty(self, property, objectID=0): propID = property.getPropertyID() if (propID == PropertyID.PID_Demo_Value): self.count = property else: raise APIError.APIError('Unknown property ID')
def _tracerProcessEnded(self, lines): # Check if process ended correctly # TODO! raise APIError (temporarily commented out for testing) if "########## Tracing done ################" in lines: logger.info("Tracing successful!") else: for line in lines: logger.debug(line) print(lines) logger.info("Tracing was not successful!") raise APIError.APIError("Tracing was not successful!") # Read absorption data (points, absorb) = vtkS.readAbsorptionData(self._absorptionFilePath) # print(points) # print(absorb) # Get field key = (FieldID.FID_Thermal_absorption_volume, self._curTStep) print(self.fields) f = self.fields[key] # Convert point data to field mesh if self._convertPointData: if meshS.FASTisAvailable(): meshS.convertPointDataToMeshFAST( pointdataVTKfile=self._absorptionFilePath, field=f, inplace=True) else: meshS.convertPointDataToMesh(points, absorb, f, inplace=True) # Read line data (if needed): (TODO: not tested) # (pts, wv, offs) = vtkS.readLineData("ray_paths.vtp") # Read photometric data from overall detector df = ft.loadDetectorData('AllDetector_1_LED.bin') data = dt.convertToSphere(df) # Set data to properties # Spectrum key = (PropertyID.PID_LEDSpectrum, objID.OBJ_LED, self._curTStep) p = self.properties[key] p.value['wavelengths'] = data['wavelengths'] p.value['intensities'] = data['intensities'] # Color x key = (PropertyID.PID_LEDColor_x, objID.OBJ_LED, self._curTStep) p = self.properties[key] p.value = data['color_x'] # Color y key = (PropertyID.PID_LEDColor_y, objID.OBJ_LED, self._curTStep) p = self.properties[key] p.value = data['color_y'] # CCT key = (PropertyID.PID_LEDCCT, objID.OBJ_LED, self._curTStep) p = self.properties[key] p.value = data['CCT'] # RadPower key = (PropertyID.PID_LEDRadiantPower, objID.OBJ_LED, self._curTStep) p = self.properties[key] p.value = data['radPower']
def _writeInputJSON(self, tstep): """ Writes input JSON for the raytracer. The fields and parameters should be accessible before calling this method. """ # update json based on the Properties: # print("Property keys:") for key in self.properties.index: # print(key) prop = self.properties[key] if (key[0] == PropertyID.PID_RefractiveIndex and key[2] == tstep and key[1] == objID.OBJ_CONE): print("PID_RefractiveIndex, ", prop.getValue()) parent = self._jsondata['materials'] parent[3]["refractiveIndex"] = prop.getValue() elif (key[0] == PropertyID.PID_NumberOfRays and key[2] == tstep): print("PID_NumberOfRays, ", prop.getValue()) parent = self._jsondata['sources'] for item in parent: item["rays"] = prop.getValue() elif (key[0] == PropertyID.PID_ChipSpectrum and key[2] == tstep): print("PID_ChipSpectrum, ", prop.getValue()) parent = self._jsondata['sources'] for item in parent: item["wavelengths"] = prop.getValue( )["wavelengths"].tolist() item["intensities"] = prop.getValue( )["intensities"].tolist() elif (key[0] == PropertyID.PID_ParticleNumberDensity and key[2] == tstep): print("PID_ParticleNumberDensity, ", prop.getValue()) parent = self._jsondata['materials'] if prop.getValueType() is ValueType.Scalar: parent[3]["particleDensities"] = [prop.getValue()] else: parent[3]["particleDensities"] = prop.getValue() elif (key[0] == PropertyID.PID_ScatteringCrossSections and key[2] == tstep): pass elif (key[0] == PropertyID.PID_InverseCumulativeDist and key[2] == tstep): pass # Datafiles: parent = self._jsondata['materials'] n_particle_key = (PropertyID.PID_NumberOfFluorescentParticles, objID.OBJ_CONE, tstep) n_particles = self.properties[n_particle_key] parent[3]['numberOfFluorescentParticles'] = n_particles.getValue() print("n_particles=", n_particles.getValue(), parent[3]['numberOfFluorescentParticles']) # Phosphor efficiences: if PropertyID.PID_PhosphorEfficiency in\ self.properties.index.get_level_values('propertyID'): effs = self.properties.xs( (PropertyID.PID_PhosphorEfficiency, tstep), level=('propertyID', 'tstep')) efflist = [] for i, row in effs.iteritems(): p = row.getValue() efflist.extend([p]) parent[3]["phosphorEfficiencies"] = efflist if len(efflist) != n_particles.getValue(): raise APIError.APIError("Number of phosphor efficiencies \ (%d) does not match with number of \ fluorescent particles (%d)" % (len(efflist), n_particles.getValue())) else: raise APIError.APIError( "Did not find phosphor efficiencies in Properties!") # Properties containing emission spectrums if PropertyID.PID_EmissionSpectrum in\ self.properties.index.get_level_values('propertyID'): em = self.properties.xs((PropertyID.PID_EmissionSpectrum, tstep), level=('propertyID', 'tstep')) em_fname = [] for i, row in em.iteritems(): p = row.getValue() fname = 'InvCumul_EM_%d.dat' % i gS.writeEmissionSpectrumFile(p["wavelengths"], p["intensities"], fname) em_fname.extend([fname]) parent[3]["cumulativeEmissionSpectrumFilenames"] = em_fname if len(em_fname) != n_particles.getValue(): raise APIError.APIError( "Number of em spectrum file names \ (%d) does not match with number of \ fluorescent particles (%d)" % (len(em_fname), n_particles.getValue())) else: raise APIError.APIError( "Did not find em spectrum file names in Properties!") # Excitation spectrum property if PropertyID.PID_ExcitationSpectrum in\ self.properties.index.get_level_values('propertyID'): ex = self.properties.xs((PropertyID.PID_ExcitationSpectrum, tstep), level=('propertyID', 'tstep')) ex_fname = [] for i, row in ex.iteritems(): p = row.getValue() fname = 'InvCumul_EX_%d.dat' % i gS.writeExAbsSpectrumFile(p["wavelengths"], p["intensities"], fname) ex_fname.extend([fname]) parent[3]["excitationSpectrumFilenames"] = ex_fname if len(ex_fname) != n_particles.getValue(): raise APIError.APIError( "Number of ex spectrum file names \ (%d) does not match with number of \ fluorescent particles (%d)" % (len(ex_fname), n_particles.getValue())) else: raise APIError.APIError( "Did not find ex spectrum file names in Properties!") # Absorption spectrum property if PropertyID.PID_AsorptionSpectrum in\ self.properties.index.get_level_values('propertyID'): aabs = self.properties.xs( (PropertyID.PID_AsorptionSpectrum, tstep), level=('propertyID', 'tstep')) aabs_fname = [] for i, row in aabs.iteritems(): p = row.getValue() fname = 'InvCumul_ABS_%d.dat' % i gS.writeExAbsSpectrumFile(p["wavelengths"], p["intensities"], fname) aabs_fname.extend([fname]) parent[3]["absorptionSpectrumFilenames"] = aabs_fname if len(aabs_fname) != n_particles.getValue(): raise APIError.APIError( "Number of abs spectrum \ file names (%d) does not match \ with number of fluorescent \ particles (%d)" % (len(aabs_fname), n_particles.getValue())) else: raise APIError.APIError( "Did not find abs spectrum file names in Properties!") # write the json file: f = open('input.json', 'w') f.write(json.dumps(self._jsondata)) f.close()