casa
$Rev:20696$
|
00001 import sys 00002 import os 00003 import inspect 00004 import string 00005 import time 00006 from taskinit import * 00007 import viewertool 00008 00009 00010 class __msview_class(object): 00011 "msview() task with local state for created viewer tool" 00012 00013 def __init__( self ): 00014 self.local_vi = None 00015 self.local_ving = None 00016 00017 def __call__(self, infile=None,displaytype=None,channel=None,zoom=None,outfile=None,outscale=None,outdpi=None,outformat=None,outlandscape=None,gui=None): 00018 """ The msview will display measurement sets in raster form 00019 Many display and editing options are available. 00020 00021 examples of usage: 00022 00023 msview 00024 msview "mymeasurementset.ms" 00025 msview "myrestorefile.rstr" 00026 00027 Executing the msview task will bring up a display panel 00028 window, which can be resized. If no data file was specified, 00029 a Load Data window will also appear. Click on the desired data 00030 file and choose the display type; the rendered data should appear 00031 on the display panel. 00032 00033 A Data Display Options window will also appear. It has drop-down 00034 subsections for related options, most of which are self-explanatory. 00035 00036 The state of the msview task -- loaded data and related display 00037 options -- can be saved in a 'restore' file for later use. 00038 You can provide the restore filename on the command line or 00039 select it from the Load Data window. 00040 00041 See the cookbook for more details on using the msview task. 00042 00043 Keyword arguments: 00044 infile -- Name of file to visualize 00045 default: '' 00046 example: infile='my.ms' 00047 If no infile is specified the Load Data window 00048 will appear for selecting data. 00049 displaytype -- (optional): method of rendering data 00050 visually (raster, contour, vector or marker). 00051 You can also set this parameter to 'lel' and 00052 provide an lel expression for infile (advanced). 00053 default: 'raster' 00054 00055 Note: there is no longer a filetype parameter; typing of 00056 data files is now done automatically. 00057 example: msview infile='my.ms' 00058 obsolete: msview infile='my.ms', filetype='ms' 00059 00060 00061 """ 00062 a=inspect.stack() 00063 stacklevel=0 00064 for k in range(len(a)): 00065 if a[k][1] == "<string>" or (string.find(a[k][1], 'ipython console') > 0 or string.find(a[k][1],"casapy.py") > 0): 00066 stacklevel=k 00067 00068 myf=sys._getframe(stacklevel).f_globals 00069 00070 #Python script 00071 try: 00072 ## vi might not be defined in taskinit if loading 00073 ## directly from python via casa.py... 00074 vwr = vi 00075 if type(gui) == bool and gui == False: 00076 vwr = ving 00077 00078 if type(vwr.cwd( )) != str: 00079 vwr = None 00080 except: 00081 vwr = None 00082 00083 if type(vwr) == type(None): 00084 need_gui = True 00085 if type(gui) == bool and gui == False: 00086 need_gui = False 00087 00088 if need_gui : 00089 if self.local_vi is not None: 00090 vwr = self.local_vi 00091 else: 00092 vwr = viewertool.viewertool( True, True, (type(myf) == dict and myf.has_key('casa') and type(myf['casa']) == type(os)) ) 00093 self.local_vi = vwr 00094 else: 00095 if self.local_ving is not None: 00096 vwr = self.local_ving 00097 else: 00098 vwr = viewertool.viewertool( False, True, (type(myf) == dict and myf.has_key('casa') and type(myf['casa']) == type(os)) ) 00099 self.local_ving = vwr 00100 00101 if type(vwr) != type(None) : 00102 ## 00103 ## (1) save current *viewer*server* path 00104 ## (2) have viewer() task follow casapy/python's cwd 00105 try: 00106 old_path = vwr.cwd( ) 00107 except: 00108 raise Exception, "msview() failed to get the current working directory" 00109 00110 try: 00111 vwr.cwd(os.path.abspath(os.curdir)) 00112 except: 00113 raise Exception, "msview() failed to change to the new working directory" 00114 00115 data = None 00116 if type(infile) == str and len(infile) > 0 : 00117 info = vwr.fileinfo(infile); 00118 if info['type'] != 'ms' : 00119 if info['type'] == 'image' : 00120 raise Exception, "msview() only displays images, try 'imview()'..." 00121 elif info['type'] == 'nonexistent' : 00122 raise Exception, "ms (" + infile + ") could not be found..." 00123 else : 00124 raise Exception, "unknow error..." 00125 00126 panel = vwr.panel("viewer") 00127 if type(displaytype) == str: 00128 data = vwr.load( infile, displaytype, panel=panel ) 00129 else: 00130 data = vwr.load( infile, panel=panel ) 00131 00132 if type(channel) == int and channel > 0 : 00133 vwr.channel(channel,panel=panel) 00134 if type(zoom) == int and zoom != 1 : 00135 vwr.zoom(zoom,panel=panel) 00136 if type(outfile) == str and len(outfile) > 0 : 00137 scale=1.0 00138 if type(outscale) == float : 00139 scale=outscale 00140 dpi=300 00141 if type(outdpi) == int : 00142 dpi=outdpi 00143 format="jpg" 00144 if type(outformat) == str : 00145 format=outformat 00146 orientation="portrait" 00147 if type(outlandscape) == bool and outlandscape : 00148 orientation="landscape" 00149 vwr.output(outfile,scale=scale,dpi=dpi,format=format,orientation=orientation,panel=panel) 00150 else: 00151 panel = vwr.panel("viewer") 00152 vwr.popup( 'open', panel=panel ) 00153 00154 00155 # it makes no sense to leave a panel open with no way of interacting with it 00156 if type(gui) == bool and not gui: 00157 vwr.close(panel) 00158 00159 ## (3) restore original path 00160 try: 00161 vwr.cwd(old_path) 00162 except: 00163 raise Exception, "msview() failed to restore the old working directory" 00164 00165 else: 00166 viewer_path = myf['casa']['helpers']['viewer'] #### set in casapy.py 00167 args = [ viewer_path ] 00168 00169 if type(infile) == str: 00170 if type(displaytype) == str: 00171 args += [ infile, displaytype ] 00172 else: 00173 args += [ infile ] 00174 00175 if (os.uname()[0]=='Darwin'): 00176 vwrpid=os.spawnvp( os.P_NOWAIT, viewer_path, args ) 00177 elif (os.uname()[0]=='Linux'): 00178 vwrpid=os.spawnlp( os.P_NOWAIT, viewer_path, *args ) 00179 else: 00180 print 'Unrecognized OS: No msview available' 00181 00182 return None 00183 00184 msview = __msview_class( )