gbm_drm_gen package

Submodules

gbm_drm_gen.basersp module

gbm_drm_gen.basersp.get_path_of_data_file(data_file)[source]
class gbm_drm_gen.basersp.DetDatabase(detector_group)[source]

Bases: object

__init__(detector_group)[source]
Parameters

detector_group

get_rsp(z, az)[source]
Parameters
  • z

  • az

Returns

gbm_drm_gen.basersp.get_database(det)[source]

gbm_drm_gen.basersp_numba module

gbm_drm_gen.basersp_numba.get_path_of_data_file(data_file)[source]
class gbm_drm_gen.basersp_numba.DetDatabase_numba(detector_group)[source]

Bases: object

__init__(detector_group)[source]
Parameters

detector_group

get_rsp(z, az)[source]
Parameters
  • z

  • az

Returns

property rsps
gbm_drm_gen.basersp_numba.get_database(det)[source]
class gbm_drm_gen.basersp_numba.TrigdatPrecalcDetDatabase_numba(detector_group, mask)[source]

Bases: object

__init__(detector_group, mask)[source]
Parameters

detector_group

get_rsp(z, az)[source]
Parameters
  • z

  • az

Returns

property rsps
gbm_drm_gen.basersp_numba.get_trigdat_precalc_database(det, mask)[source]

gbm_drm_gen.create_rsp2 module

gbm_drm_gen.create_rsp2.create_rsp2(file_name: str, response_generator: gbm_drm_gen.drmgen.DRMGen, ra: float, dec: float, tstart: float, tstop: float, delta_time: float = 3, overwrite: bool = False) None[source]

gbm_drm_gen.detdatabase module

gbm_drm_gen.drmgen module

class gbm_drm_gen.drmgen.DRMGen(position_interpolator: gbmgeometry.position_interpolator.PositionInterpolator, det_number: str, ebin_edge_in, mat_type: int = 0, ebin_edge_out=None, occult: bool = True, time: float = 0)[source]

Bases: object

__init__(position_interpolator: gbmgeometry.position_interpolator.PositionInterpolator, det_number: str, ebin_edge_in, mat_type: int = 0, ebin_edge_out=None, occult: bool = True, time: float = 0)[source]

A generic GBM DRM generator. This can be inherited for specific purposes. It takes as input various spacecraft files to figure out geometry. The user can either supply custom output energy edges or they can be read from a cspec file.

The great benefit here is the ability to make custom input edges if desired. The user needs to have the GBM database pointed at by the environment variable: BALROG_DB

Additionally, matrix folding routines are supplied for spectral fitting. One can also simulate Poisson rates from supplied spectral models.

Parameters
  • trigdat – the path to a trigdat file

  • det_number – the number (0-13) of the detector to be used

  • ebin_edge_in – an array of energy edges lenght 1 longer than the num of bins

  • mat_type – 0=direct 1=scattered 2=direct+scattered

  • time – time relative to trigger to pull spacecraft position

  • cspecfile – the cspecfile to pull energy output edges from

  • ebin_edge_out – an array of output edges

classmethod from_128_bin_data(det_name, time: float = 0.0, cspecfile: Optional[str] = None, trigdat: Optional[str] = None, poshist: Optional[str] = None, T0: Optional[float] = None, mat_type: int = 0, custom_input_edges: Optional[gbm_drm_gen.input_edges.InputEdges] = None, occult: bool = False)[source]

A TTE/CSPEC specific drmgen already incorporating the standard input edges. Output edges are obtained from lib import funs the input cspec file. Spacecraft position is read from the TTE file. For further details see the generic reader (DRMGen).

Parameters
  • det_name – either NAI_{**} or BGO_{**} or n* b*

  • trigdat – the path to a trigdat file

  • mat_type – 0=direct 1=scattered 2=direct+scattered

  • time – time relative to trigger to pull spacecraft position or MET if using a poshist file

  • cspecfile – the cspecfile to pull energy output edges from

  • poshist – read a poshist file

classmethod from_trigdat(trigdat_file: str, det, mat_type=0, tstart=0, tstop=0.0, time=0.0, occult=False)[source]

TODO describe function

