-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_obsid_galex.py
61 lines (45 loc) · 1.91 KB
/
parse_obsid_galex.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
"""
.. module:: parse_obsid_galex
:synopsis: Given a GALEX preview URL returns the corresponding FITS file
name.
.. moduleauthor:: Scott W. Fleming <[email protected]>
"""
import collections
import os
#--------------------
def parse_obsid_galex(obsid, url):
"""
Given an GALEX preview URL, return the FITS file to read.
:param obsid: The GALEX observation ID to retrieve the data from.
:type obsid: str
:param url: The URL for the preview jpg file.
:type url: str
:returns: tuple -- An error code and a file to read, including the path.
Error codes:
0 = No error parsing observation ID.
1 = Observation ID is a 2D spectral image, and not a 1D extracted spectrum.
2 = Extracted spectra FITS file not found.
"""
# Create namedtuple as the return object.
parsed_values = collections.namedtuple('ParseResult', ['errcode',
'specfiles'])
# Initialize error code to 0 = pass.
error_code = 0
# Check if this is a 2D spectral image. The signpost is the presence of
# an extension "int_2color.jpg".
if url[-14:] == "int_2color.jpg":
error_code = 1
return parsed_values(errcode=error_code, specfiles=[''])
# Generate the full path and name of the file to read.
file_location = (os.path.pardir + os.path.sep + os.path.pardir +
os.path.sep + "missions" + os.path.sep + "galex" +
os.path.sep +
os.path.sep.join(url.split(os.path.sep)[2:-3]) +
os.path.sep + 'SSAP' + os.path.sep)
# The name of the FITS file is equal to the GALEX observation ID.
spec_file = file_location + obsid + ".fits"
if os.path.isfile(spec_file):
return parsed_values(errcode=error_code, specfiles=[spec_file])
error_code = 2
return parsed_values(errcode=error_code, specfiles=[''])
#--------------------