Exemple #1
0
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)

    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
        ray.analyze(force=True)