def matchdf(df1, df2, ra1, de1, ra2, de2): if len(df1)<len(df2): prim=df1 primname=[ra1,de1] sec=df2 secname=[ra2,de2] else: prim=df2 primname=[ra2,de2] sec=df1 secname=[ra1,de1] colnames=prim.columns.values.tolist()+sec.columns.values.tolist() new_df=df(columns=colnames) coord=sc(prim[primname[0]], prim[primname[1]], unit='deg') for i in sec.index.values: t=sc(sec[secname[0]].values[i],sec[secname[1]].values[i], unit='deg') matches, dist = mc(t,coord,3.0,0) print matches if matches and len(matches)>0: tempdf=df([prim.values[int(matches[0])].tolist()+sec.values[i].tolist()],columns=colnames) #print tempdf[[ra1,de1,ra2,de2]] matches=None new_df=new_df.append(tempdf,ignore_index=True) return new_df
##models=df(d, index=d.get) ##print d['yr8_1285e07'] ##d=None ##print models[0] cur.close() con.close() ucoldefs=['ra','de','urat1', 'J','e_J','K','e_K','H','e_H'] con=p2.connect("dbname='stars' user='******' host='localhost'") cur=con.cursor() cur.execute("select ra, dec, mem from alejandroslist where mem > 50") ajl=df(cur.fetchall(), columns=['ra','de','mem']) cur.execute("select raj2000, dej2000, urat1, jmag, e_jmag, kmag, e_kmag, hmag, e_hmag from urat where jmag-kmag<0.6") urat=df(cur.fetchall(),columns=ucoldefs) usc=sc(urat['ra'],urat['de'],unit='deg') asc=sc(ajl['ra'],ajl['de'],unit='deg') matches, dist = mc(asc, usc, 3.0, 0) match_df=df(columns=ucoldefs+['mem','col']) for m in matches: tmp=sc(urat['ra'][m],urat['de'][m],unit='deg') temp_match,na=mc(tmp, asc, 3.0, 0) if temp_match and len(temp_match)>0: tdf=df([urat[ucoldefs].values[m]],columns=ucoldefs) mem=ajl['mem'].values[temp_match[0]] col=['#%02x%02x%02x' % (0,int(255*(.01*mem)),0)] tdf['mem']=mem tdf['col']=col match_df=match_df.append(tdf) match_df=match_df.set_index('urat1',drop = False) yrsplit=re.compile(r'yr(\d)_(\d{4})e(\d{2})') models=df(mes,columns=['name']).set_index('name', drop=False) models['age']=0