| 1 | from asap._asap import stfiller | 
|---|
| 2 | from asap import print_log | 
|---|
| 3 |  | 
|---|
| 4 | class reader(stfiller): | 
|---|
| 5 | """ | 
|---|
| 6 | This class allows the user to import single dish files | 
|---|
| 7 | (rpfits,sdfits,ms). | 
|---|
| 8 | The reader reads in integrations from the file and remains at | 
|---|
| 9 | the fileposition afterwards. | 
|---|
| 10 | Available functions are: | 
|---|
| 11 |  | 
|---|
| 12 | read() # read until the (current) end of file) | 
|---|
| 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 | stfiller.__init__(self, filename, theif, thebeam) | 
|---|
| 48 | print_log() | 
|---|
| 49 |  | 
|---|
| 50 | def read(self): | 
|---|
| 51 | """ | 
|---|
| 52 | Reads in all integrations in the data file. | 
|---|
| 53 | """ | 
|---|
| 54 | from asap import scantable | 
|---|
| 55 | from asap import asaplog | 
|---|
| 56 | asaplog.push("Reading integrations from disk...") | 
|---|
| 57 | stfiller._read(self) | 
|---|
| 58 | tbl = stfiller._getdata(self) | 
|---|
| 59 | if self.unit is not None: | 
|---|
| 60 | tbl.set_fluxunit(self.unit) | 
|---|
| 61 | print_log() | 
|---|
| 62 | return scantable(tbl) | 
|---|
| 63 |  | 
|---|
| 64 | def close(self): | 
|---|
| 65 | """ | 
|---|
| 66 | Close the reader. | 
|---|
| 67 | """ | 
|---|
| 68 | self._close() | 
|---|
| 69 |  | 
|---|
| 70 | def summary(self, name=None): | 
|---|
| 71 | """ | 
|---|
| 72 | Print a summary of all scans/integrations. This reads through the | 
|---|
| 73 | whole file once. | 
|---|
| 74 | Parameters: | 
|---|
| 75 | None | 
|---|
| 76 | Example: | 
|---|
| 77 | r.summary() | 
|---|
| 78 | """ | 
|---|
| 79 | stfiller._read(self) | 
|---|
| 80 | from asap import scantable | 
|---|
| 81 | tbl = scantable(stfiller._getdata(self)) | 
|---|
| 82 | tbl.summary(name) | 
|---|
| 83 | del tbl | 
|---|
| 84 | return | 
|---|