[103] | 1 | from asap._asap import sdreader |
---|
| 2 | |
---|
| 3 | class reader(sdreader): |
---|
| 4 | """ |
---|
| 5 | This class allows the user to import single dish files |
---|
| 6 | (rpfits,sdfits,ms). |
---|
[113] | 7 | The reader reads in integrations from the file and reamins at |
---|
| 8 | the fileposition afterwards. |
---|
[103] | 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 | |
---|
[341] | 21 | def __init__(self, filename, unit=None, theif=None, thebeam=None): |
---|
| 22 | self.unit = unit |
---|
[103] | 23 | """ |
---|
| 24 | Parameters: |
---|
| 25 | filename: the name of an rpfits/sdfits/ms file on disk |
---|
[339] | 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. |
---|
[333] | 29 | theif: select a specific IF (default is all) |
---|
| 30 | thebeam: select a specific beam (default is all) |
---|
[103] | 31 | Example: |
---|
[333] | 32 | r = reader('/tmp/2001-09-01_0332_P363.rpf', theif=2) |
---|
[103] | 33 | """ |
---|
[333] | 34 | if theif is None: |
---|
| 35 | theif = -1 |
---|
| 36 | if thebeam is None: |
---|
| 37 | thebeam = -1 |
---|
[411] | 38 | from os.path import expandvars |
---|
| 39 | filename = expandvars(filename) |
---|
[341] | 40 | sdreader.__init__(self, filename, theif, thebeam) |
---|
[103] | 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] |
---|
[113] | 49 | If not given (default) all integrations |
---|
| 50 | are read in |
---|
[103] | 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] |
---|
[127] | 59 | print "Reading integrations from disk..." |
---|
[406] | 60 | sdreader._read(self,integrations) |
---|
| 61 | tbl = sdreader._getdata(self) |
---|
[409] | 62 | sdreader._reset(self) # reset to the beginning of the file |
---|
[341] | 63 | if self.unit is not None: |
---|
| 64 | tbl.set_fluxunit(self.unit) |
---|
[103] | 65 | return scantable(tbl) |
---|
| 66 | |
---|
[411] | 67 | def summary(self, name=None): |
---|
[113] | 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 | """ |
---|
[406] | 76 | sdreader._reset(self) |
---|
| 77 | sdreader._read(self,[-1]) |
---|
[411] | 78 | from asap import scantable |
---|
| 79 | tbl = scantable(sdreader._getdata(self)) |
---|
[406] | 80 | sdreader._reset(self) |
---|
[411] | 81 | print tbl.summary(name=name) |
---|
[113] | 82 | return |
---|
[409] | 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) |
---|
[406] | 98 | |
---|