source: trunk/python/asapreader.py@ 414

Last change on this file since 414 was 411, checked in by mar637, 20 years ago

Added handling of environment variables throughout.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1from asap._asap import sdreader
2
3class reader(sdreader):
4 """
5 This class allows the user to import single dish files
6 (rpfits,sdfits,ms).
7 The reader reads in integrations from the file and reamins at
8 the fileposition afterwards.
9 Available functions are:
10
11 read(integrations)
12 summary CURRENTLY DISABLED
13
14 Example:
15 r = reader('/tmp/P389.rpf')
16 scans r.read() # reads in the complete file into 'scans'
17 print scans # summarises the contents
18 del r # destroys the reader
19 """
20
21 def __init__(self, filename, unit=None, theif=None, thebeam=None):
22 self.unit = unit
23 """
24 Parameters:
25 filename: the name of an rpfits/sdfits/ms file on disk
26 unit: brightness unit; must be consistent with K or Jy.
27 The default is that a unit is set depending on
28 the telescope. Setting this over-rides that choice.
29 theif: select a specific IF (default is all)
30 thebeam: select a specific beam (default is all)
31 Example:
32 r = reader('/tmp/2001-09-01_0332_P363.rpf', theif=2)
33 """
34 if theif is None:
35 theif = -1
36 if thebeam is None:
37 thebeam = -1
38 from os.path import expandvars
39 filename = expandvars(filename)
40 sdreader.__init__(self, filename, theif, thebeam)
41
42 def read(self,integrations=None):
43 """
44 Reads in an returns a specified sequence of integrations.
45 If no list is given all integrations a read in.
46 Parameters:
47 integrations: a 'range' of integration numbers, e.g.
48 range(100) or [0,1,2,3,4,10,11,100]
49 If not given (default) all integrations
50 are read in
51 Example:
52 r.read([0,1,2,3,4]) # reads in the first 5 integatrions
53 # NOT scans
54 r.read(range(100)) # read in the first 100 integrations
55 """
56 from asap import scantable
57 if integrations is None:
58 integrations = [-1]
59 print "Reading integrations from disk..."
60 sdreader._read(self,integrations)
61 tbl = sdreader._getdata(self)
62 sdreader._reset(self) # reset to the beginning of the file
63 if self.unit is not None:
64 tbl.set_fluxunit(self.unit)
65 return scantable(tbl)
66
67 def summary(self, name=None):
68 """
69 Print a summary of all scans/integrations. This reads through the
70 whole file once.
71 Parameters:
72 None
73 Example:
74 r.summary()
75 """
76 sdreader._reset(self)
77 sdreader._read(self,[-1])
78 from asap import scantable
79 tbl = scantable(sdreader._getdata(self))
80 sdreader._reset(self)
81 print tbl.summary(name=name)
82 return
83## def reset(self):
84## """
85## [Advanced use]
86## Reset to the beginning of the file.
87## Parameters:
88## none
89## Examples:
90## r = reader('xyz.sdfits')
91## scans0 = r.read(range(10))
92## r.reset()
93## scans1 = r.read(range(5,15))
94## # produces 2 scatables one containing integrations(rows) 0-9
95## # and a second one with rows 5-14
96## """
97## sdreader._reset(self)
98
Note: See TracBrowser for help on using the repository browser.