class TestTelescopeModel(unittest.TestCase): def setUp(self): self.label = 'test-telescope-model' self.telModel = TelescopeModel(site='North', telescopeModelName='LST-1', modelVersion='Current', label='test-telescope-model') def test_handling_parameters(self): logger.info('Old mirror_reflection_random_angle:{}'.format( self.telModel.getParameterValue('mirror_reflection_random_angle'))) logger.info('Changing mirror_reflection_random_angle') new_mrra = '0.0080 0 0' self.telModel.changeParameter('mirror_reflection_random_angle', new_mrra) self.assertEqual( self.telModel.getParameterValue('mirror_reflection_random_angle'), new_mrra) logging.info('Adding new_parameter') new_par = '23' self.telModel.addParameter('new_parameter', new_par) self.assertEqual(self.telModel.getParameterValue('new_parameter'), new_par) with self.assertRaises(InvalidParameter): self.telModel.getParameter('bla_bla') def test_flen_type(self): flenInfo = self.telModel.getParameter('focal_length') logger.info('Focal Length = {}, type = {}'.format( flenInfo['Value'], flenInfo['Type'])) self.assertIsInstance(flenInfo['Value'], float) def test_cfg_file(self): # Exporting self.telModel.exportConfigFile() logger.info('Config file: {}'.format(self.telModel.getConfigFile())) # Importing cfgFile = self.telModel.getConfigFile() tel = TelescopeModel.fromConfigFile(site='south', telescopeModelName='sst-d', label='test-sst', configFileName=cfgFile) tel.exportConfigFile()
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 ) # For debugging purposes telModel.exportConfigFile() logger.info('Validating the camera efficiency of {}'.format(telModel.name)) ce = CameraEfficiency(telescopeModel=telModel) ce.simulate(force=False) ce.analyze(force=True) # Plotting the camera efficiency for Cherenkov light plt = ce.plotCherenkovEfficiency() cherenkovPlotFileName = label + '_' + telModel.name + '_cherenkov' cherenkovPlotFile = outputDir.joinpath(cherenkovPlotFileName) for f in ['pdf', 'png']: plt.savefig(str(cherenkovPlotFile) + '.' + f, format=f, bbox_inches='tight') logger.info('Plotted cherenkov efficiency in {}'.format(cherenkovPlotFile)) plt.clf()