def __init__(self,
                 telescopeModel,
                 label=None,
                 simtelSourcePath=None,
                 filesLocation=None,
                 configData=None,
                 configFile=None,
                 singleMirrorMode=False):
        '''
        SimtelRunner.

        Parameters
        ----------
        telescopeModel: str
            Instance of TelescopeModel class.
        label: str, optional
            Instance label. Important for output file naming.
        simtelSourcePath: str (or Path), optional
            Location of sim_telarray installation. If not given, it will be taken from the
            config.yml file.
        filesLocation: str (or Path), optional
            Parent location of the output files created by this class. If not given, it will be
            taken from the config.yml file.
        configData: dict.
            Dict containing the configurable parameters.
        configFile: str or Path
            Path of the yaml file containing the configurable parameters.
        singleMirrorMode: bool
            True for single mirror simulations.
        '''
        self._logger = logging.getLogger(__name__)
        self._logger.debug('Init SimtelRunnerRayTracing')

        super().__init__(label=label,
                         simtelSourcePath=simtelSourcePath,
                         filesLocation=filesLocation)

        self.telescopeModel = self._validateTelescopeModel(telescopeModel)
        self.label = label if label is not None else self.telescopeModel.label

        # File location
        self._baseDirectory = io.getOutputDirectory(self._filesLocation,
                                                    self.label, 'ray-tracing')
        self._baseDirectory.mkdir(parents=True, exist_ok=True)

        self._singleMirrorMode = singleMirrorMode

        # RayTracing - default parameters
        self._repNumber = 0
        self.RUNS_PER_SET = 1 if self._singleMirrorMode else 20
        self.PHOTONS_PER_RUN = 10000

        # Loading configData
        _configDataIn = gen.collectDataFromYamlOrDict(configFile, configData)
        _parameterFile = io.getDataFile(
            'parameters', 'simtel-runner-ray-tracing_parameters.yml')
        _parameters = gen.collectDataFromYamlOrDict(_parameterFile, None)
        self.config = gen.validateConfigData(_configDataIn, _parameters)

        self._loadRequiredFiles()
Esempio n. 2
0
    def __init__(self,
                 label=None,
                 name=None,
                 filesLocation=None,
                 configData=None,
                 configFile=None):
        '''
        LayoutArray init.

        Parameters
        ----------
        name: str
            Name of the telescope (e.g L-01, S-05, ...)
        label: str
            Instance label.
        filesLocation: str (or Path), optional
            Parent location of the output files created by this class. If not given, it will be
            taken from the config.yml file.
        configData: dict.
            Dict containing the configurable parameters.
        configFile: str or Path
            Path of the yaml file containing the configurable parameters.
        '''
        self._logger = logging.getLogger(__name__)
        self._logger.debug('Init LayoutArray')

        self.label = label

        self.name = name
        self._telescopeList = []

        # Loading configData
        _configDataIn = gen.collectDataFromYamlOrDict(configFile,
                                                      configData,
                                                      allowEmpty=True)
        _parameterFile = io.getDataFile('parameters',
                                        'layout-array_parameters.yml')
        _parameters = gen.collectDataFromYamlOrDict(_parameterFile, None)
        self.config = gen.validateConfigData(_configDataIn, _parameters)

        # Making config entries into attributes
        for par, value in zip(self.config._fields, self.config):
            self.__dict__['_' + par] = value

        self._loadArrayCenter()

        # Output directory
        self._filesLocation = cfg.getConfigArg('outputLocation', filesLocation)
        self._outputDirectory = io.getLayoutOutputDirectory(
            self._filesLocation, self.label)
        self._outputDirectory.mkdir(parents=True, exist_ok=True)
    def __init__(self,
                 telescopeModel,
                 label=None,
                 simtelSourcePath=None,
                 filesLocation=None,
                 configData=None,
                 configFile=None):
        '''
        CameraEfficiency init.

        Parameters
        ----------
        telescopeModel: TelescopeModel
            Instance of the TelescopeModel class.
        label: str
            Instance label, optional.
        simtelSourcePath: str (or Path), optional.
            Location of sim_telarray installation. If not given, it will be taken from the
            config.yml file.
        filesLocation: str (or Path), optional.
            Parent location of the output files created by this class. If not given, it will be
            taken from the config.yml file.
        configData: dict.
            Dict containing the configurable parameters.
        configFile: str or Path
            Path of the yaml file containing the configurable parameters.
        '''
        self._logger = logging.getLogger(__name__)

        self._simtelSourcePath = Path(
            cfg.getConfigArg('simtelPath', simtelSourcePath))
        self._filesLocation = cfg.getConfigArg('outputLocation', filesLocation)
        self._telescopeModel = self._validateTelescopeModel(telescopeModel)
        self.label = label if label is not None else self._telescopeModel.label

        self._baseDirectory = io.getCameraEfficiencyOutputDirectory(
            self._filesLocation, self.label)
        self._baseDirectory.mkdir(parents=True, exist_ok=True)

        self._hasResults = False

        _configDataIn = gen.collectDataFromYamlOrDict(configFile,
                                                      configData,
                                                      allowEmpty=True)
        _parameterFile = io.getDataFile('parameters',
                                        'camera-efficiency_parameters.yml')
        _parameters = gen.collectDataFromYamlOrDict(_parameterFile, None)
        self.config = gen.validateConfigData(_configDataIn, _parameters)

        self._loadFiles()
