def test_mesh_for_duplicate_points_no_spot(self):
        for params in testutils.BINARY_SYSTEM_PARAMS.values():
            s = prepare_binary_system(params)
            # reducing runtime of the test
            s.primary.discretization_factor = up.radians(7)
            s.init()
            components_distance = s.orbit.orbital_motion(phase=0.0)[0][0]

            orbital_position_container = OrbitalPositionContainer(
                primary=StarContainer.from_properties_container(
                    s.primary.to_properties_container()),
                secondary=StarContainer.from_properties_container(
                    s.secondary.to_properties_container()),
                position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
                **s.properties_serializer())

            orbital_position_container.build_mesh(
                components_distance=components_distance)

            for component in ['primary', 'secondary']:
                component_instance = getattr(orbital_position_container,
                                             component)
                distance = round(
                    find_nearest_dist_3d(list(component_instance.points)), 10)

                if distance < 1e-10:
                    bad_points = []
                    for i, point in enumerate(component_instance.points):
                        for j, xx in enumerate(component_instance.points[i +
                                                                         1:]):
                            dist = np.linalg.norm(point - xx)
                            if dist <= 1e-10:
                                print(f'Match: {point}, {i}, {j}')
                                bad_points.append(point)
                self.assertFalse(distance < 1e-10)
 def test_build_mesh_detached_with_overlapped_like_umbra():
     s = testutils.prepare_binary_system(
         testutils.BINARY_SYSTEM_PARAMS['detached'],
         spots_primary=list(reversed(testutils.SPOTS_OVERLAPPED)))
     s.primary.discretization_factor = up.radians(5)
     s.secondary.discretization_factor = up.radians(5)
     orbital_position_container = OrbitalPositionContainer(
         primary=StarContainer.from_properties_container(
             s.primary.to_properties_container()),
         secondary=StarContainer.from_properties_container(
             s.secondary.to_properties_container()),
         position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
         **s.properties_serializer())
     orbital_position_container.build_mesh(components_distance=1.0)
    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_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_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_build_mesh_detached_with_overlapped_spots(self):
     s = testutils.prepare_binary_system(
         testutils.BINARY_SYSTEM_PARAMS['detached'],
         spots_primary=testutils.SPOTS_OVERLAPPED)
     s.primary.discretization_factor = up.radians(5)
     s.secondary.discretization_factor = up.radians(5)
     orbital_position_container = OrbitalPositionContainer(
         primary=StarContainer.from_properties_container(
             s.primary.to_properties_container()),
         secondary=StarContainer.from_properties_container(
             s.secondary.to_properties_container()),
         position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
         **s.properties_serializer())
     with self.assertRaises(Exception) as context:
         orbital_position_container.build_mesh(components_distance=1.0)
     self.assertTrue(
         "Please, specify spots wisely" in str(context.exception))
示例#7
0
def prepare_orbital_position_container(system):
    orbital_position_container = OrbitalPositionContainer(
        primary=StarContainer.from_properties_container(system.primary.to_properties_container()),
        secondary=StarContainer.from_properties_container(system.secondary.to_properties_container()),
        position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
        **system.properties_serializer()
    )
    return orbital_position_container
    def generator_test_mesh(key, d, length):
        s = prepare_binary_system(testutils.BINARY_SYSTEM_PARAMS[key])
        s.primary.discretization_factor = d
        s.secondary.discretization_factor = d

        orbital_position_container = OrbitalPositionContainer(
            primary=StarContainer.from_properties_container(
                s.primary.to_properties_container()),
            secondary=StarContainer.from_properties_container(
                s.secondary.to_properties_container()),
            position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
            **s.properties_serializer())
        orbital_position_container.build_mesh(components_distance=1.0)

        obtained_primary = np.round(orbital_position_container.primary.points,
                                    4)
        obtained_secondary = np.round(
            orbital_position_container.secondary.points, 4)
        assert_array_equal([len(obtained_primary),
                            len(obtained_secondary)], length)
    def test_make_sure_spots_are_not_overwriten_in_star_instance(self):
        s = testutils.prepare_binary_system(
            testutils.BINARY_SYSTEM_PARAMS["detached"],
            spots_primary=testutils.SPOTS_META["primary"],
            spots_secondary=testutils.SPOTS_META["secondary"])
        s.primary.discretization_factor = up.radians(10)
        s.secondary.discretization_factor = up.radians(10)

        orbital_position_container = OrbitalPositionContainer(
            primary=StarContainer.from_properties_container(
                s.primary.to_properties_container()),
            secondary=StarContainer.from_properties_container(
                s.secondary.to_properties_container()),
            position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
            **s.properties_serializer())
        orbital_position_container.build_mesh(components_distance=1.0)
        self.assertTrue(is_empty(s.primary.spots[0].points))
        self.assertTrue(is_empty(s.secondary.spots[0].points))

        self.assertTrue(is_empty(s.primary.spots[0].faces))
        self.assertTrue(is_empty(s.secondary.spots[0].faces))
    def generator_test_mesh(self, key, d):
        s = testutils.prepare_binary_system(
            testutils.BINARY_SYSTEM_PARAMS[key],
            spots_primary=testutils.SPOTS_META["primary"],
            spots_secondary=testutils.SPOTS_META["secondary"])
        s.primary.discretization_factor = d
        s.secondary.discretization_factor = d
        orbital_position_container = OrbitalPositionContainer(
            primary=StarContainer.from_properties_container(
                s.primary.to_properties_container()),
            secondary=StarContainer.from_properties_container(
                s.secondary.to_properties_container()),
            position=Position(*(0, 1.0, 0.0, 0.0, 0.0)),
            **s.properties_serializer())
        orbital_position_container.build_mesh(components_distance=1.0)

        self.assertTrue(
            len(orbital_position_container.primary.spots) == 1
            and len(orbital_position_container.secondary.spots) == 1)
        self.assertTrue(
            not is_empty(orbital_position_container.primary.spots[0].points))
        self.assertTrue(
            not is_empty(orbital_position_container.secondary.spots[0].points))
    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()