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()
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
    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)
Exemple #4
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()
Exemple #6
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()
    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
    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)