def readData(indict): """ Takes as input a dictionary with paths to data as keys, and the name of the field to select as values. Returns a record array with the field names as keys populated by the data in the file located at the path provided """ print(indict) data = None paths = indict.keys() feats = [f for f in flatten(indict.values())] dt = np.dtype([(f, float) for f in feats]) print(dt) for i, path in enumerate(paths): #Check to see what type of reader we need if ('delta' in indict[path]) and ('hlist' in str(path)): d = readHaloRnn(path) elif 'delta' in indict[path]: if '*' in path: files = glob(path) for j,f in enumerate(files): if j==0: d = readPartRnn(f) else: gd = readPartRnn(f) d = np.hstack((d,gd)) else: d = readPartRnn(path) elif 'hlist' in str(path): d = readHL(path, fields = indict[path]) elif 'z' in indict[path]: if i==0: paths.append(path) continue d = np.zeros(len(d), dtype=np.dtype([('z',float)])) d['z']+=path else: print("""This feature is not currently handled, if you would like to use it, please add a new i/o fuction """) return None if data==None: data = np.ndarray(len(d),dtype=dt) data_view = data.view(float).reshape(len(data), -1) #Add data from this path to the rec array #have to use views to change multiple columns of #rec array ii = np.ndarray(len(indict[path]), dtype=int) for i in range(len(ii)): ii[i] = np.where(np.array(dt.names)==indict[path][i])[0][0] data_view[:,ii] = d[indict[path]].view(np.float).reshape(len(d),-1) return data
def loadHalos(self): self.halos = readHL(self.hlistpath, fields=self.fields)