def setup_class(klass):
        import os

        klass.curdir = os.path.dirname(__file__)
        klass.datadir = os.path.join(klass.curdir, 'data')

        klass.fname = \
            os.path.abspath(
                os.path.join(klass.datadir, 'gauss_dec',
                             'Dec0.fits'))
        h5file = klass.fname.replace('.fits', '.hdf5')
        if os.path.exists(h5file):
            os.unlink(h5file)

        klass.config_file = \
            os.path.abspath(os.path.join(klass.datadir, 'test_config.ini'))

        read_config(klass.config_file)
Exemple #2
0
    def test_read_incomplete_config(self):
        """Test that config file are read."""
        fname = os.path.join(self.datadir, 'test_config_incomplete.ini')

        config = read_config(fname)

        np.testing.assert_almost_equal(config['pixel_size'].to(u.rad).value,
                                       np.radians(1 / 60))
        assert config['interpolation'] == 'linear'
    def setup_class(klass):

        klass.curdir = os.path.dirname(__file__)
        klass.datadir = os.path.join(klass.curdir, 'data')

        klass.fname = \
            os.path.abspath(
                os.path.join(klass.datadir, 'spectrum',
                             'roach_template.fits'))

        h5file = klass.fname.replace('.fits', '.hdf5')
        if os.path.exists(h5file):
            os.unlink(h5file)
        klass.config_file = \
            os.path.abspath(os.path.join(klass.datadir, 'spectrum.ini'))
        print(klass.config_file)

        read_config(klass.config_file)
    def setup_class(klass):
        import os

        klass.curdir = os.path.dirname(__file__)
        klass.datadir = os.path.join(klass.curdir, 'data')

        klass.config_file = \
            os.path.abspath(os.path.join(klass.datadir, "calibrators.ini"))

        klass.config_file_empty = \
            os.path.abspath(os.path.join(klass.datadir,
                                         "calibrators_nocal.ini"))

        klass.config = read_config(klass.config_file)
        klass.caldir = os.path.join(klass.datadir, 'sim', 'calibration')
        klass.caldir2 = os.path.join(klass.datadir, 'sim', 'calibration2')
        klass.caldir3 = os.path.join(klass.datadir, 'sim', 'calibration_bad')
        klass.crossdir = os.path.join(klass.datadir, 'sim', 'crossscans')
        if not os.path.exists(klass.caldir):
            print('Fake calibrators: DummyCal, 1 Jy.')
            mkdir_p(klass.caldir)
            sim_crossscans(5, klass.caldir)
        if not os.path.exists(klass.caldir2):
            print('Fake calibrators: DummyCal2, 1 Jy.')
            mkdir_p(klass.caldir2)
            sim_crossscans(5, klass.caldir2, srcname='DummyCal2')
        if not os.path.exists(klass.caldir3):
            print('Fake calibrators: DummyCal2, wrong flux 0.52 Jy.')
            mkdir_p(klass.caldir3)
            sim_crossscans(1,
                           klass.caldir3,
                           srcname='DummyCal2',
                           scan_func=source_scan_func)
        if not os.path.exists(klass.crossdir):
            print('Fake cross scans: DummySrc, 0.52 Jy.')
            mkdir_p(klass.crossdir)
            sim_crossscans(5,
                           klass.crossdir,
                           srcname='DummySrc',
                           scan_func=source_scan_func)

        klass.scan_list = \
            list_scans(klass.caldir, ['./']) + \
            list_scans(klass.caldir2, ['./']) + \
            list_scans(klass.crossdir, ['./'])

        klass.scan_list.sort()
        caltable = CalibratorTable()
        caltable.from_scans(klass.scan_list)
        caltable.update()

        klass.calfile = os.path.join(klass.curdir, 'test_calibration.hdf5')
        caltable.write(klass.calfile, overwrite=True)
        caltable.write(klass.calfile.replace('hdf5', 'csv'))
