구글 콜랩 사용을 가정하여 서술함.
from google.colab import drive
drive.mount('/content/drive/')
import numpy as np
import csv
import pandas as pd
import matplotlib.pyplot as plt
filename='/content/drive/MyDrive/외계행성.csv' #csv파일을 드라이브에 올리고 경로를 적어주세요!
# CSV 파일 읽기
df = pd.read_csv(filename)
# 데이터 추출
x = df['SEP'].astype(float)
y = df['L'].astype(float)
# 상수
a = 5.67e-8
pi = np.pi
# 거리 범위
d = np.linspace(0.1, 100, len(df['SEP'])) * 149.6e9
# 광도 계산
L1 = (4*pi*d**2)*a*(((273.15))**4)*2
L2 = (4*pi*d**2)*a*(((373.15))**4)*2
L_sun = 3.846e+26
# 상대적 광도 계산
L1_rel = L1 / L_sun
L2_rel = L2 / L_sun
# AU 단위로 변환
d_au = d / 149.6e9
# 그래프 그리기
plt.plot(d_au, L1_rel, label='T=0')
plt.plot(d_au, L2_rel, label='T=100')
# L1과 L2 사이의 점과 바깥의 점 분리
x_red = []
y_red = []
x_green = []
y_green = []
for i in range(len(df['SEP'])):
d_au=x[i]
d = d_au * 149.6e9
L1 = (4*pi*d**2)*a*(((273.15))**4)*2
L2 = (4*pi*d**2)*a*(((373.15))**4)*2
L_sun = 3.846e+26
L1_rel = L1 / L_sun
L2_rel = L2 / L_sun
if L1_rel < y[i] and y[i] < L2_rel:
x_red.append(x[i])
y_red.append(y[i])
else :
x_green.append(x[i])
y_green.append(y[i])
# 빨간색, 초록색으로 점 표시하기
plt.plot(x_red, y_red, 'o', markersize=1, color='red', label='Between T=0 and T=100')
plt.plot(x_green, y_green, 'o', markersize=1, color='green', label='exoplanet')
# 점 개수 출력
print("The number of points between T=0 and T=100: ", len(x_red))
aa = len(x_red)/len(df['SEP'])*100
print("The probability of entering the habitable zone:", aa)
# 그래프 꾸미기
plt.title('Luminosity vs. Distance')
plt.xlabel('Distance (AU)')
plt.ylabel('Relative Luminosity')
plt.xscale('log')
plt.legend()
plt.ylim(0, 20)
plt.xlim(0, 100)
# 그래프 보여주기
plt.show()