Esempio n. 1
0
def load_external_ts(filepath):
    """
    Loads space delimited time series text file from disk to be searched on.

    Args:
        filepath: path to time series file
    Returns:
        A 100 point interpolated ArrayTimeSeries object for times between 0 and 1.
    Notes:
        - Only considers the first two columns of the text file (other columns are discarded)
        - Only evaluates time values between 0 and 1
        - First column is presumed to be times and second column is presumed to be light curve values.
    """
    data = load_nparray(filepath)
    data = data[:, :2]  # truncate to first 2 cols

    # Remove rows with duplicate time values (if they exist) and resorts to ensure ts in ascending order
    _, indices = np.unique(data[:, 0], return_index=True)
    data = data[indices, :]

    times, values = data.T
    full_ts = ats.ArrayTimeSeries(times=times, values=values)
    interpolated_ats = full_ts.interpolate(
        np.arange(0.0, 1.0, (1.0 / TS_LENGTH)))
    return interpolated_ats
Esempio n. 2
0
def load_ts(ts_fname):
    """Helper to load previously generated ts file from disk"""
    if ts_fname.startswith("ts-"):
        filepath = LIGHT_CURVES_DIR + ts_fname
        data = load_nparray(filepath)
        times, values = data.T
        return ats.ArrayTimeSeries(times=times, values=values)
    else:
        raise ValueError("'%s' does not appear to be a time series file" %
                         ts_fname)
Esempio n. 3
0
def load_ts(LIGHT_CURVES_DIR):
    """Loads time series text files; returns dict keyed to filename"""
    timeseries_dict = {}
    for file in os.listdir(LIGHT_CURVES_DIR):
        if file.startswith("ts-") and file.endswith(".txt"):
            filepath = LIGHT_CURVES_DIR + file
            data = np.loadtxt(filepath)
            times, values = data.T
            ts = ats.ArrayTimeSeries(times=times, values=values)
            timeseries_dict[file] = ts
    return timeseries_dict
Esempio n. 4
0
def random_ts(jitter,length = 100):
    """
    Creates uniform random array time series object.

    Args:
        jitter: how much variation to data points should have. (A value of zero is basically a straight line.)
        length: Length of the time series. Defaults to 100 values.
    Returns:
        An array time series object.

    """
    times = np.arange(0.0, 1.0, (1.0 / length))
    values = jitter*np.random.random(100)
    return ats.ArrayTimeSeries(times=times, values=values)
Esempio n. 5
0
def tsmaker(mean, scale, jitter, length = 100):
    """
    Creates array time series object based on the normal distribution PDF.

    Args:
        mean: center of distribution
        scale: variance/spread of distribution.
        jitter: how much uniform-random variation is added on top of the distribution
        length: Length of the time series. (Defaults to 100 values)
    Returns:
        An array time series object.

    """
    times = np.arange(0.0, 1.0, (1.0 / length))
    values = norm.pdf(times, mean, scale) + jitter*np.random.randn(100)
    return ats.ArrayTimeSeries(times=times, values=values)
Esempio n. 6
0
def standardize(ts):
    """standardize timeseries ts by its mean and std deviation"""
    stand_vals = (ts.values() - ts.mean())/ts.std()
    return ats.ArrayTimeSeries(times=ts.times(), values=stand_vals)