Exemple #5
0
    def __init__(self, directories, config_file='', workers=1, verbosity=0, polling=False, port=8080):
        # Save constructor parameters
        self._directories = directories
        if not config_file:
            config_file = create_dummy_config()            
        self._config_file = config_file
        self._workers = workers
        self._verbosity = verbosity
        self._polling = polling
        self._port = port

        # Load file configuration and save needed parameters
        with warnings.catch_warnings():
            if not self._verbosity:
                warnings.simplefilter('ignore')
            configuration = read_config(config_file)
        self._productdir = configuration['productdir']
        self._workdir = configuration['workdir']
        self._extension = configuration['debug_file_format']

        # Objects needed by the file observer
        self._timers = {}
        self._processing = queue.Queue(self._workers)
        self._files = queue.Queue()

        # Initialize the event handler and the file observer
        self._event_handler = MyEventHandler(self)
        if self._polling:
            self._observer = PollingObserver()
        else:
            self._observer = Observer()

        for path in directories:
            self._observer.schedule(self._event_handler, path, recursive=True)

        self._stop = False
        self._worker_thread = None

        # Initialize the web server, this will raise a OSError if the given port is already being used
        self._web_server = WebServer(self._extension, self._port)
    def process(self, event):
        """
        event.event_type
            'modified' | 'created' | 'moved' | 'deleted'
        event.is_directory
            True | False
        event.src_path
            path/to/observed/file
        """
        global CONFIG_FILE

        infile = event.src_path
        root = infile.replace('.fits', '')
        conf = read_config(CONFIG_FILE)
        ext = conf['debug_file_format']
        try:
            sp.check_call("SDTpreprocess --debug {} -c {}".format(
                infile, CONFIG_FILE).split())
        except sp.CalledProcessError:
            return

        for debugfile in glob.glob(root + '*.{}'.format(ext)):
            newfile = debugfile.replace(root, 'latest')
            sp.check_call('cp {} {}'.format(debugfile, newfile).split())

        with open('index.html', "w") as fobj:
            print('<META HTTP-EQUIV="refresh" CONTENT="5">', file=fobj)
            allfiles = glob.glob('latest*.{}'.format(ext))
            N = len(allfiles)
            if N <= 2:
                width = "50%"
            else:
                width = "25%"
            for fname in sorted(allfiles):
                print("<div style=\"width:{}; float:left;\" />".format(width),
                      file=fobj)
                print("<img src=\"{}\" width=\"100%\"/>".format(fname),
                      file=fobj)
                print("</div>", file=fobj)
Exemple #7
0
    def setup_class(klass):
        import os

        klass.curdir = os.path.dirname(__file__)
        klass.datadir = os.path.join(klass.curdir, 'data')
        klass.sim_dir = os.path.join(klass.datadir, 'sim')

        klass.obsdir_ra = os.path.join(klass.datadir, 'sim', 'gauss_ra')
        klass.obsdir_dec = os.path.join(klass.datadir, 'sim', 'gauss_dec')
        klass.config_file = \
            os.path.abspath(os.path.join(klass.sim_dir, 'test_config_sim.ini'))
        klass.caldir = os.path.join(klass.datadir, 'sim', 'calibration')
        klass.simulated_flux = 0.25
        # First off, simulate a beamed observation  -------

        sim_config_file(klass.config_file, add_garbage=True, prefix="./")

        if (not os.path.exists(klass.obsdir_ra)) or \
                (not os.path.exists(klass.obsdir_dec)):
            mkdir_p(klass.obsdir_ra)
            mkdir_p(klass.obsdir_dec)
            print('Fake map: Point-like (but Gaussian beam shape), '
                  '{} Jy.'.format(klass.simulated_flux))
            sim_map(klass.obsdir_ra, klass.obsdir_dec)

        defective_dir = os.path.join(klass.sim_dir, 'defective')
        if not os.path.exists(defective_dir):
            shutil.copytree(os.path.join(klass.datadir, 'calibrators'),
                            defective_dir)

        # Copy skydip scan
        skydip_dir = os.path.join(klass.datadir, 'gauss_skydip')
        new_skydip_dir = os.path.join(klass.sim_dir, 'gauss_skydip')
        if os.path.exists(skydip_dir) and not os.path.exists(new_skydip_dir):
            shutil.copytree(skydip_dir, new_skydip_dir)
        caltable = CalibratorTable()
        caltable.from_scans(glob.glob(os.path.join(klass.caldir, '*.fits')),
                            debug=True)

        caltable.update()
        klass.calfile = os.path.join(klass.datadir, 'calibrators.hdf5')
        caltable.write(klass.calfile, overwrite=True)

        klass.config = read_config(klass.config_file)
        klass.raonly = os.path.abspath(
            os.path.join(klass.datadir, 'test_raonly.ini'))
        klass.deconly = os.path.abspath(
            os.path.join(klass.datadir, 'test_deconly.ini'))

        if HAS_PYREGION:
            excluded_xy, excluded_radec = \
                _excluded_regions_from_args([os.path.join(klass.datadir,
                                                          "center.reg")])
        else:
            excluded_xy, excluded_radec = None, None

        klass.scanset = ScanSet(klass.config_file,
                                nosub=False,
                                norefilt=False,
                                debug=True,
                                avoid_regions=excluded_radec)
        klass.scanset.write('test.hdf5', overwrite=True)

        klass.stdinfo = {}
        klass.stdinfo['FLAG'] = None
        klass.stdinfo['zap'] = intervals()
        klass.stdinfo['base'] = intervals()
        klass.stdinfo['fitpars'] = np.array([0, 0])

        def scan_no(scan_str):
            basename = os.path.splitext(os.path.basename(scan_str))[0]
            return int(basename.replace('Dec', '').replace('Ra', ''))

        klass.dec_scans = \
            dict([(scan_no(s), s)
                 for s in klass.scanset.scan_list if 'Dec' in s])
        klass.ra_scans = \
            dict([(scan_no(s), s)
                 for s in klass.scanset.scan_list if 'Ra' in s])
        klass.n_ra_scans = max(list(klass.ra_scans.keys()))
        klass.n_dec_scans = max(list(klass.dec_scans.keys()))

        if HAS_MPL:
            plt.ioff()