Parameters
  • cls

  • trigdat_file (str) –

  • det

  • mat_type

  • tstart

  • tstop

  • time

  • occult

Returns

property postion_interpolator: gbmgeometry.position_interpolator.PositionInterpolator
property current_met: float
met_at(t: float) float[source]

returns the MET at a given relative time

Parameters

t (float) –

Returns

property ebounds
property monte_carlo_energies
property matrix
to_3ML_response(ra, dec, coverage_interval=None)[source]

create an instrument reponse object for 3ML

Parameters
  • ra

  • dec

Returns

to_3ML_response_direct_sat_coord(az, el)[source]
to_fits(ra, dec, filename, overwrite)[source]
set_location(ra, dec) None[source]

Set the Ra and Dec of the DRM to be built. This invokes DRM generation as well.

Parameters
  • ra – ra in degrees

  • dec – dec in degrees

set_location_direct_sat_coord(az, el) None[source]

Set the AZ and EL in satellite coordinates of the DRM to be built. This invokes DRM generation as well.

Parameters
  • az – az in degrees

  • el – el in degrees

set_time(time)[source]
_compute_spacecraft_coordinates()[source]

GBM geometry calculations

gbm_drm_gen.drmgen.at_scat(tmp_out, num_theta, num_phi, theta_u, phi_u, gx, gy, gz, sf, grid_points_list, trigdat_precalc_rsps, rsps, milliaz, millizen, epx_lo, epx_hi, ichan, out_edge, at_scat_data, il_low, il_high, l_frac, trigdat)[source]
gbm_drm_gen.drmgen.msum(this_data_lo, this_data_hi, direct_diff_matrix, tmp_out, l_frac)[source]

gbm_drm_gen.drmgen_trig module

class gbm_drm_gen.drmgen_trig.DRMGenTrig(trigdat_file: str, det, mat_type=0, tstart=0, tstop=0.0, time=0.0, occult=False)[source]

Bases: gbm_drm_gen.drmgen.DRMGen

__init__(trigdat_file: str, det, mat_type=0, tstart=0, tstop=0.0, time=0.0, occult=False)[source]

Inherited drmgen from the TTE version. Builds 8-channel RSPs for trigdat data using 140 input edges :param trigdat: a TrigReader object with the background and source selection already exists :param det: a number corresponding to the GBM detector to be used :param mat_type: the type of matrix to produce: 0=direct 1=scattered 2=direct+scattered :param time: the time of the spacecraft position to use :param occult: (bool) occult points blocked by the Earth

gbm_drm_gen.drmgen_tte module

class gbm_drm_gen.drmgen_tte.DRMGenTTE(tte_file: Optional[str] = None, det_name: Optional[str] = None, time: float = 0.0, cspecfile: Optional[str] = None, trigdat: Optional[str] = None, poshist: Optional[str] = None, T0: Optional[float] = None, mat_type: int = 0, custom_input_edges: Optional[gbm_drm_gen.input_edges.InputEdges] = None, occult: bool = False)[source]

Bases: gbm_drm_gen.drmgen.DRMGen

__init__(tte_file: Optional[str] = None, det_name: Optional[str] = None, time: float = 0.0, cspecfile: Optional[str] = None, trigdat: Optional[str] = None, poshist: Optional[str] = None, T0: Optional[float] = None, mat_type: int = 0, custom_input_edges: Optional[gbm_drm_gen.input_edges.InputEdges] = None, occult: bool = False)[source]

A TTE/CSPEC specific drmgen already incorporating the standard input edges. Output edges are obtained from lib import funs the input cspec file. Spacecraft position is read from the TTE file. For further details see the generic reader (DRMGen).

Parameters
  • tte_file – the TTE file the data are associated to (used if det name NOT given)

  • det_name – either NAI_{**} or BGO_{**} or n* b*

  • trigdat – the path to a trigdat file

  • mat_type – 0=direct 1=scattered 2=direct+scattered

  • time – time relative to trigger to pull spacecraft position or MET if using a poshist file

  • cspecfile – the cspecfile to pull energy output edges from

  • poshist – read a poshist file

gbm_drm_gen.input_edges module

class gbm_drm_gen.input_edges.InputEdges(edges: numpy.array)[source]

Bases: object

