Exemple #1
0
    def __call__(self,
                 infile=None,
                 displaytype=None,
                 channel=None,
                 zoom=None,
                 outfile=None,
                 outscale=None,
                 outdpi=None,
                 outformat=None,
                 outlandscape=None,
                 gui=None):
        """ The msview will display measurement sets in raster form
		Many display and editing options are available.

		examples of usage:

		msview
		msview "mymeasurementset.ms"
		msview "myrestorefile.rstr"
		
		Executing the msview task will bring up a display panel
		window, which can be resized.  If no data file was specified,
		a Load Data window will also appear.  Click on the desired data
		file and choose the display type; the rendered data should appear
		on the display panel.

		A Data Display Options window will also appear.  It has drop-down
		subsections for related	options, most of which are self-explanatory.
	  
		The state of the msview task -- loaded data and related display
		options -- can be saved in a 'restore' file for later use.
		You can provide the restore filename on the command line or
		select it from the Load Data window.

		See the cookbook for more details on using the msview task.
	
		Keyword arguments:
		infile -- Name of file to visualize
			default: ''
			example: infile='my.ms'
			If no infile is specified the Load Data window
			will appear for selecting data.
		displaytype -- (optional): method of rendering data
			visually (raster, contour, vector or marker).  
			You can also set this parameter to 'lel' and
			provide an lel expression for infile (advanced).
			default: 'raster'

		Note: there is no longer a filetype parameter; typing of
		data files is now done automatically.
	        	example:  msview infile='my.ms'
			obsolete: msview infile='my.ms', filetype='ms'


		"""
        a = inspect.stack()
        stacklevel = 0
        for k in range(len(a)):
            if a[k][1] == "<string>" or (
                    string.find(a[k][1], 'ipython console') > 0
                    or string.find(a[k][1], "casapy.py") > 0):
                stacklevel = k

        myf = sys._getframe(stacklevel).f_globals

        #Python script
        try:
            ## vi might not be defined in taskinit if loading
            ## directly from python via casa.py...
            vwr = vi
            if type(gui) == bool and gui == False:
                vwr = ving

            if type(vwr.cwd()) != str:
                vwr = None
        except:
            vwr = None

        if type(vwr) == type(None):
            need_gui = True
            if type(gui) == bool and gui == False:
                need_gui = False

            if need_gui:
                if self.local_vi is not None:
                    vwr = self.local_vi
                else:
                    vwr = viewertool.viewertool(
                        True, True, (type(myf) == dict and myf.has_key('casa')
                                     and type(myf['casa']) == type(os)))
                    self.local_vi = vwr
            else:
                if self.local_ving is not None:
                    vwr = self.local_ving
                else:
                    vwr = viewertool.viewertool(
                        False, True, (type(myf) == dict and myf.has_key('casa')
                                      and type(myf['casa']) == type(os)))
                    self.local_ving = vwr

        if type(vwr) != type(None):
            ##
            ## (1) save current *viewer*server* path
            ## (2) have viewer() task follow casapy/python's cwd
            try:
                old_path = vwr.cwd()
            except:
                raise Exception, "msview() failed to get the current working directory"

            try:
                vwr.cwd(os.path.abspath(os.curdir))
            except:
                raise Exception, "msview() failed to change to the new working directory"

            data = None
            if type(infile) == str and len(infile) > 0:
                info = vwr.fileinfo(infile)
                if info['type'] != 'ms':
                    if info['type'] == 'image':
                        raise Exception, "msview() only displays images, try 'imview()'..."
                    elif info['type'] == 'nonexistent':
                        raise Exception, "ms (" + infile + ") could not be found..."
                    else:
                        raise Exception, "unknow error..."

                panel = vwr.panel("viewer")
                if type(displaytype) == str:
                    data = vwr.load(infile, displaytype, panel=panel)
                else:
                    data = vwr.load(infile, panel=panel)

                if type(channel) == int and channel > 0:
                    vwr.channel(channel, panel=panel)
                if type(zoom) == int and zoom != 1:
                    vwr.zoom(zoom, panel=panel)
                if type(outfile) == str and len(outfile) > 0:
                    scale = 1.0
                    if type(outscale) == float:
                        scale = outscale
                    dpi = 300
                    if type(outdpi) == int:
                        dpi = outdpi
                    format = "jpg"
                    if type(outformat) == str:
                        format = outformat
                    orientation = "portrait"
                    if type(outlandscape) == bool and outlandscape:
                        orientation = "landscape"
                    vwr.output(outfile,
                               scale=scale,
                               dpi=dpi,
                               format=format,
                               orientation=orientation,
                               panel=panel)
            else:
                panel = vwr.panel("viewer")
                vwr.popup('open', panel=panel)

            # it makes no sense to leave a panel open with no way of interacting with it
            if type(gui) == bool and not gui:
                vwr.close(panel)

            ## (3) restore original path
            try:
                vwr.cwd(old_path)
            except:
                raise Exception, "msview() failed to restore the old working directory"

        else:
            viewer_path = myf['casa']['helpers'][
                'viewer']  #### set in casapy.py
            args = [viewer_path]

            if type(infile) == str:
                if type(displaytype) == str:
                    args += [infile, displaytype]
                else:
                    args += [infile]

            if (os.uname()[0] == 'Darwin'):
                vwrpid = os.spawnvp(os.P_NOWAIT, viewer_path, args)
            elif (os.uname()[0] == 'Linux'):
                vwrpid = os.spawnlp(os.P_NOWAIT, viewer_path, *args)
            else:
                print 'Unrecognized OS: No msview available'

        return None
