def make_histograms(self): """ plots histograms of the final sma results with respect to the initial sma values of the particles sma = semi-major axis """ ###### RE-FORMAT THIS ###### two_stars = self.initial_state[0:2] transferred_sma = quantities.AdaptingVectorQuantity() keys_passing = self.passing[-1].key transferred = self.initial_state.select(lambda x : x in keys_passing , ["key"]) for b in transferred: s_b = self.shift_to_star(b, two_stars, star_choice = 0) a, ecc, T = ps.orbital_parameters(s_b.position, s_b.velocity, self.info.m0) transferred_sma.append(a) ejected_sma = quantities.AdaptingVectorQuantity() keys_unbound = self.unbound[-1].key ejected = self.initial_state.select(lambda x : x in keys_unbound , ["key"]) for b in ejected: s_b = self.shift_to_star(b, two_stars, star_choice = 0) a, ecc, T = ps.orbital_parameters(s_b.position, s_b.velocity, self.info.m0) ejected_sma.append(a) ###### RE-FORMAT THIS ###### global_max = max( len(transferred_sma), len(ejected_sma) ) name = "/plot_transferred_semimajor_axes_histogram.png" ps.make_sm_axis_histogram(transferred_sma, name, PlotFactory.c_PASSING, step_size = 5, max_count = global_max) name = "/plot_transferred_semimajor_axes_histogram_cum.png" ps.make_sm_axis_histogram(transferred_sma, name, PlotFactory.c_PASSING, cum = True, max_count = global_max) name = "/plot_ejected_semimajor_axes_histogram.png" ps.make_sm_axis_histogram(ejected_sma, name, PlotFactory.c_UNBOUND, step_size = 5, max_count = global_max) name = "/plot_ejected_semimajor_axes_histogram_cum.png" ps.make_sm_axis_histogram(ejected_sma, name, PlotFactory.c_UNBOUND, cum = True, max_count = global_max)
def init_states(self): """ Initializes the time array, the bodies at timestep 1 (start+1), and the bodies at timestep -1 (end) """ # Reset if called previously (or would prompting user be better?) self.zero_state = None self.initial_state = None self.final_state = None for b in self.bodies.history: # Mark Time self.times.append(b.collection_attributes.timestamp) # Set States if self.zero_state is None: self.zero_state = b elif self.initial_state is None: self.initial_state = b self.final_state = b # re-update until history ends # Identify limits on inner and outer disk radii (######## Eventually, replace this with reading in the info ########) self.min_a = 100000.0 | units.AU self.max_a = 0.0 | units.AU two_stars = self.initial_state[0:2] planetesimals = self.initial_state[2:] shifted = self.shift_to_star(planetesimals, two_stars, star_choice=0) for b in shifted: a, e, T = ps.orbital_parameters(b.position, b.velocity, self.info.m0) if (a > self.max_a): self.max_a = a if (a < self.min_a): self.min_a = a
def init_states(self): """ Initializes the time array, the bodies at timestep 1 (start+1), and the bodies at timestep -1 (end) """ # Reset if called previously (or would prompting user be better?) self.zero_state = None self.initial_state = None self.final_state = None for b in self.bodies.history: # Mark Time self.times.append(b.collection_attributes.timestamp) # Set States if self.zero_state is None: self.zero_state = b elif self.initial_state is None: self.initial_state = b self.final_state = b # re-update until history ends # Identify limits on inner and outer disk radii (######## Eventually, replace this with reading in the info ########) self.min_a = 100000.0|units.AU self.max_a = 0.0|units.AU two_stars = self.initial_state[0:2] planetesimals = self.initial_state[2:] shifted = self.shift_to_star(planetesimals, two_stars, star_choice = 0) for b in shifted: a, e, T = ps.orbital_parameters(b.position, b.velocity, self.info.m0) if (a > self.max_a): self.max_a = a if (a < self.min_a): self.min_a = a
def make_movies_semi_major_axes(self, movie=1, plot_kept=False, consec=False): """ Plot the evolution of the semi-major axes over time """ ############## NEEDS A LOT OF CLEAN UP, DOESN'T EVEN WORK #################### old_sm_axes = quantities.AdaptingVectorQuantity() init_two_stars = self.initial_state[0:2] planetesimals = self.initial_state[2:] ### Passing Star (Transferred) ### for i, (bodies, passing) in enumerate(zip(self.bodies.history, self.passing)): if (self.mask[i]): old_sm_axes = quantities.AdaptingVectorQuantity() new_sm_axes_p = quantities.AdaptingVectorQuantity() eccentricities = [] time = self.times[i] two_stars = bodies[0:2] # New Values s_planetesimals = self.shift_to_star(passing, two_stars, star_choice=1) s_pls = s_planetesimals # make new name later for b in s_pls: a, ecc, T = ps.orbital_parameters(b.position, b.velocity, self.info.m1) new_sm_axes_p.append( a ) # This is wrong (a is an array) <--- How to handle array? eccentricities.append(ecc) #new_sm_axes_p = a print "New" print new_sm_axes_p print # Note, using the mask isn't as helpful as it could be # The sm-axes are still re-calculated. This is bad. They should be stored in a file # Old Values selected = planetesimals.select(lambda x: x in passing.key, ["key"]) old_planetesimals = self.shift_to_star(selected, init_two_stars, star_choice=0) old_p = old_planetesimals for b in old_p: a, ecc, T = ps.orbital_parameters(b.position, b.velocity, self.info.m0) old_sm_axes.append(a) print "Old" print old_sm_axes print if len(new_sm_axes_p) > 0: print "Iteration ", i ps.make_sma_evolution_scatter_plot(old_sm_axes, new_sm_axes_p, colorcode = eccentricities, \ movie = 1, color = PlotFactory.c_PASSING, i = i, time = time, min_a = (self.info).r_in.value_in(units.AU), max_a = (self.info).r_out.value_in(units.AU)) # (1) A ps.make_sma_evolution_scatter_plot(old_sm_axes, new_sm_axes_p - old_sm_axes, \ movie = 1, color = PlotFactory.c_PASSING, i = i, time = time, delta = 1, min_a = (self.info).r_in.value_in(units.AU), max_a = (self.info).r_out.value_in(units.AU)) # (2) Delta A # Add (3) Ecc ps.make_sma_evolution_scatter_plot(old_sm_axes, eccentricities, \ movie = 1, color = PlotFactory.c_PASSING, i = i, time = time, eccentric = 1, min_a = (self.info).r_in.value_in(units.AU), max_a = (self.info).r_out.value_in(units.AU)) # (2) Delta A if movie == 1: # (4) SEMI-MAJOR AXES (transferred) sma_p_path = self.snapshot_dir + "/sma_transfer/sma_evolution_%3d.png" sma_p_movie = self.snapshot_dir + "/transferred_sma.mp4" self.make_movies(sma_p_path, sma_p_movie, consec=consec) # (5) DELTA SEMI-MAJOR AXES (transferred) d_sma_p_path = self.snapshot_dir + "/sma_transfer_delta/sma_evolution_%3d.png" d_sma_p_movie = self.snapshot_dir + "/transferred_delta_sma.mp4" self.make_movies(d_sma_p_path, d_sma_p_movie, consec=consec) ### Central Star (Kept) ### if (plot_kept): for i, (bodies, central) in enumerate( zip(self.bodies.history, self.central)): if (self.mask[i]): old_sm_axes = quantities.AdaptingVectorQuantity() new_sm_axes_c = quantities.AdaptingVectorQuantity() time = self.times[i] two_stars = bodies[0:2] s_pls = self.shift_to_star( central, two_stars, star_choice=0) # Change Name of this later for b in s_pls: a, ecc, T = ps.orbital_parameters( b.position, b.velocity, self.info.m0) new_sm_axes_c.append(a) #new_sm_axes_c = a selected = planetesimals.select(lambda x: x in central.key, ["key"]) old_planetesimals = self.shift_to_star(selected, init_two_stars, star_choice=0) old_p = old_planetesimals for b in old_p: a, ecc, T = ps.orbital_parameters( b.position, b.velocity, self.info.m0) old_sm_axes.append(a) if len(new_sm_axes_c) > 0: print "Iteration ", i ps.make_sma_evolution_scatter_plot(old_sm_axes, new_sm_axes_c, \ movie = 1, color = PlotFactory.c_CENTRAL, i = i, time = time) # (4) A ps.make_sma_evolution_scatter_plot(old_sm_axes, new_sm_axes_c - old_sm_axes, \ movie = 1, color = PlotFactory.c_CENTRAL, i = i, time = time, delta = 1) # (5) Delta A # Add (6) Ecc ps.make_sma_evolution_scatter_plot(old_sm_axes, eccentricities, \ movie = 1, color = PlotFactory.c_CENTRAL, i = i, time = time, eccentric = 1) if movie == 1: # (6) SEMI-MAJOR AXES (kept) sma_c_path = self.snapshot_dir + "/sma_kept/sma_evolution_%3d.png" sma_c_movie = self.snapshot_dir + "/kept_sma.mp4" self.make_movies(sma_c_path, sma_c_movie, consec=consec) # (7) DELTA SEMI-MAJOR AXES (kept) d_sma_c_path = self.snapshot_dir + "/sma_kept_delta/sma_evolution_%3d.png" d_sma_c_movie = self.snapshot_dir + "/kept_delta_sma.mp4" self.make_movies(d_sma_c_path, d_sma_c_movie, consec=consec)
def make_histograms(self): """ plots histograms of the final sma results with respect to the initial sma values of the particles sma = semi-major axis """ # Ensure that the last index has been sorted self.tmp_mask[-1] = 1 self.sort() ###### RE-FORMAT THIS ###### <--- Did I do this already? two_stars = self.initial_state[0:2] last_index = -1 # should be num_snapshots - 1, but not necessarily due to error in code (see below) transferred_sma = quantities.AdaptingVectorQuantity() keys_passing = self.passing[ last_index].key ##### There is a 'plus one' error in "multiple_code*.py" #### transferred = self.initial_state.select(lambda x: x in keys_passing, ["key"]) for b in transferred: s_b = self.shift_to_star(b, two_stars, star_choice=0) a, ecc, T = ps.orbital_parameters(s_b.position, s_b.velocity, self.info.m0) transferred_sma.append(a) ejected_sma = quantities.AdaptingVectorQuantity() keys_unbound = self.unbound[last_index].key ejected = self.initial_state.select(lambda x: x in keys_unbound, ["key"]) for b in ejected: s_b = self.shift_to_star(b, two_stars, star_choice=0) a, ecc, T = ps.orbital_parameters(s_b.position, s_b.velocity, self.info.m0) ejected_sma.append(a) ###### RE-FORMAT THIS ###### global_max = max(len(transferred_sma), len(ejected_sma)) if len(transferred_sma) > 0: #(a1) name = "/plot_transferred_semimajor_axes_histogram_bin5AU.png" ps.make_sm_axis_histogram( transferred_sma, name, PlotFactory.c_PASSING, step_size=5, max_count=global_max, min_a=int((self.info).r_in.value_in(units.AU)), max_a=int((self.info).r_out.value_in(units.AU))) #(a2) name = "/plot_transferred_semimajor_axes_histogram_bin1AU.png" ps.make_sm_axis_histogram( transferred_sma, name, PlotFactory.c_PASSING, max_count=global_max, min_a=int((self.info).r_in.value_in(units.AU)), max_a=int((self.info).r_out.value_in(units.AU))) #(a3) name = "/plot_transferred_semimajor_axes_histogram_cum_bin5AU.png" ps.make_sm_axis_histogram( transferred_sma, name, PlotFactory.c_PASSING, step_size=1, cum=True, max_count=global_max, min_a=int((self.info).r_in.value_in(units.AU)), max_a=int((self.info).r_out.value_in(units.AU))) #(a4) name = "/plot_transferred_semimajor_axes_histogram_cum_bin1AU.png" ps.make_sm_axis_histogram( transferred_sma, name, PlotFactory.c_PASSING, cum=True, max_count=global_max, min_a=int((self.info).r_in.value_in(units.AU)), max_a=int((self.info).r_out.value_in(units.AU))) if len(ejected_sma) > 0: #(b1) name = "/plot_ejected_semimajor_axes_histogram_bin5AU.png" ps.make_sm_axis_histogram( ejected_sma, name, PlotFactory.c_UNBOUND, step_size=5, max_count=global_max, min_a=int((self.info).r_in.value_in(units.AU)), max_a=int((self.info).r_out.value_in(units.AU))) #(b2) name = "/plot_ejected_semimajor_axes_histogram_bin1AU.png" ps.make_sm_axis_histogram( ejected_sma, name, PlotFactory.c_UNBOUND, max_count=global_max, min_a=int((self.info).r_in.value_in(units.AU)), max_a=int((self.info).r_out.value_in(units.AU))) #(b3) name = "/plot_ejected_semimajor_axes_histogram_cum_bin5AU.png" ps.make_sm_axis_histogram( ejected_sma, name, PlotFactory.c_UNBOUND, step_size=5, cum=True, max_count=global_max, min_a=int((self.info).r_in.value_in(units.AU)), max_a=int((self.info).r_out.value_in(units.AU))) #(b4) name = "/plot_ejected_semimajor_axes_histogram_cum_bin1AU.png" ps.make_sm_axis_histogram( ejected_sma, name, PlotFactory.c_UNBOUND, cum=True, max_count=global_max, min_a=int((self.info).r_in.value_in(units.AU)), max_a=int((self.info).r_out.value_in(units.AU)))
def make_histograms(self): """ plots histograms of the final sma results with respect to the initial sma values of the particles sma = semi-major axis """ # Ensure that the last index has been sorted self.tmp_mask[-1] = 1 self.sort() ###### RE-FORMAT THIS ###### <--- Did I do this already? two_stars = self.initial_state[0:2] last_index = -1 # should be num_snapshots - 1, but not necessarily due to error in code (see below) transferred_sma = quantities.AdaptingVectorQuantity() keys_passing = self.passing[last_index].key ##### There is a 'plus one' error in "multiple_code*.py" #### transferred = self.initial_state.select(lambda x : x in keys_passing , ["key"]) for b in transferred: s_b = self.shift_to_star(b, two_stars, star_choice = 0) a, ecc, T = ps.orbital_parameters(s_b.position, s_b.velocity, self.info.m0) transferred_sma.append(a) ejected_sma = quantities.AdaptingVectorQuantity() keys_unbound = self.unbound[last_index].key ejected = self.initial_state.select(lambda x : x in keys_unbound , ["key"]) for b in ejected: s_b = self.shift_to_star(b, two_stars, star_choice = 0) a, ecc, T = ps.orbital_parameters(s_b.position, s_b.velocity, self.info.m0) ejected_sma.append(a) ###### RE-FORMAT THIS ###### global_max = max( len(transferred_sma), len(ejected_sma) ) if len(transferred_sma) > 0: #(a1) name = "/plot_transferred_semimajor_axes_histogram_bin5AU.png" ps.make_sm_axis_histogram(transferred_sma, name, PlotFactory.c_PASSING, step_size = 5, max_count = global_max, min_a = int((self.info).r_in.value_in(units.AU)), max_a = int((self.info).r_out.value_in(units.AU))) #(a2) name = "/plot_transferred_semimajor_axes_histogram_bin1AU.png" ps.make_sm_axis_histogram(transferred_sma, name, PlotFactory.c_PASSING, max_count = global_max, min_a = int((self.info).r_in.value_in(units.AU)), max_a = int((self.info).r_out.value_in(units.AU))) #(a3) name = "/plot_transferred_semimajor_axes_histogram_cum_bin5AU.png" ps.make_sm_axis_histogram(transferred_sma, name, PlotFactory.c_PASSING, step_size = 1, cum = True, max_count = global_max, min_a = int((self.info).r_in.value_in(units.AU)), max_a = int((self.info).r_out.value_in(units.AU))) #(a4) name = "/plot_transferred_semimajor_axes_histogram_cum_bin1AU.png" ps.make_sm_axis_histogram(transferred_sma, name, PlotFactory.c_PASSING, cum = True, max_count = global_max, min_a = int((self.info).r_in.value_in(units.AU)), max_a = int((self.info).r_out.value_in(units.AU))) if len(ejected_sma) > 0: #(b1) name = "/plot_ejected_semimajor_axes_histogram_bin5AU.png" ps.make_sm_axis_histogram(ejected_sma, name, PlotFactory.c_UNBOUND, step_size = 5, max_count = global_max, min_a = int((self.info).r_in.value_in(units.AU)), max_a = int((self.info).r_out.value_in(units.AU))) #(b2) name = "/plot_ejected_semimajor_axes_histogram_bin1AU.png" ps.make_sm_axis_histogram(ejected_sma, name, PlotFactory.c_UNBOUND, max_count = global_max, min_a = int((self.info).r_in.value_in(units.AU)), max_a = int((self.info).r_out.value_in(units.AU))) #(b3) name = "/plot_ejected_semimajor_axes_histogram_cum_bin5AU.png" ps.make_sm_axis_histogram(ejected_sma, name, PlotFactory.c_UNBOUND, step_size = 5, cum = True, max_count = global_max, min_a = int((self.info).r_in.value_in(units.AU)), max_a = int((self.info).r_out.value_in(units.AU))) #(b4) name = "/plot_ejected_semimajor_axes_histogram_cum_bin1AU.png" ps.make_sm_axis_histogram(ejected_sma, name, PlotFactory.c_UNBOUND, cum = True, max_count = global_max, min_a = int((self.info).r_in.value_in(units.AU)), max_a = int((self.info).r_out.value_in(units.AU)))
def make_movies_semi_major_axes(self, movie = 1, plot_kept = False, consec = False): """ Plot the evolution of the semi-major axes over time """ ############## NEEDS A LOT OF CLEAN UP, DOESN'T EVEN WORK #################### old_sm_axes = quantities.AdaptingVectorQuantity() init_two_stars = self.initial_state[0:2] planetesimals = self.initial_state[2:] ### Passing Star (Transferred) ### for i, (bodies, passing) in enumerate(zip(self.bodies.history, self.passing)): if (self.mask[i]): old_sm_axes = quantities.AdaptingVectorQuantity() new_sm_axes_p = quantities.AdaptingVectorQuantity() eccentricities = [] time = self.times[i] two_stars = bodies[0:2] # New Values s_planetesimals = self.shift_to_star(passing, two_stars, star_choice = 1) s_pls = s_planetesimals # make new name later for b in s_pls: a, ecc, T = ps.orbital_parameters(b.position, b.velocity, self.info.m1) new_sm_axes_p.append(a) # This is wrong (a is an array) <--- How to handle array? eccentricities.append(ecc) #new_sm_axes_p = a print "New" print new_sm_axes_p print # Note, using the mask isn't as helpful as it could be # The sm-axes are still re-calculated. This is bad. They should be stored in a file # Old Values selected = planetesimals.select(lambda x : x in passing.key, ["key"]) old_planetesimals = self.shift_to_star(selected, init_two_stars, star_choice = 0) old_p = old_planetesimals for b in old_p: a, ecc, T = ps.orbital_parameters(b.position, b.velocity, self.info.m0) old_sm_axes.append(a) print "Old" print old_sm_axes print if len(new_sm_axes_p) > 0: print "Iteration ", i ps.make_sma_evolution_scatter_plot(old_sm_axes, new_sm_axes_p, colorcode = eccentricities, \ movie = 1, color = PlotFactory.c_PASSING, i = i, time = time, min_a = (self.info).r_in.value_in(units.AU), max_a = (self.info).r_out.value_in(units.AU)) # (1) A ps.make_sma_evolution_scatter_plot(old_sm_axes, new_sm_axes_p - old_sm_axes, \ movie = 1, color = PlotFactory.c_PASSING, i = i, time = time, delta = 1, min_a = (self.info).r_in.value_in(units.AU), max_a = (self.info).r_out.value_in(units.AU)) # (2) Delta A # Add (3) Ecc ps.make_sma_evolution_scatter_plot(old_sm_axes, eccentricities, \ movie = 1, color = PlotFactory.c_PASSING, i = i, time = time, eccentric = 1, min_a = (self.info).r_in.value_in(units.AU), max_a = (self.info).r_out.value_in(units.AU)) # (2) Delta A if movie == 1: # (4) SEMI-MAJOR AXES (transferred) sma_p_path = self.snapshot_dir + "/sma_transfer/sma_evolution_%3d.png" sma_p_movie = self.snapshot_dir + "/transferred_sma.mp4" self.make_movies(sma_p_path, sma_p_movie, consec = consec) # (5) DELTA SEMI-MAJOR AXES (transferred) d_sma_p_path = self.snapshot_dir + "/sma_transfer_delta/sma_evolution_%3d.png" d_sma_p_movie = self.snapshot_dir + "/transferred_delta_sma.mp4" self.make_movies(d_sma_p_path, d_sma_p_movie, consec = consec) ### Central Star (Kept) ### if (plot_kept): for i, (bodies, central) in enumerate(zip(self.bodies.history, self.central)): if (self.mask[i]): old_sm_axes = quantities.AdaptingVectorQuantity() new_sm_axes_c = quantities.AdaptingVectorQuantity() time = self.times[i] two_stars = bodies[0:2] s_pls = self.shift_to_star(central, two_stars, star_choice = 0) # Change Name of this later for b in s_pls: a, ecc, T = ps.orbital_parameters(b.position, b.velocity, self.info.m0) new_sm_axes_c.append(a) #new_sm_axes_c = a selected = planetesimals.select(lambda x : x in central.key, ["key"]) old_planetesimals = self.shift_to_star(selected, init_two_stars, star_choice = 0) old_p = old_planetesimals for b in old_p: a, ecc, T = ps.orbital_parameters(b.position, b.velocity, self.info.m0) old_sm_axes.append(a) if len(new_sm_axes_c) > 0: print "Iteration ", i ps.make_sma_evolution_scatter_plot(old_sm_axes, new_sm_axes_c, \ movie = 1, color = PlotFactory.c_CENTRAL, i = i, time = time) # (4) A ps.make_sma_evolution_scatter_plot(old_sm_axes, new_sm_axes_c - old_sm_axes, \ movie = 1, color = PlotFactory.c_CENTRAL, i = i, time = time, delta = 1) # (5) Delta A # Add (6) Ecc ps.make_sma_evolution_scatter_plot(old_sm_axes, eccentricities, \ movie = 1, color = PlotFactory.c_CENTRAL, i = i, time = time, eccentric = 1) if movie == 1: # (6) SEMI-MAJOR AXES (kept) sma_c_path = self.snapshot_dir + "/sma_kept/sma_evolution_%3d.png" sma_c_movie = self.snapshot_dir + "/kept_sma.mp4" self.make_movies(sma_c_path, sma_c_movie, consec = consec) # (7) DELTA SEMI-MAJOR AXES (kept) d_sma_c_path = self.snapshot_dir + "/sma_kept_delta/sma_evolution_%3d.png" d_sma_c_movie = self.snapshot_dir + "/kept_delta_sma.mp4" self.make_movies(d_sma_c_path, d_sma_c_movie, consec = consec)