def generator_test_gravity(self, key): 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 = up.radians(10) s.secondary.discretization_factor = up.radians(10) orbital_position_container = testutils.prepare_orbital_position_container( s) orbital_position_container.build_mesh(components_distance=1.0) orbital_position_container.build_faces(components_distance=1.0) orbital_position_container.build_surface_areas() orbital_position_container.build_faces_orientation( components_distance=1.0) orbital_position_container.build_surface_gravity( components_distance=1.0) self.assertTrue( hasattr(orbital_position_container.primary.spots[0], "potential_gradient_magnitudes")) self.assertTrue( hasattr(orbital_position_container.secondary.spots[0], "potential_gradient_magnitudes")) self.assertTrue( hasattr(orbital_position_container.primary.spots[0], "log_g")) self.assertTrue( hasattr(orbital_position_container.secondary.spots[0], "log_g")) self.assertTrue( not is_empty(orbital_position_container.primary.spots[0].log_g)) self.assertTrue( not is_empty(orbital_position_container.secondary.spots[0].log_g))
def test_closed_surface_over_contact(self): s = testutils.prepare_binary_system( testutils.BINARY_SYSTEM_PARAMS['over-contact'], spots_primary=testutils.SPOTS_META["primary"], spots_secondary=testutils.SPOTS_META["secondary"]) s.primary.discretization_factor = up.radians(7) s.init() orbital_position_container = testutils.prepare_orbital_position_container( s) orbital_position_container.build_mesh(components_distance=1.0) orbital_position_container.build_faces(components_distance=1.0) for component in ['primary', 'secondary']: instance = getattr(orbital_position_container, component) points = instance.points faces = instance.faces if isinstance(instance.spots, (dict, )): for idx, spot in instance.spots.items(): faces = up.concatenate((faces, spot.faces + len(points)), axis=0) points = up.concatenate((points, spot.points), axis=0) setattr(instance, 'points', points) setattr(instance, 'faces', faces) points = np.concatenate((orbital_position_container.primary.points, orbital_position_container.secondary.points)) faces = np.concatenate( (orbital_position_container.primary.faces, orbital_position_container.secondary.faces + np.shape(orbital_position_container.primary.points)[0])) self.assertTrue(testutils.surface_closed(faces=faces, points=points))
def test_calculate_polar_gravity_acceleration_eccentric(self): bs = self._binaries[1] distance = bs.orbit.orbital_motion([0.34])[0][0] orbital_position_container = testutils.prepare_orbital_position_container( bs) expected_g_cgs_primary = polar_gravity_acceleration( bs, ["primary"], distance) expected_g_cgs_secondary = polar_gravity_acceleration( bs, ["secondary"], distance) obtained_g_cgs_primary = gravity.calculate_polar_gravity_acceleration( orbital_position_container.primary, distance, bs.mass_ratio, "primary", bs.semi_major_axis, bs.primary.synchronicity, logg=False) * 100.0 obtained_g_cgs_secondary = gravity.calculate_polar_gravity_acceleration( orbital_position_container.secondary, distance, bs.mass_ratio, "secondary", bs.semi_major_axis, bs.secondary.synchronicity, logg=False) * 100.0 print(expected_g_cgs_primary, obtained_g_cgs_primary) print(expected_g_cgs_secondary, obtained_g_cgs_secondary) print(distance)
def test_calculate_polar_gravity_acceleration_circular(self): bs = self._binaries[0] orbital_position_container = testutils.prepare_orbital_position_container( bs) expected_g_cgs_primary = polar_gravity_acceleration( bs, ["primary"], 1.0) expected_g_cgs_secondary = polar_gravity_acceleration( bs, ["secondary"], 1.0) obtained_g_cgs_primary = gravity.calculate_polar_gravity_acceleration( orbital_position_container.primary, 1.0, bs.mass_ratio, "primary", bs.semi_major_axis, bs.primary.synchronicity, logg=False) * 100 obtained_g_cgs_secondary = gravity.calculate_polar_gravity_acceleration( orbital_position_container.secondary, 1.0, bs.mass_ratio, "secondary", bs.semi_major_axis, bs.secondary.synchronicity, logg=False) * 100 self.assertEqual(round(expected_g_cgs_primary, 4), round(obtained_g_cgs_primary, 4)) self.assertEqual(round(expected_g_cgs_secondary, 4), round(obtained_g_cgs_secondary, 4))
def build_system(key, d): s = testutils.prepare_binary_system( testutils.BINARY_SYSTEM_PARAMS[key]) s.primary.discretization_factor = d s.secondary.discretization_factor = d orbital_position_container = testutils.prepare_orbital_position_container( s) orbital_position_container.build_mesh(components_distance=1.0) orbital_position_container.build_faces(components_distance=1.0) return orbital_position_container
def generator_test_temperatures(self, key, allowed_range=None): settings.configure( **{ "LIMB_DARKENING_LAW": "linear", "LD_TABLES": op.join(op.dirname(op.abspath(__file__)), "data", "light_curves", "limbdarkening") }) s = testutils.prepare_binary_system( testutils.BINARY_SYSTEM_PARAMS[key]) s.primary.discretization_factor = up.radians(10) s.secondary.discretization_factor = up.radians(10) orbital_position_container = testutils.prepare_orbital_position_container( s) orbital_position_container.build_mesh(components_distance=1.0) orbital_position_container.build_faces(components_distance=1.0) orbital_position_container.build_surface_areas() orbital_position_container.build_surface_gravity( components_distance=1.0) orbital_position_container.build_faces_orientation( components_distance=1.0) orbital_position_container.build_temperature_distribution( components_distance=1.0) print() i = np.argsort(orbital_position_container.secondary.temperatures) print(orbital_position_container.secondary.points[ orbital_position_container.secondary.faces[i[:10]]]) print() if allowed_range: obtained_primary = [ np.min(orbital_position_container.primary.temperatures), np.max(orbital_position_container.primary.temperatures) ] obtained_secondary = [ np.min(orbital_position_container.secondary.temperatures), np.max(orbital_position_container.secondary.temperatures) ] self.assertTrue((obtained_primary[0] >= allowed_range[0][0]) & (obtained_primary[1] <= allowed_range[0][1])) self.assertTrue((obtained_secondary[0] >= allowed_range[1][0]) & (obtained_secondary[1] <= allowed_range[1][1]))
def test_closed_surface_over_contact(self): s = testutils.prepare_binary_system( testutils.BINARY_SYSTEM_PARAMS['over-contact']) s.primary.discretization_factor = up.radians(10) s.init() orbital_position_container = testutils.prepare_orbital_position_container( s) orbital_position_container.build_mesh(components_distance=1.0) orbital_position_container.build_faces(components_distance=1.0) points = np.concatenate((orbital_position_container.primary.points, orbital_position_container.secondary.points)) faces = np.concatenate( (orbital_position_container.primary.faces, orbital_position_container.secondary.faces + np.shape(orbital_position_container.primary.points)[0])) self.assertTrue(testutils.surface_closed(faces=faces, points=points))
def generator_test_faces(key, d, length): 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.init() orbital_position_container = testutils.prepare_orbital_position_container( s) orbital_position_container.build_mesh(components_distance=1.0) orbital_position_container.build_faces(components_distance=1.0) assert_array_equal([ len(orbital_position_container.primary.faces), len(orbital_position_container.secondary.faces), len(orbital_position_container.primary.spots[0].faces), len(orbital_position_container.secondary.spots[0].faces) ], length)
def generator_test_gravity(self, key, over): s = testutils.prepare_binary_system( testutils.BINARY_SYSTEM_PARAMS[key]) s.primary.discretization_factor = up.radians(10) s.secondary.discretization_factor = up.radians(10) orbital_position_container = testutils.prepare_orbital_position_container( s) orbital_position_container.build_mesh(components_distance=1.0) orbital_position_container.build_faces(components_distance=1.0) orbital_position_container.build_surface_areas() orbital_position_container.build_faces_orientation( components_distance=1.0) orbital_position_container.build_surface_gravity( components_distance=1.0) self.assertTrue( np.all(orbital_position_container.primary.log_g > over)) self.assertTrue( np.all(orbital_position_container.secondary.log_g > over))
def generator_test_surface_areas(self, key, d, kind, less=None): 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.init() orbital_position_container = testutils.prepare_orbital_position_container( s) orbital_position_container.build_mesh(components_distance=1.0) orbital_position_container.build_faces(components_distance=1.0) orbital_position_container.build_surface_areas() if kind == "contain": self.assertTrue( not is_empty(orbital_position_container.primary.areas)) self.assertTrue( not is_empty(orbital_position_container.secondary.areas)) self.assertTrue(not is_empty( orbital_position_container.primary.spots[0].areas)) self.assertTrue(not is_empty( orbital_position_container.secondary.spots[0].areas)) if kind == "size": self.assertTrue( np.all(up.less(orbital_position_container.primary.areas, less))) self.assertTrue( np.all( up.less(orbital_position_container.secondary.areas, less))) self.assertTrue( np.all( up.less(orbital_position_container.primary.spots[0].areas, less))) self.assertTrue( np.all( up.less( orbital_position_container.secondary.spots[0].areas, less)))
def build_system(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.init() orbital_position_container = testutils.prepare_orbital_position_container( s) orbital_position_container.build_mesh(components_distance=1.0) orbital_position_container.build_faces(components_distance=1.0) for component in ['primary', 'secondary']: instance = getattr(orbital_position_container, component) points = instance.points faces = instance.faces if isinstance(instance.spots, (dict, )): for idx, spot in instance.spots.items(): faces = up.concatenate((faces, spot.faces + len(points)), axis=0) points = up.concatenate((points, spot.points), axis=0) setattr(instance, 'points', points) setattr(instance, 'faces', faces) return orbital_position_container
def generator_test_face_orientaion(self, key, kind): 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 = up.radians(7) s.init() orbital_position_container: OrbitalPositionContainer = testutils.prepare_orbital_position_container( s) orbital_position_container.build_mesh(components_distance=1.0) orbital_position_container.build_faces(components_distance=1.0) orbital_position_container.build_surface_areas() orbital_position_container.build_faces_orientation( components_distance=1.0) if kind == 'present': self.assertTrue( not is_empty(orbital_position_container.primary.normals)) self.assertTrue( not is_empty(orbital_position_container.secondary.normals)) self.assertTrue(not is_empty( orbital_position_container.primary.spots[0].normals)) self.assertTrue(not is_empty( orbital_position_container.secondary.spots[0].normals)) _assert = self.assertTrue if kind == 'direction': o = orbital_position_container for component in ['primary', 'secondary']: star = getattr(o, component) face_points = star.points[star.faces] spot_face_points = star.spots[0].points[star.spots[0].faces] face_points[:, :, 0] = face_points[:, :, 0] - 1 if component == 'secondary' else face_points[:, :, 0] spot_face_points[:, :, 0] = spot_face_points[:, :, 0] - 1 if component == 'secondary' else \ spot_face_points[:, :, 0] # x axis all_positive = (face_points[:, :, 0] > 0).all(axis=1) _assert(np.all(star.normals[all_positive][:, 0] > 0)) all_negative = (face_points[:, :, 0] < 0).all(axis=1) _assert(np.all(star.normals[all_negative][:, 0] < 0)) all_positive = (spot_face_points[:, :, 0] > 0).all(axis=1) _assert(np.all(star.spots[0].normals[all_positive][:, 0] > 0)) all_negative = (spot_face_points[:, :, 0] <= 0).all(axis=1) _assert(np.all(star.spots[0].normals[all_negative][:, 0] < 0)) # y axis all_positive = (face_points[:, :, 1] > 0).all(axis=1) _assert(np.all(star.normals[all_positive][:, 1] > 0)) all_negative = (face_points[:, :, 1] < 0).all(axis=1) _assert(np.all(star.normals[all_negative][:, 1] < 0)) all_positive = (spot_face_points[:, :, 1] > 0).all(axis=1) _assert(np.all(star.spots[0].normals[all_positive][:, 1] > 0)) all_negative = (spot_face_points[:, :, 1] < 0).all(axis=1) _assert(np.all(star.spots[0].normals[all_negative][:, 1] < 0)) # z axis all_positive = (face_points[:, :, 2] > 0).all(axis=1) _assert(np.all(star.normals[all_positive][:, 2] > 0)) all_negative = (face_points[:, :, 2] < 0).all(axis=1) _assert(np.all(star.normals[all_negative][:, 2] < 0)) all_positive = (spot_face_points[:, :, 2] > 0).all(axis=1) _assert(np.all(star.spots[0].normals[all_positive][:, 2] > 0)) all_negative = (spot_face_points[:, :, 2] < 0).all(axis=1) _assert(np.all(star.spots[0].normals[all_negative][:, 2] < 0)) if kind == 'size': o = orbital_position_container for component in ['primary', 'secondary']: star = getattr(o, component) normals_size = np.linalg.norm(star.normals, axis=1) _assert((np.round(normals_size, 5) == 1).all()) spot_normals_size = np.linalg.norm(star.spots[0].normals, axis=1) _assert((np.round(spot_normals_size, 5) == 1).all())