Esempio n. 1
0
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 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)
Esempio n. 3
0
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)
Esempio n. 4
0
    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()
Esempio n. 5
0
    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
            })
Esempio n. 6
0
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)
Esempio n. 7
0
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)
Esempio n. 8
0
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
Esempio n. 9
0
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
Esempio n. 10
0
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)
        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,
Esempio n. 12
0
                        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)
Esempio n. 13
0
 def setUp(self):
     self.label = 'test-telescope-model'
     self.telModel = TelescopeModel(site='North',
                                    telescopeModelName='LST-1',
                                    modelVersion='Current',
                                    label='test-telescope-model')
Esempio n. 14
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()
Esempio n. 15
0
        default='info',
        help='Log level to print (default is INFO)'
    )

    args = parser.parse_args()
    label = 'validate_camera_efficiency'

    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'
Esempio n. 16
0
    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)
Esempio n. 17
0
                        action='store',
                        default='info',
                        help='Log level to print (default is INFO)')

    args = parser.parse_args()
    label = 'validate_camera_fov'

    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)

    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))
        default='info',
        help='Log level to print (default is INFO)'
    )

    args = parser.parse_args()
    label = 'compare_cumulative_psf'

    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
    )

    # New parameters
    if args.pars is not None:
        with open(args.pars) as file:
            newPars = yaml.load(file, Loader=yaml.FullLoader)
        telModel.changeParameters(**newPars)

    ray = RayTracing.fromKwargs(
        telescopeModel=telModel,
        sourceDistance=args.src_distance * u.km,
        zenithAngle=args.zenith * u.deg,
        offAxisAngle=[0. * u.deg]
    )