import sys
import stilts
import datetime
import time
import math

table = stilts.tread('/data1/rcsed_v2/photometry/results/rcsed_v2_10.fits')
cols = table.columns()
columns = []
for col in cols:
    columns.append(str(col))
    columns[-1] = columns[-1].split('(')[0]
print(columns)

convertion = {'Y_ukidss': '0.634', 'J_ukidss': '0.938', 'H_ukidss': '1.379', 
              'K_ukidss': '1.9', 'w1_wise': '2.5*log10(3631.0/302.1)', 
              'w2_wise': '2.5*log10(3631.0/168.98)',
              'w3_wise': '2.5*log10(3631.0/25.50)',
              'w4_wise': '2.5*log10(3631.0/8.363)', 'J_uhs': '0.938',
              'NUV_galex': '20.02', 'FUV_galex': '18.82', 
              'U_vst': '0.894', 'G_vst': '-0.100', 'R_vst': '0.159', 'I_vst': '0.356', 'Z_vst':'0.517',
              'u_vst': '0.894', 'g_vst': '-0.100', 'r_vst': '0.159', 'i_vst': '0.356', 'z_vst':'0.517',
              'Z_viking': '0.502','Y_viking':'0.6', 'J_viking': '0.916', 'H_viking': '1.366', 'ks_viking': '1.827', 
              'Y_vhs':'0.502', 'J_vhs': '0.916', 'H_vhs': '1.366', 'ks_vhs': '1.827'}

for col in columns:
	if col.find('kcorr')==-1 and col.find('err')==-1:
		for name in convertion:
			if col.find(name)!=-1:
				print(col, name)
				command = col + ' + ' + convertion[name]
				table = table.cmd_replacecol(col, command)

print('writing')
table.write('/data1/rcsed_v2/photometry/results/rcsed_v2_10AB.fits')
print('done')  				

