Tutorial of Pytff

First lets import the required modules


In [2]:
import os
import random

import numpy as np

import pytff
import pytff.datasets as ds

In [3]:
tff = pytff.TFFCommand(tff_path="path/to/tff")
tff


Out[3]:
<Command 'path/to/tff'> -> /tmp/tmpmSHAWa_tff

The main method of TFFCommand instance is analize


In [4]:
help(tff.analyze)


Help on method analyze in module pytff.core:

analyze(self, periods, times, values, ntbin=300, nmin=10, mindp=10, snr1min=10.0, nmatch=10, dph=1e-05, asig=555.0, jfit=-1) method of pytff.core.TFFCommand instance
    Run the tff analysis.
    
    Params
    ------
    
    periods: 1d-array-like
        An array with all the periods of the sources.
    times: 2d-array-like
        Every row represents all the times of one source
    values: 2d-array-like
        Every row represents all the magnitudes of one source
    ntbin: int
        number of bins of the templates (default: 300)
    nmin: int
        minimum number of the template data points (default: 10)
    mindp: int
        minimum number of the target data points (default: 10)
    snr1min: float
        minimum SNR1 of the template time series (default: 10.0)
    nmatch: int
        number of the top best matching templates to be printed
        (default: 10)
    dph: float
        templates are fitted with dph accuracy in phase (default: 0.00001)
    asig: float
        sigma clipping parameter for template and Fourier fits
        (default: 555.0)
    jfit: int
        template polynomial degree (if jfit < 0, then optimized)
        (default: -1)
    
    The i-nth row of times must be has the same number of values i-nth row
    of values.
    
    Return
    ------
    
    tff_data: ndarray
        Fourier decompositions, resulting from the TFF analysis.
        Fields:
    
        -   **src_idx:** In which index of periods, times and values is
            the data used for generate this fourier decomposition.
        -   **period:** The perdiod
        -   **epoch:** The epoch
        -   **average_magnitude:** average of values
        -   **N_data_point:** Size of time and value
        -   **sigma_obs_fit:** std deviation
        -   **A_1, phi_1, A_2, phi_2, ..., A_15, phi_15** The fourier
            components
    
        Form of the Fourier decomposition:
    
        ::
    
            A_0 + A_1*sin(2*pi*(t(i)-Epoch)*1/Period+Phi_1)
                  A_2*sin(2*pi*(t(i)-Epoch)*2/Period+Phi_2) +
                  A_3*sin(2*pi*(t(i)-Epoch)*3/Period+Phi_3) + ...
    
    dff_data: ndarray
        Fourier decompositions, resulting from the DFF analysis.
        Same fields as *tff_data*
    
    match_data: ndarray
        List of target/template matches. You gona have ``nmatch`` rows for
        every source.
        Fields:
    
        -   **src_idx:** In which index of periods, times and values is
            the data used for generate this match.
        -   **match_rank:** value in between 1 and nmatch that represent
            the importance of this match with the source (lower is better)
        -   **src_period:** The period of the source.
        -   **src_sigma_obs_fit:** std deviation of the source.
        -   **order_of_the_template**
        -   **snr:** is the signal-to-noise ratio of the template-fitted
            light curve. ``SNR=AMP/(sigma/sqrt(n))``, where 'AMP' is the
            total amplitude of the best fitting template, 'sigma' is the
            standard deviation of the residuals between the target and
            the template, 'n' is the number of the target data points.
        -   **template_id**
        -   **template_period**
        -   **template_sigma_obs_fit:** std deviation of the templates.
        -   **src_N_data_point:** Size of time and value.
        -   **template_phi_31**
    
    For more info please see:
    http://www.konkoly.hu/staff/kovacs/tff_in_out.inf

Fake Example

Load The Data


In [5]:
periods = np.random.rand(10)
times = np.random.rand(10, 50)
values = np.random.rand(*times.shape)

In [6]:
tff_data, dff_data, match_data = tff.analyze(periods, times, values)

In [7]:
match_data[["src_idx", "template_id"]]


