1 import types
2 import pyfits
3 from pytools import fileutil
4
6 """ Class which determines the format of the file, how to access the
7 SCI data array, and if available, any DQ array as well. The syntax
8 for accessing the data will then be kept as attributes for use by
9 other tasks/classes.
10
11 Parameters:
12 filename - name of file to be examined
13 handle - PyFITS-style file handle for image
14 dqsuffix - suffix for DQ array for non-MEF files
15
16 If 'dqsuffix' is not provided and the file is GEIS formatted,
17 then this class will search for a '.c1h' extension by default,
18 and return None if not found.
19
20 """
21 - def __init__(self,filename,handle=None,dqsuffix=None):
22
23 self.handle = handle
24 self.filename = filename
25 self.dqfile = filename
26
27 self.seperator = ','
28 self.dq_suffix = dqsuffix
29 self.dq_extname = 'dq'
30 self.sci_extname = 'sci'
31 self.sci_extn = '['+self.sci_extname+',1]'
32 self.dq_extn = '['+self.dq_extname+',1]'
33
34 if filename:
35 if filename.find('.fits') > -1:
36 if handle and len(handle) == 1:
37
38
39 self.sci_extn = None
40 self.dq_extn = None
41 self.dq_extname = None
42 self.sci_extname = None
43 else:
44
45 self.seperator = '['
46 if not dqsuffix:
47 _dqsuffix = '.c1h'
48 _indx = filename.rfind('.')
49 if fileutil.findFile(filename[:_indx]+_dqsuffix):
50 self.dq_suffix = '.c1h'
51 else:
52 self.dq_suffix = None
53
54 self.sci_extn = '[1]'
55 self.dq_extn = '[1]'
56 self.dq_extname = '1'
57 self.sci_extname = '1'
58
59
61 """ Returns the properly formatted filename to access the SCI extension."""
62
63 if section == None:
64 _extname = self.filename+self._setSciExtn(extn=extver)
65 else:
66 _extname = self.filename+'['+str(section)+']'
67
68 return _extname
69
71 """ Create the name of the file which contains the DQ array.
72 For multi-extension FITS files, this will be the same file
73 as the SCI array.
74 """
75
76 if not self.dq_suffix:
77 _dqname = self.dqfile
78 else:
79 _dqname = fileutil.buildNewRootname(self.dqfile,extn=self.dq_suffix)
80
81 if self.dq_extn:
82 _dqname += self._setDQExtn(extn=extver)
83 elif self.dq_suffix:
84 _dqname = _dqname+'[0]'
85 else:
86 _dqname = None
87
88 return _dqname
89
91 """ Builds extension specification for accessing DQ extension/group.
92 """
93 if extn != None:
94 if self.dq_extn:
95 _lensep = len(self.seperator)
96 _indx = self.dq_extn.find(self.seperator) + _lensep
97 return self.dq_extn[:_indx]+repr(extn)+self.dq_extn[_indx+1:]
98 else:
99 return ''
100 else:
101 return self.dq_extn
102
104 """ Builds extension specification for accessing SCI extension/group.
105 """
106 if extn != None:
107 if self.sci_extn:
108 _lensep = len(self.seperator)
109 _indx = self.sci_extn.find(self.seperator) + _lensep
110 return self.sci_extn[:_indx]+repr(extn)+self.sci_extn[_indx+1:]
111 else:
112 return ''
113 else:
114 return self.sci_extn
115