Esempio n. 1
0
    def __new__(cls,
                viewer='ds9',
                path=None,
                use_existing=False,
                use_dragons=False,
                wait_time=10,
                quit_window=True,
                port=None,
                browser=None):

        _possible_viewers = []
        if have_xpa:
            _possible_viewers.append("ds9")
        if have_ginga:
            _possible_viewers.append('ginga')

        vwr = viewer.lower()
        if vwr not in _possible_viewers or len(_possible_viewers) == 0:
            raise NotImplementedError(f"Unsupported viewer {vwr}, check your "
                                      "installed packages and install imexam "
                                      "and ginga")

        # Here's the DRAGONS-specific stuff
        if 'ds9' in vwr:
            target = None
            existing_ds9_viewers = [
                v[0] for v in imexam.list_active_ds9(False).values()
            ]
            if use_dragons:
                if 'DRAGONS' in existing_ds9_viewers:
                    target = 'DRAGONS'
            elif use_existing and len(existing_ds9_viewers):
                target = existing_ds9_viewers[0]

            # This Exception will be picked up by the dormant viewer
            if target is None and use_existing:
                raise ValueError("No existing viewer to use.")

            instance = ds9Viewer(target=target,
                                 path=path,
                                 wait_time=wait_time,
                                 quit_ds9_on_del=quit_window)

        else:  # Must be ginga if we've got this far
            instance = gingaViewer(port=port,
                                   close_on_del=quit_window,
                                   browser=browser)

        instance.logfile = 'imexam_log.txt'  # default logfile name
        if have_xpa:
            instance.log = imexam.util.set_logging(
            )  # points to the package logger
        instance._current_slice = None
        instance._current_frame = None

        return instance
Esempio n. 2
0
    def run_inet_ds9(self):
        """start a new ds9 window using an inet socket connection.

        Notes
        -----
        It is given a unique title so it can be identified later. I have
        copied this method so we can give the window a nice DRAGONS-y name.
        """
        env = os.environ

        existing_ds9_viewers = [
            v[0] for v in imexam.list_active_ds9(False).values()
        ]
        xpaname = 'DRAGONS'
        n = 1
        while xpaname in existing_ds9_viewers:
            n += 1
            xpaname = 'DRAGONS_{}'.format(n)
        try:
            p = Popen([self._ds9_path, "-xpa", "inet", "-title", xpaname],
                      shell=False,
                      env=env)
            self._ds9_process = p
            self._process_list.append(p)
            self._need_to_purge = False
            time.sleep(2)
            return xpaname

        except Exception as e:  # refine error class
            warnings.warn("Opening ds9 failed")
            print("Exception: {}".format(repr(e)))
            from signal import SIGTERM
            try:
                pidtokill = p.pid
            except NameError:
                # in case p failed at the initialization level
                pidtokill = None
            if pidtokill is not None:
                os.kill(pidtokill, SIGTERM)
            raise e
Esempio n. 3
0
# ============================================================================ #
# Helper script to iterate through the images and allow interaction with DS9 to
# get the sky values
# Script 1 of 3 to run
# Output: Single file with imexam stats for each image.
# ============================================================================ #

from os import walk
import imexam
from box_stats import real_m_stats

mypath = '/home/emc/GoogleDrive/Phys/Research/BothunLab/SkyPhotos/NewCamera'

#Collect the address for the current DS9 window
ds9data = imexam.list_active_ds9()
ds9data = ds9data.split()
XPA_METHOD = ds9data[3]

print('Current default path is {}'.format(mypath))
use_default = raw_input('Use default path? (y/n) ')

if use_default == 'n':
    mypath = raw_input('Enter full path of top level directory containing '
                       'images: ')
elif use_default == 'y':
    img_directory = raw_input('Enter top level dated image directory: ')
    mypath = mypath + '/' + img_directory

# Connect to DS9 and register a new task with imexam to gather stats
v = imexam.connect(XPA_METHOD)