-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_obsid_states.py
48 lines (35 loc) · 1.43 KB
/
parse_obsid_states.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
"""
.. module:: parse_obsid_states
:synopsis: Given a STATES observation ID returns the corresponding STATES
spectral file.
.. moduleauthor:: Scott W. Fleming <[email protected]>
"""
import collections
import os
#--------------------
def parse_obsid_states(obsid):
"""
Given an STATES observation ID, return the spectral file to read.
:param obsid: The STATES observation ID to retrieve the data from.
:type obsid: str
:returns: tuple -- An error code and a file to read, including the path.
Error codes:
0 = No error parsing observation ID.
1 = Extracted spectral 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
# 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 + "states" + os.path.sep +
"transmission_spectra" + os.path.sep)
# The name of the file is equal to the STATES observation ID.
spec_file = file_location + obsid + ".txt"
if os.path.isfile(spec_file):
return parsed_values(errcode=error_code, specfiles=[spec_file])
error_code = 1
return parsed_values(errcode=error_code, specfiles=[''])
#--------------------