Exemplo n.º 1
0
def libration_resonance_fixture(request):
    build_resonance(get_resonance_factory(*request.param))

    t1 = PLANET_TABLES['first_body']
    t2 = PLANET_TABLES['second_body']

    body_count = BodyNumberEnum(len(request.param[0])+1)

    query = get_resonance_query(body_count)
    query = query.filter(
        t1.longitude_coeff == 1, Asteroid.longitude_coeff == -1, t1.perihelion_longitude_coeff == 0,
        Asteroid.perihelion_longitude_coeff == 3)
    if body_count == BodyNumberEnum.three:
        query = query.filter(t2.longitude_coeff == 1, t2.perihelion_longitude_coeff == 0)
    resonance = query.first()

    session.commit()

    def tear_down():
        conn = engine.connect()
        conn.execute(Libration.__table__.delete())
        conn.execute(TwoBodyLibration.__table__.delete())
        conn.execute(TwoBodyResonance.__table__.delete())
        conn.execute(ThreeBodyResonance.__table__.delete())
        conn.execute(Planet.__table__.delete())
        conn.execute(Asteroid.__table__.delete())

    request.addfinalizer(tear_down)

    return resonance, body_count
Exemplo n.º 2
0
def test_build_resonance(input_values: List[str], asteroid_num: int, asteroid_indicies: List[int],
                         planets: Tuple[str], resonancesfixture):
    factory = get_resonance_factory(planets, input_values, asteroid_num)
    build_resonance(factory)
    planet_q = session.query(Planet)
    asteroid_q = session.query(Asteroid)
    body_count = BodyNumberEnum(len(planets) + 1)
    resonances_q = _build_resonances_query(body_count, input_values, asteroid_num, factory)

    def _check_bodies():
        """
        check values of entities from database with input values.
        :return:
        """
        resonances = resonances_q.all()
        assert len(resonances) == 1
        db_planets = planet_q.all()  # type: List[Planet]
        assert len(db_planets) == body_count.value - 1

        for planet, foreign in zip(db_planets, BODY_FOREIGNS):
            _check(planet, factory.bodies[foreign])
            assert getattr(resonances[0], foreign) == planet

        asteroids = asteroid_q.all()  # type: List[Asteroid]
        _check(asteroids[0], {'name': 'A%i' % asteroid_num,
                              LONG_COEFF: int(input_values[asteroid_indicies[0]]),
                              PERI_COEFF: int(input_values[asteroid_indicies[1]])})
        assert asteroids[0].axis == float(input_values[asteroid_indicies[2]])
        assert len(asteroids) == 1
        assert resonances[0].small_body == asteroids[0]

    _check_bodies()
    build_resonance(factory)
    _check_bodies()
Exemplo n.º 3
0
def test_id_sequences_errors(line_data: List[str], next_line_data: List[str], planets: List[Tuple],
                             test_table: Table,
                             _constraint_fixture):
    resonance_factory = get_resonance_factory(planets[0], line_data, 1)
    build_resonance(resonance_factory)

    conn = engine.connect()
    conn.execute('ALTER SEQUENCE %s_id_seq RESTART WITH 1;' % test_table.name)

    resonance_factory = get_resonance_factory(planets[1], next_line_data, 1)
    build_resonance(resonance_factory)

    for i, entry in enumerate(session.query(test_table).all()):
        assert (i + 1) == entry.id
Exemplo n.º 4
0
def build_possible_resonances(from_filepath: str, for_asteroid_num: int, planets: Tuple[str],
                              axis_swing: float) -> List[ThreeBodyResonance]:
    """
    Builds resonances, that can be for pointed asteroid. Resonance is considering if it's semi major
    axis similar to semi major axis of asteroid from catalog. Them compares with some swing, which
    which pointed in settings.
    :param axis_swing:
    :param planets:
    :param from_filepath: filepath to catalog of asteroids.
    :param for_asteroid_num: number of asteroid.
    :return: list of resonances.
    """
    res = []
    asteroid_parameters = find_by_number(for_asteroid_num)
    asteroid_axis = asteroid_parameters[1]
    try:
        with open(from_filepath) as resonance_file:
            for line in resonance_file:
                line_data = line.split()

                body_count = BodyNumberEnum(len(planets) + 1)
                assert (body_count == BodyNumberEnum.three and len(line_data) > 5 or
                        body_count == BodyNumberEnum.two)
                resonant_asteroid_axis = float(line_data[AXIS_COLUMNS[body_count]])
                if abs(resonant_asteroid_axis - asteroid_axis) <= axis_swing:
                    resonance_factory = get_resonance_factory(planets, line_data,
                                                              for_asteroid_num)
                    res.append(build_resonance(resonance_factory))
    except FileNotFoundError:
        logging.error('File %s not found. Try command resonance_table.',
                      from_filepath)
        sys.exit(1)

    return res
Exemplo n.º 5
0
def _fixture_base(asteroid_nums: Tuple, planets: Tuple[Tuple], line_data_set: List[List]):
    for line_data in line_data_set:
        for num in asteroid_nums:
            for target_planets in planets:
                resonance_factory = get_resonance_factory(target_planets, line_data, num)
                build_resonance(resonance_factory)
Exemplo n.º 6
0
def _create_two_resonances(line_data: List[str], next_line_data: List[str], planets: List[Tuple]):
    resonance_factory = get_resonance_factory(planets[0], line_data, 1)
    build_resonance(resonance_factory)

    resonance_factory = get_resonance_factory(planets[1], next_line_data, 1)
    build_resonance(resonance_factory)