Out[7]:
array([(0, 'M5 V77'), (0, 'M5 V87'), (0, 'oCen V206'), (0, 'M3 V124'),
       (0, 'FW Lup'), (0, 'M3 V62'), (0, 'M2 V10'), (0, 'oCen V170'),
       (0, 'Rup106 V13'), (0, 'M5 V75'), (1, 'FW Lup'), (1, 'M3 V62'),
       (1, 'M3 V124'), (1, 'M5 V87'), (1, 'Rup106 V18'), (1, 'M68 V30'),
       (1, 'M5 V75'), (1, 'Rup106 V16'), (1, 'M5 V77'), (1, 'Rup106 V13'),
       (2, 'M5 V87'), (2, 'M3 V124'), (2, 'FW Lup'), (2, 'Rup106 V13'),
       (2, 'M68 V30'), (2, 'Rup106 V18'), (2, 'M3 V62'), (2, 'CN Lyr'),
       (2, 'M5 V75'), (2, 'Rup106 V16'), (3, 'M3 V124'), (3, 'M5 V87'),
       (3, 'Rup106 V18'), (3, 'M68 V30'), (3, 'FW Lup'), (3, 'Rup106 V13'),
       (3, 'M3 V62'), (3, 'Rup106 V16'), (3, 'M5 V75'), (3, 'Rup106 V1'),
       (4, 'M5 V87'), (4, 'M3 V124'), (4, 'FW Lup'), (4, 'M3 V62'),
       (4, 'M68 V30'), (4, 'Rup106 V13'), (4, 'Rup106 V18'), (4, 'M5 V75'),
       (4, 'M5 V77'), (4, 'Rup106 V16'), (5, 'M5 V87'), (5, 'M3 V124'),
       (5, 'Rup106 V13'), (5, 'FW Lup'), (5, 'M68 V30'), (5, 'Rup106 V18'),
       (5, 'M3 V62'), (5, 'Rup106 V16'), (5, 'CN Lyr'), (5, 'M5 V75'),
       (6, 'M5 V87'), (6, 'M3 V124'), (6, 'FW Lup'), (6, 'Rup106 V18'),
       (6, 'M68 V30'), (6, 'Rup106 V13'), (6, 'M3 V62'), (6, 'Rup106 V16'),
       (6, 'M5 V75'), (6, 'M5 V77'), (7, 'M5 V87'), (7, 'M3 V124'),
       (7, 'Rup106 V13'), (7, 'M68 V30'), (7, 'Rup106 V18'), (7, 'FW Lup'),
       (7, 'M3 V62'), (7, 'Rup106 V16'), (7, 'CN Lyr'), (7, 'M5 V75'),
       (8, 'M3 V124'), (8, 'M5 V87'), (8, 'FW Lup'), (8, 'M68 V30'),
       (8, 'Rup106 V18'), (8, 'M3 V62'), (8, 'Rup106 V13'),
       (8, 'Rup106 V16'), (8, 'M5 V75'), (8, 'CN Lyr'), (9, 'M5 V87'),
       (9, 'M3 V124'), (9, 'FW Lup'), (9, 'M68 V30'), (9, 'Rup106 V13'),
       (9, 'Rup106 V18'), (9, 'M3 V62'), (9, 'Rup106 V16'), (9, 'M5 V75'),
       (9, 'oCen V206')], 
      dtype=[('src_idx', '<i8'), ('template_id', 'S255')])

Real Data Example

Load The Data

Real Data Example

Load The Data


In [7]:
data = np.loadtxt(ds.get("single", "ogle.dat"))
data


Out[7]:
array([[ 2088.91535,    18.868  ],
       [ 2090.87535,    19.54   ],
       [ 2103.92958,    18.704  ],
       ..., 
       [ 4853.56146,    19.116  ],
       [ 4854.56497,    18.974  ],
       [ 4864.5617 ,    18.835  ]])

Reformat the data for pytff


In [8]:
# this value is the real period of this star (i don't remember the original id
# is necesary to create an array of one element for only one star
periods = np.array([0.6347522])

# convert the first column of the data into a first row of the 2d array
times = data[:,0].reshape(1, len(data[:,0]))

# convert the second column of the data into a first row of the 2d array
values = data[:,1].reshape(1, len(data[:,1]))

In [9]:
tff_data, dff_data, match_data = tff.analyze(periods, times, values)

In [10]:
tff_data


