Esempio n. 1
0
    def test_compute_sky(self):
        """
        Tests desi_compute_sky --infile frame.fits --fiberflat fiberflat.fits --outfile skymodel.fits
        """
        self._write_frame(flavor='dark',
                          camera='b0')  # MUST MATCH FLUXCALIB ABOVE
        self._write_fiberflat()
        self._write_fibermap()

        cmd = "{} {}/desi_compute_sky --infile {} --fiberflat {} --outfile {} --qafile {} --qafig {}".format(
            sys.executable, self.binDir, self.framefile, self.fiberflatfile,
            self.skyfile, self.qa_data_file, self.qafig)
        inputs = [self.framefile, self.fiberflatfile]
        outputs = [
            self.skyfile,
            self.qa_data_file,
            self.qafig,
        ]
        err = runcmd(cmd, inputs=inputs, outputs=outputs, clobber=True)
        self.assertEqual(err, 0)

        #- Remove outputs and call again via function instead of system call
        self._remove_files(outputs)
        args = desispec.scripts.sky.parse(cmd.split()[2:])
        err = runcmd(desispec.scripts.sky.main,
                     args=[
                         args,
                     ],
                     inputs=inputs,
                     outputs=outputs,
                     clobber=True)
        self.assertEqual(err, None)
Esempio n. 2
0
    def test_compute_fiberflat(self):
        """
        Tests desi_compute_fiberflat --infile frame.fits --outfile fiberflat.fits
        """
        self._write_frame(flavor='flat')
        self._write_fibermap()

        # QA fig requires fibermapfile
        cmd = '{} {}/desi_compute_fiberflat --infile {} --outfile {} --qafile {} --qafig {}'.format(
                sys.executable, self.binDir, self.framefile,
                self.fiberflatfile, self.qa_calib_file, self.qafig)
        outputs = [self.fiberflatfile,self.qa_calib_file,self.qafig]
        inputs = [self.framefile,]
        err = runcmd(cmd, inputs=inputs, outputs=outputs, clobber=True)
        self.assertEqual(err, 0)

        #- Confirm that the output file can be read as a fiberflat
        ff1 = io.read_fiberflat(self.fiberflatfile)
        
        #- Remove outputs and call again via function instead of system call
        self._remove_files(outputs)
        args = desispec.scripts.fiberflat.parse(cmd.split()[2:])        
        err = runcmd(desispec.scripts.fiberflat.main, args=[args,],
            inputs=inputs, outputs=outputs, clobber=True)

        #- Confirm that the output file can be read as a fiberflat
        ff2 = io.read_fiberflat(self.fiberflatfile)
        
        self.assertTrue(np.all(ff1.fiberflat == ff2.fiberflat))
        self.assertTrue(np.all(ff1.ivar == ff2.ivar))
        self.assertTrue(np.all(ff1.mask == ff2.mask))
        self.assertTrue(np.all(ff1.meanspec == ff2.meanspec))
        self.assertTrue(np.all(ff1.wave == ff2.wave))
        self.assertTrue(np.all(ff1.fibers == ff2.fibers))        
Esempio n. 3
0
 def test_existing_outputs(self):
     token = uuid4().hex
     cmd = 'echo {} > {}'.format(token, self.testfile)
     self.assertEqual(0, runcmd(cmd, outputs=[self.outfile]))
     fx = open(self.testfile)
     line = fx.readline().strip()
     #- command should not have run, so tokens should not be equal
     self.assertNotEqual(token, line)
Esempio n. 4
0
 def test_clobber(self):
     token = uuid4().hex
     cmd = 'echo {} > {}'.format(token, self.testfile)
     self.assertEqual(0, runcmd(cmd, outputs=[self.outfile], clobber=True))
     fx = open(self.testfile)
     line = fx.readline().strip()
     #- command should have run, so tokens should be equal
     self.assertEqual(token, line)
Esempio n. 5
0
 def test_existing_outputs(self):
     token = uuid4().hex
     cmd = 'echo {} > {}'.format(token, self.testfile)
     self.assertEqual(0, runcmd(cmd, outputs=[self.outfile]))
     fx = open(self.testfile)
     line = fx.readline().strip()
     #- command should not have run, so tokens should not be equal
     self.assertNotEqual(token, line)
Esempio n. 6
0
 def test_clobber(self):
     token = uuid4().hex
     cmd = 'echo {} > {}'.format(token, self.testfile)
     self.assertEqual(0, runcmd(cmd, outputs=[self.outfile], clobber=True))
     fx = open(self.testfile)
     line = fx.readline().strip()
     #- command should have run, so tokens should be equal
     self.assertEqual(token, line)
Esempio n. 7
0
    def test_compute_sky(self):
        """
        Tests desi_compute_sky --infile frame.fits --fiberflat fiberflat.fits --outfile skymodel.fits
        """
        self._write_frame(flavor='dark', camera='b0')  # MUST MATCH FLUXCALIB ABOVE
        self._write_fiberflat()
        self._write_fibermap()

        cmd = "{} {}/desi_compute_sky --infile {} --fiberflat {} --outfile {} --qafile {} --qafig {}".format(
            sys.executable, self.binDir, self.framefile, self.fiberflatfile, self.skyfile, self.qa_data_file, self.qafig)
        inputs  = [self.framefile, self.fiberflatfile]
        outputs = [self.skyfile,self.qa_data_file,self.qafig,]
        err = runcmd(cmd, inputs=inputs, outputs=outputs, clobber=True)
        self.assertEqual(err, 0)

        #- Remove outputs and call again via function instead of system call
        self._remove_files(outputs)
        args = desispec.scripts.sky.parse(cmd.split()[2:])        
        err = runcmd(desispec.scripts.sky.main, args=[args,],
            inputs=inputs, outputs=outputs, clobber=True)
        self.assertEqual(err, None)
Esempio n. 8
0
    def test_compute_sky(self):
        """
        Tests desi_compute_sky.py --infile frame.fits --fibermap fibermap.fits --fiberflat fiberflat.fits --outfile skymodel.fits
        """
        self._write_frame()
        self._write_fiberflat()
        self._write_fibermap()

        cmd = "{} {}/desi_compute_sky.py --infile {} --fibermap {} --fiberflat {} --outfile {}".format(
            sys.executable, self.binDir, self.framefile, self.fibermapfile, self.fiberflatfile, self.skyfile)
        err = runcmd(cmd,
                inputs  = [self.framefile, self.fiberflatfile, self.fibermapfile],
                outputs = [self.skyfile,], clobber=True )
        self.assertEqual(err, 0)
Esempio n. 9
0
    def test_compute_fiberflat(self):
        """
        Tests desi_compute_fiberflat.py --infile frame.fits --outfile fiberflat.fits
        """
        self._write_frame()
        #- run the command and confirm error code = 0
        cmd = '{} {}/desi_compute_fiberflat.py --infile {} --outfile {}'.format(
            sys.executable, self.binDir, self.framefile, self.fiberflatfile)
        # self.assertTrue(os.path.exists(os.path.join(self.binDir,'desi_compute_fiberflat.py')))
        err = runcmd(cmd, [self.framefile,], [self.fiberflatfile,], clobber=True)
        self.assertEqual(err, 0)

        #- Confirm that the output file can be read as a fiberflat
        ff = io.read_fiberflat(self.fiberflatfile)
Esempio n. 10
0
    def test_zz(self):
        """
        Even if clobber=False and outputs exist, run cmd if inputs are
        newer than outputs.  Run this test last since it alters timestamps.
        """
        #- update input timestamp to be newer than output
        fx = open(self.infile, 'w')
        fx.write('This file is leftover from a test; you can remove it\n')
        fx.close()

        #- run a command
        token = uuid4().hex
        cmd = 'echo {} > {}'.format(token, self.testfile)
        self.assertEqual(0, runcmd(cmd, outputs=[self.outfile], clobber=False))

        #- command should have run even though outputs exist,
        #- so tokens should be equal
        fx = open(self.testfile)
        line = fx.readline().strip()
        self.assertNotEqual(token, line)
Esempio n. 11
0
    def test_zz(self):
        """
        Even if clobber=False and outputs exist, run cmd if inputs are
        newer than outputs.  Run this test last since it alters timestamps.
        """
        #- update input timestamp to be newer than output
        fx = open(self.infile, 'w')
        fx.write('This file is leftover from a test; you can remove it\n')
        fx.close()
        
        #- run a command
        token = uuid4().hex
        cmd = 'echo {} > {}'.format(token, self.testfile)
        self.assertEqual(0, runcmd(cmd, outputs=[self.outfile], clobber=False))

        #- command should have run even though outputs exist,
        #- so tokens should be equal
        fx = open(self.testfile)
        line = fx.readline().strip()        
        self.assertNotEqual(token, line)
Esempio n. 12
0
 def test_existing_inputs(self):
     cmd = 'echo hello > /dev/null'
     self.assertEqual(0, runcmd(cmd, inputs=[self.infile]))
Esempio n. 13
0
 def test_existing_inputs(self):
     cmd = 'echo hello > /dev/null'
     self.assertEqual(0, runcmd(cmd, inputs=[self.infile]))
Esempio n. 14
0
    def test_function(self):
        def blat(*args):
            return list(args)

        self.assertEqual(runcmd(blat, args=[1, 2, 3]), [1, 2, 3])
        self.assertEqual(runcmd(blat), [])
Esempio n. 15
0
 def test_missing_outputs(self):
     cmd = 'echo hello > /dev/null'
     self.assertNotEqual(0, runcmd(cmd, outputs=[uuid4().hex]))
Esempio n. 16
0
 def test_runcmd(self):
     self.assertEqual(0, runcmd('echo hello > /dev/null'))
Esempio n. 17
0
 def test_runcmd(self):
     self.assertEqual(0, runcmd('echo hello > /dev/null'))
Esempio n. 18
0
 def test_missing_outputs(self):
     cmd = 'echo hello > /dev/null'
     self.assertNotEqual(0, runcmd(cmd, outputs=[uuid4().hex]))
Esempio n. 19
0
 def test_function(self):
     def blat(*args):
         return list(args)
     
     self.assertEqual(runcmd(blat, args=[1,2,3]), [1,2,3])
     self.assertEqual(runcmd(blat), [])