In [60]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import astropy.coordinates as coord
import astropy.units as u
from mpl_toolkits.mplot3d import Axes3D
from astropy.io import ascii

tbl = ascii.read('/home/glauffer/Dropbox/FURG/final_project/data/cepFU_ID_RA_DEC_I.txt', guess=False, Reader=ascii.Tab)
tbl


Out[60]:
IdRADECI
OGLE-LMC-CEP-000204:31:47.04-69:49:09.6015.672
OGLE-LMC-CEP-000504:35:31.52-69:44:05.9014.661
OGLE-LMC-CEP-001204:37:48.73-67:12:51.9015.469
OGLE-LMC-CEP-001604:38:32.52-67:38:46.7013.707
OGLE-LMC-CEP-001704:38:56.83-69:41:18.2015.345
OGLE-LMC-CEP-001804:38:58.98-68:57:24.8015.222
OGLE-LMC-CEP-002104:39:30.96-69:15:42.6014.722
OGLE-LMC-CEP-002304:40:47.48-68:59:08.3016.325
OGLE-LMC-CEP-002504:40:54.37-69:06:54.3015.343
OGLE-LMC-CEP-002604:41:12.24-68:47:59.1015.466
OGLE-LMC-CEP-002704:41:19.49-67:20:08.1015.039
............
OGLE-LMC-CEP-333105:58:52.51-69:10:13.4014.638
OGLE-LMC-CEP-333305:59:21.09-69:55:20.8015.948
OGLE-LMC-CEP-333506:00:23.91-68:33:22.5014.164
OGLE-LMC-CEP-333806:01:59.96-71:11:42.2015.381
OGLE-LMC-CEP-333906:02:24.35-69:15:14.4013.979
OGLE-LMC-CEP-334206:04:42.54-68:32:09.8015.422
OGLE-LMC-CEP-335206:06:33.38-71:36:26.0015.018
OGLE-LMC-CEP-335306:08:08.05-68:56:59.1015.199
OGLE-LMC-CEP-335506:10:41.63-71:31:43.5015.569
OGLE-LMC-CEP-335706:11:34.36-71:09:41.5015.088
OGLE-LMC-CEP-337205:32:32.49-67:45:40.5016.6

In [61]:
#convertendo RA e DEC
ra = coord.Angle(tbl['RA'], unit = u.hour)
dec = coord.Angle(tbl['DEC'], unit = u.degree)
#Converter RA e Dec em X e Y de acordo com o paper do Pejcha (2009)
import numpy as np
x = (ra.degree - 80.35) * np.cos(dec.degree)
y = dec.degree + 69.68
ra_dec = np.around(np.column_stack((x,y)), decimals=1) #arrendondamento para o primeiro decimal apos a virgula
print(ra_dec)


[[-9.5 -0.1]
 [-9.3 -0.1]
 [ 3.5  2.5]
 ..., 
 [-9.2 -1.8]
 [-5.7 -1.5]
 [ 0.6  1.9]]

In [62]:
ext_map = np.array(np.loadtxt('/home/glauffer/Dropbox/FURG/final_project/data/extinction_map/lmcextmap.dat', skiprows=29))
x_map = np.column_stack((ext_map.T[0], ext_map.T[1]))
y_map = np.column_stack((ext_map.T[2], ext_map.T[3]))

ext = np.ones(len(ra_dec))

for i in range(len(ra_dec)):
    if ra_dec[i,0]>(-4.7): # or ():
        ext[i] = 0
    if ra_dec[i,0]>4.9:
        ext[i] = 0
    if ra_dec[i,1]>(-3.4): #or 
        ext[i] = 0
    if ra_dec[i,1]>3.2:
        ext[i] = 0
    else:
        try:
            ext[i] = ext_map[np.where((x_map.T[0] == ra_dec[i,0]) & (y_map.T[0] == ra_dec[i,1]))][0][4]
        except IndexError:
            ext[i] = 0
ext


Out[62]:
array([ 0.,  0.,  0., ...,  0.,  0.,  0.])

In [63]:
magI_correct = tbl['I'] - 1.10*ext
#magI_correct = tbl['I'] - 0.45
#tbl['I']
magI_correct


Out[63]:
<Column name='I' unit=None format=None description=None>
array([ 15.672,  14.661,  15.469, ...,  15.569,  15.088,  16.6  ])

In [64]:
ce_p = ascii.read('/home/glauffer/Dropbox/FURG/final_project/data/cep_FU_CEperiod.txt', guess=False, Reader=ascii.Tab)
len(ce_p['CE_p'])


