-
Notifications
You must be signed in to change notification settings - Fork 1
/
measure_v2.pro
315 lines (263 loc) · 8.9 KB
/
measure_v2.pro
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
pro measure, input_file, file_key=file_key
;+
; NAME:
; MEASURE
;
;
PURPOSE:
; This procedure measures spectral indices of IR spectra.
; Indices measured are: TiO 5, Ti0 4, Ti0 3, TiO 2, H-alpha,
; CaOH, CaH 1, CaH 2, Cah 3,and all indices from Table 7 of
; Kirkpatrick et al. 1999.
;
; CALLING SEQUENCE:
;
; MEASURE, Input_file, Output_file
;
; INPUTS:
; Input_file: File that contains list of FITS files.
;
; Output_file: Name of comma-delimted file as described below.
;
; OUTPUTS:
; This procedure returns the spectral indices to a comma-delimted file
; with a header row. Following the header, each row has the object
; name (from FITS header) followed by the spectral indices.
;
; PROCEDURE:
;
;
;
; ROUTINES CALLED:
; avgflux
;
; EXAMPLE:
; Please provide a simple example here. An example from the PICKFILE
; documentation is shown below. Please try to include examples that
; do not rely on variables or data files that are not defined in
; the example code. Your example should execute properly if typed
; in at the IDL command line with no other preparation.
;
; Create a PICKFILE widget that lets users select only files with
; the extensions 'pro' and 'dat'. Use the 'Select File to Read' title
; and store the name of the selected file in the variable F. Enter:
;
; F = PICKFILE(/READ, FILTER = ['pro', 'dat'])
;
; MODIFICATION HISTORY:
; Written by: Kelle Cruz, March 2001. (v1)
; Major overhaul, Feb 2006
;-
if N_params() lt 1 then begin
print,"Syntax - MEASURE_KPNO, 'Input_file, 'Output_file'"
print,"Input_file should have list of fits files"
print, "Output_file is the name of the file to be created."
return
endif
root='/data/hillary/2/kelle/optical_spectra/2M_all/fits/'
READCOL, input_file,ref,desig,sp_type,spectra_files,format='A,A,A,A',/PRESERVE_NULL
num_files = n_elements(spectra_files)
output_file=input_file+'_indices.txt'
OPENW, unit, output_file,/get_lun ; open output file for writing
FOR y = 0, num_files-1 DO BEGIN
data_file = spectra_files[y]
spec=KREADSPEC(root+data_file,h,/silent)
wavelength = REFORM(spec[0,*])
flux = REFORM(spec[1,*])
object=strtrim(sxpar(h,'OBJECT'),2)
file_name=(strsplit(data_file,'.',/extract))[0]
IF keyword_set(file_key) then sobject = file_name else $
sobject = object
print, ' '
print, sobject
;Measure indices
i=0
index=fltarr(39)
name=strarr(39)
;--------------------
;PMSU Spectral Ratios
;--------------------
name[i]='TiO5'
num = avgflux(7126., 7135, wavelength, flux)
den = avgflux(7042., 7046, wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='TiO4'
num = avgflux(7130., 7135., wavelength, flux)
den = avgflux(7115., 7120., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='TiO3'
num = avgflux(7092., 7097., wavelength, flux)
den = avgflux(7079., 7084., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='TiO2'
num = avgflux(7058., 7061., wavelength, flux)
den = avgflux(7043., 7046., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='Halpha'
num = avgflux(6560., 6566., wavelength, flux)
den = avgflux(6545., 6555., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='CaOH'
num = avgflux(6230., 6240., wavelength, flux)
den = avgflux(6345., 6354., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='CaH1'
num = avgflux(6380., 6390., wavelength, flux)
den1 = avgflux(6345., 6355., wavelength, flux)
den2 = avgflux(6410., 6420., wavelength, flux)
index[i] = strtrim(string(num/((den1+den2)/2)),1)
;IF den1 eq -1 THEN cah1 = 0 ELSE cah1 = num/((den1+den2)/2)
print, name[i],index[i] & i=++i
name[i]='CaH2'
num = avgflux(6814., 6846., wavelength, flux)
den = avgflux(7042., 7046., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='CaH3'
num = avgflux(6960., 6990., wavelength, flux)
den = avgflux(7042., 7046., wavelength, flux)
index[i]= strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
;--------------------
;K99 Spectral Ratios
;--------------------
name[i]='Rb-a'
num1 = avgflux(7775.2, 7785.2, wavelength, flux)
num2 = avgflux(7815.2, 7825.2, wavelength, flux)
den = avgflux(7795.2, 7805.2, wavelength, flux)
index[i]= strtrim(string((num1+num2)/2/den),1)
print, name[i],index[i] & i=++i
name[i]='Rb-b'
num1 = avgflux(7922.6, 7932.6, wavelength, flux)
num2 = avgflux(7962.6, 7972.6, wavelength, flux)
den = avgflux(7942.6, 7952.6, wavelength, flux)
index[i]= strtrim(string((num1+num2)/2/den),1)
print, name[i],index[i] & i=++i
name[i]='Na-a'
num = avgflux(8153.3, 8163.3, wavelength, flux)
den = avgflux(8178.3, 8188.3, wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='Na-b'
;INCORRECT IN K99 PAPER
num = avgflux(8153.5, 8163.3, wavelength, flux)
den = avgflux(8189.8, 8199.8, wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='Cs-a'
num1 = avgflux(8496.1, 8506.1, wavelength, flux)
num2 = avgflux(8536.1, 8546.1, wavelength, flux)
den = avgflux(8516.1, 8526.1, wavelength, flux)
index[i]= strtrim(string((num1+num2)/2/den),1)
print, name[i],index[i] & i=++i
name[i]='Cs-b'
num1 = avgflux(8918.5, 8928.5, wavelength, flux)
num2 = avgflux(8958.5, 8968.5, wavelength, flux)
den = avgflux(8938.5, 8948.5, wavelength, flux)
index[i]= strtrim(string((num1+num2)/2/den),1)
print, name[i],index[i] & i=++i
name[i]='TiO-a'
num = avgflux(7033., 7048., wavelength, flux)
den = avgflux(7058., 7073., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='TiO-b'
num = avgflux(8400., 8415., wavelength, flux)
den = avgflux(8455., 8470., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='VO-a'
num1 = avgflux(7350., 7370., wavelength, flux)
num2 = avgflux(7550., 7570., wavelength, flux)
den = avgflux(7430., 7470., wavelength, flux)
index[i] = strtrim(string((num1+num2)/den/2),1)
print, name[i],index[i] & i=++i
name[i]='VO-b'
num1 = avgflux(7860., 7880. ,wavelength, flux)
num2 = avgflux(8080., 8100., wavelength, flux)
den = avgflux(7960., 8000., wavelength, flux)
index[i] = strtrim(string((num1+num2)/den/2),1)
print, name[i],index[i] & i=++i
name[i]='CrH-a'
num = avgflux(8580., 8600., wavelength, flux)
den = avgflux(8621., 8641., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='CrH-b'
num = avgflux(9940., 9960., wavelength, flux)
den = avgflux(9970., 9990., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='FeH-a'
num = avgflux(8660., 8680., wavelength, flux)
den = avgflux(8700., 8720., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='FeH-b'
num = avgflux(9863., 9883., wavelength, flux)
den = avgflux(9908.0, 9928., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='Color-a'
num = avgflux(9800., 9850., wavelength, flux)
den = avgflux(7300., 7350., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='Color-b'
num = avgflux(9800., 9850., wavelength, flux)
den = avgflux(7000., 7050., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='Color-c'
num = avgflux(9800., 9850., wavelength, flux)
den = avgflux(8100., 8150., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='Color-d'
num = avgflux(9675., 9875., wavelength, flux)
den = avgflux(7350., 7550., wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
;--------------------
;Martin et al 1999 Spectral Ratios
;--------------------
name[i]='VO1'
num = avgflux(7540, 7580, wavelength, flux)
den = avgflux(7420, 7460, wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='VO2'
num = avgflux(7990, 8030, wavelength, flux)
den = avgflux(7900, 7940, wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
name[i]='PC3'
num = avgflux(8230, 8270, wavelength, flux)
den = avgflux(7540, 7580, wavelength, flux)
index[i] = strtrim(string(num/den),1)
print, name[i],index[i] & i=++i
index_name = name[0:i-1]
index = index[0:i-1]
;Make header and print if it's the first object
if y eq 0 then begin
header = 'OBJECT'+ ','+ STRJOIN(name,', ')
;header = STRJOIN(name,', ')
printf, unit, header
indices=fltarr(num_files,i)
ENDIF
;Format output for comma-delimited file
dataline = sobject +',' + STRJOIN(index,', ')
;dataline = STRJOIN(index,', ')
printf, unit, dataline
indices[y,*]=index
ENDFOR ;stop looping through spectra
save, file=output_file+'.sav',indices,index_name
close, unit ;close output file
FREE_LUN,unit
END