def read_data(self, filename): count = 0 #fields = [['name', 'RA', 'type1','type3', 'mag1', 'mag3', 'T1', 'P_orb', 'P3', 'EB', 'Spectr2', 'M1_M2', 'Incl', 'M1', 'M2'], #['Alt_name', 'DEC', 'type2','type4', 'mag2', 'mag4', 'T2', 'P2', 'P4', 'SB', 'Spectr1', 'e_M1_M2', 'e_Incl', 'e_M1', 'e_M2']] fields = ['name', 'alias', 'flag1', 'flag2', 'ra', 'dec', 'type1', 'type2', 'type3', 'type4', 'mag1', 'mag2', 'mag3', 'mag4', 'T1', 'T2', 'P0', 'P2', 'P3', 'P4', 'EB', 'SB', 'spectr2', 'spectr1', 'q', 'q_E', 'Incl', 'Incl_E', 'M1', 'M1_E', 'M2', 'M2_E'] data = [] with open(filename,'r') as fp: datalines = itt.filterfalse( lambda s: s.startswith(('\n','-')), fp ) header = [next(datalines), next(datalines)]#consume(datalines, 2) #header splitter = lambda line: map( str.strip, line.strip('\n|\r').split('|') ) for i, lpair in enumerate( grouper(datalines, 2) ): data.append( interleave( *map( splitter, lpair ) ) ) #data.append( dat ) #Interleaving data and fields (every 2 lines refer to a single catalogue object) #data = [interleave(*s) for s in zip(*data)] #fields = interleave(fields) print('Data for %i objects successfully read.\n\n' %(i+1)) return np.array(fields), np.array(data).T
def mask2intervals(a, mask=None): '''Retrun index tuples of contiguous masked values.''' if mask is None: mask = a.mask #NOTE: If a is a masked array, this function will return masked values!!! if ~np.any(mask): return () from recipes.iter import interleave w, = np.where(mask) l1 = w - np.roll(w,1) > 1 l2 = np.roll(w,-1) -w > 1 idx = [w[0]] + interleave(w[l2], w[l1]) + [w[-1]] return a[idx].reshape(-1,2)