-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathqueryned.pro
More file actions
executable file
·270 lines (236 loc) · 8.84 KB
/
queryned.pro
File metadata and controls
executable file
·270 lines (236 loc) · 8.84 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
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
pro queryned $
, list $
, found=found $
, MU=mu $
, ERRMU=errmu $
, DIST=D $
, ERRDIST=errD $
, MINDIST=minD $
, MAXDIST=maxD $
, DISTMOD=distmod $
, VHEL=vhel $
, ERRVHEL=errvhel $
, RADEG=ra_deg $
, DECDEG=dec_deg $
, AV=av $
, STRUCT=struct $
, OUTLINES=outlines $
, HEADER=header $
, OUTFILE=outfile $
, quiet=quiet
;+
;
; Script to query NED for distances from Brent Groves. Also now grabs
; the Schlafly+ A_V value. Other minor modifications (NaN default
; values and traps the case of no error on the heliocentric velocity).
;
; TBD - it may make sense to use ONLY PGC numbers for a LEDA-based
; query. There are a few cases (some ESO names) where other
; systems fail.
;
;-
; Check inputs
On_Error,2
n_list = n_elements(list)
IF n_list EQ 0 then begin
print, "distned, list, [mu, errmu, D, errD, minD, maxD]"
return
ENDIF
; Initialize strings strings
if not keyword_set(distmod) then $
distmod = "D (Virgo + GA only)"
strvhel = "V (Heliocentric)"
strradec = "Equatorial (J2000.0)"
; initialize outputs to be extracted from NED
nan = !values.f_nan
mu = dblarr(n_list)*nan
errmu = dblarr(n_list)*nan
vhel = dblarr(n_list)*nan
errvhel = dblarr(n_list)*nan
D = dblarr(n_list)*nan
errD = dblarr(n_list)*nan
minD = dblarr(n_list)*nan
maxD = dblarr(n_list)*nan
ra_deg = dblarr(n_list)*nan
dec_deg = dblarr(n_list)*nan
av = dblarr(n_list)*nan
; Loop over list entries
found = bytarr(n_list)*0B
for i=0, n_list-1 do begin
if keyword_set(quiet) eq 0 then $
print,"----- "+list[i]+"-----"
spawn,"rm -rf tmp_ned.out"
spawn,"wget --quiet -O tmp_ned.out http://nedwww.ipac.caltech.edu/cgi-bin/nph-objsearch\?objname="+strtrim(list[i])+$
"\&extend=no\&hconst=73\&omegam=0.27\&omegav=0.73\&corr_z=3"+$
"\&out_csys=Equatorial\&out_equinox=J2000.0\&obj_sort=RA+or+Longitude"+$
"\&of=pre_text\&zv_breaker=30000.0\&list_limit=5\&img_stamp=NO"
dummy = file_search('tmp_ned.out', count=ct)
if ct ne 1 then begin
message, "No match for WGET attempt. Proceeding.", /info
continue
endif
fail_string = "There is no object with this name in NED."
spawn, 'grep "'+fail_string+'" tmp_ned.out', dummy
if strpos(dummy, fail_string) ne -1 then begin
message, "Object not found in NED. Proceeding.", /info
continue
endif
found[i] = 1B
; ...redshift distance
;;;
spawn,"awk '/Mean/ {print $3, $7}; /Min./ && /Max./ {print $3, $6}' tmp_ned.out", distances
; print,distances
IF n_elements(distances) EQ 2 THEN BEGIN
D[i] =double(strmid(distances[0],4,6))
IF NOT STRMATCH(distances[0],'*N/A*') THEN BEGIN
this_dist_err = double(strmid(distances[0],25,4))
if this_dist_err ne 0.0 then $
errD[i]=this_dist_err $
else $
message, 'No distance error.', /info
ENDIF
temp=strsplit(distances[1],'><',/extract)
minD[i]=double(temp[1])
maxD[i]=double(temp[6])
ENDIF
spawn,"awk '/Mean/ {print $2, $6};' tmp_ned.out", NEDdistmod
mu[i] = double(strmid(NEDdistmod[0],4,5))
IF NOT STRMATCH(NEDdistmod[0],'*N/A*') THEN errmu[i]=double(strmid(NEDdistmod[0],19,4))
;;; grep "D (Virgo + GA only)" tmp_ned.out | cut -b 65-70,75-79
; spawn,"grep '"+distmod+"' tmp_ned.out | cut -b 65-70,75-79",strdum
; mu[i] = double(strmid(strdum[0],0,5))
; errmu[i] = double(strmid(strdum[0],7,4))
; ...Heliocentric velocity [in km/s]
;;; grep "V (Heliocentric)" tmp_ned.out | cut -b 30-36,41-47
spawn,"grep '"+strvhel+"' tmp_ned.out | cut -b 30-36,41-47",strdum
vhel[i] = double(strmid(strdum[0],0,8))
this_errvhel = double(strmid(strdum[0],8,8))
if this_errvhel ne 0.0 then $
errvhel[i] = this_errvhel $
else $
message, 'No heliocentric velocity error.', /info
; ...position RA,DEC [in degrees]
;;; grep "Equatorial (J2000.0)" tmp_ned.out | cut -b 22-32,34-44
spawn,"grep '"+strradec+"' tmp_ned.out | cut -b 22-32,34-44",strdum
ra_deg[i] = double(strmid(strdum[0],0,11))
dec_deg[i] = double(strmid(strdum[0],11,11))
; &%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
; FIND FOREGROUND EXTINCTION AT V BAND
; &%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
spawn,"grep '<td>Filter' tmp_ned.out -m 1", strext
for kk = 0, 11 do begin
next_pos = strpos(strext, '<td>')
strext = strmid(strext, next_pos+4)
stop_pos = strpos(strext, '</td>')
band_string = strmid(strext, 0, stop_pos)
if (strcompress(band_string, /rem)) eq 'V(0.54)' then begin
vnum = kk
break
endif
endfor
spawn,"grep '<tr><td>A<sub>λ</sub>' tmp_ned.out -m 1", strext
if n_elements(vnum) eq 0 then begin
message, 'No V-band extinction found. Skipping.', /info
continue
stop
endif
for kk = 0, vnum do begin
next_pos = strpos(strext, '<td>')
strext = strmid(strext, next_pos+4)
endfor
stop_pos = strpos(strext, '</td>')
av_string = strmid(strext, 0, stop_pos)
av[i] = float(av_string)
endfor
; remove temporary files
spawn,"rm -rf tmp_ned.out"
; &%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
; FORMAT OUTPUT
; &%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%&%
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; BUILD A STRUCTURE
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
empty_struct = $
{ $
name: "", $
ra:nan, $
dec:nan, $
mu:nan, $
errmu:nan, $
d:nan, $
errd:nan, $
mind:nan, $
maxd:nan, $
vhel:nan, $
errvhel:nan, $
av:nan $
}
out_struct = replicate(empty_struct, n_list)
for ii = 0, n_list-1 do begin
out_struct.name = list
out_struct.ra = ra_deg
out_struct.dec = dec_deg
out_struct.mu = mu
out_struct.errmu = errmu
out_struct.d = d
out_struct.errd = errd
out_struct.mind = mind
out_struct.maxd = maxd
out_struct.vhel = vhel
out_struct.errvhel = errvhel
out_struct.av = av
endfor
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; FORMAT OUTPUT LINES
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if n_elements(header) eq 0 then begin
header = "# NED distances "
header = [header, "#"]
header = [header,"# name = galaxy name"]
header = [header,"# RA,DEC = RA, DEC (J2000) [in degrees]"]
header = [header,"# mu = distance modulus (+error) derived from z [in mag]"]
header = [header,"# D = mean distance (+error) [in Mpc]"]
header = [header,"# minD = min distance in NED [in Mpc]"]
header = [header,"# maxD = max distance in NED [in Mpc]"]
header = [header,"# Vhel = Heliocentric velocity [in kms]"]
header = [header,"# A_V = foreground extinction [in mag] from Schlafly+ '11"]
header = [header,"#"]
header = [header,"# Total number of galaxies: "+strcompress(string(n_list),/REMOVE_ALL)]
header = [header,"#"]
header = [header,"###########################################################################################################################"]
header = [header,"#name | RA[deg] | DEC[deg] | mu[mag] | mu_err | D[Mpc] | D_err | minD[Mpc] | maxD[Mpc] | Vhel[kms] | Vhel_err | A_V[mag] "]
endif
first = 1B
for i=0,n_list-1 do begin
line = ''
line += string(list[i], format='(a15)')+' | '
line += string(ra_deg[i], format='(d12.6)')+' | '
line += string(dec_deg[i], format='(d12.6)')+' | '
line += string(mu[i], format='(d12.6)')+' | '
line += string(errmu[i], format='(d12.6)')+' | '
line += string(d[i], format='(d12.6)')+' | '
line += string(errd[i], format='(d12.6)')+' | '
line += string(mind[i], format='(d12.6)')+' | '
line += string(maxd[i], format='(d12.6)')+' | '
line += string(vhel[i], format='(d12.6)')+' | '
line += string(errvhel[i], format='(d12.6)')+' | '
line += string(av[i], format='(d12.6)')
if first then $
outlines = line $
else $
outlines = [outlines, line]
first = 0B
endfor
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; PRINT TO A FILE
; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if n_elements(outfile) gt 0 then begin
openw,unit,outfile, /get_lun
for ii = 0, n_elements(header)-1 do $
printf, unit, header[ii]
for ii = 0, n_elements(outlines)-1 do $
printf, unit, outlines[ii]
close,unit
free_lun, unit
endif
end