__init__(edges: numpy.array)[source]
property edges
classmethod from_log_bins(n_bins: int)[source]
classmethod from_custom_array(edges: numpy.array)[source]

create edges from a custom set of energies.

The end points must be those of the original edges.

This will be corrected if not done… but might cause errors

class gbm_drm_gen.input_edges.NaiTTEEdges(edges)[source]

Bases: gbm_drm_gen.input_edges.InputEdges

__init__(edges)[source]
class gbm_drm_gen.input_edges.BgoTTEEdges(edges)[source]

Bases: gbm_drm_gen.input_edges.InputEdges

__init__(edges)[source]

gbm_drm_gen.matrix_functions module

gbm_drm_gen.matrix_functions.closest(point_assume_f, grid_points_list_f)[source]
gbm_drm_gen.matrix_functions.trfind(point_assume_f, grid_points_list_f)[source]
gbm_drm_gen.matrix_functions.calc_weights_numba(p1, p2, p3, p_find)[source]

###################### Weights from https://codeplea.com/triangular-interpolation ############ p1_lat = np.arcsin(p1[2]) p1_lon = np.arctan2(p1[1],p1[0])

p2_lat = np.arcsin(p2[2]) p2_lon = np.arctan2(p2[1],p2[0])

p3_lat = np.arcsin(p3[2]) p3_lon = np.arctan2(p3[1],p3[0])

pf_lat = np.arcsin(p_find[2]) pf_lon = np.arctan2(p_find[1],p_find[0])

W1 = ((p2_lat-p3_lat)*(pf_lon-p3_lon)+(p3_lon-p2_lon)*(pf_lat-p3_lat))/((p2_lat-p3_lat)*(p1_lon-p3_lon)+(p3_lon-p2_lon)*(p1_lat-p3_lat)) W2 = ((p3_lat-p1_lat)*(pf_lon-p3_lon)+(p1_lon-p3_lon)*(pf_lat-p3_lat))/((p2_lat-p3_lat)*(p1_lon-p3_lon)+(p3_lon-p2_lon)*(p1_lat-p3_lat)) W3 = 1-W1-W2

gbm_drm_gen.matrix_functions.geocoords(theta_geo, phi_geo, theta_source, phi_source)[source]
gbm_drm_gen.matrix_functions.geo_to_space(theta_u, phi_u, gx, gy, gz)[source]
gbm_drm_gen.matrix_functions.calc_sphere_dist(ra1, dec1, ra2, dec2, dtr)[source]
gbm_drm_gen.matrix_functions.highres_ephoton_interpolator(ebin_edge_in, ein, matrix, edif_edge_lo, edif_edge_hi, nhbins)[source]
gbm_drm_gen.matrix_functions.atscat_highres_ephoton_interpolator(ebin_edge_in, ein, matrix)[source]
gbm_drm_gen.matrix_functions.echan_integrator(diff_matrix, edif_edge_lo, edif_edge_hi, nhbins, ebin_edge_out)[source]

Module contents

class gbm_drm_gen.DRMGenTTE(tte_file: Optional[str] = None, det_name: Optional[str] = None, time: float = 0.0, cspecfile: Optional[str] = None, trigdat: Optional[str] = None, poshist: Optional[str] = None, T0: Optional[float] = None, mat_type: int = 0, custom_input_edges: Optional[gbm_drm_gen.input_edges.InputEdges] = None, occult: bool = False)[source]

Bases: gbm_drm_gen.drmgen.DRMGen

__init__(tte_file: Optional[str] = None, det_name: Optional[str] = None, time: float = 0.0, cspecfile: Optional[str] = None, trigdat: Optional[str] = None, poshist: Optional[str] = None, T0: Optional[float] = None, mat_type: int = 0, custom_input_edges: Optional[gbm_drm_gen.input_edges.InputEdges] = None, occult: bool = False)[source]

A TTE/CSPEC specific drmgen already incorporating the standard input edges. Output edges are obtained from lib import funs the input cspec file. Spacecraft position is read from the TTE file. For further details see the generic reader (DRMGen).