Esempio n. 4
0
def test_collect_dict_data():
    inDict = {'k1': 2, 'k2': 'bla'}
    inYaml = io.getTestDataFile('test_collect_dict_data.yml')

    d1 = gen.collectDataFromYamlOrDict(None, inDict)
    assert 'k2' in d1.keys()
    assert d1['k1'] == 2

    d2 = gen.collectDataFromYamlOrDict(inYaml, None)
    assert 'k3' in d2.keys()
    assert d2['k4'] == ['bla', 2]

    d3 = gen.collectDataFromYamlOrDict(inYaml, inDict)
    assert d3 == d2
Esempio n. 5
0
    def __init__(self,
                 arrayModel,
                 label=None,
                 simtelSourcePath=None,
                 filesLocation=None,
                 configData=None,
                 configFile=None):
        '''
        SimtelRunnerArray.

        Parameters
        ----------
        arrayModel: str
            Instance of TelescopeModel class.
        label: str, optional
            Instance label. Important for output file naming.
        simtelSourcePath: str (or Path), optional
            Location of sim_telarray installation. If not given, it will be taken from the
            config.yml file.
        filesLocation: str (or Path), optional
            Parent location of the output files created by this class. If not given, it will be
            taken from the config.yml file.
        configData: dict.
            Dict containing the configurable parameters.
        configFile: str or Path
            Path of the yaml file containing the configurable parameters.
        '''
        self._logger = logging.getLogger(__name__)
        self._logger.debug('Init SimtelRunnerArray')

        super().__init__(label=label,
                         simtelSourcePath=simtelSourcePath,
                         filesLocation=filesLocation)

        self.arrayModel = self._validateArrayModel(arrayModel)
        self.label = label if label is not None else self.arrayModel.label

        # File location
        self._baseDirectory = io.getOutputDirectory(self._filesLocation,
                                                    self.label, 'array')
        self._baseDirectory.mkdir(parents=True, exist_ok=True)

        # Loading configData
        _configDataIn = gen.collectDataFromYamlOrDict(configFile, configData)
        _parameterFile = io.getDataFile('parameters',
                                        'simtel-runner-array_parameters.yml')
        _parameters = gen.collectDataFromYamlOrDict(_parameterFile, None)
        self.config = gen.validateConfigData(_configDataIn, _parameters)

        self._loadSimtelDataDirectories()
Esempio n. 6
0
def test_validate_config_data():

    parameterFile = io.getTestDataFile('test_parameters.yml')
    parameters = gen.collectDataFromYamlOrDict(parameterFile, None)

    configData = {
        'zenith': 0 * u.deg,
        'offaxis': [0 * u.deg, 0.2 * u.rad, 3 * u.deg],
        'cscat': [0, 10 * u.m, 3 * u.km],
        'sourceDistance': 20000 * u.m,
        'testName': 10,
        'dictPar': {
            'blah': 10,
            'bleh': 5 * u.m
        }
    }

    validatedData = gen.validateConfigData(configData=configData,
                                           parameters=parameters)

    # Testing undefined len
    assert len(validatedData.offAxisAngle) == 3

    # Testing name validation
    assert validatedData.validatedName == 10

    # Testing unit convertion
    assert validatedData.sourceDistance == 20

    # Testing dict par
    assert validatedData.dictPar['bleh'] == 500
