data_persist.py
Go to the documentation of this file.
1 '''
2 ROS Anomaly Detector Framework
3 
4 Author:
5  Vedanth Narayanan
6 File:
7  Data Persistence class
8 Date:
9  15 May, 2018
10 
11 NOTE:
12  - Data persistence involves taking modified data and storing it.
13  - That data can easily be retrieved with this class.
14 
15 '''
16 
17 import numpy as np
18 import os
19 
20 class DataPersist(object):
21 
22 
23  def __init__(self):
24  pass
25 
26 
27  def __store_data_loc(self, name):
28  '''
29  Given a name of a file, returns location and name of where
30  the modified data is stored and retrieved from.
31  Used both of dumping and retrieving.
32  '''
33 
34  path_parts = name.split('.')[0].split('/')
35  file_name = path_parts[len(path_parts)-1]
36  path = ['mod_data' if x=='data' else x for x in path_parts[:-1]]
37  path = '/'.join(path)
38  loc = path + '/' + file_name + '.npz'
39 
40  if not os.path.exists(os.path.abspath(path)):
41  os.makedirs(os.path.abspath(path))
42 
43  return loc
44 
45 
46  def dump_data(self, name, x, y):
47  '''
48  Given name of csv file, x and y data is stored in the
49  mod_data/ directory.
50  '''
51 
52  loc = self.__store_data_loc(name)
53  np.savez(open(loc, 'w+'), x=x, y=y)
54 
55  print 'Saved to', loc
56 
57 
58  def retrieve_dumped_data(self, name):
59  '''
60  Given location and file, file data is retrieved.
61  '''
62 
63  loc = self.__store_data_loc(name)
64  data = np.load(loc)
65  x = data['x']
66  y = data['y']
67  data.close()
68 
69  return x, y
def dump_data(self, name, x, y)
Definition: data_persist.py:46


mh5_anomaly_detector
Author(s): Vedanth Narayanan
autogenerated on Mon Jun 10 2019 13:49:20