Exemple #2
0
        except Exception, instance:
            if hasattr(myclog, "post"):
                myclog.post('*** Error "%s" updating HISTORY of %s' % (instance, vis), "SEVERE")
            retval = False
        finally:
            if isopen:
                myms.close()
        return retval

    ###done with common tools

    # setup viewer tool
    # jagonzal (CAS-4322): Don't load viewer at the engine level
    if not os.environ.has_key("CASA_ENGINE"):
        try:
            ving = viewertool.viewertool(False)
            if casa["flags"].has_key("--nogui"):
                vi = ving
            else:
                vi = viewertool.viewertool(True)
        except:
            print "Unable to start viewer, maybe no dbus available?"

    defaultsdir = {}
    defaultsdir["alma"] = casa["dirs"]["xml"] + "/almadefaults.xml"
    defaultsdir["evla"] = casa["dirs"]["xml"] + "/evladefaults.xml"

    def selectfield(vis, minstring):
        """Derive the fieldid from  minimum matched string(s): """

        tb.open(vis + "/FIELD")
Exemple #3
0
    def __call__( self, raster=None, contour=None, zoom=None, axes=None, out=None ):
        """ Old parameters:
               infile=None,displaytype=None,channel=None,zoom=None,outfile=None,
               outscale=None,outdpi=None,outformat=None,outlandscape=None,gui=None
        The imview task will display images in raster, contour, vector or
        marker form.  Images can be blinked, and movies are available
        for spectral-line image cubes.  For measurement sets, many
        display and editing options are available.

        examples of usage:

        imview
        imview "myimage.im"
        imview "myrestorefile.rstr"
        
        imview "myimage.im", "contour"

        imview "'myimage1.im' - 2 * 'myimage2.im'", "lel"
    
        Executing imview( ) will bring up a display panel
        window, which can be resized.  If no data file was specified,
        a Load Data window will also appear.  Click on the desired data
        file and choose the display type; the rendered data should appear
        on the display panel.

        A Data Display Options window will also appear.  It has drop-down
        subsections for related options, most of which are self-explanatory.
      
        The state of the imview task -- loaded data and related display
        options -- can be saved in a 'restore' file for later use.
        You can provide the restore filename on the command line or
        select it from the Load Data window.

        See the cookbook for more details on using the imview task.
    
        Keyword arguments:
        infile -- Name of file to visualize
            default: ''
            example: infile='ngc5921.image'
            If no infile is specified the Load Data window
            will appear for selecting data.
        displaytype -- (optional): method of rendering data
            visually (raster, contour, vector or marker).  
            You can also set this parameter to 'lel' and
            provide an lel expression for infile (advanced).
            default: 'raster'
            example: displaytype='contour'

        Note: the filetype parameter is optional; typing of
                data files is now inferred.
                example:  imview infile='my.im'
            implies:  imview infile='my.im', filetype='raster'
        the filetype is still used to load contours, etc.


        """
        a=inspect.stack()
        stacklevel=0
        for k in range(len(a)):
            if a[k][1] == "<string>" or (string.find(a[k][1], 'ipython console') > 0 or string.find(a[k][1],"casapy.py") > 0):
                stacklevel=k

        myf=sys._getframe(stacklevel).f_globals

        casalog.origin('imview')
        
        if (type(out) == str and len(out) != 0) or \
               (type(out) == dict and len(out) != 0) :
            gui = False
            (out_file, out_format, out_scale, out_dpi, out_orientation) = self.__extract_outputinfo( out )
        else:
            gui = True

        if gui and self.local_vi is None or \
           not gui and self.local_ving is None:
            try:
                ## vi/ving might not be defined in taskinit if
                ## loading directly from python via casa.py...
                vwr = vi if gui else ving

                if type(vwr) == type(None) or type(vwr.cwd( )) != str:
                    vwr = viewertool.viewertool( gui, True, (type(myf) == dict and myf.has_key('casa') and type(myf['casa']) == type(os)) )
            except:
                vwr = None

            if gui:
                self.local_vi = vwr
            else:
                self.local_ving = vwr
        else:
            vwr = self.local_vi if gui else self.local_ving

        if type(vwr) == type(None):
            casalog.post( "failed to find a viewertool...", 'SEVERE')
            raise Exception, "failed to find a viewertool..."

        self.__pushd( vwr, os.path.abspath(os.curdir) )

        if (raster is None or len(raster) == 0) and \
           (contour is None or len(contour) == 0) :
            panel = self.__panel(vwr)
        else:
            panel = self.__load_files( "raster", vwr, None, raster )
            panel = self.__load_files( "contour", vwr, panel, contour )
            
        self.__set_axes( vwr, panel, axes )
        self.__zoom( vwr, panel, zoom )
        self.__process_colorwedges( vwr, panel )
        #vwr.unfreeze( panel )

        if not gui:
            vwr.output(out,scale=out_scale,dpi=out_dpi,format=out_format,orientation=out_orientation,panel=panel)
            vwr.close(panel)

        self.__popd( vwr )

        return None
