asgardpy.config.generator module

Main AsgardpyConfig Generator Module

pydantic model asgardpy.config.generator.AsgardpyConfig[source]

Bases: BaseConfig

Asgardpy analysis configuration, based on Gammapy Analysis Config.

Fields:
field dataset1d: Dataset1DConfig = Dataset1DConfig(type='1d', instruments=[Dataset1DBaseConfig(name='Instrument-name', input_dl3=[InputDL3Config(type='type', input_dir=PosixPath('.'), glob_pattern={})], input_dl4=False, dataset_info=Dataset1DInfoConfig(name='dataset-name', geom=GeomConfig(wcs=WcsConfig(skydir=SkyPositionConfig(frame='icrs', lon=<Quantity 0. deg>, lat=<Quantity 0. deg>, radius=<Quantity 0. deg>), binsize=<Quantity 0.1 deg>, proj='TAN', map_frame_shape=MapFrameShapeConfig(width=<Quantity 5. deg>, height=<Quantity 5. deg>), binsize_irf=<Quantity 0.2 deg>), selection=SelectionConfig(offset_max=<Quantity 2.5 deg>), axes=[MapAxesConfig(name='energy', axis=EnergyAxisConfig(min=<Quantity 1. GeV>, max=<Quantity 1. TeV>, nbins=5, per_decade=True), axis_custom=EnergyEdgesCustomConfig(edges=[], unit='TeV'))], from_events_file=True, reco_psf=False), observation=ObservationsConfig(obs_ids=[], event_type=[], obs_file=PosixPath('.'), obs_time=[], obs_cone=SkyPositionConfig(frame='icrs', lon=<Quantity 0. deg>, lat=<Quantity 0. deg>, radius=<Quantity 0. deg>), required_irfs=['aeff']), background=BackgroundConfig(method='reflected', region_finder_method='wobble', parameters={}, exclusion=ExclusionRegionsConfig(target_source=True, regions=[], exclusion_file=PosixPath('.'))), safe_mask=SafeMaskConfig(methods=[], parameters={}), on_region=SkyPositionConfig(frame='icrs', lon=<Quantity 0. deg>, lat=<Quantity 0. deg>, radius=<Quantity 0. deg>), containment_correction=True, map_selection=[]), dl4_dataset_info=DL4BaseConfig(dl4_dataset=InputDL4Config(type='MapDataset', input_dir=PosixPath('.'), glob_pattern={}, dl4_format='gadf'), spectral_energy_range=MapAxesConfig(name='energy', axis=EnergyAxisConfig(min=<Quantity 1. GeV>, max=<Quantity 1. TeV>, nbins=5, per_decade=True), axis_custom=EnergyEdgesCustomConfig(edges=[], unit='TeV'))))])
field dataset3d: Dataset3DConfig = Dataset3DConfig(type='3d', instruments=[Dataset3DBaseConfig(name='Instrument-name', input_dl3=[InputDL3Config(type='type', input_dir=PosixPath('.'), glob_pattern={})], input_dl4=False, dataset_info=Dataset3DInfoConfig(name='dataset-name', key=[], observation=ObservationsConfig(obs_ids=[], event_type=[], obs_file=PosixPath('.'), obs_time=[], obs_cone=SkyPositionConfig(frame='icrs', lon=<Quantity 0. deg>, lat=<Quantity 0. deg>, radius=<Quantity 0. deg>), required_irfs=['aeff']), map_selection=['counts', 'exposure', 'background', 'psf', 'edisp'], geom=GeomConfig(wcs=WcsConfig(skydir=SkyPositionConfig(frame='icrs', lon=<Quantity 0. deg>, lat=<Quantity 0. deg>, radius=<Quantity 0. deg>), binsize=<Quantity 0.1 deg>, proj='TAN', map_frame_shape=MapFrameShapeConfig(width=<Quantity 5. deg>, height=<Quantity 5. deg>), binsize_irf=<Quantity 0.2 deg>), selection=SelectionConfig(offset_max=<Quantity 2.5 deg>), axes=[MapAxesConfig(name='energy', axis=EnergyAxisConfig(min=<Quantity 1. GeV>, max=<Quantity 1. TeV>, nbins=5, per_decade=True), axis_custom=EnergyEdgesCustomConfig(edges=[], unit='TeV'))], from_events_file=True, reco_psf=False), background=BackgroundConfig(method='reflected', region_finder_method='wobble', parameters={}, exclusion=ExclusionRegionsConfig(target_source=True, regions=[], exclusion_file=PosixPath('.'))), safe_mask=SafeMaskConfig(methods=[], parameters={}), on_region=SkyPositionConfig(frame='icrs', lon=<Quantity 0. deg>, lat=<Quantity 0. deg>, radius=<Quantity 0. deg>), containment_correction=True), dl4_dataset_info=DL4BaseConfig(dl4_dataset=InputDL4Config(type='MapDataset', input_dir=PosixPath('.'), glob_pattern={}, dl4_format='gadf'), spectral_energy_range=MapAxesConfig(name='energy', axis=EnergyAxisConfig(min=<Quantity 1. GeV>, max=<Quantity 1. TeV>, nbins=5, per_decade=True), axis_custom=EnergyEdgesCustomConfig(edges=[], unit='TeV'))))])
field fit_params: FitConfig = FitConfig(fit_range=EnergyRangeConfig(min=<Quantity 1. GeV>, max=<Quantity 1. TeV>), backend='minuit', optimize_opts={}, covariance_opts={}, confidence_opts={}, store_trace=True)
field flux_points_params: FluxPointsConfig = FluxPointsConfig(parameters={'selection_optional': 'all'}, reoptimize=False)
field general: GeneralConfig = GeneralConfig(log=LogConfig(level='info', filename='', filemode='w', format='', datefmt=''), outdir=PosixPath('.'), n_jobs=1, parallel_backend='multiprocessing', steps=[], overwrite=True, stacked_dataset=False)
field target: Target = Target(source_name='', sky_position=SkyPositionConfig(frame='icrs', lon=<Quantity 0. deg>, lat=<Quantity 0. deg>, radius=<Quantity 0. deg>), use_uniform_position=True, models_file=PosixPath('.'), datasets_with_fov_bkg_model=[], use_catalog=CatalogConfig(name='', selection_radius=<Quantity 0. deg>, exclusion_radius=<Quantity 0. deg>), components=[ModelComponent(name='', type='SkyModel', datasets_names=[''], spectral=SpectralModelConfig(type='', parameters=[ModelParams(name='', value=1.0, unit=' ', error=0.1, min=0.1, max=10.0, frozen=True)], ebl_abs=EBLAbsorptionModel(filename=PosixPath('.'), reference='', type='EBLAbsorptionNormSpectralModel', redshift=0.0, alpha_norm=1.0)), spatial=SpatialModelConfig(type='', frame='icrs', parameters=[ModelParams(name='', value=1.0, unit=' ', error=0.1, min=0.1, max=10.0, frozen=True)]))], covariance='', from_3d=False, roi_selection=RoISelectionConfig(roi_radius=<Quantity 0. deg>, free_sources=[]))
classmethod from_yaml(config_str)[source]

