[1996] | 1 | from asap.asapplotter import asapplotter
|
---|
| 2 | from asap.logging import asaplog, asaplog_post_dec
|
---|
| 3 |
|
---|
| 4 | from asap.parameters import rcParams
|
---|
| 5 | from asap.selector import selector
|
---|
| 6 | from asap.scantable import scantable
|
---|
| 7 | import matplotlib.axes
|
---|
| 8 | from matplotlib.font_manager import FontProperties
|
---|
| 9 | from matplotlib.text import Text
|
---|
| 10 |
|
---|
| 11 | class flagplotter(asapplotter):
|
---|
| 12 | """
|
---|
| 13 | The flag plotter
|
---|
| 14 | Only row based panneling is allowed.
|
---|
| 15 |
|
---|
| 16 | Example:
|
---|
[2001] | 17 | scan = asa p.scantable(filename='your_filename',average=False)
|
---|
[1996] | 18 | guiflagger = asap.flagplotter(visible=True)
|
---|
| 19 | guiflagger.plot(scan)
|
---|
| 20 | ### flag/Unflag data graphically.
|
---|
[2001] | 21 | guiflagger.save_data(name='flagged_file.asap',format='ASAP')
|
---|
[1996] | 22 |
|
---|
| 23 | NOTICE:
|
---|
| 24 | The flagged data is not saved until you explicitly run scantable.save
|
---|
| 25 | """
|
---|
| 26 | def __init__(self, visible=None, **kwargs):
|
---|
[2117] | 27 | self._scan = None
|
---|
[1996] | 28 | asapplotter.__init__(self,visible=visible, **kwargs)
|
---|
[2173] | 29 | self._plotter._set_window_title('Flag Plotter')
|
---|
[1996] | 30 | self._panelling = 'r'
|
---|
[2001] | 31 | self.set_stacking('scan')
|
---|
[2115] | 32 | self._ismodified = False
|
---|
[1996] | 33 |
|
---|
[2173] | 34 | def _new_custombar(self):
|
---|
[2117] | 35 | backend = matplotlib.get_backend()
|
---|
[2173] | 36 | # Flag plotter relys on supported GUI backends
|
---|
| 37 | if not self._visible:
|
---|
| 38 | asaplog.push("GUI backend is not available")
|
---|
| 39 | asaplog.post("ERROR")
|
---|
| 40 | elif backend == "TkAgg":
|
---|
[2155] | 41 | from asap.customgui_tkagg import CustomFlagToolbarTkAgg
|
---|
[1996] | 42 | return CustomFlagToolbarTkAgg(self)
|
---|
[2173] | 43 | elif backend == "Qt4Agg":
|
---|
| 44 | from asap.customgui_qt4agg import CustomFlagToolbarQT4Agg
|
---|
| 45 | return CustomFlagToolbarQT4Agg(self)
|
---|
| 46 | else:
|
---|
| 47 | asaplog.push("Unsupported backend for interactive flagging. Use either TkAgg or PyQt4Agg")
|
---|
| 48 | asaplog.post("ERROR")
|
---|
[1996] | 49 |
|
---|
| 50 | @asaplog_post_dec
|
---|
| 51 | def _invalid_func(self, name):
|
---|
| 52 | msg = "Invalid function 'flagplotter."+name+"'"
|
---|
[2001] | 53 | #raise AttributeError(msg)
|
---|
[1996] | 54 | asaplog.push(msg)
|
---|
| 55 | asaplog.post('ERROR')
|
---|
| 56 |
|
---|
[2001] | 57 | def set_panelling(self,which='r'):
|
---|
| 58 | """ This function is not available for the class flagplotter """
|
---|
| 59 | if which.lower().startswith('r'):
|
---|
| 60 | return
|
---|
| 61 | msg = "Pannel setting is fixed to row mode in 'flagplotter'"
|
---|
| 62 | asaplog.push(msg)
|
---|
| 63 | asaplog.post('ERROR')
|
---|
| 64 | self._panelling = 'r'
|
---|
| 65 |
|
---|
| 66 | def plotazel(self,*args,**kwargs):
|
---|
| 67 | """ This function is not available for the class flagplotter """
|
---|
| 68 | self._invalid_func(name='plotazel')
|
---|
| 69 |
|
---|
| 70 | def plotpointing(self,*args,**kwargs):
|
---|
| 71 | """ This function is not available for the class flagplotter """
|
---|
| 72 | self._invalid_func(name='plotpointing')
|
---|
[2117] | 73 |
|
---|
[2001] | 74 | def plottp(self,*args,**kwargs):
|
---|
| 75 | """ This function is not available for the class flagplotter """
|
---|
| 76 | self._invalid_func(name='plottp')
|
---|
| 77 |
|
---|
[1996] | 78 | def save_data(self, name=None, format=None, overwrite=False):
|
---|
[2001] | 79 | """
|
---|
| 80 | Store the plotted scantable on disk.
|
---|
| 81 | This function simply redirects call to scantable.save()
|
---|
| 82 |
|
---|
| 83 | Parameters:
|
---|
| 84 |
|
---|
| 85 | name: the name of the outputfile. For format "ASCII"
|
---|
| 86 | this is the root file name (data in 'name'.txt
|
---|
| 87 | and header in 'name'_header.txt)
|
---|
| 88 |
|
---|
| 89 | format: an optional file format. Default is ASAP.
|
---|
| 90 | Allowed are:
|
---|
| 91 | * 'ASAP' (save as ASAP [aips++] Table),
|
---|
| 92 | * 'SDFITS' (save as SDFITS file)
|
---|
| 93 | * 'ASCII' (saves as ascii text file)
|
---|
| 94 | * 'MS2' (saves as an casacore MeasurementSet V2)
|
---|
| 95 | * 'FITS' (save as image FITS - not readable by class)
|
---|
| 96 | * 'CLASS' (save as FITS readable by CLASS)
|
---|
| 97 |
|
---|
| 98 | overwrite: If the file should be overwritten if it exists.
|
---|
| 99 | The default False is to return with warning
|
---|
| 100 | without writing the output. USE WITH CARE.
|
---|
| 101 | """
|
---|
[1996] | 102 | # simply calls scantable.save
|
---|
| 103 | self._data.save(name,format,overwrite)
|
---|
[2115] | 104 |
|
---|
| 105 | def set_data(self, scan, refresh=True):
|
---|
| 106 | if self._is_new_scan(scan):
|
---|
| 107 | self._ismodified = False
|
---|
| 108 | asapplotter.set_data(self, scan, refresh)
|
---|
| 109 | set_data.__doc__ = asapplotter.set_data.__doc__
|
---|
| 110 |
|
---|
| 111 | @asaplog_post_dec
|
---|
| 112 | def plot(self, scan=None):
|
---|
| 113 | if self._is_new_scan(scan):
|
---|
| 114 | self._ismodified = False
|
---|
| 115 | asapplotter.plot(self,scan)
|
---|
| 116 | plot.__doc__ = asapplotter.plot.__doc__
|
---|
| 117 |
|
---|
[2175] | 118 | @asaplog_post_dec
|
---|
| 119 | def _plot(self, scan):
|
---|
| 120 | asapplotter._plot(self,scan)
|
---|
| 121 | # rescale x-range of subplots 5% margins
|
---|
| 122 | ganged = (self._plotter.axes._sharex != None)
|
---|
| 123 | if ganged:
|
---|
| 124 | np = 1
|
---|
| 125 | else:
|
---|
| 126 | np = len(self._plotter.subplots)
|
---|
| 127 | for ip in xrange(np):
|
---|
| 128 | ax = self._plotter.subplots[ip]['axes']
|
---|
| 129 | lim0 = ax.get_xlim()
|
---|
| 130 | offset = (lim0[1]-lim0[0])*0.05
|
---|
| 131 | ax.set_xlim(lim0[0]-offset,lim0[1]+offset)
|
---|
| 132 | del ax, lim0, offset
|
---|
| 133 | _plot.__doc__ = asapplotter._plot.__doc__
|
---|
| 134 |
|
---|
[2115] | 135 | def _is_new_scan(self,scan):
|
---|
| 136 | if isinstance(scan, scantable):
|
---|
| 137 | if self._data is not None:
|
---|
| 138 | if scan != self._data:
|
---|
| 139 | return True
|
---|
| 140 | else:
|
---|
| 141 | return True
|
---|
| 142 | return False
|
---|