예제 #1
0
    def test_wavelength_conversion_roundtrip(self, filepath):
        cube = HyperspectralCube.from_fits(filepath)

        # For each spectral pixel index
        for pixel in range(0, cube.shape[0]):
            self.assertEqual(
                round(cube.pixel_of(cube.wavelength_of(pixel))), pixel,
                "Wavelength conversion from pixel index #%d to λ "
                "and back from λ to pixel index #%d." % (pixel, pixel))
    def test_wavelength_conversion_roundtrip(self, filepath):
        cube = HyperspectralCube.from_fits(filepath)

        # For each spectral pixel index
        for pixel in range(0, cube.shape[0]):
            self.assertEqual(
                round(cube.pixel_of(cube.wavelength_of(pixel))),
                pixel,
                "Wavelength conversion from pixel index #%d to λ "
                "and back from λ to pixel index #%d." % (pixel, pixel)
            )
예제 #3
0
    def test_wavelength_of(self):
        # This test is hardwired to muse_01.fits
        cube = HyperspectralCube.from_fits(self.muse_01_filename)

        # With a singe pixel position
        self.assertEqual(u.Quantity(6734.7802734375, 'Angstrom'),
                         cube.wavelength_of(3))

        # With a list of pixel positions
        self.assertArrayEqual([6734.7802734375, 6737.2802734375],
                              cube.wavelength_of([3, 5]).value)
        self.assertEqual(u.Unit('Angstrom'), cube.wavelength_of([3, 5]).unit)
    def test_wavelength_of(self):
        # This test is hardwired to muse_01.fits
        cube = HyperspectralCube.from_fits(self.muse_01_filename)

        # With a singe pixel position
        self.assertEqual(u.Quantity(6734.7802734375, 'Angstrom'),
                         cube.wavelength_of(3))

        # With a list of pixel positions
        self.assertArrayEqual([6734.7802734375, 6737.2802734375],
                              cube.wavelength_of([3, 5]).value)
        self.assertEqual(u.Unit('Angstrom'), cube.wavelength_of([3, 5]).unit)
예제 #5
0
    def test_pixel_of(self):
        # This test is hardwired to muse_01.fits
        cube = HyperspectralCube.from_fits(self.muse_01_filename)

        # With a single wavelength expressed as a simple float
        self.assertEqual(3, cube.pixel_of(6734.7802734375))

        # With a list of wavelengths
        self.assertArrayEqual([3, 5],
                              cube.pixel_of([6734.7802734375,
                                             6737.2802734375]),
                              "pixel_of() supports a list as input")

        # With a ndarray of wavelengths
        self.assertArrayEqual(
            numpy.array([3, 5]),
            cube.pixel_of(numpy.array([6734.7802734375, 6737.2802734375])),
            "pixel_of() supports a numpy array as input")
예제 #6
0
    def test_getting_steps(self):
        # This test is hardwired to muse_01.fits
        cube = HyperspectralCube.from_fits(self.muse_01_filename)

        # Collect the data
        steps = cube.get_steps()
        # print "STEPS: %s" % steps
        # <Quantity 1.25 Angstrom>
        # <Quantity 5.55555555556e-05 deg>
        # <Quantity -5.55555555556e-05 deg>

        # Test the success/failure of the API
        self.assertEqual(steps[0], cube.get_step(0))
        self.assertEqual(steps[1], cube.get_step(1))
        self.assertEqual(steps[2], cube.get_step(2))

        # Test unit conversion -- this test is hardwired to muse_01.fits
        self.assertEqual(cube.get_step(0).value, 1.25)
        self.assertAlmostEqual(
            cube.get_step(0).to(u.Unit('micron')).value, 1.25e-4)
    def test_write_to_fits_file(self):
        cube = HyperspectralCube.from_fits(self.muse_01_filename)
        fits_out_filename = os.path.join(self.fits_folder, 'tmp_output.fits')

        self.assertFalse(os.path.isfile(fits_out_filename),
                         "Sanity check : Output FITS file should not exist ; "
                         "Please remove it by hand and then "
                         "re-run this test : %s" % fits_out_filename)
        cube.to_fits(fits_out_filename)
        self.assertTrue(os.path.isfile(fits_out_filename),
                        "Output FITS file should be created")

        # `clobber` option should be false by default
        with self.assertRaises(IOError):
            cube.to_fits(fits_out_filename)

        # clobber without raising
        cube.to_fits(fits_out_filename, clobber=True)

        os.remove(fits_out_filename)  # cleanup
    def test_pixel_of(self):
        # This test is hardwired to muse_01.fits
        cube = HyperspectralCube.from_fits(self.muse_01_filename)

        # With a single wavelength expressed as a simple float
        self.assertEqual(3, cube.pixel_of(6734.7802734375))

        # With a list of wavelengths
        self.assertArrayEqual(
            [3, 5],
            cube.pixel_of([6734.7802734375, 6737.2802734375]),
            "pixel_of() supports a list as input"
        )

        # With a ndarray of wavelengths
        self.assertArrayEqual(
            numpy.array([3, 5]),
            cube.pixel_of(numpy.array([6734.7802734375, 6737.2802734375])),
            "pixel_of() supports a numpy array as input"
        )
예제 #9
0
    def test_write_to_fits_file(self):
        cube = HyperspectralCube.from_fits(self.muse_01_filename)
        fits_out_filename = os.path.join(self.fits_folder, 'tmp_output.fits')

        self.assertFalse(
            os.path.isfile(fits_out_filename),
            "Sanity check : Output FITS file should not exist ; "
            "Please remove it by hand and then "
            "re-run this test : %s" % fits_out_filename)
        cube.to_fits(fits_out_filename)
        self.assertTrue(os.path.isfile(fits_out_filename),
                        "Output FITS file should be created")

        # `clobber` option should be false by default
        with self.assertRaises(IOError):
            cube.to_fits(fits_out_filename)

        # clobber without raising
        cube.to_fits(fits_out_filename, clobber=True)

        os.remove(fits_out_filename)  # cleanup
    def test_getting_steps(self):
        # This test is hardwired to muse_01.fits
        cube = HyperspectralCube.from_fits(self.muse_01_filename)

        # Collect the data
        steps = cube.get_steps()
        # print "STEPS: %s" % steps
        # <Quantity 1.25 Angstrom>
        # <Quantity 5.55555555556e-05 deg>
        # <Quantity -5.55555555556e-05 deg>

        # Test the success/failure of the API
        self.assertEqual(steps[0], cube.get_step(0))
        self.assertEqual(steps[1], cube.get_step(1))
        self.assertEqual(steps[2], cube.get_step(2))

        # Test unit conversion -- this test is hardwired to muse_01.fits
        self.assertEqual(cube.get_step(0).value, 1.25)
        self.assertAlmostEqual(
            cube.get_step(0).to(u.Unit('micron')).value,
            1.25e-4
        )
예제 #11
0
 def test_init_with_unfit_filename(self):
     with self.assertRaises(IOError):
         cube = HyperspectralCube.from_fits('this_is_not_a_fits_file')
예제 #12
0
 def test_from_fits(self, filepath):
     cube = HyperspectralCube.from_fits(filepath)  # should not raise
     print cube
 def test_init_with_unfit_filename(self):
     with self.assertRaises(IOError):
         cube = HyperspectralCube.from_fits('this_is_not_a_fits_file')
 def test_from_fits(self, filepath):
     cube = HyperspectralCube.from_fits(filepath)  # should not raise
     print cube