-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_extinction_curves.py
More file actions
executable file
·123 lines (118 loc) · 4.46 KB
/
Copy pathget_extinction_curves.py
File metadata and controls
executable file
·123 lines (118 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/python3
'''
Abstract:
This is a program for getting extinction curves of near IR
from Synthetic Extinction Curves
given by https://www.astro.princeton.edu/~draine/dust/dustmix.html
Usage:
get_extinction_curves.py [a text file saved extinction curves table]
Editor:
Jacob975
##################################
# Python3 #
# This code is made in python3 #
##################################
20180813
####################################
update log
20180813 version alpha 1
1. The code works
'''
import numpy as np
import time
from sys import argv
import matplotlib.pyplot as plt
# Find the closest freq with the given freq
def match_freq(extinction_table, freq):
for index in range(len(extinction_table)):
if freq < extinction_table[index][0]:
return index
return -1
# Calculate the interpolation of two value in given indices.
def interpolation(extinction_table, freq, index_1, index_2):
value_1 = extinction_table[index_1][3]
value_2 = extinction_table[index_2][3]
weight_1 = abs(freq - extinction_table[index_2][0])
weight_2 = abs(freq - extinction_table[index_1][0] )
value = (value_1 * weight_1 + value_2 * weight_2) \
/ (weight_1 + weight_2)
return value
#--------------------------------------------
# main code
if __name__ == "__main__":
VERBOSE = 0
# measure time
start_time = time.time()
#-----------------------------------
# Load argv
if len(argv) != 2:
print ("Wrong number of arguments")
print ("Usage: get_extinction_curves.py [extinction curves table]")
exit(1)
table_name = argv[1]
#-----------------------------------
# Load table
extinction_table = np.loadtxt( table_name,
dtype = float,
comments = "#")
extinction_table = extinction_table[ \
extinction_table[:,0].argsort()]
#-----------------------------------
# For 2MASS, IRAC, and MIPS
# Initialize
band_freq_list = [[ 'V', 0.546, 0.0],
[ 'J', 1.235, 0.0],
[ 'H', 1.662, 0.0],
[ 'K', 2.159, 0.0],
['IR1', 3.6 , 0.0],
['IR2', 4.5 , 0.0],
['IR3', 5.8 , 0.0],
['IR4', 8.0 , 0.0],
['MP1', 24. , 0.0]]
# Calculate the result
for band in band_freq_list:
index = match_freq(extinction_table, band[1])
band[2] = interpolation(extinction_table, \
band[1], \
index, \
index - 1)
band_freq_array = np.array(band_freq_list, dtype = object)
band_freq_array[:,2] = np.divide( band_freq_array[:,2], \
band_freq_array[0,2])
print ("-------------------------")
print ("For 2MASS, IRAC, and MIPS")
print ("name wave_length A_lambda/A_v")
for band in band_freq_array:
print ("{0} {1} {2:.4f}".format(band[0], band[1], band[2]))
#-----------------------------------
# For UKIDSS, IRAC, and MIPS
# Initialize
band_freq_list = [[ 'V', 0.546, 0.0],
[ 'J', 1.248, 0.0],
[ 'H', 1.631, 0.0],
[ 'K', 2.201, 0.0],
['IR1', 3.6 , 0.0],
['IR2', 4.5 , 0.0],
['IR3', 5.8 , 0.0],
['IR4', 8.0 , 0.0],
['MP1', 24. , 0.0]]
# Calculate the result
for band in band_freq_list:
index = match_freq(extinction_table, band[1])
band[2] = interpolation(extinction_table,
band[1],
index,
index - 1)
band_freq_array = np.array( band_freq_list,
dtype = object)
band_freq_array[:,2] = np.divide( band_freq_array[:,2],
band_freq_array[0,2])
print ("--------------------------")
print ("For UKIDSS, IRAC, and MIPS")
print ("name wave_length A_lambda/A_v")
for band in band_freq_array:
print ("{0} {1} {2:.4f}".format(band[0], band[1], band[2]))
#-----------------------------------
# measure time
elapsed_time = time.time() - start_time
print ("Exiting Main Program, spending ", elapsed_time, "seconds.")