Analysis
FermiAnalysis
- class vtspy.analysis.FermiAnalysis(status_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 status of the analysis (See fermipy documentation for details) will be saved in the numpy array format (npy).
- Parameters
status_file (str) – status filename (npy) Default: initial
config_file (str) – config filename (yaml) Default: config.yaml
overwrite (bool) – overwrite the status 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'], status_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’]
status_file (str) – output status filename (npy) Default: analyzed
**kwargs – passed to GTanalysis.sed
- construct_dataset(psf_cut=10, min_energy_cut=None, fix_other_srcs=True, eventlist='ft1_00.fits', exposure='bexpmap_00.fits', psf='gtpsf_00.fits', **kwargs)
Construct a dataset for the gammapy analysis.
- Parameters
psf_cut (float) – apply a psf cut. Ignore energy channels whose
number. (99.9% angular resolution is higher than an input) – Default: 10
min_energy_cut (float) – apply a minimum energy cut. Default: None
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(status_file='wt_new_srcs', re_fit=True, return_srcs=False, **kwargs)
Find sources within the ROI (using GTanalysis.find_sources).
- Parameters
status_file (str) – output status filename (npy) Default: wt_new_srcs
re_fit (bool) – re fit the ROI with new sources Default: True
return_srcs (bool) – return source dictionaries Default: False
**kwargs – passed to fit.
- Returns
output of GTanalysis.find_sources
- Return type
dict
- fit(status_file='simple', pre_status=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
status_file (str) – output status 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_status (str, optional) – input status filename (npy). If not defined, starting from the current status. Default: None
**kwargs – passed to fermipy.GTAnalysis.free_sources function
- Return
dict: the output of the fitting when return_output is True
- load_status(status_file)
Load the status
- Parameters
status_file (str) – passed to fermipy.write_roi
- peek_events()
Show event information
- peek_irfs()
Show instrument response function (irf) information
- plot(output, status_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”]
status_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_status(status_file, init=False)
Save the status
- Parameters
status_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(status_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'], status_file='analyzed', **kwargs)
Perform a simple analysis, e.g., SED, lightcurve
- Parameters
jobs (list) – list of jobs, ‘sed’, and/or ‘lc’. Default: [‘sed’]
status_file (str) – status 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', status_file='simple', save_status=True, **kwargs)
Perform a simple fitting with a given model: PowerLaw, LogParabola, …
- Parameters
model (str or gammapy.models) – model name or function Default: “PowerLaw”
status_file (str) – status filename (pickle) Default: simple
save_status (bool) – Default: True
**kwargs – passed to vtspy.model.default_model
- load_status(status_file)
Load the status
Args: status_file (str): the name of status
- 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_status(status_file, init=False)
Save the status
- Parameters
status_file (str) – the name of status
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) – status filename or class for VERITAS Default: initial
fermi (str or vtspy.FermiAnalysis) – status filename or class for Fermi-LAT Default: initial
config_file (str) – config filename (yaml) Default: config.yaml
verbosity (int) –
**kwargs – passed to JointAnalysis.construct_dataset
- 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_status(status_file, reconstruct=False)
Load the status
Args: status_file (str): the name of status reconstruct (bool): re-construct the datasets
Default: False
- optimize(method='flux', 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 10 and strategy of 0 (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_status(status_file)
Save the status
- Parameters
status_file (str) – the name of status
- property target_model
Return: gammapy.modeling.models.SkyModel
- property target_name
Return: tuple: target name (veritas and fermi)
- property verbosity
Return: int