Analysis
FermiAnalysis
- class vtspy.analysis.FermiAnalysis(state_file='initial', config_file='config.yaml', overwrite=False, remove_weak_srcs=False, construct_dataset=False, verbosity=True, **kwargs)
Bases:
objectThis is to perform a simple Fermi-LAT analysis and to prepare the joint-fit analysis. All fermipy.GTanalysis functions and attributes can be accessed with the ‘gta’ arribute. e.g.,
fermi = FermiAnalysis() fermi.gta.optimize()
All information about the state of the analysis (See fermipy documentation for details) will be saved in the numpy array format (npy).
- Parameters
state_file (str) – state filename (npy) Default: initial
config_file (str) – config filename (yaml) Default: config.yaml
overwrite (bool) – overwrite the state Default: False
remove_weak_srcs (bool) – remove sources with TS of nan or 0 Default: False
construct_dataset (bool) – construct dataset for the gammapy analysis Default: False
verbosity (int) –
**kwargs – passed to fermipy.GTAnalysis module
- analysis(jobs=['ts', 'resid', 'sed'], state_file='analyzed', **kwargs)
Perform various analyses: TS map, Residual map, and SED.
- Parameters
jobs (str or list) – list of jobs, ‘ts’, ‘resid’, and/or ‘sed’. Default: [‘ts’, ‘resid’, ‘sed’]
state_file (str) – output state filename (npy) Default: analyzed
**kwargs – passed to GTanalysis.sed
- construct_dataset(fix_other_srcs=False, eventlist='ft1_00.fits', exposure='bexpmap_00.fits', psf='gtpsf_00.fits')
Construct a dataset for the gammapy analysis.
- Parameters
fix_other_srcs (bool) – fix source parameters except for the target Default: False
eventlist (str) – event list file (gtapp.maketime) Default: ft1_00.fits
exposure (str) – exposure map file (gtapp.gtexpmap)
psf (str) – psf file (gtapp.gtpsf)
- find_sources(state_file='wt_new_srcs', re_fit=True, **kwargs)
Find sources within the ROI (using GTanalysis.find_sources).
- Parameters
state_file (str) – output state filename (npy) Default: wt_new_srcs
re_fit (bool) – re fit the ROI with new sources
**kwargs – passed to fit.
- Returns
output of GTanalysis.find_sources
- Return type
dict
- fit(state_file='simple', pre_state=None, free_all=False, free_target=True, remove_weak_srcs=False, fix_index=False, min_ts=5, distance=3.0, optimizer='NEWMINUIT', return_output=False, **kwargs)
Perform a simple fitting with various cuts
- Parameters
state_file (str) – output state filename (npy) Default: simple
free_all (bool) – make the target’s all parameters free Default: True
free_all – make all sources parameters free Default: False
remove_weak_srcs (bool) – remove sources with TS of nan or 0. This setting will trigger another round of fit process after the first run. Default: False
fix_index (bool) – fix spectral shapes for sources for TS less than min_ts Default: False
min_ts (int) – minimum TS value for fixing a spectral shape Default: 5
distance (float) – parameters for sources outside of a certain distance from the center are fixed, except for the normalization Default: 3.0
optimizer (str) – either MINUIT or NEWMINUIT Default: NEWMINUIT
return_output (bool) – return the fitting result (dict) Default: False
pre_state (str, optional) – input state filename (npy). If not defined, starting from the current state. Default: None
**kwargs – passed to fermipy.GTAnalysis.free_sources function
- Return
dict: the output of the fitting when return_output is True
- load_state(state_file)
Load the state
- Parameters
state_file (str) – passed to fermipy.write_roi
- peek_events()
Show event information
- peek_irfs()
Show instrument response function (irf) information
- plot(output, state_file='analyzed', **kwargs)
Show various plots: TS map, Residual map, and SED.
- Parameters
output (str or list) – list of plots to show Options: [“sqrt_ts”, “npred”, “ts_hist”, “data”, “model”, “sigma”, “excess”, “resid”, “sed”]
state_file (str) – read the output (from FermiAnalysis.analysis)
- print_association()
Print sources within ROI and their associations.
- print_model()
Print source models within ROI
- print_params(full_output=False)
Print parameters of sources within ROI
- print_target()
Print the target properties
- remove_weak_srcs(ts_cut=1, npred_cut=0)
Remove sources within ROI if they are too weak. :param ts_cut: remove sources with a TS cut
Default: 1
- Parameters
npred_cut (float) – remove sources with a npred cut Default: 0
- save_state(state_file, init=False)
Save the state
- Parameters
state_file (str) – passed to fermipy.write_roi
init (bool) – check whether this is the initial analysis. Default: False
- set_target(target)
Set/change the target
- Parameters
target (str or int) – target name or id
- property target
Return: fermipy.roi_model.Source
- property target_id
Return: int: target id
- property target_name
Return: str: target name
- property verbosity
Return: int
VeritasAnalysis
- class vtspy.analysis.VeritasAnalysis(state_file='initial', config_file='config.yaml', overwrite=False, verbosity=1, **kwargs)
Bases:
object- add_exclusion_region(coord=None, name=None, radius=0.3, update_dataset=False, **kwargs)
Add exclusion region manually
- Parameters
coord (list, optioanl) – [ra, dec]
name (list, optional) – [ra, dec]
radius (float) – size of an exlusion region
update_dataset (bool) – update dataset with the new exclusion region
- analysis(jobs=['sed'], state_file='analyzed', **kwargs)
Perform a simple analysis, e.g., SED, lightcurve
- Parameters
jobs (list) – list of jobs, ‘sed’, and/or ‘lc’. Default: [‘sed’]
state_file (str) – state filename (pickle) Default: analyzed
**kwargs – passed to vtspy.utils.define_time_intervals
- construct_dataset(**kwargs)
Construct dataset for the gammapy analysis
- Parameters
**kwargs – e.g., eff_cut, bias_cut, max_region_number, or others
- property energy_bins
Return: MapAxis.edges: energy bins used in flux points.
- fit(model='PowerLaw', state_file='simple', save_state=True, **kwargs)
Perform a simple fitting with a given model: PowerLaw, LogParabola, …
- Parameters
model (str or gammapy.models) – model name or function Default: “PowerLaw”
state_file (str) –
- state filename (pickle)
Default: simple
- save_state(bool)
Default: True
**kwargs: passed to vtspy.model.default_model
- load_state(state_file)
Load the state
Args: state_file (str): the name of state
- property obs_ids
Return: list: list of observation id
- peek_dataset()
Show dataset information
- plot(output, **kwargs)
Show various results: fit result, flux, SED, and lightcurve
- Parameters
output (str) – a plot to show Options: [“roi”, “fit”, “flux”, “sed”, “lc”]
filename (str) – read the output (from FermiAnalysis.analysis)
- print_flux()
- Returns
flux points in SED
- Return type
astropy.table
- print_lightcurve(sed_type='eflux')
- Returns
flux points in lightcurve
- Return type
astropy.table
- print_models()
- Returns
fit parameters
- Return type
astropy.table
- save_state(state_file, init=False)
Save the state
- Parameters
state_file (str) – the name of state
init (bool) – check whether this is the initial analysis. Default: False
- setup(**kwargs)
This is to initialize the VERITAS analysis; e.g., construct datasets To change the setting for this setup, check config file.
VeritasAnalysis.config
- Parameters
**kwargs – passed to VeritasAnalysis.construct_dataset
- property target
Return: astropy.SkyCoord
- property target_name
Return: str: target name
- property verbosity
Return: int
JointAnalysis
- class vtspy.analysis.JointAnalysis(veritas=None, fermi=None, config_file='config.yaml', verbosity=1, **kwargs)
Bases:
objectThis is to perform a joint VERITAS and Fermi-LAT analysis. This class exploits results from VeritasAnalysis and FermiAnalysis.
- Parameters
veritas (str or vtspy.VeritasAnalysis) – state filename or class for VERITAS Default: initial
fermi (str or vtspy.FermiAnalysis) – state filename or class for Fermi-LAT Default: initial
config_file (str) – config filename (yaml) Default: config.yaml
verbosity (int) –
- add_dataset(data, sync=True, model=None, **kwargs)
To add a new dataset.
- Parameters
data (str or gammapy.estimators.FluxPoints) – new dataset
sync (bool) – synchronize with the target model Default: True
model (gammapy.modeling.models.SpectralModel) – a model for the new dataset
**kwargs – passed to gammapy.estimators.FluxPointsDataset
- analysis(**kwargs)
Perform a SED analysis.
- Parameters
**kwargs – passed to FluxPointsEstimator
- change_model(model, optimize=False, **kwargs)
To change a target model
- Parameters
model (str or gammapy.modeling.models.SpectralModel) – a new target model
optimize (bool) – perform optimization (JointAnalysis.optimize) Default: False
**kwargs – passed to JointAnalysis.optimize
- fit(**kwargs)
Perform a joint-fit analysis
- Parameters
**kwargs – passed to vtspy.JointAnalysis.optimize
- load_state(state_file)
Load the state
Args: state_file (str): the name of state
- optimize(method='flux', model=None, instrument='VERITAS', **kwargs)
To find good initial parameters for a given model.
- Parameters
method (str) – either “flux”, “rough” or “inst”. The “flux” method will fit flux points from VeritasAnalysis.analysis(“sed”) and FermiAnalysis.analysis(“sed”). The “rough” method will fit the dataset with tol of 1 and strategy of 1 (fast). The “inst” method will fit the model with one of datasets (defined by instrument) Default: flux
model (gammapy.modeling.models.SpectralModel) – a model to fit Default: None (fit with the current target model)
instrument (str) – instrument used for the “inst” method Default: VERITAS
**kwargs –
- plot(output, **kwargs)
Show various results: SED
- Parameters
output (str) – a plot to show Options: [“sed”]
**kwargs – passed to vtspy.JointAnalysis.plot_sed
- plot_sed(fermi=True, veritas=True, joint=True, show_model=True, show_flux_points=True, **kwargs)
Plot a spectral energy distribution (SED) with a model and flux points.
- Parameters
fermi (bool) – show Fermi-LAT results Default: True
veritas (bool) – show VERITAS results Default: True
fermi – show Joint-fit results Default: True
show_flux_points (bool) – slow flux points Default: True
show_model (bool) – Default: True
**kwargs – passed to plotting.plot_sed
- print_datasets()
Print datasets
- Returns
astropy.table
- print_models(full_output=False)
Print model and parameters
- Parameters
full_output (bool) – return a target model or all models default: False
- Returns
astropy.table
- save_state(state_file)
Save the state
- Parameters
state_file (str) – the name of state
- property target_model
Return: gammapy.modeling.models.SkyModel
- property target_name
Return: str: target name
- property verbosity
Return: int