Exemple #4
0
                'SEVERE')
        retval = False
    finally:
        if isopen:
            myms.close()
    return retval


###done with common tools

# setup viewer tool
# jagonzal (CAS-4322): Don't load viewer at the engine level
if not os.environ.has_key('CASA_ENGINE'):
    try:
        if casa.has_key('state') and casa['state'].has_key('startup'):
            ving = viewertool.viewertool(False,
                                         pre_launch=casa['state']['startup'])
            if casa['flags'].has_key('--nogui'):
                vi = ving
            else:
                vi = viewertool.viewertool(True,
                                           pre_launch=casa['state']['startup'])
    except:
        print "Unable to start viewer, maybe no dbus available?"

defaultsdir = {}
defaultsdir['alma'] = 'file:///' + os.environ.get('CASAPATH').split(
)[0] + '/' + os.environ.get('CASAPATH').split()[1] + '/xml/almadefaults.xml'
defaultsdir['evla'] = 'file:///' + os.environ.get('CASAPATH').split(
)[0] + '/' + os.environ.get('CASAPATH').split()[1] + '/xml/evladefaults.xml'

Exemple #5
0
	def __call__(self, infile=None,displaytype=None,channel=None,zoom=None,outfile=None,outscale=None,outdpi=None,outformat=None,outlandscape=None,gui=None):
		""" The viewer will display images in raster, contour, vector or
		marker form.  Images can be blinked, and movies are available
		for spectral-line image cubes.  For measurement sets, many
		display and editing options are available.

		examples of usage:

		viewer
		viewer "myimage.im"
		viewer "mymeasurementset.ms"
		viewer "myrestorefile.rstr"
		
		viewer "myimage.im", "contour"

		viewer "'myimage1.im' - 2 * 'myimage2.im'", "lel"
	
		The viewer can be run outside of casapy by typing <casaviewer>.

		Executing viewer <viewer> will bring up a display panel
		window, which can be resized.  If no data file was specified,
		a Load Data window will also appear.  Click on the desired data
		file and choose the display type; the rendered data should appear
		on the display panel.

		A Data Display Options window will also appear.  It has drop-down
		subsections for related	options, most of which are self-explanatory.
	  
		The state of the viewer -- loaded data and related display
		options -- can be saved in a 'restore' file for later use.
		You can provide the restore filename on the command line or
		select it from the Load Data window.

		See the cookbook for more details on using the viewer.
	
		Keyword arguments:
		infile -- Name of file to visualize
			default: ''
			example: infile='ngc5921.image'
			If no infile is specified the Load Data window
			will appear for selecting data.
		displaytype -- (optional): method of rendering data
			visually (raster, contour, vector or marker).  
			You can also set this parameter to 'lel' and
			provide an lel expression for infile (advanced).
			default: 'raster'
			example: displaytype='contour'

		Note: there is no longer a filetype parameter; typing of
		data files is now done automatically.
	        	example:  viewer infile='my.ms'
			obsolete: viewer infile='my.ms', filetype='ms'


		"""
		a=inspect.stack()
		stacklevel=0
		for k in range(len(a)):
			if a[k][1] == "<string>" or (string.find(a[k][1], 'ipython console') > 0 or string.find(a[k][1],"casapy.py") > 0):
				stacklevel=k

		myf=sys._getframe(stacklevel).f_globals

		#Python script
		try:
			## vi might not be defined in taskinit if loading
			## directly from python via casa.py...
			vwr = vi
			if type(gui) == bool and gui == False:
				vwr = ving

			if type(vwr.cwd( )) != str:
				vwr = None
		except:
			vwr = None

		if type(vwr) == type(None):
			need_gui = True
			if type(gui) == bool and gui == False:
				need_gui = False

			if need_gui :
				if self.local_vi is not None:
					vwr = self.local_vi
				else:
					vwr = viewertool.viewertool( True, True, (type(myf) == dict and myf.has_key('casa') and type(myf['casa']) == type(os)) )
					self.local_vi = vwr
			else:
				if self.local_ving is not None:
					vwr = self.local_ving
				else:
					vwr = viewertool.viewertool( False, True, (type(myf) == dict and myf.has_key('casa') and type(myf['casa']) == type(os)) )
					self.local_ving = vwr

		if type(vwr) != type(None) :
			##
			## (1) save current *viewer*server* path
			## (2) have viewer() task follow casapy/python's cwd
			try:
				old_path = vwr.cwd( )
			except:
				raise Exception, "viewer() failed to get the current working directory [" + str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1]) + "]"

			try:
				vwr.cwd(os.path.abspath(os.curdir))
			except:
				raise Exception, "viewer() failed to change to the new working directory (" + os.path.abspath(os.curdir) + ") [" + str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1]) + "]"

			panel = vwr.panel("viewer")
			data = None
			if type(infile) == str and len(infile) > 0 :
				if type(displaytype) == str:
					data = vwr.load( infile, displaytype, panel=panel )
				else:
					data = vwr.load( infile, panel=panel )

				if type(channel) == int and channel > 0 :
					vwr.channel(channel,panel=panel)
				if type(zoom) == int and zoom != 1 :
					vwr.zoom(zoom,panel=panel)
				if type(outfile) == str and len(outfile) > 0 :
					scale=1.0
					if type(outscale) == float :
						scale=outscale
					dpi=300
					if type(outdpi) == int :
						dpi=outdpi
					format="jpg"
					if type(outformat) == str :
						format=outformat
					orientation="portrait"
					if type(outlandscape) == bool and outlandscape :
						orientation="landscape"
					vwr.output(outfile,scale=scale,dpi=dpi,format=format,orientation=orientation,panel=panel)
			else:
				vwr.popup( 'open', panel=panel )


			# it makes no sense to leave a panel open with no way of interacting with it
			if type(gui) == bool and not gui:
				vwr.close(panel)

			## (3) restore original path
			try:
				vwr.cwd(old_path)
			except:
				raise Exception, "viewer() failed to restore the old working directory (" + old_path + ") [" + str(sys.exc_info()[0]) + ": " + str(sys.exc_info()[1]) + "]"

		else:
			viewer_path = myf['casa']['helpers']['viewer']   #### set in casapy.py
			args = [ viewer_path ]

			if type(infile) == str:
				if type(displaytype) == str:
					args += [ infile, displaytype ]
				else:
					args += [ infile ]

			if (os.uname()[0]=='Darwin'):
				vwrpid=os.spawnvp( os.P_NOWAIT, viewer_path, args )
			elif (os.uname()[0]=='Linux'):
				vwrpid=os.spawnlp( os.P_NOWAIT, viewer_path, *args )
			else:
				print 'Unrecognized OS: No viewer available'

		return None
