def test_main(): tel = TelescopeModel(site='north', telescopeModelName='lst-1', modelVersion='p3', label='test_camera_eff') ce = CameraEfficiency(telescopeModel=tel) ce.simulate(force=True) ce.analyze(force=True) # Plotting Cherenkov plt.figure(figsize=(8, 6), tight_layout=True) ax = plt.gca() ax.set_xlabel('wl') ax.set_ylabel('eff') ce.plot('cherenkov') plotFileCherenkov = io.getTestPlotFile('camera_eff_cherenkov.pdf') plt.savefig(plotFileCherenkov) # Plotting NSB plt.figure(figsize=(8, 6), tight_layout=True) ax = plt.gca() ax.set_yscale('log') ax.set_xlabel('wl') ax.set_ylabel('eff') ce.plot('nsb') plotFileNSB = io.getTestPlotFile('camera_eff_nsb.pdf') plt.savefig(plotFileNSB)
def test_integral_curve(): version = 'prod4' label = 'lst_integral' configData = { 'sourceDistance': 10 * u.km, 'zenithAngle': 20 * u.deg, 'offAxisAngle': [0] * u.deg } tel = TelescopeModel(site='north', telescopeModelName='mst-FlashCam-D', modelVersion=version, label=label) ray = RayTracing(telescopeModel=tel, configData=configData) ray.simulate(test=True, force=True) ray.analyze(force=True) # Plotting cumulative curve for each image plt.figure(figsize=(8, 6), tight_layout=True) ax = plt.gca() ax.set_xlabel('radius [cm]') ax.set_ylabel('relative intensity') for im in ray.images(): im.plotCumulative(color='b') plotFile = io.getTestPlotFile('test_cumulative_psf.pdf') plt.savefig(plotFile)
def test_plot_image(): version = 'prod3' label = 'test-astri' configData = { 'sourceDistance': 10 * u.km, 'zenithAngle': 20 * u.deg, 'offAxisAngle': [0, 2.5, 5.0] * u.deg } tel = TelescopeModel(site='south', telescopeModelName='sst-D', modelVersion=version, label=label) ray = RayTracing(telescopeModel=tel, configData=configData) ray.simulate(test=True, force=True) ray.analyze(force=True) # Plotting images for ii, image in enumerate(ray.images()): plt.figure(figsize=(8, 6), tight_layout=True) ax = plt.gca() ax.set_xlabel('X [cm]') ax.set_ylabel('Y [cm]') image.plotImage(psf_color='b') plotFile = io.getTestPlotFile('test_plot_image_{}.pdf'.format(ii)) plt.savefig(plotFile)
def setUp(self): self.telescopeModel = TelescopeModel(site='north', telescopeModelName='lst-1', modelVersion='Current', label='test-simtel') self.simtelRunner = SimtelRunnerRayTracing( telescopeModel=self.telescopeModel, configData={ 'zenithAngle': 20 * u.deg, 'offAxisAngle': 2 * u.deg, 'sourceDistance': 12 * u.km })
def test_ssts(telescopeModelName): # Test with 3 SSTs version = 'prod3' configData = { 'sourceDistance': 10 * u.km, 'zenithAngle': 20 * u.deg, 'offAxisAngle': [0, 1.0, 2.0, 3.0, 4.0] * u.deg } tel = TelescopeModel(site='south', telescopeModelName=telescopeModelName, modelVersion=version, label='test-sst') ray = RayTracing(telescopeModel=tel, configData=configData) ray.simulate(test=True, force=True) ray.analyze(force=True)
def test_rx(): version = 'current' label = 'test-lst' configData = { 'sourceDistance': 10 * u.km, 'zenithAngle': 20 * u.deg, 'offAxisAngle': [0, 2.5, 5.0] * u.deg } tel = TelescopeModel(site='north', telescopeModelName='lst-1', modelVersion=version, label=label) ray = RayTracing(telescopeModel=tel, configData=configData) ray.simulate(test=True, force=True) ray_rx = copy(ray) ray.analyze(force=True) ray_rx.analyze(force=True, useRX=True) # Plotting d80 plt.figure(figsize=(8, 6), tight_layout=True) ax = plt.gca() ax.set_xlabel('off-axis') ax.set_ylabel('d80') ray.plot('d80_deg', marker='o', linestyle=':') ray_rx.plot('d80_deg', marker='s', linestyle='--') plotFilePSF = io.getTestPlotFile('d80_test_rx.pdf') plt.savefig(plotFilePSF) # Plotting effArea plt.figure(figsize=(8, 6), tight_layout=True) ax = plt.gca() ax.set_xlabel('off-axis') ax.set_ylabel('eff. area') ray.plot('eff_area', marker='o', linestyle=':') ray_rx.plot('d80_deg', marker='s', linestyle='--') plotFileArea = io.getTestPlotFile('effArea_test_rx.pdf') plt.savefig(plotFileArea)
def test_config_data(): label = 'test-config-data' version = 'prod4' configData = { 'sourceDistance': 10 * u.km, 'zenithAngle': 30 * u.deg, 'offAxisAngle': [0, 2] * u.deg } tel = TelescopeModel(site='north', telescopeModelName='mst-FlashCam-D', modelVersion=version, label=label) ray = RayTracing(telescopeModel=tel, configData=configData) assert ray.config.zenithAngle == 30 assert len(ray.config.offAxisAngle) == 2
def test_from_kwargs(): label = 'test-from-kwargs' version = 'prod4' sourceDistance = 10 * u.km zenithAngle = 30 * u.deg offAxisAngle = [0, 2] * u.deg tel = TelescopeModel(site='north', telescopeModelName='mst-FlashCam-D', modelVersion=version, label=label) ray = RayTracing.fromKwargs(telescopeModel=tel, sourceDistance=sourceDistance, zenithAngle=zenithAngle, offAxisAngle=offAxisAngle) assert ray.config.zenithAngle == 30 assert len(ray.config.offAxisAngle) == 2
def test_single_mirror(plot=False): # Test MST, single mirror PSF simulation version = 'prod3' configData = {'mirrorNumbers': list(range(1, 5)), 'singleMirrorMode': True} tel = TelescopeModel(site='north', telescopeModelName='mst-FlashCam-D', modelVersion=version, label='test-mst') ray = RayTracing(telescopeModel=tel, configData=configData) ray.simulate(test=True, force=True) ray.analyze(force=True) # Plotting d80 histogram plt.figure(figsize=(8, 6), tight_layout=True) ax = plt.gca() ax.set_xlabel('d80') ray.plotHistogram('d80_cm', color='r', bins=10) plotFile = io.getTestPlotFile('d80_hist_test.pdf') plt.savefig(plotFile)
def _buildArrayModel(self): ''' Build the site parameters and the list of telescope models, including reading the parameters from the DB. ''' # Getting site parameters from DB db = db_handler.DatabaseHandler() self._siteParameters = db.getSiteParameters(self.site, self.modelVersion, onlyApplicable=True) # Building telescope models self._telescopeModel = list() # List of telescope models _allTelescopeModelNames = list( ) # List of telescope names without repetition _allParsToChange = dict() for tel in self.layout: telSize = tel.getTelescopeSize() # Collecting telescope name and pars to change from arrayConfigData telModelName, parsToChange = self._getSingleTelescopeInfoFromArrayConfig( tel.name, telSize) if len(parsToChange) > 0: _allParsToChange[tel.name] = parsToChange self._logger.debug('TelModelName: {}'.format(telModelName)) # Building the basic models - no pars to change yet if telModelName not in _allTelescopeModelNames: # First time a telescope name is built _allTelescopeModelNames.append(telModelName) telModel = TelescopeModel( site=self.site, telescopeModelName=telModelName, modelVersion=self.modelVersion, label=self.label, modelFilesLocations=self._modelFilesLocations, filesLocation=self._filesLocation) else: # Telescope name already exists. # Finding the TelescopeModel and copying it. for tel in self._telescopeModel: if tel.name != telModelName: continue self._logger.debug( 'Copying tel model {} already loaded from DB'.format( tel.name)) telModel = copy(tel) break self._telescopeModel.append(telModel) # Checking whether the size of the telescope list and the layout match if len(self._telescopeModel) != len(self.layout): self._logger.warning( 'Number of telescopes in the list of telescope models does ' 'not match the number of telescopes in the LayoutArray - something is wrong!' ) # Changing parameters, if there are any in allParsToChange if len(_allParsToChange) > 0: for telData, telModel in zip(self.layout, self._telescopeModel): if telData.name not in _allParsToChange.keys(): continue self._logger.debug('Changing {} pars of a {}: {}, ...'.format( len(_allParsToChange[telData.name]), telData.name, *_allParsToChange[telData.name])) telModel.changeMultipleParameters( **_allParsToChange[telData.name]) telModel.setExtraLabel(telData.name)
default='info', help='Log level to print (default is INFO).' ) args = parser.parse_args() 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,
default='info', help='Log level to print (default is INFO)') args = parser.parse_args() label = 'validate_optics' 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) telModel = TelescopeModel(site=args.site, telescopeModelName=args.telescope, modelVersion=args.model_version, label=label, readFromDB=True) print('\nValidating telescope optics with ray tracing simulations' ' for {}\n'.format(telModel.name)) ray = RayTracing.fromKwargs( telescopeModel=telModel, sourceDistance=args.src_distance * u.km, zenithAngle=args.zenith * u.deg, offAxisAngle=np.linspace(0, args.max_offset, int(args.max_offset / 0.25) + 1) * u.deg) ray.simulate(test=args.test, force=False) ray.analyze(force=True)
def setUp(self): self.label = 'test-telescope-model' self.telModel = TelescopeModel(site='North', telescopeModelName='LST-1', modelVersion='Current', label='test-telescope-model')