Parameters
  • tte_file – the TTE file the data are associated to (used if det name NOT given)

  • det_name – either NAI_{**} or BGO_{**} or n* b*

  • trigdat – the path to a trigdat file

  • mat_type – 0=direct 1=scattered 2=direct+scattered

  • time – time relative to trigger to pull spacecraft position or MET if using a poshist file

  • cspecfile – the cspecfile to pull energy output edges from

  • poshist – read a poshist file

class gbm_drm_gen.DRMGenTrig(trigdat_file: str, det, mat_type=0, tstart=0, tstop=0.0, time=0.0, occult=False)[source]

Bases: gbm_drm_gen.drmgen.DRMGen

__init__(trigdat_file: str, det, mat_type=0, tstart=0, tstop=0.0, time=0.0, occult=False)[source]

Inherited drmgen from the TTE version. Builds 8-channel RSPs for trigdat data using 140 input edges :param trigdat: a TrigReader object with the background and source selection already exists :param det: a number corresponding to the GBM detector to be used :param mat_type: the type of matrix to produce: 0=direct 1=scattered 2=direct+scattered :param time: the time of the spacecraft position to use :param occult: (bool) occult points blocked by the Earth

class gbm_drm_gen.NaiTTEEdges(edges)[source]

Bases: gbm_drm_gen.input_edges.InputEdges

__init__(edges)[source]
class gbm_drm_gen.BgoTTEEdges(edges)[source]

Bases: gbm_drm_gen.input_edges.InputEdges

__init__(edges)[source]
class gbm_drm_gen.BALROG_DRM(drm_generator, ra, dec)[source]

Bases: threeML.utils.OGIP.response.InstrumentResponse

__init__(drm_generator, ra, dec)[source]
Parameters
  • drm_generator – BALROG DRM generator

  • ra – RA of the source

  • dec – DEC of the source

set_location(ra, dec, cache=False)[source]

Set the source location :param ra: :param dec: :return:

set_time(time)[source]

set the time of the source :param time: :return:

class gbm_drm_gen.BALROGLike(name, observation, drm_generator=None, background=None, time=0, free_position=True, verbose=True, use_cache=False, **kwargs)[source]

Bases: threeML.plugins.DispersionSpectrumLike.DispersionSpectrumLike

__init__(name, observation, drm_generator=None, background=None, time=0, free_position=True, verbose=True, use_cache=False, **kwargs)[source]

BALROGLike is a general plugin for fitting GBM spectra and locations at the same time

Parameters
  • name – plugin name

  • observation – observed spectrum

  • drm_generator – the drm generator for this

  • background – background spectrum

  • time – time of the observation

  • free_position – keep the position free

  • verbose – the verbosity level of the plugin

set_model(likelihoodModel)[source]

Set the model and free the location parameters

Parameters

likelihoodModel

Returns

None

get_model(precalc_fluxes=None)[source]

The model integrated over the energy bins. Note that it only returns the model for the currently active channels/measurements

Returns

array of folded model

classmethod from_spectrumlike(spectrum_like, time, drm_generator=None, free_position=True)[source]

Generate a BALROGlike from an existing SpectrumLike child

Parameters
  • spectrum_like – the existing spectrumlike

  • time – the time to generate the RSPs at

  • drm_generator – optional BALROG DRM generator

  • free_position – if the position should be free

Returns

class gbm_drm_gen.BALROGHealpixMap(analysis_results, nside=32)[source]

Bases: object

__init__(analysis_results, nside=32)[source]
write_map(filename)[source]
property map
property ra
property ra_healpix
property dec
class gbm_drm_gen.Palantir(result, nside=64, trigdat=None, poshist=None, time=0.0)[source]

Bases: object

__init__(result, nside=64, trigdat=None, poshist=None, time=0.0)[source]

View the 3ML BALROG results

Parameters
  • result – 3ML BALROG result

  • nside – power of 2

  • trigdat – optional trigdat files

  • time – time of observation

add_healpix_map(healpix_map, name, cmap)[source]
skymap(*dets, **kwargs)[source]
Parameters
  • dets – optional detectors

  • cmap – colormap for location

  • show_earth – show the earth points

  • width – no idea

  • fov – FOV of GBM detectors

Returns

figure

get_flux_upper_bound(ene_min, ene_max, percentile=95.0)[source]
property healpix_map
property balrog_map