Exemple #6
0
    def __call__( self, raster=None, contour=None, zoom=None, axes=None, out=None ):
        """ Old parameters:
               infile=None,displaytype=None,channel=None,zoom=None,outfile=None,
               outscale=None,outdpi=None,outformat=None,outlandscape=None,gui=None
        The imview task will display images in raster, contour, vector or
        marker form.  Images can be blinked, and movies are available
        for spectral-line image cubes.  For measurement sets, many
        display and editing options are available.

        examples of usage:

        imview
        imview "myimage.im"
        imview "myrestorefile.rstr"
        
        imview "myimage.im", "contour"

        imview "'myimage1.im' - 2 * 'myimage2.im'", "lel"
    
        Executing imview( ) will bring up a display panel
        window, which can be resized.  If no data file was specified,
        a Load Data window will also appear.  Click on the desired data
        file and choose the display type; the rendered data should appear
        on the display panel.

        A Data Display Options window will also appear.  It has drop-down
        subsections for related options, most of which are self-explanatory.
      
        The state of the imview task -- loaded data and related display
        options -- can be saved in a 'restore' file for later use.
        You can provide the restore filename on the command line or
        select it from the Load Data window.

        See the cookbook for more details on using the imview task.
    
        Keyword arguments:
        infile -- Name of file to visualize
            default: ''
            example: infile='ngc5921.image'
            If no infile is specified the Load Data window
            will appear for selecting data.
        displaytype -- (optional): method of rendering data
            visually (raster, contour, vector or marker).  
            You can also set this parameter to 'lel' and
            provide an lel expression for infile (advanced).
            default: 'raster'
            example: displaytype='contour'

        Note: the filetype parameter is optional; typing of
                data files is now inferred.
                example:  imview infile='my.im'
            implies:  imview infile='my.im', filetype='raster'
        the filetype is still used to load contours, etc.


        """
        myf=stack_frame_find( )
        vi = myf['vi'] if myf.has_key('vi') else None
        ving = myf['ving'] if myf.has_key('ving') else None

        casalog.origin('imview')
        
        if (type(out) == str and len(out) != 0) or \
               (type(out) == dict and len(out) != 0) :
            gui = False
            (out_file, out_format, out_scale, out_dpi, out_orientation) = self.__extract_outputinfo( out )
        else:
            gui = True

        if gui and self.local_vi is None or \
           not gui and self.local_ving is None:
            try:
                ## vi/ving might not be defined in taskinit if
                ## loading directly from python via casa.py...
                vwr = vi if gui else ving

                if type(vwr) == type(None) or type(vwr.cwd( )) != str:
                    vwr = viewertool.viewertool( gui, True, (type(myf) == dict and myf.has_key('casa') and type(myf['casa']) == type(os)) )
            except:
                vwr = None

            if gui:
                self.local_vi = vwr
            else:
                self.local_ving = vwr
        else:
            vwr = self.local_vi if gui else self.local_ving

        if type(vwr) == type(None):
            casalog.post( "failed to find a viewertool...", 'SEVERE')
            raise Exception, "failed to find a viewertool..."

        self.__pushd( vwr, os.path.abspath(os.curdir) )

        if (raster is None or len(raster) == 0) and \
           (contour is None or len(contour) == 0) :
            panel = self.__panel(vwr)
        else:
            panel = self.__load_files( "raster", vwr, None, raster )
            panel = self.__load_files( "contour", vwr, panel, contour )
            
        self.__set_axes( vwr, panel, axes )
        self.__zoom( vwr, panel, zoom )
        self.__process_colorwedges( vwr, panel )
        #vwr.unfreeze( panel )

        if not gui:
            vwr.output(out,scale=out_scale,dpi=out_dpi,format=out_format,orientation=out_orientation,panel=panel)
            vwr.close(panel)

        self.__popd( vwr )

        return None
