cosmogrb.utils package

Submodules

cosmogrb.utils.array_to_cmap module

cosmogrb.utils.array_to_cmap.array_to_cmap(values, cmap, use_log=False)[source]

Generates a color map and color list that is normalized to the values in an array. Allows for adding a 3rd dimension onto a plot

Parameters:
  • values – a list a values to map into a cmap
  • cmap – the mpl colormap to use
  • use_log – if the mapping should be done in log space

cosmogrb.utils.file_utils module

cosmogrb.utils.file_utils.file_existing_and_readable(filename)[source]
cosmogrb.utils.file_utils.if_directory_not_existing_then_make(directory)[source]

If the given directory does not exists, then make it :param directory: directory to check or make :return: None

cosmogrb.utils.file_utils.path_exists_and_is_directory(path)[source]
cosmogrb.utils.file_utils.sanitize_filename(filename, abspath=False)[source]
cosmogrb.utils.file_utils.within_directory(directory)[source]

cosmogrb.utils.fits_file module

class cosmogrb.utils.fits_file.FITSExtension(data_tuple, header_tuple)[source]

Bases: responsum.utils.fits_file.FITSExtension

cosmogrb.utils.hdf5_utils module

cosmogrb.utils.hdf5_utils.recursively_load_dict_contents_from_group(h5file, path)[source]

read a dictionary from and HDF5 file

Parameters:
  • h5file
  • path
Returns:

Return type:

cosmogrb.utils.hdf5_utils.recursively_save_dict_contents_to_group(h5file, path, dic)[source]

save a dictionary to an HDf5 file

Parameters:
  • h5file
  • path
  • dic
Returns:

Return type:

cosmogrb.utils.logging module

cosmogrb.utils.package_utils module

cosmogrb.utils.package_utils.copy_package_data(data_file)[source]
cosmogrb.utils.package_utils.get_path_of_data_dir()[source]
cosmogrb.utils.package_utils.get_path_of_data_file(data_file)[source]
cosmogrb.utils.package_utils.get_path_of_user_dir()[source]

Returns the path of the directory containing the user data (~/.cosmogrb)

Returns:an absolute path

cosmogrb.utils.response_file module

class cosmogrb.utils.response_file.EBOUNDS(energy_boundaries)[source]

Bases: cosmogrb.utils.fits_file.FITSExtension

class cosmogrb.utils.response_file.MATRIX(mc_energies, channel_energies, matrix)[source]

Bases: cosmogrb.utils.fits_file.FITSExtension

Represents the MATRIX extension of a response FITS file following the OGIP format :param mc_energies_lo: lower bound of MC energies (in keV) :param mc_energies_hi: hi bound of MC energies (in keV) :param channel_energies_lo: lower bound of channel energies (in keV) :param channel_energies_hi: hi bound of channel energies (in keV :param matrix: the redistribution matrix, representing energy dispersion effects

class cosmogrb.utils.response_file.RMF(mc_energies, ebounds, matrix, telescope_name, instrument_name)[source]

Bases: responsum.utils.fits_file.FITSFile

A RMF file, the OGIP format for a matrix representing energy dispersion effects.

class cosmogrb.utils.response_file.RSP(mc_energies, ebounds, matrix, telescope_name, instrument_name)[source]

Bases: responsum.utils.fits_file.FITSFile

A response file, the OGIP format for a matrix representing both energy dispersion effects and effective area, in the same matrix.

class cosmogrb.utils.response_file.SPECRESP_MATRIX(mc_energies, channel_energies, matrix)[source]

Bases: cosmogrb.utils.response_file.MATRIX

Represents the SPECRESP_MATRIX extension of a response FITS file following the OGIP format :param mc_energies_lo: lower bound of MC energies (in keV) :param mc_energies_hi: hi bound of MC energies (in keV) :param channel_energies_lo: lower bound of channel energies (in keV) :param channel_energies_hi: hi bound of channel energies (in keV :param matrix: the redistribution matrix, representing energy dispersion effects and effective area information

cosmogrb.utils.time_interval module

exception cosmogrb.utils.time_interval.IntervalsDoNotOverlap[source]

Bases: RuntimeError

exception cosmogrb.utils.time_interval.IntervalsNotContiguous[source]

Bases: RuntimeError

class cosmogrb.utils.time_interval.TimeInterval(start, stop, counts=None, dead_time=0, swap_if_inverted=False)[source]

Bases: object

counts
dead_time
exposure
intersect(interval)[source]

Returns a new time interval corresponding to the intersection between this interval and the provided one.

Parameters:interval (Interval) – a TimeInterval instance
Returns:new interval covering the intersection

:raise IntervalsDoNotOverlap : if the intervals do not overlap

merge(interval)[source]

Returns a new interval corresponding to the merge of the current and the provided time interval. The intervals must overlap.

Parameters:interval – a TimeInterval instance :type interval : Interval
Returns:a new TimeInterval instance
mid_point
overlaps_with(interval)[source]

Returns whether the current time interval and the provided one overlap or not

Parameters:interval (Interval) – a TimeInterval instance
Returns:True or False
rate
start
stop
to_string()[source]

returns a string representation of the time interval that is like the argument of many interval reading funcitons

Returns:
width
class cosmogrb.utils.time_interval.TimeIntervalSet(list_of_intervals=())[source]

Bases: object

A set of intervals

absolute_start

the minimum of the start times :return:

absolute_stop

the maximum of the stop times :return:

argsort()[source]

Returns the indices which order the set

Returns:
bin_stack
get a stacked view of the bins [[start_1,stop_1 ],
[start_2,stop_2 ]]
Returns:
containing_bin(value)[source]

finds the index of the interval containing :param value: :return:

containing_interval(start, stop, inner=True, as_mask=False)[source]

returns either a mask of the intervals contained in the selection or a new set of intervals within the selection. NOTE: no sort is performed

Parameters:
  • start – start of interval
  • stop – stop of interval
  • inner – if True, returns only intervals strictly contained within bounds, if False, returns outer bounds as well
  • as_mask – if you want a mask or the intervals
Returns:

counts
edges

return an array of time edges if contiguous :return:

exposures
extend(list_of_intervals)[source]
classmethod from_list_of_edges(edges)[source]

Builds a IntervalSet from a list of time edges:

edges = [-1,0,1] -> [-1,0], [0,1]

Parameters:edges
Returns:
classmethod from_starts_and_stops(starts, stops, counts=None, dead_time=None)[source]

Builds a TimeIntervalSet from a list of start and stop times:

start = [-1,0] -> [-1,0], [0,1] stop = [0,1]

Parameters:
  • starts
  • stops
Returns:

is_contiguous(relative_tolerance=1e-05)[source]

Check whether the time intervals are all contiguous, i.e., the stop time of one interval is the start time of the next

Returns:True or False
is_sorted

Check whether the time intervals are sorted :return: True or False

merge_intersecting_intervals(in_place=False)[source]

merges intersecting intervals into a contiguous intervals

Returns:
mid_points
plot_intervals(as_rates=True, ax=None, **kwargs)[source]

plot the intervals as rates or counts

Parameters:
  • as_rates
  • ax
Returns:

Return type:

pop(index)[source]
rates
sort()[source]

Returns a sorted copy of the set (sorted according to the tstart of the time intervals)

Returns:
starts

Return the starts fo the set

Returns:list of start times
stops

Return the stops of the set

Returns:
to_string()[source]

returns a set of string representaitons of the intervals :return:

widths

cosmogrb.utils.tte_file module

class cosmogrb.utils.tte_file.EBOUNDS(det_name, tstart, tstop, trigger_time, ra, dec, channel, emin, emax)[source]

Bases: cosmogrb.utils.fits_file.FITSExtension

class cosmogrb.utils.tte_file.EVENTS(det_name, tstart, tstop, trigger_time, ra, dec, pha, time)[source]

Bases: cosmogrb.utils.fits_file.FITSExtension

class cosmogrb.utils.tte_file.GTI(det_name, tstart, tstop, trigger_time, ra, dec)[source]

Bases: cosmogrb.utils.fits_file.FITSExtension

class cosmogrb.utils.tte_file.TTEFile(det_name, tstart, tstop, trigger_time, ra, dec, channel, emin, emax, pha, time)[source]

Bases: responsum.utils.fits_file.FITSFile

Module contents