source: tags/asap-4.0.0/python/flagplotter.py@ 2354

Last change on this file since 2354 was 2175, checked in by Kana Sugimoto, 13 years ago

New Development: No

JIRA Issue: No (a minor improvement)

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs: plot spectra with flagplotter

Put in Release Notes: No

Module(s): flagplotter, sdflag

Description: flagplotter automatically sets 5% margin between subplot x-boundaries

and spectral edges. hope this to be help for users to see/flag band edge features.


File size: 5.2 KB
Line 
1from asap.asapplotter import asapplotter
2from asap.logging import asaplog, asaplog_post_dec
3
4from asap.parameters import rcParams
5from asap.selector import selector
6from asap.scantable import scantable
7import matplotlib.axes
8from matplotlib.font_manager import FontProperties
9from matplotlib.text import Text
10
11class flagplotter(asapplotter):
12 """
13 The flag plotter
14 Only row based panneling is allowed.
15
16 Example:
17 scan = asa p.scantable(filename='your_filename',average=False)
18 guiflagger = asap.flagplotter(visible=True)
19 guiflagger.plot(scan)
20 ### flag/Unflag data graphically.
21 guiflagger.save_data(name='flagged_file.asap',format='ASAP')
22
23 NOTICE:
24 The flagged data is not saved until you explicitly run scantable.save
25 """
26 def __init__(self, visible=None, **kwargs):
27 self._scan = None
28 asapplotter.__init__(self,visible=visible, **kwargs)
29 self._plotter._set_window_title('Flag Plotter')
30 self._panelling = 'r'
31 self.set_stacking('scan')
32 self._ismodified = False
33
34 def _new_custombar(self):
35 backend = matplotlib.get_backend()
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":
41 from asap.customgui_tkagg import CustomFlagToolbarTkAgg
42 return CustomFlagToolbarTkAgg(self)
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")
49
50 @asaplog_post_dec
51 def _invalid_func(self, name):
52 msg = "Invalid function 'flagplotter."+name+"'"
53 #raise AttributeError(msg)
54 asaplog.push(msg)
55 asaplog.post('ERROR')
56
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')
73
74 def plottp(self,*args,**kwargs):
75 """ This function is not available for the class flagplotter """
76 self._invalid_func(name='plottp')
77
78 def save_data(self, name=None, format=None, overwrite=False):
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 """
102 # simply calls scantable.save
103 self._data.save(name,format,overwrite)
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
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
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
Note: See TracBrowser for help on using the repository browser.