Create from YAML string.

classmethod read(path)[source]

Reads from YAML file.

set_logging()[source]

Set logging config. Calls logging.basicConfig, i.e. adjusts global logging state.

to_yaml()[source]

Convert to YAML string.

update(config=None, merge_recursive=False)[source]

Update config with provided settings. :type config: default: None :param config: The other configuration settings provided in dict() syntax. :type config: string dict or AsgardpyConfig object :type merge_recursive: default: False :param merge_recursive: Perform a recursive merge from the other config onto the parent config. :type merge_recursive: bool

Returns:

config – Updated config object.

Return type:

AsgardpyConfig object

write(path, overwrite=False)[source]

Write to YAML file.

pydantic model asgardpy.config.generator.GeneralConfig[source]

Bases: BaseConfig

Config section for general information for running AsgardpyAnalysis.

Fields:
field log: LogConfig = LogConfig(level='info', filename='', filemode='w', format='', datefmt='')
field n_jobs: int = 1
field outdir: Annotated[str | Path] = 'None'
Constraints:
  • func = <function <lambda> at 0x7f5167d96020>

  • json_schema_input_type = PydanticUndefined

  • return_type = <class ‘pathlib.Path’>

  • when_used = json-unless-none

field overwrite: bool = True
field parallel_backend: ParallelBackendEnum = ParallelBackendEnum.multi
field stacked_dataset: bool = False
field steps: list[AnalysisStepEnum] = []
asgardpy.config.generator.gammapy_model_to_asgardpy_model_config(gammapy_model, asgardpy_config_file=None, recursive_merge=True)[source]

