예제 #1
0
def lightcurve_moments(ftimes, fmags, ferrs):
    '''This calculates the weighted mean, stdev, median, MAD, percentiles, skew,
    kurtosis, fraction of LC beyond 1-stdev, and IQR.

    Parameters
    ----------

    ftimes,fmags,ferrs : np.array
        The input mag/flux time-series with all non-finite elements removed.

    Returns
    -------

    dict
        A dict with all of the light curve moments calculated.

    '''

    ndet = len(fmags)

    if ndet > 9:

        # now calculate the various things we need
        series_median = npmedian(fmags)
        series_wmean = (npsum(fmags * (1.0 / (ferrs * ferrs))) /
                        npsum(1.0 / (ferrs * ferrs)))
        series_mad = npmedian(npabs(fmags - series_median))
        series_stdev = 1.483 * series_mad
        series_skew = spskew(fmags)
        series_kurtosis = spkurtosis(fmags)

        # get the beyond1std fraction
        series_above1std = len(fmags[fmags > (series_median + series_stdev)])
        series_below1std = len(fmags[fmags < (series_median - series_stdev)])

        # this is the fraction beyond 1 stdev
        series_beyond1std = (series_above1std + series_below1std) / float(ndet)

        # get the magnitude percentiles
        series_mag_percentiles = nppercentile(
            fmags, [5.0, 10, 17.5, 25, 32.5, 40, 60, 67.5, 75, 82.5, 90, 95])

        return {
            'median': series_median,
            'wmean': series_wmean,
            'mad': series_mad,
            'stdev': series_stdev,
            'skew': series_skew,
            'kurtosis': series_kurtosis,
            'beyond1std': series_beyond1std,
            'mag_percentiles': series_mag_percentiles,
            'mag_iqr': series_mag_percentiles[8] - series_mag_percentiles[3],
        }

    else:
        LOGERROR('not enough detections in this magseries '
                 'to calculate light curve moments')
        return None
예제 #2
0
def lightcurve_flux_measures(ftimes, fmags, ferrs, magsarefluxes=False):
    '''This calculates percentiles and percentile ratios of the flux.

    Parameters
    ----------

    ftimes,fmags,ferrs : np.array
        The input mag/flux time-series with all non-finite elements removed.

    magsarefluxes : bool
        If the `fmags` array actually contains fluxes, will not convert `mags`
        to fluxes before calculating the percentiles.

    Returns
    -------

    dict
        A dict with all of the light curve flux percentiles and percentile
        ratios calculated.

    '''

    ndet = len(fmags)

    if ndet > 9:

        # get the fluxes
        if magsarefluxes:
            series_fluxes = fmags
        else:
            series_fluxes = 10.0**(-0.4 * fmags)

        series_flux_median = npmedian(series_fluxes)

        # get the percent_amplitude for the fluxes
        series_flux_percent_amplitude = (npmax(npabs(series_fluxes)) /
                                         series_flux_median)

        # get the flux percentiles
        series_flux_percentiles = nppercentile(
            series_fluxes,
            [5.0, 10, 17.5, 25, 32.5, 40, 60, 67.5, 75, 82.5, 90, 95])
        series_frat_595 = (series_flux_percentiles[-1] -
                           series_flux_percentiles[0])
        series_frat_1090 = (series_flux_percentiles[-2] -
                            series_flux_percentiles[1])
        series_frat_175825 = (series_flux_percentiles[-3] -
                              series_flux_percentiles[2])
        series_frat_2575 = (series_flux_percentiles[-4] -
                            series_flux_percentiles[3])
        series_frat_325675 = (series_flux_percentiles[-5] -
                              series_flux_percentiles[4])
        series_frat_4060 = (series_flux_percentiles[-6] -
                            series_flux_percentiles[5])

        # calculate the flux percentile ratios
        series_flux_percentile_ratio_mid20 = series_frat_4060 / series_frat_595
        series_flux_percentile_ratio_mid35 = series_frat_325675 / series_frat_595
        series_flux_percentile_ratio_mid50 = series_frat_2575 / series_frat_595
        series_flux_percentile_ratio_mid65 = series_frat_175825 / series_frat_595
        series_flux_percentile_ratio_mid80 = series_frat_1090 / series_frat_595

        # calculate the ratio of F595/median flux
        series_percent_difference_flux_percentile = (series_frat_595 /
                                                     series_flux_median)
        series_percentile_magdiff = -2.5 * nplog10(
            series_percent_difference_flux_percentile)

        return {
            'flux_median': series_flux_median,
            'flux_percent_amplitude': series_flux_percent_amplitude,
            'flux_percentiles': series_flux_percentiles,
            'flux_percentile_ratio_mid20': series_flux_percentile_ratio_mid20,
            'flux_percentile_ratio_mid35': series_flux_percentile_ratio_mid35,
            'flux_percentile_ratio_mid50': series_flux_percentile_ratio_mid50,
            'flux_percentile_ratio_mid65': series_flux_percentile_ratio_mid65,
            'flux_percentile_ratio_mid80': series_flux_percentile_ratio_mid80,
            'percent_difference_flux_percentile': series_percentile_magdiff,
        }

    else:

        LOGERROR('not enough detections in this magseries '
                 'to calculate flux measures')
        return None
