In [1]:
# Import numpy
import numpy as np
# Importing plotting stuff
import matplotlib.pyplot as plt
%matplotlib inline
from scipy import stats
# Use seaborn plotting style defaults
#import seaborn as sns; sns.set()
# Import Astropy things we need
from astropy.io import ascii
import astropy.coordinates as coord
import astropy.units as u
from astropy.table import Table
#Import Pandas
import pandas as pd
# Importing Principal Component Analysis
from sklearn.decomposition import PCA
In [2]:
# Query OGLE-III database for Type II Cepheids: http://ogledb.astrouw.edu.pl/~ogle/CVS/
data = ascii.read('AllTypeIICepheidsinOGLE.txt') # All of the Type II Cepheids in the OGLE Survey
data
Out[2]:
In [3]:
# Getting all Type II Cepheids coordinates in OGLE
ra = coord.Angle(data['RA'], unit=u.hour)
ra.degree
ra = ra.wrap_at(180*u.degree)
dec = coord.Angle(data['Decl'], unit=u.degree)
dec.degree
# Plotting all Cepheids
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111, projection="mollweide")
ax.scatter(ra.radian, dec.radian)
Out[3]:
In [4]:
# Dec, RA in hours.
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(111, projection="mollweide")
ax.scatter(ra.radian, dec.radian)
ax.set_xticklabels(['14h','16h','18h','20h','22h','0h','2h','4h','6h','8h','10h'])
ax.grid(True)
In [5]:
# Save map of Type IIs in LMC, SMC, Bulge in pdf.
fig.savefig("TypeIICepheidsMap.pdf")
In [6]:
# Put Period and I-band mean in arrays.
#P = data['P_1']
#I_mean = data['I']
#V_mean = data['V']
#labels = data['Type']
plt.clf()
def find_unique_elements(arr):
elements_list = []
elements_list.append(arr[0])
for i in range(1,len(arr)):
if arr[i] not in elements_list:
elements_list.append(arr[i])
return elements_list
#number_list = [1, 5, 0, 3, 3]
label_list = find_unique_elements(data['Type'])
label_list
Out[6]:
In [7]:
colors = plt.cm.jet(np.linspace(0,1,len(label_list)))
# Plot Period and I_mean.
for j in range(len(label_list)):
#index = np.where(np.asarray(label_list) == labels)[0]
plt.semilogx(data['P_1'][data['Type'] == label_list[j]], data['I'][data['Type'] == label_list[j]], label=label_list[j],\
linestyle='None', marker='o', color=colors[j])
plt.title("LMC, SMC & Bulge Type II Cepheids in OGLE-III")
plt.ylabel("I Magnitude")
plt.xlabel("log(P)")
plt.legend(loc='best')
plt.gca().invert_yaxis()
plt.show
Out[7]:
In [8]:
# Putting Period and I_mag in same array.
P_I = np.array([data['P_1'], data['I']]).T
In [10]:
# Using 2 PCA Componenets to fit P_I_array.
pca = PCA(n_components=2)
pca.fit(P_I)
print(pca.explained_variance_)
print(pca.components_)
In [15]:
from sklearn.cluster import KMeans
est = KMeans(4) # 4 clusters
est.fit(P_I)
y_kmeans = est.predict(P_I)
plt.scatter(P_I[:, 0], P_I[:, 1], c=y_kmeans, s=50, cmap='rainbow')
x
In [32]:
labels = "pWVir"
len(data['P_1'][data['Type'] == labels])
Out[32]:
In [43]:
print np.where(np.asarray(label_list) == 'BLHer')
ex = np.array([0, 1, 2])
print np.where(ex == 1)
In [38]:
print label_list
In [ ]: