How to use the stingray.events.EventList function in stingray

To help you get started, we’ve selected a few stingray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github StingraySoftware / dave / src / main / python / utils / dataset_helper.py View on Github external
except:
            dataset.tables["EVENTS"].columns["PHA"].values = \
                np.zeros(len(dataset.tables["EVENTS"].columns[CONFIG.TIME_COLUMN].values),
                         dtype=int)
            logging.warn("PHA column will be empty")

    # Extract axis values
    time_data = np.array(dataset.tables["EVENTS"].columns[CONFIG.TIME_COLUMN].values)
    pha_data = np.array(dataset.tables["EVENTS"].columns["PHA"].values)

    # Extract GTIs
    gti = get_stingray_gti_from_gti_table (dataset.tables["GTI"])

    # Returns the EventList
    if len(gti) > 0:
        return EventList(time_data, gti=gti, pi=pha_data)
    else:
        return EventList(time_data, pi=pha_data)
github StingraySoftware / dave / src / main / python / utils / dave_reader.py View on Github external
from stingray.events import EventList
    from stingray.crossspectrum import Crossspectrum
    from hendrics.io import get_file_type
    from stingray.io import _retrieve_pickle_object

    # This will return an EventList, a light curve, a Powerspectrum, ...
    # depending on the contents of the file
    try:
        ftype, contents = get_file_type(fname)
    except:
        contents = _retrieve_pickle_object(fname)

    if isinstance(contents, Lightcurve):
        return DataSet.get_lightcurve_dataset_from_stingray_Lightcurve(contents)

    elif isinstance(contents, EventList):
        return DataSet.get_eventlist_dataset_from_stingray_Eventlist(contents)

    # This also work for Powerspectrum and AveragedCrosspowerspectrum, clearly
    elif isinstance(contents, Crossspectrum):
        logging.error("Unsupported intermediate file type: Crossspectrum")

    else:
        logging.error("Unsupported intermediate file type: %s" % type(stingray_object).__name__)

    return None
github StingraySoftware / dave / src / main / python / utils / dave_engine.py View on Github external
if len(events_table.columns[CONFIG.TIME_COLUMN].values) > 0:
                min_time = events_table.columns[CONFIG.TIME_COLUMN].values[0]
                max_time = events_table.columns[CONFIG.TIME_COLUMN].values[len(events_table.columns[CONFIG.TIME_COLUMN].values) - 1]
                duration = [(max_time - min_time)]

                if "E" in events_table.columns:

                    pds, lc, gti = create_power_density_spectrum(src_destination, bck_destination, gti_destination,
                                                   filters, axis, dt, nsegm, segm_size, norm, pds_type, df)
                    if pds:

                        if not math.isclose(dt, lc.dt, abs_tol=0.001):
                            warnmsg = ["@WARN@Overriden Bin Size: " + str(lc.dt)]

                        #Preapares the eventlist with energies and gtis
                        event_list = EventList()
                        event_list.time = np.array(events_table.columns[CONFIG.TIME_COLUMN].values)
                        event_list.ncounts = len(event_list.time)
                        event_list.gti = gti
                        event_list.energy = np.array(events_table.columns["E"].values)

                        # Calculates the energy range
                        if energy_range[0] < 0:
                            min_energy = min(event_list.energy)
                        else:
                            min_energy = energy_range[0]

                        if energy_range[1] >= min_energy:
                            max_energy = energy_range[1]
                        else:
                            max_energy = max(event_list.energy)
github StingraySoftware / dave / src / main / python / utils / dave_engine.py View on Github external
def get_white_noise_offset (event_arr, gti, dt, pds_type, segm_size, df):
    white_noise_offset = 0.0
    evt_list = EventList(event_arr[:,0], pi=event_arr[:,1])
    if evt_list and evt_list.ncounts > 1:
        if (evt_list.time[evt_list.ncounts - 1] - evt_list.time[0]) >= dt:

            lc = evt_list.to_lc(dt)
            if lc and np.sqrt(lc.meancounts * lc.meancounts) > 0:

                if not gti:
                    gti = lc.gti

                if segm_size > lc.tseg:
                    segm_size = lc.tseg
                    logging.warn("get_white_noise_offset: segmsize bigger than lc.duration, lc.duration applied instead.")

                pds = None
                if pds_type == 'Sng':
                    pds = Powerspectrum(lc, norm='leahy', gti=gti)
github StingraySoftware / dave / src / main / python / utils / dataset_helper.py View on Github external
np.zeros(len(dataset.tables["EVENTS"].columns[CONFIG.TIME_COLUMN].values),
                         dtype=int)
            logging.warn("PHA column will be empty")

    # Extract axis values
    time_data = np.array(dataset.tables["EVENTS"].columns[CONFIG.TIME_COLUMN].values)
    pha_data = np.array(dataset.tables["EVENTS"].columns["PHA"].values)

    # Extract GTIs
    gti = get_stingray_gti_from_gti_table (dataset.tables["GTI"])

    # Returns the EventList
    if len(gti) > 0:
        return EventList(time_data, gti=gti, pi=pha_data)
    else:
        return EventList(time_data, pi=pha_data)
github StingraySoftware / dave / src / main / python / utils / dave_engine.py View on Github external
max_energy = max(event_list[:,1]) - min_energy

                    event_list = event_list[ (max_energy>event_list[:,1]) & (event_list[:,1]>min_energy) ]

                    time_step = duration[0] / nsegm

                    for i in range(nsegm):

                        time_low = min_energy + (i * time_step)
                        time_high = time_low + time_step

                        try:
                            filtered_event_list = event_list[ (time_high>event_list[:,0]) & (event_list[:,0]>time_low) ]
                            if (len(filtered_event_list) > 0):

                                evt_list = EventList(filtered_event_list[:,0], pi=filtered_event_list[:,1])
                                if evt_list and evt_list.ncounts > 1:

                                    if (evt_list.time[evt_list.ncounts - 1] - evt_list.time[0]) >= dt:

                                        lc = evt_list.to_lc(dt)
                                        if lc and np.sqrt(lc.meancounts * lc.meancounts) > 0:

                                            rms, rms_err = 0, 0

                                            gti = base_gti
                                            if not gti:
                                                gti = lc.gti

                                            pds = Powerspectrum(lc, norm='frac', gti=gti)
                                            if pds:
github StingraySoftware / dave / src / main / python / utils / dave_engine.py View on Github external
energy_step = energy_range / n_bands

                    for i in range(n_bands):

                        energy_low = min_energy + (i * energy_step)
                        energy_high = energy_low + energy_step

                        energy_arr.extend([(energy_low + energy_high) / 2])

                        rms, rms_err = 0, 0

                        try:
                            filtered_event_list = event_list[ (energy_high>event_list[:,1]) & (event_list[:,1]>energy_low) ]
                            if (len(filtered_event_list) > 0):

                                evt_list = EventList(filtered_event_list[:,0], pi=filtered_event_list[:,1])
                                if evt_list and evt_list.ncounts > 1:

                                    if (evt_list.time[evt_list.ncounts - 1] - evt_list.time[0]) >= dt:

                                        lc = evt_list.to_lc(dt)
                                        if lc and np.sqrt(lc.meancounts * lc.meancounts) > 0:

                                            gti = base_gti
                                            if not gti:
                                                gti = lc.gti

                                            if segm_size > lc.tseg:
                                                segm_size = lc.tseg
                                                logging.warn("get_rms_spectrum: range: " + str(energy_low) + " to " + str(energy_high) + ", segmsize bigger than lc.duration, lc.duration applied instead.")

                                            pds = None