source: branches/Release-2-fixes/python/asapreader.py@ 1952

Last change on this file since 1952 was 415, checked in by mar637, 20 years ago

Made note about reader limitation on rpfits.
fixed up summary (again)

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