Exemple #7
0
            if hasattr(myclog, 'post'):
                myclog.post("*** Error \"%s\" updating HISTORY of %s" % (instance, vis),
                            'SEVERE')
            retval = False
        finally:
            if isopen:
                myms.close()
        return retval

    ###done with common tools

    # setup viewer tool
    # jagonzal (CAS-4322): Don't load viewer at the engine level
    if not os.environ.has_key('CASA_ENGINE'):
        try:
            ving = viewertool.viewertool( False )
            if casa['flags'].has_key('--nogui') :
                vi = ving
            else:
                vi = viewertool.viewertool( True )
        except :
            print "Unable to start viewer, maybe no dbus available?"

    defaultsdir = {}
    defaultsdir['alma'] = casa['dirs']['xml'] + '/almadefaults.xml'
    defaultsdir['evla'] = casa['dirs']['xml'] + '/evladefaults.xml'


    def selectfield(vis,minstring):
        """Derive the fieldid from  minimum matched string(s): """
Exemple #8
0
                        myclog.post("*** Error \"%s\" updating HISTORY of %s" % (instance, vis),
                                    'SEVERE')
                retval = False
        finally:
                if isopen:
                        myms.close()
        return retval        

###done with common tools

# setup viewer tool
# jagonzal (CAS-4322): Don't load viewer at the engine level
if not os.environ.has_key('CASA_ENGINE'):
	try : 
		if casa.has_key('state') and casa['state'].has_key('startup') :
			ving = viewertool.viewertool( False, pre_launch=casa['state']['startup'] )
			if casa['flags'].has_key('--nogui') :
				vi = ving
			else:
				vi = viewertool.viewertool( True, pre_launch=casa['state']['startup'] )
	except :
		print "Unable to start viewer, maybe no dbus available?"

