How to use the stingray.AveragedPowerspectrum 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 / dave_engine.py View on Github external
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)
                else:
                    pds = AveragedPowerspectrum(lc=lc, segment_size=segm_size, norm='leahy', gti=gti)

                if pds:

                    if df > 0:
                        pds = pds.rebin(df=df)

                    num_tries = 0
                    while white_noise_offset <= 0.0 and num_tries < 5:
                        amp, x0, fwhm, wno = ModelHelper.fit_data_with_lorentz_and_const(pds.freq, pds.power)
                        white_noise_offset = wno
                        num_tries += 1

    return white_noise_offset
github StingraySoftware / dave / src / main / python / utils / dave_engine.py View on Github external
logging.warn("Can't create lightcurve or is empty")
        return None, None, None

    # Prepares GTI if passed
    gti = load_gti_from_destination (gti_destination)
    if not gti:
        logging.debug("External GTIs not loaded using defaults")
        gti = lc.gti

    # Creates the power density spectrum
    logging.debug("Create power density spectrum")

    if pds_type == 'Sng':
        pds = Powerspectrum(lc, norm=norm, gti=gti)
    else:
        pds = AveragedPowerspectrum(lc=lc, segment_size=segm_size, norm=norm, gti=gti)

    if pds:
        if df > 0:
            pds = pds.rebin(df=df)
        #pds = rebin_spectrum_if_necessary(pds)
    else:
        logging.warn("Can't create power spectrum")

    return pds, lc, gti
github StingraySoftware / dave / src / main / python / utils / dave_engine.py View on Github external
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
                                            if pds_type == 'Sng':
                                                pds = Powerspectrum(lc, norm=norm, gti=gti)
                                            else:
                                                pds = AveragedPowerspectrum(lc=lc, segment_size=segm_size, norm=norm, gti=gti)

                                            if pds:

                                                if df > 0:
                                                    pds = pds.rebin(df=df)

                                                #amp, x0, fwhm, white_noise_offset = ModelHelper.fit_data_with_lorentz_and_const(pds.freq, pds.power)
                                                #logging.info("get_rms_spectrum: amp: " + str(amp) + ", x0: " + str(x0) + ", fwhm: " + str(fwhm) + ", white_noise: " + str(white_noise))

                                                if freq_range[0] < 0:
                                                    freq_low = min(pds.freq)
                                                else:
                                                    freq_low = freq_range[0]

                                                if freq_min_max[0] >= 0:
                                                    freq_min_max[0] = min([freq_min_max[0], freq_low])
github StingraySoftware / dave / src / main / python / utils / dave_engine.py View on Github external
#logging.debug('get_bootstrap_results N: ' + str(N))

                models_params = []
                powers = []

                for i in range(n_iter):
                    try:
                        the_simulator = simulator.Simulator(N=N, dt=dt, mean=mean,
                                                             rms=rms, red_noise=red_noise, random_state=seed)

                        sim_lc = the_simulator.simulate(fit_model)

                        if pds_type == 'Sng':
                            sim_pds = Powerspectrum(sim_lc, norm=norm, gti=gti)
                        else:
                            sim_pds = AveragedPowerspectrum(lc=sim_lc, segment_size=segm_size, norm=norm, gti=gti)

                        if sim_pds:

                            if df > 0:
                                pds = pds.rebin(df=df)

                            #sim_pds = rebin_spectrum_if_necessary(sim_pds)

                            parest, res = fit_powerspectrum(sim_pds, fit_model, starting_pars,
                                            max_post=False, priors=None, fitmethod="L-BFGS-B")

                            models_params.append(res.p_opt)
                            powers.append(sim_pds.power)

                        else:
                            logging.warn(ExHelper.getException('get_bootstrap_results: cant create powerspectrum for i: ' + str(i)))