Exemple #8
0
    def setup_class(klass):
        import os

        klass.curdir = os.path.dirname(__file__)
        klass.datadir = os.path.join(klass.curdir, 'data')
        klass.specdir = os.path.join(klass.datadir, 'spectrum')
        klass.config_file = \
            os.path.abspath(os.path.join(klass.datadir, 'test_config.ini'))

        config = read_config(klass.config_file)

        dummy = os.path.join(klass.datadir, "srt_data_dummy.fits")
        klass.proddir, _ = \
            product_path_from_file_name(dummy, workdir=config['workdir'],
                                        productdir=config['productdir'])

        klass.config = config

        klass.file_empty_init = \
            os.path.abspath(os.path.join(klass.datadir, 'spectrum',
                                         "srt_data.fits"))
        klass.file_empty_init_single_feed = \
            os.path.abspath(os.path.join(klass.datadir, 'spectrum',
                                         "new_sardara.fits5"))

        klass.file_empty = os.path.abspath(dummy)
        klass.file_empty_single_feed = os.path.abspath(dummy) + '5'

        klass.file_empty_hdf5 = \
            os.path.abspath(os.path.join(klass.datadir,
                                         "srt_data_dummy.hdf5"))
        klass.file_empty_pdf0 = \
            os.path.abspath(os.path.join(klass.datadir,
                                         "srt_data_dummy_0.png"))
        klass.file_empty_pdf1 = \
            os.path.abspath(os.path.join(klass.datadir,
                                         "srt_data_dummy_1.png"))
        klass.file_empty_hdf5_alt = \
            os.path.abspath(os.path.join(klass.proddir,
                                         "srt_data_dummy.hdf5"))
        klass.file_empty_pdf0_alt = \
            os.path.abspath(os.path.join(klass.proddir,
                                         "srt_data_dummy_0.png"))
        klass.file_empty_pdf1_alt = \
            os.path.abspath(os.path.join(klass.proddir,
                                         "srt_data_dummy_1.png"))
        klass.file_empty_pdf10 = \
            os.path.abspath(os.path.join(klass.proddir,
                                         "srt_data_dummy5_0.png"))
        klass.file_empty_hdf5_SF = \
            os.path.abspath(os.path.join(klass.proddir,
                                         "srt_data_dummy5.hdf5"))
        klass.file_index = 'index.html'
        klass.dummy_config = 'monitor_config.ini'

        if os.path.exists(klass.file_empty):
            os.unlink(klass.file_empty)
        if os.path.exists(klass.file_empty_single_feed):
            os.unlink(klass.file_empty_single_feed)
        if os.path.exists(klass.file_empty_pdf0):
            os.unlink(klass.file_empty_pdf0)
        if os.path.exists(klass.file_empty_pdf1):
            os.unlink(klass.file_empty_pdf1)