Esempio n. 7
0
    def __init__(
        self,
        site,
        layoutName,
        label=None,
        keepSeeds=False,
        filesLocation=None,
        simtelSourcePath=None,
        corsikaParametersFile=None,
        corsikaConfigData=None,
        corsikaConfigFile=None
    ):
        '''
        CorsikaRunner init.

        Parameters
        ----------
        site: str
            South or North.
        layoutName: str
            Name of the layout.
        label: str
            Instance label.
        keepSeeds: bool
            If True, seeds generated by CorsikaConfig, based on the \
            run number and the primary particle will be used. \
            If False, random seeds will be defined automatically by sim_telarray.
        filesLocation: str or Path.
            Location of the output files. If not given, it will be set from \
            the config.yml file.
        simtelSourcePath: str or Path
            Location of source of the sim_telarray/CORSIKA package.
        corsikaConfigData: dict
            Dict with CORSIKA config data.
        corsikaConfigFile: str or Path
            Path to yaml file containing CORSIKA config data.
        corsikaParametersFile: str or Path
            Path to yaml file containing CORSIKA parameters.
        '''

        self._logger = logging.getLogger(__name__)
        self._logger.debug('Init CorsikaRunner')

        self.label = label
        self.site = names.validateSiteName(site)
        self.layoutName = names.validateLayoutArrayName(layoutName)

        self._keepSeeds = keepSeeds

        self._simtelSourcePath = Path(cfg.getConfigArg('simtelPath', simtelSourcePath))
        self._filesLocation = cfg.getConfigArg('outputLocation', filesLocation)
        self._outputDirectory = io.getCorsikaOutputDirectory(self._filesLocation, self.label)
        self._outputDirectory.mkdir(parents=True, exist_ok=True)
        self._logger.debug('Creating output dir {}, if needed,'.format(self._outputDirectory))

        corsikaConfigData = collectDataFromYamlOrDict(corsikaConfigFile, corsikaConfigData)
        self._loadCorsikaConfigData(corsikaConfigData)

        self._loadCorsikaDataDirectories()
Esempio n. 8
0
    def _loadArrayConfigData(self, configData):
        ''' Load configData, create arrayModel and store reamnining parameters in config. '''
        _arrayModelConfig, _restConfig = self._collectArrayModelParameters(
            configData)

        _parameterFile = io.getDataFile('parameters',
                                        'array-simulator_parameters.yml')
        _parameters = gen.collectDataFromYamlOrDict(_parameterFile, None)
        self.config = gen.validateConfigData(_restConfig, _parameters)

        self.arrayModel = ArrayModel(label=self.label,
                                     arrayConfigData=_arrayModelConfig)
Esempio n. 9
0
    def __init__(self,
                 site,
                 layoutName,
                 label=None,
                 filesLocation=None,
                 corsikaConfigData=None,
                 corsikaConfigFile=None,
                 corsikaParametersFile=None):
        '''
        CorsikaConfig init.

        Parameters
        ----------
        site: str
            South or North.
        layoutName: str
            Name of the layout.
        layout: LayoutArray
            Instance of LayoutArray.
        label: str
            Instance label.
        filesLocation: str or Path.
            Main location of the output files.
        corsikaConfigData: dict
            Dict with CORSIKA config data.
        corsikaConfigFile: str or Path
            Path to yaml file containing CORSIKA config data.
        corsikaParametersFile: str or Path
            Path to yaml file containing CORSIKA parameters.
        '''

        self._logger = logging.getLogger(__name__)
        self._logger.debug('Init CorsikaConfig')

        self.label = label
        self.site = names.validateSiteName(site)

        self._filesLocation = cfg.getConfigArg('outputLocation', filesLocation)

        # Grabbing layout name and building LayoutArray
        self.layoutName = names.validateLayoutArrayName(layoutName)
        self.layout = LayoutArray.fromLayoutArrayName(self.site + '-' +
                                                      self.layoutName,
                                                      label=self.label)

        # Load parameters
        self._loadCorsikaParametersFile(corsikaParametersFile)

        corsikaConfigData = collectDataFromYamlOrDict(corsikaConfigFile,
                                                      corsikaConfigData)
        self.setUserParameters(corsikaConfigData)
        self._isFileUpdated = False