defaultsdir = {}
defaultsdir['alma'] = 'file:///'+os.environ.get('CASAPATH').split()[0]+'/'+os.environ.get('CASAPATH').split()[1]+'/xml/almadefaults.xml'
defaultsdir['evla'] = 'file:///'+os.environ.get('CASAPATH').split()[0]+'/'+os.environ.get('CASAPATH').split()[1]+'/xml/evladefaults.xml'


def selectfield(vis,minstring):
        """Derive the fieldid from  minimum matched string(s): """
Exemple #9
0
	def __call__(self, infile=None,displaytype=None,channel=None,zoom=None,outfile=None,outscale=None,outdpi=None,outformat=None,outlandscape=None,gui=None):
		""" The msview will display measurement sets in raster form
		Many display and editing options are available.

		examples of usage:

		msview
		msview "mymeasurementset.ms"
		msview "myrestorefile.rstr"
		
		Executing the msview task will bring up a display panel
		window, which can be resized.  If no data file was specified,
		a Load Data window will also appear.  Click on the desired data
		file and choose the display type; the rendered data should appear
		on the display panel.

		A Data Display Options window will also appear.  It has drop-down
		subsections for related	options, most of which are self-explanatory.
	  
		The state of the msview task -- loaded data and related display
		options -- can be saved in a 'restore' file for later use.
		You can provide the restore filename on the command line or
		select it from the Load Data window.

		See the cookbook for more details on using the msview task.
	
		Keyword arguments:
		infile -- Name of file to visualize
			default: ''
			example: infile='my.ms'
			If no infile is specified the Load Data window
			will appear for selecting data.
		displaytype -- (optional): method of rendering data
			visually (raster, contour, vector or marker).  
			You can also set this parameter to 'lel' and
			provide an lel expression for infile (advanced).
			default: 'raster'

		Note: there is no longer a filetype parameter; typing of
		data files is now done automatically.
	        	example:  msview infile='my.ms'
			obsolete: msview infile='my.ms', filetype='ms'


		"""
                myf=stack_frame_find( )
                vi = myf['vi'] if myf.has_key('vi') else None
                ving = myf['ving'] if myf.has_key('ving') else None

		#Python script
		try:
			## vi might not be defined in taskinit if loading
			## directly from python via casa.py...
			vwr = vi
			if type(gui) == bool and gui == False:
				vwr = ving

			if type(vwr.cwd( )) != str:
				vwr = None
		except:
			vwr = None

		if type(vwr) == type(None):
			need_gui = True
			if type(gui) == bool and gui == False:
				need_gui = False

			if need_gui :
				if self.local_vi is not None:
					vwr = self.local_vi
				else:
					vwr = viewertool.viewertool( True, True, (type(myf) == dict and myf.has_key('casa') and type(myf['casa']) == type(os)) )
					self.local_vi = vwr
			else:
				if self.local_ving is not None:
					vwr = self.local_ving
				else:
					vwr = viewertool.viewertool( False, True, (type(myf) == dict and myf.has_key('casa') and type(myf['casa']) == type(os)) )
					self.local_ving = vwr

		if type(vwr) != type(None) :
			##
			## (1) save current *viewer*server* path
			## (2) have viewer() task follow casapy/python's cwd
			try:
				old_path = vwr.cwd( )
			except:
				raise Exception, "msview() failed to get the current working directory"

			try:
				vwr.cwd(os.path.abspath(os.curdir))
			except:
				raise Exception, "msview() failed to change to the new working directory"
				
			data = None
			if type(infile) == str and len(infile) > 0 :
				info = vwr.fileinfo(infile);
				if info['type'] != 'ms' :
					if info['type'] == 'image' :
						raise Exception, "msview() only displays images, try 'imview()'..."
					elif info['type'] == 'nonexistent' :
						raise Exception, "ms (" + infile + ") could not be found..."
					else :
						raise Exception, "unknow error..."

				panel = vwr.panel("viewer")
				if type(displaytype) == str:
					data = vwr.load( infile, displaytype, panel=panel )
				else:
					data = vwr.load( infile, panel=panel )

				if type(channel) == int and channel > 0 :
					vwr.channel(channel,panel=panel)
				if type(zoom) == int and zoom != 1 :
					vwr.zoom(zoom,panel=panel)
				if type(outfile) == str and len(outfile) > 0 :
					scale=1.0
					if type(outscale) == float :
						scale=outscale
					dpi=300
					if type(outdpi) == int :
						dpi=outdpi
					format="jpg"
					if type(outformat) == str :
						format=outformat
					orientation="portrait"
					if type(outlandscape) == bool and outlandscape :
						orientation="landscape"
					vwr.output(outfile,scale=scale,dpi=dpi,format=format,orientation=orientation,panel=panel)
			else:
				panel = vwr.panel("viewer")
				vwr.popup( 'open', panel=panel )


			# it makes no sense to leave a panel open with no way of interacting with it
			if type(gui) == bool and not gui:
				vwr.close(panel)

			## (3) restore original path
			try:
				vwr.cwd(old_path)
			except:
				raise Exception, "msview() failed to restore the old working directory"

		else:
			viewer_path = myf['casa']['helpers']['viewer']   #### set in casapy.py
			args = [ viewer_path ]

			if type(infile) == str:
				if type(displaytype) == str:
					args += [ infile, displaytype ]
				else:
					args += [ infile ]

			if (os.uname()[0]=='Darwin'):
				vwrpid=os.spawnvp( os.P_NOWAIT, viewer_path, args )
			elif (os.uname()[0]=='Linux'):
				vwrpid=os.spawnlp( os.P_NOWAIT, viewer_path, *args )
			else:
				print 'Unrecognized OS: No msview available'

		return None
