def test_classify_from_db(ResonanceOrbitalElementSetFacadeMock, libration_resonance_fixture: Tuple[ResonanceMixin, BodyNumberEnum], circulation_breaks, is_apocentric): orbital_element_set = ResonanceOrbitalElementSetFacadeMock() resonance, body_count = libration_resonance_fixture libration_cls = Libration if body_count == BodyNumberEnum.three else TwoBodyLibration libration = libration_cls(resonance, circulation_breaks, X_STOP, is_apocentric) resonance.libration = libration session.commit() classifier = LibrationClassifier(True, body_count) classifier.set_resonance(resonance) resonant_phases = [ {'year': 0.0, 'value': 0.0}, {'year': 3.0, 'value': 0.0}, {'year': 6.0, 'value': 0.0}, {'year': 9.0, 'value': 0.0} ] if circulation_breaks == [3., 6., 9.]: with pytest.raises(InvalidRequestError): classifier.classify(orbital_element_set, resonant_phases) else: res = classifier.classify(orbital_element_set, resonant_phases) assert res is True
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
def find(self, start: int, stop: int, aei_paths: tuple): """Analyze resonances for pointed half-interval of numbers of asteroids. It gets resonances aggregated to asteroids. Computes resonant phase by orbital elements from prepared aei files of three bodies (asteroid and two planets). After this it finds circulations in vector of resonant phases and solves, based in circulations, libration does exists or no. :param aei_paths: :param start: start point of half-interval. :param stop: stop point of half-interval. It will be excluded. :return: """ orbital_element_sets = None pathbuilder = FilepathBuilder(aei_paths, self._is_recursive, self._clear_s3) filepaths = [pathbuilder.build('%s.aei' % x) for x in self._planets] try: orbital_element_sets = build_bigbody_elements(filepaths) except AEIValueError: logging.error('Incorrect data in %s' % ' or in '.join(filepaths)) exit(-1) aei_getter = AEIDataGetter(pathbuilder, self._clear) classifier = LibrationClassifier(self._is_current, BodyNumberEnum(len(self._planets) + 1)) phase_builder = PhaseBuilder(self._phase_storage) p_bar = None if self._is_verbose: p_bar = ProgressBar((stop + 1 - start), 'Find librations') asteroid_name = None for resonance, aei_data in get_aggregated_resonances(start, stop, False, self._planets, aei_getter): if self._is_verbose and asteroid_name != resonance.small_body.name: p_bar.update() asteroid_name = resonance.small_body.name broken_asteroid_mediator = _BrokenAsteroidMediator(asteroid_name) if broken_asteroid_mediator.check(): continue logging.debug('Analyze asteroid %s, resonance %s' % (asteroid_name, resonance)) resonance_id = resonance.id classifier.set_resonance(resonance) orbital_elem_set_facade = ResonanceOrbitalElementSetFacade(orbital_element_sets, resonance) try: serialized_phases = phase_builder.build(aei_data, resonance_id, orbital_elem_set_facade) except AEIValueError: broken_asteroid_mediator.save() continue classifier.classify(orbital_elem_set_facade, serialized_phases) session.flush() session.commit()
def _resonance_fixture_different_librations(request): asteroid_nums = 1, 211, 78 planets = request.param['planets'] line_data_set = request.param['line_data_set'] _fixture_base(asteroid_nums, (planets,), line_data_set) request.addfinalizer(clear_resonance_finalizer) cls = ThreeBodyResonance if len(planets) == 2 else TwoBodyResonance libration_cls = Libration if len(planets) == 2 else TwoBodyLibration resonance = session.query(cls).outerjoin(Asteroid).filter( Asteroid.number == asteroid_nums[0]).first() libration = libration_cls(resonance, [], 0, False) session.commit() return asteroid_nums, planets, libration
def test_classify_without_db(ResonanceOrbitalElementSetFacadeMock, libration_resonance_fixture: Tuple[ResonanceMixin, BodyNumberEnum], resonant_phases, is_apocentric): orbital_element_set = ResonanceOrbitalElementSetFacadeMock() resonance, body_count = libration_resonance_fixture classifier = LibrationClassifier(False, body_count) classifier.set_resonance(resonance) res = classifier.classify(orbital_element_set, resonant_phases) assert res is True assert len(session.new) == 1 libration = [x for x in session.new][0] assert libration.resonance == resonance assert libration == resonance.libration session.commit()