def _loadMirrors(self): ''' Load the attribute mirrors by creating a Mirrors object iwth the mirror list file. ''' mirrorListFileName = self._parameters['mirror_list']['Value'] try: mirrorListFile = cfg.findFile(mirrorListFileName, self._configFileDirectory) except FileNotFoundError: mirrorListFile = cfg.findFile(mirrorListFileName, self._modelFilesLocations) self._logger.warning( 'MirrorListFile was not found in the config directory - ' 'Using the one found in the modelFilesLocations') self._mirrors = Mirrors(mirrorListFile)
def _loadCamera(self): ''' Loading camera attribute by creating a Camera object with the camera config file. ''' cameraConfigFile = self.getParameterValue('camera_config_file') focalLength = self.getParameterValue('effective_focal_length') if focalLength == 0.: self._logger.warning( 'Using focal_length because effective_focal_length is 0.') focalLength = self.getParameterValue('focal_length') try: cameraConfigFilePath = cfg.findFile(cameraConfigFile, self._configFileDirectory) except FileNotFoundError: self._logger.warning( 'CameraConfigFile was not found in the config directory - ' 'Using the one found in the modelFilesLocations') cameraConfigFilePath = cfg.findFile(cameraConfigFile, self._modelFilesLocations) self._camera = Camera(telescopeModelName=self.name, cameraConfigFile=cameraConfigFilePath, focalLength=focalLength)
def run(rnda, plot=False): ''' Runs the simulations for one given value of rnda ''' tel.changeParameter('mirror_reflection_random_angle', str(rnda)) ray = RayTracing.fromKwargs( telescopeModel=tel, singleMirrorMode=True, mirrorNumbers=list(range(1, 10)) if args.test else 'all', useRandomFocalLength=args.use_random_flen ) ray.simulate(test=False, force=True) # force has to be True, always ray.analyze(force=True) # Plotting D80 histograms if plot: plt.figure(figsize=(8, 6), tight_layout=True) ax = plt.gca() ax.set_xlabel(r'D$_{80}$ [cm]') bins = np.linspace(0.8, 3.5, 27) ray.plotHistogram( 'd80_cm', color='r', linestyle='-', alpha=0.5, facecolor='r', edgecolor='r', bins=bins, label='simulated' ) # Only plot measured D80 if the data is given if args.d80_list is not None: d80ListFile = cfg.findFile(args.d80_list) plotMeasuredDistribution( d80ListFile, color='b', linestyle='-', facecolor='None', edgecolor='b', bins=bins, label='measured' ) ax.legend(frameon=False) plotFileName = label + '_' + tel.name + '_' + 'D80-distributions' plotFile = outputDir.joinpath(plotFileName) plt.savefig(str(plotFile) + '.pdf', format='pdf', bbox_inches='tight') plt.savefig(str(plotFile) + '.png', format='png', bbox_inches='tight') return ray.getMean('d80_cm').to(u.cm).value, ray.getStdDev('d80_cm').to(u.cm).value
def isFile2D(self, par): ''' Check if the file referenced by par is a 2D table. Parameters ---------- par: str Name of the parameter. Returns ------- bool: True if the file is a 2D map type, False otherwise. ''' if not self.hasParameter(par): logging.error('Parameter {} does not exist'.format(par)) return False fileName = self.getParameterValue(par) file = cfg.findFile(fileName) with open(file, 'r') as f: is2D = '@RPOL@' in f.read() return is2D
label = 'derive_mirror_rnda' logger = logging.getLogger() logger.setLevel(gen.getLogLevelFromUser(args.logLevel)) # Output directory to save files related directly to this app outputDir = io.getApplicationOutputDirectory(cfg.get('outputLocation'), label) tel = TelescopeModel( site=args.site, telescopeModelName=args.telescope, modelVersion=args.model_version, label=label ) if args.mirror_list is not None: mirrorListFile = cfg.findFile(name=args.mirror_list) tel.changeParameter('mirror_list', args.mirror_list) tel.addParameterFile('mirror_list', mirrorListFile) if args.random_flen is not None: tel.changeParameter('random_focal_length', str(args.random_flen)) def run(rnda, plot=False): ''' Runs the simulations for one given value of rnda ''' tel.changeParameter('mirror_reflection_random_angle', str(rnda)) ray = RayTracing.fromKwargs( telescopeModel=tel, singleMirrorMode=True, mirrorNumbers=list(range(1, 10)) if args.test else 'all', useRandomFocalLength=args.use_random_flen ) ray.simulate(test=False, force=True) # force has to be True, always
def test_find_file(): f1 = cfg.findFile('mirror_MST_D80.dat') print(f1) f2 = cfg.findFile('parValues-LST.yml') print(f2)
# Output directory to save files related directly to this app outputDir = io.getApplicationOutputDirectory(cfg.get('outputLocation'), label) telModel = TelescopeModel(site=args.site, telescopeModelName=args.telescope, modelVersion=args.model_version, label=label) print('\nValidating the camera FoV of {}\n'.format(telModel.name)) cameraConfigFile = telModel.getParameterValue('camera_config_file') focalLength = float(telModel.getParameterValue('effective_focal_length')) camera = Camera(telescopeModelName=telModel.name, cameraConfigFile=cfg.findFile(cameraConfigFile), focalLength=focalLength) fov, rEdgeAvg = camera.calcFOV() print('\nEffective focal length = ' + '{0:.3f} cm'.format(focalLength)) print('{0} FoV = {1:.3f} deg'.format(telModel.name, fov)) print('Avg. edge radius = {0:.3f} cm\n'.format(rEdgeAvg)) # Now plot the camera as well plt = camera.plotPixelLayout() plotFileName = label + '_' + telModel.name + '_pixelLayout' plotFile = outputDir.joinpath(plotFileName) for f in ['pdf', 'png']: plt.savefig(str(plotFile) + '.' + f, format=f, bbox_inches='tight') print('\nPlotted camera in {}\n'.format(plotFile))
offAxisAngle=[0. * u.deg] ) ray.simulate(test=args.test, force=False) ray.analyze(force=False) # Plotting cumulative PSF im = ray.images()[0] print('d80 in cm = {}'.format(im.getPSF())) # Plotting cumulative PSF dataToPlot = OrderedDict() dataToPlot[r'sim$\_$telarray'] = im.getCumulativeData() if args.data is not None: dataFile = cfg.findFile(args.data) dataToPlot['measured'] = loadData(dataFile) plt = visualize.plot1D(dataToPlot) plt.gca().set_ylim(0, 1.05) plotFileName = label + '_' + telModel.name + '_cumulativePSF' plotFile = outputDir.joinpath(plotFileName) for f in ['pdf', 'png']: plt.savefig(str(plotFile) + '.' + f, format=f, bbox_inches='tight') plt.clf() # Plotting image dataToPlot = im.getImageData() visualize.plotHist2D(dataToPlot, bins=80) circle = plt.Circle((0, 0), im.getPSF(0.8) / 2, color='k', fill=False, lw=2, ls='--') plt.gca().add_artist(circle)