Esempio n. 10
0
    def __init__(self,
                 name=None,
                 prodId=dict(),
                 configData=None,
                 configFile=None):
        '''
        TelescopeData init.

        Parameters
        ----------
        name: str
            Name of the telescope (e.g L-01, S-05, ...)
        prodId: dict
            ...
        configData: dict.
            Dict containing the configurable parameters.
        configFile: str or Path
            Path of the yaml file containing the configurable parameters.
        '''

        self._logger = logging.getLogger(__name__)
        self._logger.debug('Init TelescopeData')

        self.name = name
        self._prodId = prodId

        # Loading configData
        _configDataIn = gen.collectDataFromYamlOrDict(configFile,
                                                      configData,
                                                      allowEmpty=True)
        _parameterFile = io.getDataFile('parameters',
                                        'telescope-data_parameters.yml')
        _parameters = gen.collectDataFromYamlOrDict(_parameterFile, None)
        self.config = gen.validateConfigData(_configDataIn, _parameters)

        # Making config entries into attributes
        for par, value in zip(self.config._fields, self.config):
            self.__dict__['_' + par] = value
Esempio n. 11
0
    def __init__(self,
                 label=None,
                 arrayConfigFile=None,
                 arrayConfigData=None,
                 modelFilesLocations=None,
                 filesLocation=None):
        '''
        ArrayModel.

        Parameters
        ----------
        arrayConfigFile: str
            Path to a yaml file with the array config data.
        arrayConfigData: dict
            Dict with the array config data.
        label: str, optional
            Instance label. Important for output file naming.
        modelFilesLocation: str (or Path), optional
            Location of the MC model files. If not given, it will be taken from the
            config.yml file.
        filesLocation: str (or Path), optional
            Parent location of the output files created by this class. If not given, it will be
            taken from the config.yml file.
        '''
        self._logger = logging.getLogger(__name__)
        self._logger.debug('Init ArrayModel')

        self.label = label
        self.site = None
        self.layout = None
        self.layoutName = None
        self.modelVersion = None

        self._modelFilesLocations = cfg.getConfigArg('modelFilesLocations',
                                                     modelFilesLocations)
        self._filesLocation = cfg.getConfigArg('outputLocation', filesLocation)

        arrayConfigData = collectDataFromYamlOrDict(arrayConfigFile,
                                                    arrayConfigData)
        self._loadArrayData(arrayConfigData)

        self._setConfigFileDirectory()

        self._buildArrayModel()
Esempio n. 12
0
    def __init__(self,
                 label=None,
                 filesLocation=None,
                 simtelSourcePath=None,
                 configData=None,
                 configFile=None):
        '''
        ArraySimulator init.

        Parameters
        ----------
        label: str
            Instance label.
        filesLocation: str or Path.
            Location of the output files. If not given, it will be set from \
            the config.yml file.
        simtelSourcePath: str or Path
            Location of source of the sim_telarray/CORSIKA package.
        configData: dict
            Dict with configurable data.
        configFile: str or Path
            Path to yaml file containing configurable data.
        '''
        self._logger = logging.getLogger(__name__)
        self._logger.debug('Init ArraySimulator')

        self.label = label

        self._simtelSourcePath = Path(
            cfg.getConfigArg('simtelPath', simtelSourcePath))
        self._filesLocation = cfg.getConfigArg('outputLocation', filesLocation)

        configData = gen.collectDataFromYamlOrDict(configFile, configData)
        self._loadArrayConfigData(configData)
        self._setSimtelRunner()

        # Storing list of files
        self._results = dict()
        self._results['output'] = list()
        self._results['input'] = list()
        self._results['log'] = list()