Out[64]:
1818

In [65]:
#Removendo as entrelas que nao possuem banda I
exception = np.where(tbl['I'] <= 10)
new_magI_correct = np.delete(magI_correct, exception)
len(new_magI_correct)


Out[65]:
1818

In [66]:
A = np.column_stack((np.log(ce_p['CE_p']), np.ones_like(ce_p['CE_p'])))
x, res, rank, s = np.linalg.lstsq(A,new_magI_correct)
print('m - A= ', x[0], '*log P + ', x[1])


m - A=  -1.29201094747 *log P +  16.8783009955

In [67]:
plt.plot(np.log(ce_p['CE_p']), new_magI_correct, 'go', ms=0.5)
plt.plot(np.log(ce_p['CE_p']), x[0]*np.log(ce_p['CE_p']) + x[1], 'r-', label='m - A= %f*log P +%f'%(x[0],x[1]))
plt.gca().invert_yaxis()
plt.legend()


Out[67]:
<matplotlib.legend.Legend at 0x7fd56736db70>

In [68]:
#calculando o modulo de distancia
u = new_magI_correct - x[0]*np.log(ce_p['CE_p'])-x[1]
#print(new_magI_correct[1], new_magI_correct[1]-u[1])
#passando para distancia -> r = 10**(0.2*(u+5))
r = np.zeros(len(u))
r =10**(0.2*u+0.2*5)
#new_ext = np.delete(ext, exception)
#r = 10**(0.2*(u+5+1.10*new_ext))
#print(r[1])
#sendo a distancia media 50 kpc -> r_lmc = r+50
r_lmc = np.zeros(len(r))
r_lmc = (r + 50e3)/1000
print(r_lmc)


     CE_p    
-------------
 50.011287367
50.0100523777
50.0093532134
 50.008833627
50.0107105456
50.0107165855
50.0101684653
50.0106347861
50.0107980398
50.0091520319
50.0090686299
          ...
50.0090075329
50.0100998125
50.0090703416
50.0091138753
50.0096952775
50.0087021305
50.0097668348
50.0094682058
50.0091455655
50.0097295841
50.0133216892

In [69]:
#plot das coordenadas RA e DEC
plt.plot(ra.degree, dec.degree, 'bo', ms=1.)
plt.plot(np.mean(ra.degree), np.mean(dec.degree), 'go')
print(np.mean(ra.degree), np.mean(dec.degree))


79.9377471606 -69.5521387537

In [75]:
#Calculando as coordenadas x, y, z
new_ra = np.delete(ra.radian, exception)
new_dec =np.delete(dec.radian, exception)

r_lmc_0 = 50
ra_0 = np.mean(ra.radian)
dec_0 = np.mean(dec.radian)

x = -r_lmc * np.sin(new_ra - ra_0) * np.cos(new_dec)
y = r_lmc * np.sin(new_dec)*np.cos(dec_0) - r_lmc * np.sin(dec_0) * np.cos(new_ra - ra_0) * np.cos(new_dec)
z = r_lmc_0 - r_lmc * np.sin(new_dec) * np.sin(dec_0) - r_lmc * np.cos(dec_0)*np.cos(new_ra) - ra_0 * np.cos(new_dec)

In [76]:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.plot(x, y, z, 'go' ,ms=1.5)


Out[76]:
[<mpl_toolkits.mplot3d.art3d.Line3D at 0x7fd5673e8240>]

In [72]:
exception


Out[72]:
(array([  33,   36,   68,   73,  138,  186,  243,  260,  290,  291,  302,
        334,  352,  370,  423,  534,  535,  546,  562,  567,  619,  625,
        717,  875,  897,  900,  920, 1245, 1393, 1564, 1744]),)

In [73]:
fu_exception = np.array([33, 36, 68, 73, 138, 186, 243, 260, 290, 291, 302, 334, 352, 370, 423, 534, 535, 546, 562,
                567, 619, 625, 717, 875, 897, 900, 920, 1245, 1393, 1564,1744])
fu_exception


Out[73]:
array([  33,   36,   68,   73,  138,  186,  243,  260,  290,  291,  302,
        334,  352,  370,  423,  534,  535,  546,  562,  567,  619,  625,
        717,  875,  897,  900,  920, 1245, 1393, 1564, 1744])

In [77]:
np.savetxt('fu50e3_plot.txt', np.dstack((x, y, z))[0], fmt='%s')

In [74]: