Exemple #1
0
    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()
Exemple #2
0
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()
Exemple #3
0
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