Read the Gammapy Models object and save it as AsgardpyConfig object.

The gammapy_model object may be a YAML config filename/path/object or a Gammapy Models object itself.

Returns:

asgardpy_config – Updated AsgardpyConfig object

Return type:

asgardpy.config.generator.AsgardpyConfig

asgardpy.config.generator.write_asgardpy_model_to_file(gammapy_model, output_file=None, recursive_merge=True)[source]

Read the Gammapy Models object and save it as AsgardpyConfig YAML file containing only the Model parameters, similar to the model templates available.

Template AsgardpyConfig

# Configuration file template for Data analysis of 3D+1D DL3 datasets

# General settings
general:
  log:
    level: info
    filename: filename.log
    filemode: a
    format: "%(asctime)s - %(message)s"
    datefmt: "%d-%b-%y %H:%M:%S"
  outdir: .
  n_jobs: 10
  parallel_backend: multiprocessing
  steps: [datasets-3d, datasets-1d, fit, flux-points]
  overwrite: true
  stacked_dataset: true

# Target settings
target:
  source_name: PG1553+113
  sky_position: &source_pos {frame: icrs, lon: 238.92934976 deg, lat: 11.19010155 deg, radius: 0 deg}
  use_uniform_position: true
  datasets_with_fov_bkg_model: []
  #models_file: "template_model.yaml"
  #use_catalog:
    #name: "3fgl"
    #selection_radius: 0.4 deg
    #exclusion_radius: 0.5 deg
  components:
  -   name: PG1553+113
      type: SkyModel
      spectral:
          type: LogParabolaSpectralModel
          parameters:
          -   name: amplitude
              value: 1.0e-05
              unit: cm-2 s-1 TeV-1
              error: 1.5e-06
              min: 1.0e-13
              max: 0.01
              frozen: false
          -   name: reference
              value: 0.0015
              unit: TeV
              error: 0.0
              min: 0.0001
              max: 100.0
              frozen: true
          -   name: alpha
              value: 1.5
              unit: ''
              error: 0.1
              min: 0.5
              max: 5.0
              frozen: false
          -   name: beta
              value: 0.1
              unit: ''
              error: 0.01
              min: 1.0e-6
              max: 1.0
              frozen: false
          ebl_abs:
            reference: dominguez
            type: EBLAbsorptionNormSpectralModel
            redshift: 0.433
            alpha_norm: 1.0
  covariance: None
  from_3d: false
  roi_selection:
    roi_radius: 5 deg
    free_sources: [None]

# Instrument datasets with 3D info
dataset3d:
  type: "3d"
  instruments:
  -   name: Fermi-LAT
      input_dl3:
      -   type: lat
          input_dir: "."
          glob_pattern:
            events: "*MkTime.fits*"
            edisp: "*eDRM.fits*"
            xml_model: "*out.xml"
            exposure: "*BinnedMap.fits*"
            psf: "*psf.fits*"
      -   type: lat-aux
          input_dir: "."
          glob_pattern:
            gal_diffuse: "gll_iem_v07.fits*"
            iso_diffuse: "iso_P8R3_SOURCE_V3_*.txt"
      input_dl4: false
      dataset_info:
        name: Fermi-LAT
        key: ["FRONT", "BACK"]
        # map_selection: []
        geom:
          from_events_file: True
          wcs:
            binsize: 0.1 deg
            proj: TAN
            map_frame_shape:
              width: 10 deg
              height: 10 deg
          axes:
          -   name: energy
              axis:
                min: "100 MeV"
                max: "1 TeV"
                nbins: 8
                per_decade: true
        background:
        # method: reflected
        # parameters:
          exclusion:
            target_source: true
            regions:
            -   type: CircleAnnulusSkyRegion
                name: None
                position: *source_pos
                parameters:
                  rad_0: 8 deg
                  rad_1: 30 deg
        safe_mask:
          methods: []
          parameters:
            min: 0.001 TeV
            max: 1 TeV
        on_region: *source_pos
          # radius: 0.4 deg
        containment_correction: true
      dl4_dataset_info:
        # dl4_dataset:
          # type: MapDatasetOnOff
          # input_dir: "."
          # glob_pattern:
          #   dl4_files: "pha*fits"
          # dl4_format: "ogip"
        spectral_energy_range:
          name: energy
          axis:
            min: "100 MeV"
            max: "1 TeV"
            nbins: 4
            per_decade: true
        #  axis_custom:
        #    edges: [0.01, 0.05, 0.1, 0.5, 1, 5, 10]
        #    unit: "TeV"
