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_is_empty(self): empty = [None, dict(), list(), np.array([]), np.nan, pd.NaT] result = np.array([utils.is_empty(val) for val in empty]) self.assertTrue(np.all(result)) not_empty = [0, 1, -1, dict(x=1), [1], [0, 0], np.array([0])] result = np.array([utils.is_empty(val) for val in not_empty]) self.assertTrue(np.all(up.invert(result)))
def plot(self): plt.figure(figsize=(8, 6)) if not is_empty(self.mp_result["n_phases"]): plt.plot(self.mp_result["n_phases"], np.round(self.mp_result["elapsed_time"], 2), label=f"multiprocessing") if not is_empty(self.sc_result["n_phases"]): plt.plot(self.sc_result["n_phases"], np.round(self.sc_result["elapsed_time"], 2), label=f"singlecore") plt.legend() plt.xlabel('n_phases [-]') plt.ylabel('elapsed_time [s]') plt.show()
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)))
def parse_row(row): placeholder = list() for r in row: r = str(r).strip() if not utils.is_empty(r): placeholder.append(remove_parenthesis(r)) return placeholder
def export_all_to_elisa_format(path): for law in ["lin", "log", "sqrt"]: for passband, band in __PASSBANDS_MAP__.items(): for mh in const.METALLICITY_LIST_LD: pd_records = pd.DataFrame(columns=__TABLE_HEADERS__[law]) for t in const.CK_TEMPERATURE_LIST_ATM: for g in const.GRAVITY_LIST_LD: obtained_record = get_record(t, g, mh, band) if utils.is_empty(obtained_record): continue for rec in obtained_record: if passband in rec: rec = rec[passband] try: df = pd.DataFrame( columns=__TABLE_HEADERS__[law]) df[__TABLE_HEADERS__[law][2:]] = rec[ __TABLE_HEADERS__[law][2:]] df[__TABLE_HEADERS__[law][0:2]] = [t, g] pd_records = pd.concat((pd_records, df)) except KeyError: pass tablename = get_elisa_filename(mh, law, passband) print(f"saving table {tablename}") pd_records.to_csv(pjoin(path, tablename), index=False)
def plot_points(points_1, points_2, label): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.set_aspect('equal') var = up.concatenate([points_1, points_2]) if not is_empty(points_2) else points_1 xx = np.array(list(zip(*var))[0]) yy = np.array(list(zip(*var))[1]) zz = np.array(list(zip(*var))[2]) scat = ax.scatter(xx, yy, zz) scat.set_label(label) ax.legend() max_range = np.array([xx.max() - xx.min(), yy.max() - yy.min(), zz.max() - zz.min()]).max() / 2.0 mid_x = (xx.max() + xx.min()) * 0.5 mid_y = (yy.max() + yy.min()) * 0.5 mid_z = (zz.max() + zz.min()) * 0.5 ax.set_xlim(mid_x - max_range, mid_x + max_range) ax.set_ylim(mid_y - max_range, mid_y + max_range) ax.set_zlim(mid_z - max_range, mid_z + max_range) ax.set_xlabel("x") ax.set_ylabel("y") ax.set_zlabel("z") plt.show()
def generator_test_mesh(self, key, d): s = prepare_single_system(testutils.SINGLE_SYSTEM_PARAMS[key], spots=testutils.SPOTS_META["primary"]) s.star.discretization_factor = d system_container = testutils.prepare_single_system_container(s) system_container.build_mesh() self.assertTrue(len(system_container.star.spots) == 1) self.assertTrue(not is_empty(system_container.star.spots[0].points))
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 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 get_section(data, header): section = list() ends_on = "Teff = " found_section = False for line in data.split('\n'): line = str(line).strip() if line == header: found_section = True continue if found_section and ends_on in line: break if found_section and not utils.is_empty(line): section.append(line) return section
def generator_test_face_orientaion(self, key, kind): s = testutils.prepare_single_system(testutils.SINGLE_SYSTEM_PARAMS[key], spots=testutils.SPOTS_META["primary"], ) s.star.discretization_factor = up.radians(7) s.init() position_container = testutils.prepare_single_system_container(s) position_container.build_mesh() position_container.build_faces() position_container.build_surface_areas() position_container.build_faces_orientation() if kind == 'present': self.assertTrue(not is_empty(position_container.star.normals)) self.assertTrue(not is_empty(position_container.star.spots[0].normals)) _assert = self.assertTrue if kind == 'direction': o = position_container face_points = o.star.points[o.star.faces] spot_face_points = o.star.spots[0].points[o.star.spots[0].faces] # x axis all_positive = (face_points[:, :, 0] >= 0).all(axis=1) _assert(np.all(o.star.normals[all_positive][:, 0] > 0)) all_negative = (face_points[:, :, 0] <= 0).all(axis=1) _assert(np.all(o.star.normals[all_negative][:, 0] < 0)) all_positive = (spot_face_points[:, :, 0] >= 0).all(axis=1) _assert(np.all(o.star.spots[0].normals[all_positive][:, 0] > 0)) all_negative = (spot_face_points[:, :, 0] <= 0).all(axis=1) _assert(np.all(o.star.spots[0].normals[all_negative][:, 0] < 0)) # y axis all_positive = (face_points[:, :, 1] >= 0).all(axis=1) _assert(np.all(o.star.normals[all_positive][:, 1] > 0)) all_negative = (face_points[:, :, 1] <= 0).all(axis=1) _assert(np.all(o.star.normals[all_negative][:, 1] < 0)) all_positive = (spot_face_points[:, :, 1] >= 0).all(axis=1) _assert(np.all(o.star.spots[0].normals[all_positive][:, 1] > 0)) all_negative = (spot_face_points[:, :, 1] <= 0).all(axis=1) _assert(np.all(o.star.spots[0].normals[all_negative][:, 1] < 0)) # z axis all_positive = (face_points[:, :, 2] >= 0).all(axis=1) _assert(np.all(o.star.normals[all_positive][:, 2] > 0)) all_negative = (face_points[:, :, 2] <= 0).all(axis=1) _assert(np.all(o.star.normals[all_negative][:, 2] < 0)) all_positive = (spot_face_points[:, :, 2] >= 0).all(axis=1) _assert(np.all(o.star.spots[0].normals[all_positive][:, 2] > 0)) all_negative = (spot_face_points[:, :, 2] <= 0).all(axis=1) _assert(np.all(o.star.spots[0].normals[all_negative][:, 2] < 0)) if kind == 'size': o = position_container normals_size = np.linalg.norm(o.star.normals, axis=1) _assert((np.round(normals_size, 5) == 1).all()) spot_normals_size = np.linalg.norm(o.star.spots[0].normals, axis=1) _assert((np.round(spot_normals_size, 5) == 1).all())
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())