def test_star_container_is_indempotent(self):
        system = OrbitalPositionContainer.from_binary_system(self.s, Position(0, 1.0, 0.0, 0.0, 0.0))
        system.build(components_distance=1.0)
        star = system.primary

        flatt_1 = star.flatt_it()
        flatt_2 = star.flatt_it()
        self.assertTrue(len(flatt_1.points) == len(flatt_2.points))
    def test_orbital_position_container_is_indempotent(self):
        settings.configure(LD_TABLES=op.join(self.base_path, "data", "light_curves", "limbdarkening"))

        system = OrbitalPositionContainer.from_binary_system(self.s, Position(0, 1.0, 0.0, 0.0, 0.0))
        system.build(components_distance=1.0)
        flatt_1 = system.flatt_it()
        flatt_2 = system.flatt_it()
        self.assertTrue(len(flatt_1.primary.points) == len(flatt_2.primary.points))
    def test_from_binary_system(self):
        system = OrbitalPositionContainer.from_binary_system(self.s, Position(0, 1.0, 0.0, 0.0, 0.0))
        self.assertTrue(isinstance(system, OrbitalPositionContainer))
        self.assertTrue(isinstance(system.primary, StarContainer))
        self.assertTrue(isinstance(system.secondary, StarContainer))

        has_attr = [hasattr(system, atr) for atr in self.props]
        self.assertTrue(all(has_attr))
    def test_visible_indices_when_darkside_filter_apply(self):
        settings.configure(
            **{
                "LD_TABLES": op.join(self.lc_base_path, "limbdarkening"),
                "CK04_ATM_TABLES": op.join(self.lc_base_path, "atmosphere")
            })

        bs = prepare_binary_system(BINARY_SYSTEM_PARAMS['detached-physical'])
        from_this = dict(binary_system=bs,
                         position=const.Position(0, 1.0, 0.0, 0.0, 0.0))
        system = OrbitalPositionContainer.from_binary_system(**from_this)
        system.build(components_distance=1.0)
        system.calculate_face_angles(line_of_sight=const.LINE_OF_SIGHT)
        system.apply_darkside_filter()
        self.assertTrue((not is_empty(system.primary.indices))
                        and (not is_empty(system.secondary.indices)))
        system=binary
    )  # specifying the binary system to use in light curve synthesis
    phases, curves[ii] = o.lc(
        from_phase=-0.5,
        to_phase=0.5,
        phase_step=0.005,
        # phase_step=0.01,
        # normalize=True,
    )
    curves[ii] = curves[ii]['Generic.Bessell.V']

    y_data = curves[ii] / np.mean(curves[ii])
    mean = np.sqrt(np.mean(np.power(y_data - 1, 2)))
    print(f'factor: {alpha}, mean noise: {mean}')
    plt.plot(phases,
             y_data,
             label='factor: {0}, mean noise: {1:.2E}'.format(alpha, mean))

    position = binary.calculate_orbital_motion(0.0)[0]
    container = OrbitalPositionContainer.from_binary_system(binary, position)
    container.build()

    print(
        f'{alpha} {container.primary.points.shape[0]}    {container.primary.faces.shape[0]} {mean}'
    )

plt.xlabel('Phase')
plt.ylabel('Normalized flux')
plt.legend()
plt.show()