Esempio n. 1
0
    def test_stack_targets_same_sizes(self):
        times = [[0, 1, 2], [3, 4, 5]]
        expected_times = np.array([[0., 1., 2.],
                                   [3., 4., 5.]])

        values = [[0, 1, 2], [3, 4, 5]]
        expected_values = np.array([[0., 1., 2.],
                                    [3., 4., 5.]])

        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)

        # same sizes array
        times = [np.array([0, 1, 2]), np.array([3, 4, 5])]
        values = [np.array([0, 1, 2]), np.array([3, 4, 5])]
        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)

        # arrays more dimensions
        times = [np.array([[0, 1, 2]]), np.array([[3, 4, 5]])]
        values = [np.array([[0, 1, 2]]), np.array([[3, 4, 5]])]
        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)
Esempio n. 2
0
    def test_stack_targets_empty(self):
        expected_times = np.array([[], []])
        expected_values = np.array([[], []])

        times = [[], []]
        values = [[], []]
        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)

        times = [np.array([]), []]
        values = [[], np.array([])]
        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)

        times = [np.array([]), np.array([])]
        values = [np.array([]), np.array([])]
        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)

        expected_times = np.array([[np.nan], [1]])
        expected_values = np.array([[np.nan], [1]])
        times = [np.array([]), np.array([1])]
        values = [np.array([]), np.array([1])]
        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)

        times = np.array([[], [1]])
        values = np.array([[], [1]])
        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)
Esempio n. 3
0
    def test_stack_targets_diferent_sizes(self):
        # Diferent sizes
        times = [[0, 1, 2], [3, 4, 5, 6]]
        expected_times = np.array([[0., 1., 2., np.nan],
                                   [3., 4., 5., 6.]])

        values = [[0, 1, 2], [3, 4, 5, 7]]
        expected_values = np.array([[0., 1., 2., np.nan],
                                    [3., 4., 5., 7.]])

        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)

        # diferent sizes array
        times = [np.array([0, 1, 2]), np.array([3, 4, 5, 6])]
        values = [np.array([0, 1, 2]), np.array([3, 4, 5, 7])]
        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)

        # more dimensions
        times = [np.array([[0, 1, 2]]), np.array([[3, 4, 5, 6]])]
        values = [np.array([[0, 1, 2]]), np.array([[3, 4, 5, 7]])]
        stk_times, stk_values = pytff.stack_targets(times, values)
        np.testing.assert_array_equal(stk_times, expected_times)
        np.testing.assert_array_equal(stk_values, expected_values)
Esempio n. 4
0
 def get_obs(self, vvv_ids, obs_table):
     times, values = [], []
     for vvv_id in vvv_ids:
         query, data = "source_id == " + str(int(vvv_id)), []
         for r in obs_table.where(query):
             data.append({k: r[k] for k in obs_table.colnames})
         obs = pd.DataFrame(data)[obs_table.colnames]
         obs = obs.sort_values("hjd")
         times.append(obs.hjd.values)
         values.append(obs.mag.values)
     return pytff.stack_targets(times, values)
Esempio n. 5
0
    def test_write_stk_targets(self):
        periods = [1, 2]
        times = [[0, 1, 2], [3, 4, 5, 6]]
        values = [[0, 1, 2], [3, 4, 5, 7]]
        self.tff.debug = True
        self.tff.analyze(periods, times, values)

        targets = np.dstack(pytff.stack_targets(times, values))
        for idx, t in enumerate(targets):
            ch = pytff.cache_hash(t)
            self.assertIn(ch, self.tff.targets_cache)
            with open(self.tff.targets_cache[ch]) as fp:
                linenos = len(fp.readlines())
            self.assertTrue(len(times[idx]) == len(values[idx]) == linenos)
Esempio n. 6
0
    def test_split_data(self):
        ogle_0_path = datasets.get("split_dat", "ogle_0.dat")
        ogle_1_path = datasets.get("split_dat", "ogle_1.dat")
        ogle_tff_path = datasets.get("split_dat", "tff.dat")
        ogle_dff_path = datasets.get("split_dat", "dff.dat")
        ogle_mch_path = datasets.get("split_dat", "match.dat")

        ogle_tff = pytff.load_tff_dat(ogle_tff_path, self.tff.process_tff)
        ogle_dff = pytff.load_tff_dat(ogle_dff_path, self.tff.process_dff)
        ogle_mch = pytff.load_match_dat(ogle_mch_path, self.tff.process_matchs)

        times_0, values_0 = pytff.loadtarget(ogle_0_path)
        times_1, values_1 = pytff.loadtarget(ogle_1_path)
        times, values = pytff.stack_targets(
            (times_0, times_1), (values_0, values_1))
        periods = np.array([0.6347522] * 2)

        tff_data, dff_data, mch_data = self.tff.analyze(periods, times, values)

        np.testing.assert_array_equal(tff_data, ogle_tff)
        np.testing.assert_array_equal(dff_data, ogle_dff)
        np.testing.assert_array_equal(mch_data, ogle_mch)