# - name: CTA
#    ... full description ...

# Instrument datasets with 1D info
dataset1d:
  type: "1d"
  instruments:
  -   name: LST-1
      input_dl3:
      -   type: gadf-dl3
          input_dir: "."
          glob_pattern:
            dl3_files: ""
      input_dl4: false
      dataset_info:
        name: LST-1
        geom:
          wcs:
            binsize: 0.05 deg
            proj: TAN
            map_frame_shape:
              width: 6.25 deg
              height: 6.25 deg
          selection:
            offset_max: "2.5 deg"
          axes:
          -   name: energy
              axis: &lst_energy
                min: "10 GeV"
                max: "10 TeV"
                nbins: 5
                per_decade: true
          -   name: energy_true
              axis: *lst_energy
        observation:
          # obs_ids: []
          # obs_file: None
          # obs_time:
          required_irfs: ["aeff", "edisp", "rad_max"]
        background:
          method: reflected
          region_finder_method: wobble
          parameters:
            n_off_regions: 1
          # exclusion:
        safe_mask:
          methods: ["custom-mask"] #["aeff-max", "aeff-default", "edisp-bias", "offset-max", "bkg-peak"]
          parameters:
            min: "10 GeV"
            max: "10 TeV"
            aeff_percent: 10
            bias_percent: 10
            fixed_offset: 0.1 deg
            offset_max: 3 deg
            position: *source_pos
        on_region: *source_pos
        containment_correction: false
        map_selection: [counts, exposure, edisp]
      dl4_dataset_info:
        # dl4_dataset:
          # type: SpectrumDatasetOnOff
          # input_dir: "."
          # glob_pattern:
          #   dl4_files: "obs_*fits"
          # dl4_format: "gadf"
        spectral_energy_range:
          name: energy
          axis:
            min: "10 GeV"
            max: "10 TeV"
            nbins: 5
            per_decade: true
          #axis_custom:
          #   edges: [0.01, 0.05, 0.1, 0.5, 1, 5, 10]
          #   unit: "TeV"
#  - name: MAGIC
#      ... full description ...

# Fit parameters
fit_params:
  fit_range:
    min: "100 MeV"
    max: "1 TeV"
  backend: minuit
  optimize_opts: {}
  covariance_opts: {}
  confidence_opts: {}
  store_trace: true

flux_points_params:
  parameters:
    selection_optional: "all"
  reoptimize: false

Template models file

target:
  components:
  -   type: SkyModel
      spectral:
          type: LogParabolaSpectralModel
          parameters:
          -   name: amplitude
              value: 1.0e-05
              unit: cm-2 s-1 TeV-1
              error: 1.5e-06
              min: 1.0e-13
              max: 0.01
              frozen: false
          -   name: reference
              value: 0.0015
              unit: TeV
              error: 0.0
              min: 0.0001
              max: 100.0
              frozen: true
          -   name: alpha
              value: 2
              unit: ''
              error: 0.1
              min: 0.5
              max: 5.0
              frozen: false
          -   name: beta
              value: 0.1
              unit: ''
              error: 0.01
              min: 0.01
              max: 1.0
              frozen: false