Out[10]:
array([ (0, 0.63475, 0.0, 19.034, 654.0, 0.2288, 0.1481, 4.1906, 0.0493, 4.8528, 0.0192, 5.9558, 0.005, 1.1047, 0.0043, 2.6569, 0.0049, 3.4054, 0.0036, 4.5121, 0.0034, 5.5922, 0.0017, 0.0709, 0.0015, 0.5639, 0.0, 0.2353, 0.0, 0.0276, 0.0, 0.0846, 0.0, 3.8838, 0.0, 0.6126)], 
      dtype=[('src_idx', '<i8'), ('period', '<f8'), ('epoch', '<f8'), ('average_magnitude', '<f8'), ('N_data_point', '<f8'), ('sigma_obs_fit', '<f8'), ('A_1', '<f8'), ('phi_1', '<f8'), ('A_2', '<f8'), ('phi_2', '<f8'), ('A_3', '<f8'), ('phi_3', '<f8'), ('A_4', '<f8'), ('phi_4', '<f8'), ('A_5', '<f8'), ('phi_5', '<f8'), ('A_6', '<f8'), ('phi_6', '<f8'), ('A_7', '<f8'), ('phi_7', '<f8'), ('A_8', '<f8'), ('phi_8', '<f8'), ('A_9', '<f8'), ('phi_9', '<f8'), ('A_10', '<f8'), ('phi_10', '<f8'), ('A_11', '<f8'), ('phi_11', '<f8'), ('A_12', '<f8'), ('phi_12', '<f8'), ('A_13', '<f8'), ('phi_13', '<f8'), ('A_14', '<f8'), ('phi_14', '<f8'), ('A_15', '<f8'), ('phi_15', '<f8')])

In [11]:
tff_data[0] # our first and only source


Out[11]:
(0, 0.63475, 0.0, 19.034, 654.0, 0.2288, 0.1481, 4.1906, 0.0493, 4.8528, 0.0192, 5.9558, 0.005, 1.1047, 0.0043, 2.6569, 0.0049, 3.4054, 0.0036, 4.5121, 0.0034, 5.5922, 0.0017, 0.0709, 0.0015, 0.5639, 0.0, 0.2353, 0.0, 0.0276, 0.0, 0.0846, 0.0, 3.8838, 0.0, 0.6126)

In [12]:
tff_data["period"]


Out[12]:
array([ 0.63475])

In [13]:
match_data


Out[13]:
array([ (0, 1, 0.63475, 0.2288, 0, 9.5541, 'M3 V124', 0.75243, 0.2288, 654, 5.9504),
       (0, 2, 0.63475, 0.2288, 0, 9.5541, 'M5 V87', 0.73921, 0.2299, 654, 6.0107),
       (0, 3, 0.63475, 0.2288, 0, 9.5541, 'Rup106 V13', 0.65315, 0.2345, 654, 4.9328),
       (0, 4, 0.63475, 0.2288, 0, 9.5541, 'FW Lup', 0.48417, 0.2347, 654, 5.7156),
       (0, 5, 0.63475, 0.2288, 0, 9.5541, 'M68 V30', 0.73364, 0.235, 654, 5.3584),
       (0, 6, 0.63475, 0.2288, 0, 9.5541, 'Rup106 V18', 0.63547, 0.2383, 654, 5.4264),
       (0, 7, 0.63475, 0.2288, 0, 9.5541, 'M3 V62', 0.65241, 0.2464, 654, 5.6235),
       (0, 8, 0.63475, 0.2288, 0, 9.5541, 'Rup106 V16', 0.62851, 0.2501, 654, 5.2816),
       (0, 9, 0.63475, 0.2288, 0, 9.5541, 'CN Lyr', 0.41138, 0.2563, 654, 5.5319),
       (0, 10, 0.63475, 0.2288, 0, 9.5541, 'M5 V75', 0.68547, 0.2574, 654, 5.6388)], 
      dtype=[('src_idx', '<i8'), ('match_rank', '<i8'), ('src_period', '<f8'), ('src_sigma_obs_fit', '<f8'), ('order_of_the_template', '<i8'), ('snr', '<f8'), ('template_id', 'S255'), ('template_period', '<f8'), ('template_sigma_obs_fit', '<f8'), ('src_N_data_point', '<i8'), ('template_phi_31', '<f8')])

In [ ]: