Пример #1
0
    def test_darkCorrect_errors(self, tmpdir):
        tmpsubdir = tmpdir.mkdir('ghost_dcerrors')
        os.chdir(os.path.join(tmpsubdir.dirname, tmpsubdir.basename))

        ad = self.generate_minimum_file()
        dark = self.generate_minimum_file()
        dark.filename = 'dark.fits'

        gs = GHOSTSpect([])

        # Passing in data inputs with different binnings
        with pytest.raises(IOError):
            ad2 = copy.deepcopy(ad)
            ad2[0].hdr.set('CCDSUM', '2 2')
            gs.darkCorrect([
                ad,
                ad2,
            ], dark=[
                dark,
                dark,
            ])

        # Mismatched list lengths
        with pytest.raises(Exception):
            gs.darkCorrect([
                ad,
                ad2,
                ad,
            ], dark=[
                dark,
                dark,
            ])

        # Teardown - remove calibrations and output file
        for _ in glob.glob(
                os.path.join(tmpsubdir.dirname, tmpsubdir.basename, '*.fits')):
            os.remove(_)
        try:
            shutil.rmtree(
                os.path.join(tmpsubdir.dirname, tmpsubdir.basename,
                             'calibrations'))
        except OSError:
            pass
Пример #2
0
    def test_darkCorrect_rebin(self, xbin, ybin, tmpdir):
        """
        Checks to make:

        - Ensure re-binning of darks is correctly triggered (i.e. deliberately
          pass science and dark data w/ different binning, ensure no failure)
        - Error mode check: see for error if length of dark list != length of
          science list
        - Check for DARKIM in output header
        - Check before & after data shape
        """
        tmpsubdir = tmpdir.mkdir('ghost_darkcorrect')
        os.chdir(os.path.join(tmpsubdir.dirname, tmpsubdir.basename))

        ad = self.generate_minimum_file()
        dark = self.generate_minimum_file()
        dark.filename = 'dark.fits'

        # 'Re-bin' the data file
        ad[0].data = np.ones((
            int(1024 / ybin),
            int(1024 / xbin),
        ),
                             dtype=np.float64)
        ad[0].hdr.set('CCDSUM', '{} {}'.format(
            xbin,
            ybin,
        ))

        gs = GHOSTSpect([])
        input_shape = ad[0].data.shape
        ad_out = gs.darkCorrect([
            ad,
        ], dark=[
            dark,
        ])[0]

        assert ad_out[0].data.shape == input_shape, "darkCorrect has mangled " \
                                                    "the shape of the input " \
                                                    "data"
        # Teardown - remove calibrations and output file
        for _ in glob.glob(
                os.path.join(tmpsubdir.dirname, tmpsubdir.basename, '*.fits')):
            os.remove(_)
        try:
            shutil.rmtree(
                os.path.join(tmpsubdir.dirname, tmpsubdir.basename,
                             'calibrations'))
        except OSError:
            pass
Пример #3
0
    def test_darkCorrect(self, tmpdir):
        tmpsubdir = tmpdir.mkdir('ghost_darkcorr')
        os.chdir(os.path.join(tmpsubdir.dirname, tmpsubdir.basename))

        ad = self.generate_minimum_file()
        dark = self.generate_minimum_file()
        dark.filename = 'dark.fits'

        gs = GHOSTSpect([])
        ad_out = gs.darkCorrect([
            ad,
        ], dark=[
            dark,
        ])

        # import pdb; pdb.set_trace()

        assert ad_out[0].phu.get('DARKIM') == dark.filename, \
            "darkCorrect failed to record the name of the dark " \
            "file used in the output header (expected {}, got {})".format(
                dark.filename, ad_out[0].phu.get('DARKIM'),
            )

        assert ad_out[0].phu.get(
            gs.timestamp_keys['darkCorrect']), "darkCorrect did not " \
                                               "timestamp-mark the " \
                                               "output file"

        # Teardown - remove calibrations and output file
        for _ in glob.glob(
                os.path.join(tmpsubdir.dirname, tmpsubdir.basename, '*.fits')):
            os.remove(_)
        try:
            shutil.rmtree(
                os.path.join(tmpsubdir.dirname, tmpsubdir.basename,
                             'calibrations'))
        except OSError:
            pass