Exemplo n.º 1
0
    def test_find_global_atm_bandwidth(self):
        c1 = atm.AtmDataContainer(AtmModel(**{
            "flux": np.array([1, 2, 3, 4, 5]),
            "wavelength": np.array([1, 2, 3, 4, 5])
        }), 10, 10, 10)

        c2 = atm.AtmDataContainer(AtmModel(**{
            "flux": np.array([0.4, 2, 3, 4.3, 5]),
            "wavelength": np.array([0.9, 2, 3, 4.1, 5])
        }), 5, 5, 5)

        result = atm.find_global_atm_bandwidth([c1, c2])
        expected = (1, 5)
        self.assertTupleEqual(result, expected)
Exemplo n.º 2
0
    def test_strip_atm_container_by_bandwidth(self):
        c = atm.AtmDataContainer(AtmModel.from_dataframe(pd.DataFrame({
            settings.ATM_MODEL_DATAFRAME_FLUX: up.arange(0, 100, 10, dtype=np.float),
            settings.ATM_MODEL_DATAFRAME_WAVE: up.arange(10, dtype=np.float)
        })), 10, 10, 10)

        l_band, r_band = 3.1, 7.8
        result = atm.strip_atm_container_by_bandwidth(c, l_band, r_band)
        expected_df = pd.DataFrame({
            settings.ATM_MODEL_DATAFRAME_FLUX: [31, 40, 50, 60, 70, 78],
            settings.ATM_MODEL_DATAFRAME_WAVE: [3.1, 4., 5., 6., 7., 7.8]
        })
        assert_frame_equal(expected_df, result.model.to_dataframe(), check_dtype=False)

        # global is set but right and left are valid for given model
        gl_band, gr_band = 4.0, 6.5
        result = atm.strip_atm_container_by_bandwidth(c, l_band, r_band, global_left=gl_band, global_right=gr_band)
        assert_frame_equal(expected_df, result.model.to_dataframe(), check_dtype=False)

        # global is set
        l_band, r_band = -1, 10000
        gl_band, gr_band = 4.0, 6.5
        result = atm.strip_atm_container_by_bandwidth(c, l_band, r_band, global_left=gl_band, global_right=gr_band)
        expected_df = pd.DataFrame({
            settings.ATM_MODEL_DATAFRAME_FLUX: [40, 50, 60, 65],
            settings.ATM_MODEL_DATAFRAME_WAVE: [4, 5., 6, 6.5]
        })
        assert_frame_equal(expected_df, result.model.to_dataframe(), check_dtype=False)
Exemplo n.º 3
0
    def test_arange_atm_to_same_wavelength(self):
        c1 = atm.AtmDataContainer(AtmModel(**{
            "flux": np.array([1, 2, 3, 4, 5]),
            "wavelength": np.array([1, 2, 3, 4, 5])
        }), 10, 10, 10)

        c2 = atm.AtmDataContainer(AtmModel(**{
            "flux": np.array([0.4, 2, 3, 4.3, 5]),
            "wavelength": np.array([0.9, 2, 3, 4.1, 5])
        }), 5, 5, 5)

        result = atm.arange_atm_to_same_wavelength([c1, c2])
        expected_wavelength = np.array([0.9, 1, 2, 3, 4, 4.1, 5])

        # are aligned?
        assert_array_equal(result[0].model.wavelength,
                           result[1].model.wavelength)
        # are xpected
        assert_array_equal(result[0].model.wavelength, expected_wavelength)
Exemplo n.º 4
0
    def test_extend_atm_container_on_bandwidth_boundary(self):
        c = atm.AtmDataContainer(AtmModel.from_dataframe(pd.DataFrame({
            settings.ATM_MODEL_DATAFRAME_FLUX: up.arange(0, 100, 10, dtype=np.float),
            settings.ATM_MODEL_DATAFRAME_WAVE: up.arange(10, dtype=np.float)
        })), 10, 10, 10)

        l_band, r_band = 0.4, 8.8
        result = atm.extend_atm_container_on_bandwidth_boundary(c, l_band, r_band).\
            model.to_dataframe().sort_index(axis=1)
        expected = pd.DataFrame({
            settings.ATM_MODEL_DATAFRAME_WAVE: [0.4] + list(range(1, 9, 1)) + [8.8],
            settings.ATM_MODEL_DATAFRAME_FLUX: [4] + list(range(10, 90, 10)) + [88]
        }).sort_index(axis=1)
        assert_frame_equal(result, expected, check_dtype=False)
Exemplo n.º 5
0
    def test_apply_passband(self):
        atmc = atm.AtmDataContainer(AtmModel.from_dataframe(pd.DataFrame({
            settings.ATM_MODEL_DATAFRAME_FLUX: up.arange(10, dtype=np.float),
            settings.ATM_MODEL_DATAFRAME_WAVE: up.arange(0, 100, 10, dtype=np.float)
        })), 0, 0, 0)

        bandc = PassbandContainer(
            pd.DataFrame({
                settings.PASSBAND_DATAFRAME_THROUGHPUT: [0.2, 1.0, 0.2, 0.2, 0.4],
                settings.PASSBAND_DATAFRAME_WAVE: [1, 10, 25, 40, 50]
            }),
            passband="bandc"
        )

        passband = dict(bandc=bandc)

        obtained = np.round(atm.apply_passband([atmc], passband)["bandc"][0].model.to_dataframe(), 4)
        expected = pd.DataFrame({
            settings.ATM_MODEL_DATAFRAME_FLUX: [0.02, 1., 0.8117, 0.5077, 0.8, 2.],
            settings.ATM_MODEL_DATAFRAME_WAVE: [1., 10., 20., 30., 40., 50.]
        })
        assert_frame_equal(expected, obtained, check_dtype=False)
Exemplo n.º 6
0
 def setUp(self):
     super(TestAtmDataContainer, self).setUp()
     df = pd.DataFrame({settings.ATM_MODEL_DATAFRAME_FLUX: np.array([1, 2, 3, 4, 5]),
                        settings.ATM_MODEL_DATAFRAME_WAVE: np.array([10, 20, 30, 40, 50])})
     self.container = atm.AtmDataContainer(df, 10, 10, 10, fpath="path")
Exemplo n.º 7
0
 def test_find_atm_defined_wavelength(self):
     cs = [atm.AtmDataContainer(pd.DataFrame({settings.ATM_MODEL_DATAFRAME_WAVE: list(range(10)),
                                              settings.ATM_MODEL_DATAFRAME_FLUX: list(range(10))}), 0, 0, 0)] * 10
     expected = list(range(10))
     obtained = atm.find_atm_defined_wavelength(cs)
     assert_array_equal(expected, obtained)
Exemplo n.º 8
0
 def test_find_atm_si_multiplicators(self):
     expected = (1e-7 * 1e4 * 1e10, 1e-10)
     cs = [atm.AtmDataContainer(AtmModel.from_dataframe(pd.DataFrame({settings.ATM_MODEL_DATAFRAME_WAVE: [1, 2, 3],
                                                        settings.ATM_MODEL_DATAFRAME_FLUX: [1, 2, 3]})), 0, 0, 0)] * 10
     mults = atm.find_atm_si_multiplicators(cs)
     self.assertTupleEqual(mults, expected)