def integrate_minimum_distance(particles, end_position): from amuse.lab import ph4, nbody_system convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[0].position.length()) gravity = ph4(convert_nbody) gravity.particles.add_particles(particles) bh1 = gravity.particles[0] bh2 = gravity.particles[1] hvgc = gravity.particles[2] hvgc_vel_list = [] | units.kms gcbh1_dist = [] | units.parsec gcbh2_dist = [] | units.parsec hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() while hvgc_pos < end_position: gravity.evolve_model(gravity.model_time + (100 | units.yr)) gcbh1_dist.append((hvgc.position - bh1.position).length()) gcbh2_dist.append((hvgc.position - bh2.position).length()) hvgc_vel_list.append(hvgc.velocity.length()) hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() gcbh1_distmin = min(gcbh1_dist) gcbh2_distmin = min(gcbh2_dist) hvgc_max_vel = max(hvgc_vel_list) print hvgc_max_vel print gcbh1_distmin print gcbh2_distmin hvgc_vel = (hvgc.vx**2 + hvgc.vy**2 + hvgc.vz**2).sqrt() gravity.stop() return hvgc_vel, gcbh1_distmin, gcbh2_distmin
def integrate_solar_system(particles, end_time): from amuse.lab import Huayno, nbody_system from amuse.units import quantities convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[1].position.length()) gravity = Huayno(convert_nbody) gravity.particles.add_particles(particles) venus = gravity.particles[1] earth = gravity.particles[2] x_earth = [] | units.AU y_earth = [] | units.AU x_venus = [] | units.AU y_venus = [] | units.AU while gravity.model_time < end_time: gravity.evolve_model(gravity.model_time + (10 | units.day)) x_earth.append(earth.x) y_earth.append(earth.y) x_venus.append(venus.x) y_venus.append(venus.y) # from amuse.lab import * # write_set_to_file(gravity.particles, "gravity.h5", "hdf5") gravity.stop() return x_earth, y_earth, x_venus, y_venus
def integrate_plotting(particles, end_position): """Input: Set of particles and end condition. Integrates until GC reaches end condition. Records positions of each particle throughout integration in steps of 100 years.""" from amuse.lab import ph4, nbody_system convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[0].position.length()) gravity = ph4(convert_nbody) gravity.particles.add_particles(particles) print gravity.parameters bh1 = gravity.particles[0] bh2 = gravity.particles[1] hvgc = gravity.particles[2] x_hvgc = [] | units.parsec y_hvgc = [] | units.parsec x_bh1 = [] | units.parsec y_bh1 = [] | units.parsec x_bh2 = [] | units.parsec y_bh2 = [] | units.parsec gcbh1_dist = [] | units.parsec gcbh2_dist = [] | units.parsec hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() while hvgc_pos < end_position: gravity.evolve_model(gravity.model_time + (100 | units.yr)) x_hvgc.append(hvgc.x) y_hvgc.append(hvgc.y) x_bh1.append(bh1.x) y_bh1.append(bh1.y) x_bh2.append(bh2.x) y_bh2.append(bh2.y) gcbh1_dist.append(hvgc.position.length() - bh1.position.length()) hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() gcbh1_distmin = min(gcbh1_dist) hvgc_vel = (hvgc.vx**2 + hvgc.vy**2 + hvgc.vz**2).sqrt() gravity.stop() return hvgc_vel, x_hvgc, y_hvgc, x_bh1, y_bh1, x_bh2, y_bh2
def integrate_solar_system(particles, end_time): from amuse.lab import Hermite, nbody_system, Brutus convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[1].position.length()) gravity = Hermite(convert_nbody) gravity.particles.add_particles(particles) sun = gravity.particles[0] venus = gravity.particles[1] earth = gravity.particles[2] def to_float(c): return [ c[0].value_in(units.AU), c[1].value_in(units.AU), c[2].value_in(units.AU) ] sun_pos = [to_float([sun.x, sun.y, sun.z])] earth_pos = [to_float([earth.x, earth.y, earth.z])] venus_pos = [to_float([venus.x, venus.y, venus.z])] start_array = np.array([sun_pos, earth_pos, venus_pos]).reshape([-1, 3]) start = pd.DataFrame(data=start_array, columns=["x", "y", "z"]) while gravity.model_time < end_time: gravity.evolve_model(gravity.model_time + (1 | units.day)) sun_pos.append(to_float([sun.x, sun.y, sun.z])) earth_pos.append(to_float([earth.x, earth.y, earth.z])) venus_pos.append(to_float([venus.x, venus.y, venus.z])) gravity.stop() return sun_pos, earth_pos, venus_pos, start
def integrate_system(particles, end_position): """Given a set of particles, will integrate system until particle[2] reaches end_position. Returns the velocity of particle[2] at end_position.""" from amuse.lab import ph4, nbody_system convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[0].position.length()) gravity = ph4(convert_nbody) gravity.particles.add_particles(particles) hvgc = gravity.particles[2] hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() captured = False while hvgc_pos < end_position: gravity.evolve_model(gravity.model_time + (100 | units.yr)) hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() if gravity.model_time > (400000 | units.yr): hvgc_pos = end_position captured = True break if captured == True: hvgc_vel = 0 | units.kms else: hvgc_vel = (hvgc.vx**2 + hvgc.vy**2 + hvgc.vz**2).sqrt() gravity.stop() print hvgc_vel print captured return hvgc_vel
def integrate_system_final(particles, end_position): from amuse.lab import ph4, nbody_system convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[0].position.length()) gravity = ph4(convert_nbody) gravity.particles.add_particles(particles) hvgc = gravity.particles[2] bh1 = gravity.particles[0] bh2 = gravity.particles[1] hvgc_energy = [] hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() while hvgc_pos < end_position: captured = False gravity.evolve_model(gravity.model_time + (2000 | units.yr)) # hvgc_v = (hvgc.vx**2 + hvgc.vy**2 + hvgc.vz**2).sqrt() # hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() # energy = 0.5*hvgc.mass*hvgc_v**2 - constants.G*(bh1.mass + bh2.mass)*hvgc.mass/hvgc_pos # hvgc_energy.append(energy.value_in(units.J)) hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() if gravity.model_time > (300000 | units.yr): hvgc_pos = end_position captured = True break hvgc_vel = (hvgc.vx**2 + hvgc.vy**2 + hvgc.vz**2).sqrt() if captured == True: hvgc_vel = 0 | units.kms gravity.stop() return hvgc_vel, hvgc_energy
def integrate_solar_system(particles, end_time): from amuse.lab import Huayno, nbody_system from amuse.units.generic_unit_converter import ConvertBetweenGenericAndSiUnits from amuse.units import constants, units #print(particles) #converter_body = nbody_system.nbody_to_si(particles.mass.sum(), # particles[1].position.length()) converter_body = nbody_system.nbody_to_si(1 | units.kg, 1 | units.m) #print(convert_nbody) #converter = ConvertBetweenGenericAndSiUnits(particles)#???????????????????? #gravity = Huayno(converter.to_si(particles)) gravity = Huayno(converter_body) gravity.particles.add_particles(particles) sun = gravity.particles[0] venus = gravity.particles[1] earth = gravity.particles[2] x_earth = [] | units.m y_earth = [] | units.m x_venus = [] | units.m y_venus = [] | units.m x_sun = [] | units.m y_sun = [] | units.m while gravity.model_time < end_time: gravity.evolve_model(gravity.model_time + (1 | units.s)) x_sun.append(sun.x) y_sun.append(sun.y) x_earth.append(earth.x) y_earth.append(earth.y) x_venus.append(venus.x) y_venus.append(venus.y) gravity.stop() return x_earth, y_earth, x_venus, y_venus, x_sun, y_sun
def integrate_energy(particles, end_condition): """Given particle set and end condition, integrate system and record energy of each particle. Return individual energies, total energy, time.""" from amuse.lab import ph4, nbody_system convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[0].position.length()) gravity = ph4(convert_nbody) gravity.particles.add_particles(particles) bh1 = gravity.particles[0] bh2 = gravity.particles[1] hvgc = gravity.particles[2] bh1_energy = [] bh2_energy = [] bbh_energy = [] hvgc_energy = [] total_energy = [] time = [] hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() while hvgc_pos < end_condition: gravity.evolve_model(gravity.model_time + (1000 | units.yr)) com_pos = particles.center_of_mass() com_vel = particles.center_of_mass_velocity() rel_hvgc_pos = hvgc.position - com_pos rel_hvgc_vel = hvgc.velocity - com_vel #bh1_total_energy = bh1.specific_kinetic_energy()*bh1.mass.in_(units.kg) - bh1.potential()*bh1.mass.in_(units.kg) #bh2_total_energy = bh2.specific_kinetic_energy()*bh2.mass.in_(units.kg) - bh2.potential()*bh2.mass.in_(units.kg) #hvgc_total_energy = hvgc.specific_kinetic_energy()*hvgc.mass.in_(units.kg) - hvgc.potential()*hvgc.mass.in_(units.kg) hvgc_total_energy = 0.5 * hvgc.mass * ( rel_hvgc_vel.x**2 + rel_hvgc_vel.y**2 + rel_hvgc_vel.z**2 ) - (constants.G * hvgc.mass * (bh1.mass + bh2.mass)) / (rel_hvgc_pos.x**2 + rel_hvgc_pos.y**2 + rel_hvgc_pos.z**2).sqrt() time.append(gravity.model_time.value_in(units.yr)) #bh1_energy.append(bh1_total_energy.value_in(units.J)) #bh2_energy.append(bh2_total_energy.value_in(units.J)) #bbh_energy.append(bh1_total_energy.value_in(units.J) + bh2_total_energy.value_in(units.J)) hvgc_energy.append(hvgc_total_energy.value_in(units.J)) #total_energy.append(-1*(particles.kinetic_energy() + particles.potential_energy()).value_in(units.J)) hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() # if gravity.model_time > (600000 | units.yr): # hvgc_pos = end_condition hvgc_vel = (hvgc.vx**2 + hvgc.vy**2 + hvgc.vz**2).sqrt() gravity.stop() print hvgc_vel print "Initial cluster energy: {:.2E}".format(hvgc_energy[0]) print "Final cluster energy: {:.2E}".format(hvgc_energy[-1]) print(hvgc_energy[-1] - hvgc_energy[0]) / hvgc_energy[-1] return bh1_energy, bh2_energy, bbh_energy, hvgc_energy, total_energy, time
def plummer(mass, radius, N): conv = nbody_system.nbody_to_si(radius, mass) pm = new_plummer_model(N, convert_nbody=conv, do_scale=True) gravity = ph4(conv) pm.positon = pm.position + ((100, 100, 100) | units.parsec) pm.velocity = pm.velocity + ((-1000, -1000, -1000) | (units.km / units.s)) lr, mf = pm.LagrangianRadii(unit_converter=conv) print lr, mf #print 'position of pm[0] before gravity evolution: ',pm[0].position #print 'velocity of pm[0] before gravity evolution: ',pm[0].velocity #while gravity.model_time < 1000000 | units.yr: #print gravity.particles[0].position #gravity.evolve_model(gravity.model_time + (100000 | units.yr)) #print 'position of pm[0] after gravity evolution: ',pm[0].position #print 'velocity of pm[0] after gravity evolution: ',pm[0].velocity gravity.stop()
def evolve_sun_jupiter(particles, tend, dt): SunJupiter = Particles() SunJupiter.add_particle(particles[0]) SunJupiter.add_particle(particles[1]) converter = nbody_system.nbody_to_si(particles.mass.sum(), particles[1].position.length()) gravity = ph4(converter) gravity.particles.add_particles(particles) channel_from_to_SunJupiter = gravity.particles.new_channel_to(SunJupiter) semi_major_axis = [] eccentricity = [] times = quantities.arange(0 | units.yr, tend, dt) for i, t in enumerate(times): print "Time=", t.in_(units.yr) channel_from_to_SunJupiter.copy() orbital_elements = orbital_elements_from_binary(SunJupiter, G=constants.G) a = orbital_elements[2] e = orbital_elements[3] semi_major_axis.append(a.value_in(units.AU)) eccentricity.append(e) gravity.evolve_model(t, timestep=dt) # Plot fig = plt.figure(figsize=(8, 6)) ax1 = fig.add_subplot(211, xlabel='time(yr)', ylabel='semi major axis (AU)') ax1.plot(times.value_in(units.yr), semi_major_axis) ax2 = fig.add_subplot(212, xlabel='time(yr)', ylabel='eccentriity') ax2.plot(times.value_in(units.yr), eccentricity) plt.show() gravity.stop()
def evolve_sun_jupiter(particles, tend, dt): SunJupiter = Particles() SunJupiter.add_particle(particles[0]) SunJupiter.add_particle(particles[1]) converter=nbody_system.nbody_to_si(particles.mass.sum(), particles[1].position.length()) gravity = ph4(converter) gravity.particles.add_particles(particles) channel_from_to_SunJupiter = gravity.particles.new_channel_to(SunJupiter) semi_major_axis = list() eccentricity = list() times = quantities.arange(0|units.yr, tend+dt, dt) for i,t in enumerate(times): #print "Time =", t.in_(units.yr) channel_from_to_SunJupiter.copy() orbital_elements = orbital_elements_from_binary(SunJupiter, G=constants.G) a = orbital_elements[2] e = orbital_elements[3] semi_major_axis.append(a.value_in(units.AU)) eccentricity.append(e) gravity.evolve_model(t, timestep=dt) gravity.stop() # save the data: times, semi_major_axis and eccentricity of Jupiter's orbit t_a_e = np.column_stack((times.value_in(units.yr), semi_major_axis, eccentricity)) np.savetxt('t_a_e.txt', t_a_e, delimiter=',') # make plots fig = plt.figure(figsize = (8, 6)) ax1 = fig.add_subplot(211, xlabel = 'time(yr)', ylabel = 'semi major axis (AU)') ax1.plot(times.value_in(units.yr), semi_major_axis) ax2 = fig.add_subplot(212, xlabel = 'time(yr)', ylabel = 'eccentriity') ax2.plot(times.value_in(units.yr), eccentricity) plt.show()
def integrate_solar_system(particles, end_time): from amuse.lab import Huayno, nbody_system convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[1].position.length()) gravity = Huayno(convert_nbody) gravity.particles.add_particles(particles) venus = gravity.particles[1] earth = gravity.particles[2] x_earth = [] | units.AU y_earth = [] | units.AU x_venus = [] | units.AU y_venus = [] | units.AU while gravity.model_time < end_time: gravity.evolve_model(gravity.model_time + (1 | units.day)) x_earth.append(earth.x) y_earth.append(earth.y) x_venus.append(venus.x) y_venus.append(venus.y) gravity.stop() return x_earth, y_earth, x_venus, y_venus
def integrate_solar_system(particles, end_time): from amuse.lab import Hermite, nbody_system convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[1].position.length()) gravity = Hermite(convert_nbody) gravity.particles.add_particles(particles) sun = gravity.particles[0] venus = gravity.particles[1] earth = gravity.particles[2] def to_float(c): return [c[0].value_in(units.AU), c[1].value_in(units.AU), c[2].value_in(units.AU)] sun_pos = [to_float([sun.x,sun.y,sun.z])] earth_pos = [to_float([earth.x,earth.y,earth.z])] venus_pos = [to_float([venus.x,venus.y,venus.z])] while gravity.model_time < end_time: gravity.evolve_model(gravity.model_time + (1 | units.day)) sun_pos.append(to_float([sun.x,sun.y,sun.z])) earth_pos.append(to_float([earth.x,earth.y,earth.z])) venus_pos.append(to_float([venus.x,venus.y,venus.z])) gravity.stop() return sun_pos, earth_pos, venus_pos
def integrate_solar_system(particles, end_time): ''' Caclulate the trajectory initial potitions until end_time You can use any integrater ''' from amuse.lab import Hermite, nbody_system, Brutus convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[1].position.length()) gravity = Brutus(convert_nbody) # you can use any integrator here gravity.particles.add_particles(particles) planet_1 = gravity.particles[0] planet_2 = gravity.particles[1] planet_3 = gravity.particles[2] def to_float(c): return [ c[0].value_in(units.AU), c[1].value_in(units.AU), c[2].value_in(units.AU) ] planet_1_pos = [to_float([planet_1.x, planet_1.y, planet_1.z])] planet_2_pos = [to_float([planet_2.x, planet_2.y, planet_2.z])] planet_3_pos = [to_float([planet_3.x, planet_3.y, planet_3.z])] start_array = np.array([planet_1_pos, planet_2_pos, planet_3_pos]).reshape([-1, 3]) start = pd.DataFrame(data=start_array, columns=["x", "y", "z"]) while gravity.model_time < end_time: gravity.evolve_model(gravity.model_time + (1 | units.day)) # define the timesteps you want planet_1_pos.append(to_float([planet_1.x, planet_1.y, planet_1.z])) planet_2_pos.append(to_float([planet_2.x, planet_2.y, planet_2.z])) planet_3_pos.append(to_float([planet_3.x, planet_3.y, planet_3.z])) gravity.stop() return planet_1_pos, planet_2_pos, planet_3_pos, start
def tidal_ratio(gc_closest_ratio, bbh_mass_ratio, bbh_separation, phase): bbh_mass = 7e9 | units.MSun gc_inf = 500 | (units.km / units.s) gc_closest = bbh_separation * gc_closest_ratio end_position = 120 | units.parsec particles = bbh_hvgc(bbh_mass, bbh_mass_ratio, bbh_separation, phase, gc_closest, gc_inf) from amuse.lab import ph4, nbody_system convert_nbody = nbody_system.nbody_to_si(particles.mass.sum(), particles[0].position.length()) gravity = ph4(convert_nbody) gravity.particles.add_particles(particles) bh1 = gravity.particles[0] bh2 = gravity.particles[1] hvgc = gravity.particles[2] hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() hvgc_int_acc = 1e7 / 1000 tide_ratio1 = [] tide_ratio2 = [] while hvgc_pos < end_position: gravity.evolve_model(gravity.model_time + (200 | units.yr)) r_bh1 = (hvgc.position - bh1.position).length().value_in(units.parsec) r_bh2 = (hvgc.position - bh2.position).length().value_in(units.parsec) bh1_tide = bh1.mass.value_in(units.MSun) / r_bh1**3 bh2_tide = bh2.mass.value_in(units.MSun) / r_bh2**3 bh1_tide_ratio = bh1_tide / hvgc_int_acc bh2_tide_ratio = bh2_tide / hvgc_int_acc tide_ratio1.append(bh1_tide_ratio) tide_ratio2.append(bh2_tide_ratio) hvgc_pos = (hvgc.x**2 + hvgc.y**2 + hvgc.z**2).sqrt() max_tide1 = max(tide_ratio1) max_tide2 = max(tide_ratio2) gravity.stop() return max_tide1, max_tide2
't step (Myr)': [t_end.value_in(units.Myr)], #m31 dynamic parameters 'm31_radvel_factor (* 117 km/s)': [m31_radvel_factor], 'm31_transvel_factor (* 42 km/s)': [m31_transvel_factor], #solar tracker parameters 'add_solar': [SOLAR], 'n_stars': [n_stars], 'solar_radial_distance (kpc)': [solar_radial_distance], 'solar_system_radius (kpc)': [system_radius.value_in(units.kpc)], #igm parameters 'add_igm': [IGM] } ###### galaxy initialization ###### converter = nbody_system.nbody_to_si(scale_mass_galaxy, scale_radius_galaxy) if GENERATION: print('Generating new galaxies', flush=True) mw, _ = gal.make_galaxy( mw_parameters['n_halo'], converter, mw_parameters['name'], test=TEST, #output dir output_directory='/data1/brentegani/', #halo parameters #halo_scale_radius = glxy_param['halo_scale_radius'], #disk parameters disk_number_of_particles=mw_parameters['disk_number_of_particles'], disk_mass=mw_parameters['disk_mass'],
complete_system = add_comet_objects(basic_giants_system, N_objects, positions, velocities) # In[ ]: final_system = complete_system final_system.move_to_center() # In[ ]: #Here we perform the conversion for the system converter_length = get_orbital_elements_from_binary(final_system[0:2], G = constants.G)[2].in_(units.AU) # Typical distance used for calculation (=distance from Sun to Jupiter) final_converter=nbody_system.nbody_to_si(final_system.mass.sum(), converter_length) # In[ ]: #Here we evolve the basic system, without grandtack or Milky way potential def vanilla_evolver(particle_system, converter, N_objects, end_time, time_step): names = ['Sun', 'Jupiter', 'Saturn', 'Uranus', 'Neptune'] gravity_code = MercuryWayWard() gravity_code.initialize_code() gravity_code.central_particle.add_particle(particle_system[0])
def rgb_frame( stars, dryrun=False, vmax=None, percentile=0.9995, multi_psf=False, sourcebands="ubvri", image_width=12. | units.parsec, image_size=[1024, 1024], mapper_factory=None, gas=None, ): if gas is None: gas = Particles() print("luminosities..") for band in sourcebands: setattr( stars, band + "_band", 4 * numpy.pi * stars.radius**2 * filter_band_flux( "bess-" + band + ".pass", lambda x: B_lambda(x, stars.temperature), ), ) print("..raw images..") if mapper_factory: mapper = mapper_factory() else: converter = nbody_system.nbody_to_si(stars.total_mass(), image_width) mapper = FiMap(converter, mode="openmp", redirection="none") mapper.parameters.image_width = image_width mapper.parameters.image_size = image_size stars_in_mapper = mapper.particles.add_particles(stars) gas_in_mapper = mapper.particles.add_particles(gas) mapper.parameters.projection_direction = [0, 0, 1] mapper.parameters.upvector = [0, -1, 0] raw_images = dict() for band in sourcebands: assign_weights_and_opacities( band, stars_in_mapper, gas_in_mapper, stars, gas, Nstar=200, ) # mapper.particles.weight = getattr( # stars, # band+"_band" # ).value_in(units.LSun) im = mapper.image.pixel_value raw_images[band] = im mapper.stop() convolved_images = dict() print("..convolving..") if multi_psf: a = numpy.arange(image_size[0]) / float(image_size[0] - 1) b = numpy.arange(image_size[1]) / float(image_size[1] - 1) w1 = numpy.outer(a, b) w2 = numpy.outer(1. - a, b) w3 = numpy.outer(a, 1. - b) w4 = numpy.outer(1. - a, 1. - b) for key, val in raw_images.items(): im1 = Convolve(val, psf[key + '0']) im2 = Convolve(val, psf[key + '1']) im3 = Convolve(val, psf[key + '2']) im4 = Convolve(val, psf[key + '3']) convolved_images[key] = w1 * im1 + w2 * im2 + w3 * im3 + w4 * im4 else: for key, val in raw_images.items(): im1 = Convolve(val, psf[key + '0']) convolved_images[key] = im1 print("..conversion to rgb") source = [filter_data['bess-' + x + '.pass'] for x in sourcebands] target = [xyz_data['x'], xyz_data['y'], xyz_data['z']] conv = ColorConverter(source, target) ubv = numpy.array([convolved_images[x] for x in sourcebands]) xyz = numpy.tensordot(conv.conversion_matrix, ubv, axes=(1, 0)) conv_xyz_to_lin = XYZ_to_sRGB_linear() srgb_l = numpy.tensordot( conv_xyz_to_lin.conversion_matrix, xyz, axes=(1, 0), ) if dryrun or vmax is None: flat_sorted = numpy.sort(srgb_l.flatten()) n = len(flat_sorted) vmax = flat_sorted[int(1. - 3 * (1. - percentile) * n)] print("vmax:", vmax) if dryrun: return vmax conv_lin_to_sRGB = sRGB_linear_to_sRGB() srgb = conv_lin_to_sRGB.convert(srgb_l / vmax) # r = srgb[0,:,:].transpose() # g = srgb[1,:,:].transpose() # b = srgb[2,:,:].transpose() r = numpy.fliplr(srgb[0, :, :]) g = numpy.fliplr(srgb[1, :, :]) b = numpy.fliplr(srgb[2, :, :]) rgb = numpy.zeros(image_size[0] * image_size[1] * 3) rgb = rgb.reshape(image_size[0], image_size[1], 3) rgb[:, :, 0] = r rgb[:, :, 1] = g rgb[:, :, 2] = b image = dict( pixels=rgb, size=rgb.size, ) return vmax, image
def semi_major_axis_next_step_out(time_now, time_start, a_end, a_start, time_scale): travel_distance = a_end - a_start sma_next_step = a_start + travel_distance * (1 / (1 - 1 / math.e)) * ( 1 - np.exp(-(time_now - time_start) / time_scale)) return sma_next_step # In[ ]: #Here we create the converter converter_length = get_orbital_elements_from_binary( complete_pre_tack_system[0:2], G=constants.G)[2].in_( units.AU ) # Typical distance used for calculation (=distance from Sun to Jupiter) converter = nbody_system.nbody_to_si(complete_pre_tack_system.mass.sum(), converter_length) # In[ ]: #Here we manually create all the timesteps that we want the model to evolve to #Due to the different timescales of migration, each stage in the migration requires #It's own time array. We also manually create the times at which to save the data files jupiter_inward_times = np.arange(0, 1 * 10**5, 3) saturn_inward_times = np.arange(1 * 10**5, 1.025 * 10**5, 0.5) outward_times = np.arange(1.025 * 10**5, 6 * 10**5, 15) post_tack_times = np.arange(6 * 10**5, 10**8, 1 * 10**3) final_time_range = np.concatenate((jupiter_inward_times, saturn_inward_times, outward_times, post_tack_times)) | units.yr save_file_times = np.concatenate(
def integrate_solar_system(): # Get initial conditions. solar = planetary_system()[0] debris = planetary_system()[1] star = solar[0] planet = solar[1] moon = solar[2] # Integrators set to Huayno. converter = nbody_system.nbody_to_si(star.mass, 1. | units.AU) system_gravity = Huayno(converter) system_gravity.particles.add_particle(star) system_gravity.particles.add_particle(planet) system_gravity.particles.add_particle(moon) disk_gravity = Huayno(converter) disk_gravity.particles.add_particle(debris) # Set up channels. channel_from_system_to_framework = system_gravity.particles.new_channel_to( solar) channel_from_disk_to_framework = disk_gravity.particles.new_channel_to( debris) # Set up bridge. gravity = bridge.Bridge(use_threading=False, method=SPLIT_4TH_S_M4) gravity.add_system(system_gravity, (disk_gravity, )) gravity.add_system(disk_gravity, (system_gravity, )) # Record positions. x_planet = quantities.AdaptingVectorQuantity() y_planet = quantities.AdaptingVectorQuantity() x_moon = quantities.AdaptingVectorQuantity() y_moon = quantities.AdaptingVectorQuantity() x_debris = quantities.AdaptingVectorQuantity() y_debris = quantities.AdaptingVectorQuantity() # Evolving time. t = 0 | units.day dt = 1 | units.day # to make sure getting 250 snapshots t_end = 1 | units.yr # 29.4571 yr Saturn's orbital period # Record time and energies. time = quantities.AdaptingVectorQuantity() system_E = quantities.AdaptingVectorQuantity() disk_E = quantities.AdaptingVectorQuantity() bridge_E = quantities.AdaptingVectorQuantity() # Evolve model. print 'Begin evolving' while t < t_end: t += dt gravity.evolve_model(t) channel_from_system_to_framework.copy() channel_from_disk_to_framework.copy() x_planet.append(planet.x) y_planet.append(planet.y) x_moon.append(moon.x) y_moon.append(moon.y) x_debris.append(debris.x) y_debris.append(debris.y) time.append(t) system_E.append(system_gravity.kinetic_energy + system_gravity.potential_energy) disk_E.append(disk_gravity.kinetic_energy + disk_gravity.potential_energy) bridge_E.append(gravity.kinetic_energy + gravity.potential_energy) pyplot.clf() pyplot.xlabel('x [au]') pyplot.ylabel('y [au]') #pyplot.xlim(-2.2, -1.9) #pyplot.ylim(8.7, 8.8) pyplot.scatter(star.x.value_in(units.AU), star.y.value_in(units.AU), color='black', label='star') pyplot.scatter(planet.x.value_in(units.AU), planet.y.value_in(units.AU), color='blue', label='planet') pyplot.scatter(moon.x.value_in(units.AU), moon.y.value_in(units.AU), color='red', label='moon') pyplot.scatter(debris.x.value_in(units.AU), debris.y.value_in(units.AU), color='green', s=1, label='disk') #pyplot.legend() pyplot.savefig( '/home/rywang/capexam/plots/animation/positions_{0:03}.png'.format( t.number)) print 'Generating plot{}'.format(t.number) gravity.stop() print 'End evolving' # Making animation. subprocess.call( "mencoder 'mf:///home/rywang/capexam/plots/animation/positions_*.png' -mf type=png:fps=20 -ovc lavc -lavcopts vcodec=wmv2 -oac copy -o /home/rywang/capexam/plots/animation/animation.mpg", shell=True) return time, system_E, disk_E, bridge_E, x_planet, y_planet, x_moon, y_moon, x_debris, y_debris