Exemple #1
0
 def run_simulation(self, simulation_input):
     sim = self.init_rebound_simulation(simulation_input)
     feature_classifier_model = FeatureClassifier()
     deep_regressor_model = DeepRegressor()
     stability_probability = feature_classifier_model.predict_stable(sim)
     median, lower, upper = deep_regressor_model.predict_instability_time(sim, samples=10000)
     return {"star_mass": simulation_input.star_mass,
             "periods": ",".join([str(planet_period) for planet_period in simulation_input.planet_periods]),
             "masses": ",".join([str(mass_value) for mass_value in simulation_input.mass_arr]),
             "inclinations": ",".join([str(ecc_value) for ecc_value in simulation_input.inc_arr]),
             "eccentricities": ",".join([str(ecc_value) for ecc_value in simulation_input.ecc_arr]),
             "arg_periastron": ",".join([str(ecc_value) for ecc_value in simulation_input.omega_arr]),
             "stability_probability": stability_probability, "median_expected_instability_time": median}
Exemple #2
0
 def run(self, planet_params):
     sim = rebound.Simulation()
     sim.integrator = "whfast"
     sim.ri_whfast.safe_mode = 0
     sim.dt = 1e-2
     sim.add(m=1.0)
     for planet_param in planet_params:
         sim.add(m=self.mass_from_radius(planet_param.r) * 0.000003003 /
                 self.star_mass,
                 P=planet_param.P,
                 e=planet_param.e,
                 omega=planet_param.omega)
     #sim.status()
     sim.move_to_com()
     model = FeatureClassifier()
     print("SPOCK=" + str(model.predict_stable(sim)))
			break

		unstable = 'n' #### initialize assuming stability, until shown otherwise.

		try:
			running_period_list = np.load(projectdir+'/running_list_of_derived_TTV_periods.npy').tolist()
		except:
			running_period_list = []		

		### create a simulations instance.
		sim = rebound.Simulation()
		if include_J2 == 'y':
			rebx = reboundx.Extras(sim)
			gh = rebx.load_force('gravitational_harmonics')
			rebx.add_force(gh)
		stability_model = FeatureClassifier()

		### put these in familiar units
		sim.G = G.value
		sim.units = ('s', 'm', 'kg') ### mks 


		#### now let's add Jupiter, Io, Europa, Ganymede, and Callisto!

		### Jupiter

		if make_imaginary_system == 'n':
			### MAKE JUPITER!
			sim.add(m=M_jup.value, hash='Jupiter')
			system_dict = {}
			moon_dict = {} ### make a dictionary
 def setUp(self):
     self.model = FeatureClassifier()
class TestClassifier(unittest.TestCase):
    def setUp(self):
        self.model = FeatureClassifier()
    
    def test_list(self):
        stable_target = [0, 0, 0, 0.7]
        stable = self.model.predict_stable([hyperbolicsim(), escapesim(), unstablesim(), longstablesim()])
        self.assertEqual(stable[0], 0)
        self.assertEqual(stable[1], 0)
        self.assertEqual(stable[2], 0)
        self.assertGreater(stable[3], 0.7) 
    
    def test_sim_unchanged(self):
        sim = rebound.Simulation()
        sim.add(m=1.)
        sim.add(m=1.e-5, P=1.)
        sim.add(m=1.e-5, P=2.)
        sim.add(m=1.e-5, P=3.)
        sim.integrate(1.2)
        x0 = sim.particles[1].x
        p1 = self.model.predict_stable(sim)
        self.assertEqual(sim.particles[1].x, x0)

    def test_repeat(self):
        sim = rebound.Simulation()
        sim.add(m=1.)
        sim.add(m=1.e-5, P=1.)
        sim.add(m=1.e-5, P=2.)
        sim.add(m=1.e-5, P=3.)
        p1 = self.model.predict_stable(sim)
        p2 = self.model.predict_stable(sim)
        self.assertEqual(p1, p2)

    def test_same_trajectory(self):
        sim = longstablesim()
        init_sim_parameters(sim)
        _, _ = get_tseries(sim, (1e4, 80, [[1,2,3]]))
        x1 = sim.particles[1].x

        sim = longstablesim()
        nbody = NbodyRegressor()
        nbody.predict_stable(sim, tmax=1e4, archive_filename='temp.bin', archive_interval=1.e4)
        sa = rebound.SimulationArchive('temp.bin')
        sim = sa[-1]
        x2 = sim.particles[1].x
        self.assertAlmostEqual(x1, x2, delta=1.e-5)
   
    # when chaotic realization matters, probs will vary more (eg t_inst=2e4)
    def test_galilean_transformation(self):
        sim = longstablesim()
        sim.move_to_com()
        p_com = self.model.predict_stable(sim)

        sim = longstablesim()
        for p in sim.particles:
            p.vx += 1000
        p_moving = self.model.predict_stable(sim)
        self.assertAlmostEqual(p_com, p_moving, delta=1.e-2)
   
    def test_rescale_distances(self):
        sim = longstablesim()
        p0 = self.model.predict_stable(sim)

        sim = longstablesim()
        sim = rescale(sim, dscale=1e10, tscale=1, mscale=1)
        p1 = self.model.predict_stable(sim)
        self.assertAlmostEqual(p0, p1, delta=1.e-2)
    
    def test_rescale_times(self):
        sim = longstablesim()
        p0 = self.model.predict_stable(sim)

        sim = longstablesim()
        sim = rescale(sim, dscale=1, tscale=1e10, mscale=1)
        p1 = self.model.predict_stable(sim)
        self.assertAlmostEqual(p0, p1, delta=1.e-1)

    def test_rescale_masses(self):
        sim = longstablesim()
        p0 = self.model.predict_stable(sim)

        sim = longstablesim()
        sim = rescale(sim, dscale=1, tscale=1, mscale=1e10)
        p1 = self.model.predict_stable(sim)
        self.assertAlmostEqual(p0, p1, delta=1.e-2)
    
    def test_hyperbolic(self):
        sim = hyperbolicsim()
        self.assertEqual(self.model.predict_stable(sim), 0)
    
    def test_escape(self):
        sim = escapesim()
        self.assertEqual(self.model.predict_stable(sim), 0)
    
    def test_unstable_in_short_integration(self):
        sim = unstablesim()
        self.assertEqual(self.model.predict_stable(sim), 0)
    
    def test_solarsystem(self):
        sim = solarsystemsim()
        self.assertGreater(self.model.predict_stable(sim), 0.7)
    
    def test_stable(self):
        sim = longstablesim()
        self.assertGreater(self.model.predict_stable(sim), 0.7)