Esempio n. 13
0
    def __init__(
        self,
        label=None,
        filesLocation=None,
        simtelSourcePath=None,
        showerConfigData=None,
        showerConfigFile=None
    ):
        '''
        ShowerSimulator init.

        Parameters
        ----------
        label: str
            Instance label.
        filesLocation: str or Path.
            Location of the output files. If not given, it will be set from \
            the config.yml file.
        simtelSourcePath: str or Path
            Location of source of the sim_telarray/CORSIKA package.
        showerConfigData: dict
            Dict with shower config data.
        showerConfigFile: str or Path
            Path to yaml file containing shower config data.
        '''
        self._logger = logging.getLogger(__name__)
        self._logger.debug('Init CorsikaRunner')

        self.label = label

        self._simtelSourcePath = Path(cfg.getConfigArg('simtelPath', simtelSourcePath))
        self._filesLocation = cfg.getConfigArg('outputLocation', filesLocation)
        self._outputDirectory = io.getCorsikaOutputDirectory(self._filesLocation, self.label)
        self._outputDirectory.mkdir(parents=True, exist_ok=True)
        self._logger.debug(
            'Output directory {} - creating it, if needed.'.format(self._outputDirectory)
        )

        showerConfigData = collectDataFromYamlOrDict(showerConfigFile, showerConfigData)
        self._loadShowerConfigData(showerConfigData)
        self._setCorsikaRunner()
Esempio n. 14
0
    def __init__(self,
                 telescopeModel,
                 label=None,
                 simtelSourcePath=None,
                 filesLocation=None,
                 configData=None,
                 configFile=None):
        '''
        RayTracing init.

        Parameters
        ----------
        telescopeModel: TelescopeModel
            Instance of the TelescopeModel class.
        label: str
            Instance label.
        simtelSourcePath: str (or Path), optional
            Location of sim_telarray installation. If not given, it will be taken from the
            config.yml file.
        filesLocation: str (or Path), optional
            Parent location of the output files created by this class. If not given, it will be
            taken from the config.yml file.
        configData: dict.
            Dict containing the configurable parameters.
        configFile: str or Path
            Path of the yaml file containing the configurable parameters.
        '''
        self._logger = logging.getLogger(__name__)

        self._simtelSourcePath = Path(
            cfg.getConfigArg('simtelPath', simtelSourcePath))
        self._filesLocation = cfg.getConfigArg('outputLocation', filesLocation)

        self._telescopeModel = self._validateTelescopeModel(telescopeModel)

        # Loading configData
        _configDataIn = gen.collectDataFromYamlOrDict(configFile, configData)
        _parameterFile = io.getDataFile('parameters',
                                        'ray-tracing_parameters.yml')
        _parameters = gen.collectDataFromYamlOrDict(_parameterFile, None)
        self.config = gen.validateConfigData(_configDataIn, _parameters)

        self.label = label if label is not None else self._telescopeModel.label

        self._outputDirectory = io.getRayTracingOutputDirectory(
            self._filesLocation, self.label)
        self._outputDirectory.mkdir(parents=True, exist_ok=True)

        # Loading relevant attributes in case of single mirror mode.
        if self.config.singleMirrorMode:
            # Recalculating source distance.
            self._logger.debug(
                'Single mirror mode is activate - source distance is being recalculated to 2 * flen'
            )
            mirFlen = self._telescopeModel.getParameterValue(
                'mirror_focal_length')
            self._sourceDistance = 2 * float(mirFlen) * u.cm.to(u.km)  # km

            # Setting mirror numbers.
            if self.config.mirrorNumbers is None:
                self._mirrorNumbers = list(
                    range(0, self._telescopeModel.mirrors.numberOfMirrors))
            else:
                self._mirrorNumbers = self.config.mirrorNumbers
        else:
            self._sourceDistance = self.config.sourceDistance

        self._hasResults = False

        # Results file
        fileNameResults = names.rayTracingResultsFileName(
            self._telescopeModel.site, self._telescopeModel.name,
            self._sourceDistance, self.config.zenithAngle, self.label)
        self._outputDirectory.joinpath('results').mkdir(parents=True,
                                                        exist_ok=True)
        self._fileResults = self._outputDirectory.joinpath('results').joinpath(
            fileNameResults)