Esempio n. 1
0
def main(arguments):
    parser = argparse.ArgumentParser(
        description='Number of timeseries to generate')
    parser.add_argument('ts', help="TimeSeries of interest", type=str)
    parser.add_argument('--n', help='Top N similar', type=int, default=1)
    parser.add_argument('--save',
                        help='Save Results',
                        type=bool,
                        default=False)
    parser.add_argument('--f',
                        help='Path to results folder',
                        type=str,
                        default='results.p')
    args = parser.parse_args(arguments)
    ts_name = args.ts
    n = args.n
    f = args.f
    save = args.save
    ts = pickle.load(open(ts_name + ".p", "rb"))
    ts_stand = util.stand(ts, ts.mean(), ts.std())
    vantage = pickle.load(open("ts_data/vantage_points.p", "rb"))
    if n == 1:
        closest_vantage, closest_distance = eval_closest_vantage(
            ts_stand, vantage)
        closest_in_all = in_radius_from_vantage(ts_stand, closest_vantage[0])
    else:
        closest_in_all = []
        for v in vantage:
            closest_in_all += in_radius_from_vantage(ts_stand, v)
        closest_in_all = list(set(closest_in_all))

    return_top(ts_stand, closest_in_all, n, save, f)
    def get(self, ident):
        '''Returns the time series stored under the identifier `ident`.
        
        Args: 
             `ident` (string): The identifier for the time series to retrieve.

        Raises: 
             KeyError: No time series was found under identifier `ident`.'''

        # First try to retrieve from cache
        try:
            ats = self._cache_get(ident)
        # Retrieve from storage if not in cache
        except:
            try:
                fname = '{}/{}.npy'.format(self._storage, ident)
                dstore = np.load(fname)
                ats = ArrayTimeSeries(dstore[0], dstore[1])
                self._cache_store(ident, ats)
            # Raise an exception if identifier not recognized
            except:
                raise KeyError(
                    'No time series was found associated with id `{}`'.format(
                        ident))

        return ats
    def __init__(self,
                 time_points=None,
                 data_points=None,
                 ident=None,
                 sm=None):
        '''Implements the SizedContainerTimeSeriesInterface using a StorageManager for storage.
           If no `ident` is supplied, identical time series will receive the same identifier.

            Args:
                `time_points` (sequence): A sequence of time points. Must have length equal to `data_points.`
                `data_points` (sequence): A sequence of data points. Must have length equal to `time_points.`
                `ident` (int or string): An identifier for the time series. 
                                         If it is already in use by the FileStorageManager, the existing SMTimeSeries will be overwritten. 
                                         If not supplied, an identifier will be generated from the hash of the data.
                `sm` (StorageManager): A storage manager to use for underlying storage. 
                                       If not supplied, the class storage manager will be used be default.
                     
            Returns:
                SMTimeSeries: A time series containing time and data points.'''

        if ident is None:
            ident = hash((tuple(time_points), tuple(data_points)))
        else:
            ident = str(ident)
        self._ident = ident

        if sm is None:
            if SMTimeSeries._fsm is None:
                SMTimeSeries._fsm = FileStorageManager()
            self._sm = SMTimeSeries._fsm
        else:
            self._sm = sm

        # Only store if we aren't initializing an empty object
        if time_points is not None and data_points is not None:
            self._sm.store(ident, ArrayTimeSeries(time_points, data_points))
Esempio n. 4
0
def load_ts_data(file_name):
    "load timeseries data form given file name"
    ts_raw_data = np.loadtxt(file_name, delimiter=' ')
    ts_data = ts.ArrayTimeSeries(ts_raw_data[:, 1], ts_raw_data[:, 0])
    return ts_data
Esempio n. 5
0
def tsmaker(m, s, j):
    t = np.arange(0.0, 1.0, 0.01)
    #v = norm.pdf(t, m, s) + j * np.random.randn(100)
    v = j * np.random.randn(100)
    return ts.TimeSeries(list(v), list(t))
Esempio n. 6
0
def stand(x, m, s):
    "standardize timeseries x by mean m and std deviation s"
    return ts.ArrayTimeSeries((x.values - m) / s, x.times)
Esempio n. 7
0
def random_ts(a):
    t = np.arange(0.0, 1.0, 0.01)
    v = a * np.random.random(100)
    return ts.TimeSeries(list(v), list(t))
Esempio n. 8
0
def random_ts(a):
    t = np.arange(0.0, 1.0, 0.01)
    v = a * np.random.random(100)
    return ts.ArrayTimeSeries(t, v)
Esempio n. 9
0
def tsmaker(m, s, j):
    t = np.arange(0.0, 1.0, 0.01)
    v = norm.pdf(t, m, s) + j * np.random.randn(100)
    return ts.ArrayTimeSeries(t, v)