Exemple #10
0
    def __call__(self,
                 infile=None,
                 displaytype=None,
                 channel=None,
                 zoom=None,
                 outfile=None,
                 outscale=None,
                 outdpi=None,
                 outformat=None,
                 outlandscape=None,
                 gui=None):
        """ The viewer will display images in raster, contour, vector or
		marker form.  Images can be blinked, and movies are available
		for spectral-line image cubes.  For measurement sets, many
		display and editing options are available.

		examples of usage:

		viewer
		viewer "myimage.im"
		viewer "mymeasurementset.ms"
		viewer "myrestorefile.rstr"
		
		viewer "myimage.im", "contour"

		viewer "'myimage1.im' - 2 * 'myimage2.im'", "lel"
	
		The viewer can be run outside of casapy by typing <casaviewer>.

		Executing viewer <viewer> will bring up a display panel
		window, which can be resized.  If no data file was specified,
		a Load Data window will also appear.  Click on the desired data
		file and choose the display type; the rendered data should appear
		on the display panel.

		A Data Display Options window will also appear.  It has drop-down
		subsections for related	options, most of which are self-explanatory.
	  
		The state of the viewer -- loaded data and related display
		options -- can be saved in a 'restore' file for later use.
		You can provide the restore filename on the command line or
		select it from the Load Data window.

		See the cookbook for more details on using the viewer.
	
		Keyword arguments:
		infile -- Name of file to visualize
			default: ''
			example: infile='ngc5921.image'
			If no infile is specified the Load Data window
			will appear for selecting data.
		displaytype -- (optional): method of rendering data
			visually (raster, contour, vector or marker).  
			You can also set this parameter to 'lel' and
			provide an lel expression for infile (advanced).
			default: 'raster'
			example: displaytype='contour'

		Note: there is no longer a filetype parameter; typing of
		data files is now done automatically.
	        	example:  viewer infile='my.ms'
			obsolete: viewer infile='my.ms', filetype='ms'


		"""
        myf = stack_frame_find()
        vi = myf['vi'] if myf.has_key('vi') else None
        ving = myf['ving'] if myf.has_key('ving') else None

        #Python script
        try:
            vwr = vi
            if type(gui) == bool and gui == False:
                vwr = ving

            if type(vwr.cwd()) != str:
                vwr = None
        except:
            vwr = None

        if type(vwr) == type(None):
            need_gui = True
            if type(gui) == bool and gui == False:
                need_gui = False

            if need_gui:
                if self.local_vi is not None:
                    vwr = self.local_vi
                else:
                    vwr = viewertool.viewertool(
                        True, True, (type(myf) == dict and myf.has_key('casa')
                                     and type(myf['casa']) == type(os)))
                    self.local_vi = vwr
            else:
                if self.local_ving is not None:
                    vwr = self.local_ving
                else:
                    vwr = viewertool.viewertool(
                        False, True, (type(myf) == dict and myf.has_key('casa')
                                      and type(myf['casa']) == type(os)))
                    self.local_ving = vwr

        if type(vwr) != type(None):
            ##
            ## (1) save current *viewer*server* path
            ## (2) have viewer() task follow casapy/python's cwd
            try:
                old_path = vwr.cwd()
            except:
                raise Exception, "viewer() failed to get the current working directory [" + str(
                    sys.exc_info()[0]) + ": " + str(sys.exc_info()[1]) + "]"

            try:
                vwr.cwd(os.path.abspath(os.curdir))
            except:
                raise Exception, "viewer() failed to change to the new working directory (" + os.path.abspath(
                    os.curdir) + ") [" + str(sys.exc_info()[0]) + ": " + str(
                        sys.exc_info()[1]) + "]"

            panel = vwr.panel("viewer")
            data = None
            if type(infile) == str and len(infile) > 0:
                if type(displaytype) == str:
                    data = vwr.load(infile, displaytype, panel=panel)
                else:
                    data = vwr.load(infile, panel=panel)

                if type(channel) == int and channel > 0:
                    vwr.channel(channel, panel=panel)
                if type(zoom) == int and zoom != 1:
                    vwr.zoom(zoom, panel=panel)
                if type(outfile) == str and len(outfile) > 0:
                    scale = 1.0
                    if type(outscale) == float:
                        scale = outscale
                    dpi = 300
                    if type(outdpi) == int:
                        dpi = outdpi
                    format = "jpg"
                    if type(outformat) == str:
                        format = outformat
                    orientation = "portrait"
                    if type(outlandscape) == bool and outlandscape:
                        orientation = "landscape"
                    vwr.output(outfile,
                               scale=scale,
                               dpi=dpi,
                               format=format,
                               orientation=orientation,
                               panel=panel)
            else:
                vwr.popup('open', panel=panel)

            # it makes no sense to leave a panel open with no way of interacting with it
            if type(gui) == bool and not gui:
                vwr.close(panel)

            ## (3) restore original path
            try:
                vwr.cwd(old_path)
            except:
                raise Exception, "viewer() failed to restore the old working directory (" + old_path + ") [" + str(
                    sys.exc_info()[0]) + ": " + str(sys.exc_info()[1]) + "]"

        else:
            viewer_path = myf['casa']['helpers'][
                'viewer']  #### set in casapy.py
            args = [viewer_path]

            if type(infile) == str:
                if type(displaytype) == str:
                    args += [infile, displaytype]
                else:
                    args += [infile]

            if (os.uname()[0] == 'Darwin'):
                vwrpid = os.spawnvp(os.P_NOWAIT, viewer_path, args)
            elif (os.uname()[0] == 'Linux'):
                vwrpid = os.spawnlp(os.P_NOWAIT, viewer_path, *args)
            else:
                print 'Unrecognized OS: No viewer available'

        return None