예제 #3
0
def lightcurve_flux_measures(ftimes, fmags, ferrs, magsarefluxes=False):
    '''
    This calculates percentiles of the flux.

    '''

    ndet = len(fmags)

    if ndet > 9:

        # get the fluxes
        if magsarefluxes:
            series_fluxes = fmags
        else:
            series_fluxes = 10.0**(-0.4 * fmags)

        series_flux_median = npmedian(series_fluxes)

        # get the percent_amplitude for the fluxes
        series_flux_percent_amplitude = (npmax(npabs(series_fluxes)) /
                                         series_flux_median)

        # get the flux percentiles
        series_flux_percentiles = nppercentile(
            series_fluxes,
            [5.0, 10, 17.5, 25, 32.5, 40, 60, 67.5, 75, 82.5, 90, 95])
        series_frat_595 = (series_flux_percentiles[-1] -
                           series_flux_percentiles[0])
        series_frat_1090 = (series_flux_percentiles[-2] -
                            series_flux_percentiles[1])
        series_frat_175825 = (series_flux_percentiles[-3] -
                              series_flux_percentiles[2])
        series_frat_2575 = (series_flux_percentiles[-4] -
                            series_flux_percentiles[3])
        series_frat_325675 = (series_flux_percentiles[-5] -
                              series_flux_percentiles[4])
        series_frat_4060 = (series_flux_percentiles[-6] -
                            series_flux_percentiles[5])

        # calculate the flux percentile ratios
        series_flux_percentile_ratio_mid20 = series_frat_4060 / series_frat_595
        series_flux_percentile_ratio_mid35 = series_frat_325675 / series_frat_595
        series_flux_percentile_ratio_mid50 = series_frat_2575 / series_frat_595
        series_flux_percentile_ratio_mid65 = series_frat_175825 / series_frat_595
        series_flux_percentile_ratio_mid80 = series_frat_1090 / series_frat_595

        # calculate the ratio of F595/median flux
        series_percent_difference_flux_percentile = (series_frat_595 /
                                                     series_flux_median)
        series_percentile_magdiff = -2.5 * nplog10(
            series_percent_difference_flux_percentile)

        return {
            'flux_median': series_flux_median,
            'flux_percent_amplitude': series_flux_percent_amplitude,
            'flux_percentiles': series_flux_percentiles,
            'flux_percentile_ratio_mid20': series_flux_percentile_ratio_mid20,
            'flux_percentile_ratio_mid35': series_flux_percentile_ratio_mid35,
            'flux_percentile_ratio_mid50': series_flux_percentile_ratio_mid50,
            'flux_percentile_ratio_mid65': series_flux_percentile_ratio_mid65,
            'flux_percentile_ratio_mid80': series_flux_percentile_ratio_mid80,
            'percent_difference_flux_percentile': series_percentile_magdiff,
        }

    else:

        LOGERROR('not enough detections in this magseries '
                 'to calculate flux measures')
        return None