-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVizier.py
executable file
·131 lines (109 loc) · 4.68 KB
/
Vizier.py
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
#################################################################
# Name: Vizier.py #
# Author: Yuan Qi Ni #
# Version: February 9, 2017 #
# Function: Program contains routines for obtaining differential#
# photometric catalogs by querying Vizier database. #
# Currently supports AAVSO-APASS-DR9 and USNO-B1. #
#################################################################
import numpy as np
#Query AAVSO APASS DR9 catalog
def aavso(radeg,decdeg,fovam,band,out=False):
import urllib as url
str1 = 'http://webviz.u-strasbg.fr/viz-bin/asu-tsv/?-source=II/336'
str2 = '&-c.ra={:4.6f}&-c.dec={:4.6f}&-c.bm={:4.7f}/{:4.7f}&-out.max=unlimited'.format(radeg,decdeg,fovam,fovam)
# Make sure str2 does not have any spaces or carriage returns/line feeds when you # cut and paste into your code
sr = str1+str2
f = url.urlopen(sr)
# Read from the object, storing the page's contents in 's'.
s = f.read()
f.close()
#write text file
if out:
#outname = 'AAVSO-APASS-DR9_ra{:4.6f}dec{:4.6f}bm{:3.1f}x{:3.1f}.cat'.format(radeg,decdeg,fovam,fovam)
outname = out
f = open(outname, 'w')
f.write(s)
f.close()
return aavso_static(s, band)
#read static Vizier AAVSO APASS DR9 catalog
def aavso_static(lines, band):
RAcol = 1
DEcol = 2
#bands = {'B-V':8, 'B': 12, 'V': 10, 'i': 18, 'r': 16}
#banderrs = {'B-V':9, 'B': 13, 'V': 11, 'i': 19, 'r': 17}
#AAVSO updated format ~Jan 2025
bands = {'B-V':7, 'B': 11, 'V': 9, 'i': 17, 'r': 15}
banderrs = {'B-V':8, 'B': 12, 'V': 10, 'i': 18, 'r': 16}
null = ' '
#parse text
sl = lines.splitlines()
#sl = sl[53:-1] # get rid of header
sl = sl[52:-1] # get rid of header
name = np.array([])
rad = np.array([]) # RA in degrees
ded = np.array([]) # DEC in degrees
rmag = np.array([]) # rmag
rmagerr = np.array([]) # rmag error
for k in sl:
kw = k.split('\t')
if kw[0] != '':
name = np.append(name,kw[0])
#rad = np.append(rad,float(kw[1]))
#ded = np.append(ded,float(kw[2]))
#AAVSO updated format ~Jan 2025
rad = np.append(rad,float(kw[0]))
ded = np.append(ded,float(kw[1]))
# deal with case where no mag is reported
if (kw[bands[band]] != null) and (kw[banderrs[band]]) != null:
rmag = np.append(rmag,float(kw[bands[band]]))
rmagerr = np.append(rmagerr,float(kw[banderrs[band]]))
else:
rmag = np.append(rmag,np.nan)
rmagerr = np.append(rmagerr,np.nan)
return name,rad,ded,rmag,rmagerr,lines
#query Vizier USNO-B1 catalog
def usnoB(radeg,decdeg,fovam,band,out=False): # RA/Dec in decimal degrees/J2000.0 FOV in arc min.
import urllib as url
str1 = 'http://webviz.u-strasbg.fr/viz-bin/asu-tsv/?-source=USNO-B1'
str2 = '&-c.ra={:4.6f}&-c.dec={:4.6f}&-c.bm={:4.7f}/{:4.7f}&-out.max=unlimited'.format(radeg,decdeg,fovam,fovam)
RAcol = 1
DEcol = 2
bands = {'B': 12}
#banderrs = {'B': 13}
null = ' '
empt = ''
# Make sure str2 does not have any spaces or carriage returns/line feeds when you # cut and paste into your code
sr = str1+str2
f = url.urlopen(sr)
# Read from the object, storing the page's contents in 's'.
s = f.read()
f.close()
#write text file
if out:
outname = 'USNO-B1_ra{:4.6f}dec{:4.6f}bm{:4.1f}x{:4.1f}.cat'.format(radeg,decdeg,fovam,fovam)
f = open(outname, 'w')
f.write(s)
f.close()
sl = s.splitlines()
sl = sl[46:] # get rid of header
name = np.array([])
rad = np.array([]) # RA in degrees
ded = np.array([]) # DEC in degrees
rmag = np.array([]) # rmage
for k in sl:
kw = k.split('\t')
if kw[0] != '':
name = np.append(name,kw[0])
rad = np.append(rad,float(kw[1]))
ded = np.append(ded,float(kw[2]))
# deal with case where no mag is reported
#if (kw[bands[band]] != null) and (kw[banderrs[band]]) != null:
if (kw[bands[band]] != null) and (kw[bands[band]] != empt):
print "Mag", kw[bands[band]], "len", len(kw[bands[band]])
rmag = np.append(rmag,float(kw[bands[band]]))
#rmagerr = np.append(rmag,float(kw[banderrs[band]]))
else:
rmag = np.append(rmag,np.nan)
#rmagerr = np.append(rmagerr,np.nan)
return name,rad,ded,rmag,s