def connect_to_ginga(host='localhost', port=9000, raise_err=False, allow_new=False): """ Connect to a RC Ginga. Args: host (:obj:`str`, optional): Host name. port (:obj:`int`, optional): Probably should remain at 9000 raise_err (:obj:`bool`, optional): Raise an error if no connection is made, otherwise just raise a warning and continue allow_new (:obj:`bool`, optional): Allow a subprocess to be called to execute a new ginga viewer if one is not already running. Returns: RemoteClient: connection to ginga viewer. """ # Start viewer = grc.RemoteClient(host, port) # Test sh = viewer.shell() try: tmp = sh.get_current_workspace() except: if allow_new: subprocess.Popen(['ginga', '--modules=RC']) # NOTE: time.sleep(3) is now insufficient. The loop below # continues to try to connect with the ginga viewer that # was just instantiated for a maximum number of iterations. # If the connection is remains unsuccessful, an error is # thrown stating that the connection timed out. maxiter = int(1e6) for i in range(maxiter): try: viewer = grc.RemoteClient(host, port) sh = viewer.shell() tmp = sh.get_current_workspace() except: continue else: break if i == maxiter-1: msgs.error('Timeout waiting for ginga to start. If window does not appear, type ' '`ginga --modules=RC` on the command line. In either case, wait for ' 'the ginga viewer to open and try the pypeit command again.') return viewer if raise_err: raise ValueError else: msgs.warn('Problem connecting to Ginga. Launch an RC Ginga viewer and ' 'then continue: \n ginga --modules=RC') # Return return viewer
def show_fits(fits_file, host='localhost', port=9000, **kwargs): ''' Read a binary FITS file into an active Ginga window Parameters --------- fits_file: str Filename host: str, optional Name of the host; Default='localhost' port: int, optional Value of the port; Default=9000 ''' # Full path? if fits_file[0] != '/': fil = os.getcwd() + '/' + fits_file else: fil = fits_file # Check for file if not os.path.isfile(fil): raise ValueError('File={:s} not found!'.format(fil)) # Connect to ginga RC (should have error checking here) client = grc.RemoteClient(host, port) # Connect to ginga widget method = getattr(client, 'ginga') # Set up args command = 'load_file' args = [command, fil] # Execute res = method(*args, **kwargs)
def connect_to_ginga(host='localhost', port=9000, raise_err=False): """ Connect to an active RC Ginga Args: host (str, optional): port (int, optional): Probably should remain at 9000 raise_err (bool, optional): Raise an error if no connection is made, otherwise just raise a warning and continue Returns: RemoteClient: connection to ginga viewer """ # Start viewer = grc.RemoteClient(host, port) # Test ginga = viewer.shell() try: tmp = ginga.get_current_workspace() except: if raise_err: raise ValueError else: msgs.warn( "Problem connecting to Ginga. Launch an RC Ginga viewer: ginga --modules=RC then continue." ) # Return return viewer
def connect_to_ginga(host='localhost', port=9000): """ Connect to an active RC Ginga Parameters ---------- host : str, optional port : int, optional Returns ------- viewer : RemoteClient connectoin to Ginga """ from ginga.util import grc as ggrc # Start viewer = ggrc.RemoteClient(host, port) # Test ginga = viewer.shell() try: tmp = ginga.get_current_workspace() except: msgs.warn( "Problem connecting to Ginga. Launch an RC Ginga viewer then continue." ) debugger.set_trace() # Return return viewer
def connect_to_ginga(host='localhost', port=9000, raise_err=False, allow_new=False): """ Connect to a RC Ginga. Args: host (:obj:`str`, optional): Host name. port (:obj:`int`, optional): Probably should remain at 9000 raise_err (:obj:`bool`, optional): Raise an error if no connection is made, otherwise just raise a warning and continue allow_new (:obj:`bool`, optional): Allow a subprocess to be called to execute a new ginga viewer if one is not already running. Returns: RemoteClient: connection to ginga viewer. """ # Start viewer = grc.RemoteClient(host, port) # Test ginga = viewer.shell() try: tmp = ginga.get_current_workspace() except: if allow_new: subprocess.Popen(['ginga', '--modules=RC']) time.sleep(3) return grc.RemoteClient(host, port) if raise_err: raise ValueError else: msgs.warn( 'Problem connecting to Ginga. Launch an RC Ginga viewer and ' 'then continue: \n ginga --modules=RC') # Return return viewer
def show_img(img, host='localhost', port=9000, name='image', **kwargs): """ Show a numpy image in the Ginga display Parameters ---------- img kwargs Returns ------- """ viewer = grc.RemoteClient(host, port) ch = viewer.channel('Image') ch.load_np(name, img, 'fits', {})