print("ZEROS: %d" % ((new_looper.tr.track_dict['density'] == 0).sum())) if 'new_looper' not in dir() and disk_or_new == 'disk': print("reload") file_list = ['TEMP.h5'] new_looper = looper.core_looper(directory=dl.sims[this_simname]) new_looper.plot_directory = "/home/dccollins/PigPen" for nfile, fname in enumerate(file_list): new_looper.load_loop(fname) print("File %d of %d" % (nfile, len(file_list))) new_looper.tr.sort_time() #import loop_tools #loop_tools.re_shift_snaps(new_looper) if 0: import colors reload(colors) core_cmap = colors.make_core_cmap(new_looper.core_list) reload(loop_apps) loop_apps.core_proj_multiple( new_looper, #core_list=[258], #frame_list=[0], axis_list=[1], color_dict=core_cmap, particles=True, only_sphere=False, zoom=False, center_on_sphere=False, annotate=True, tracker_positions=True, shifted_tracker=False)
core_list=None, fields_from_grid=fields, derived=derived, do_shift=False, plot_directory="./plots_to_sort") Lfull.read_targets(mountain_top_fname) Lfull.get_tracks() # # Project tracks # if 1: import colors reload(colors) core_cmap = colors.make_core_cmap(Lfull.core_list) loop_apps.core_proj_multiple( Lfull, #core_list=[258], #frame_list=[0], axis_list=[1], color_dict=core_cmap, particles=True, only_sphere=True, zoom=True, center_on_sphere=True, annotate=False, tracker_positions=True, shifted_tracker=True) if 0: #read_write tests
fields_from_grid=fields, derived=derived, do_shift=False, plot_directory="./plots_to_sort") print("READ TARGETS", mountain_top_name) L258.read_targets(mountain_top_name) L258.get_tracks() # # Project tracks # if 1: import colors reload(colors) core_cmap = colors.make_core_cmap(L258.core_list) loop_apps.core_proj_multiple( L258, #core_list=[258], #frame_list=[0], axis_list=[0], color_dict=core_cmap, particles=True, only_sphere=True, zoom=True, center_on_sphere=True, annotate=False, tracker_positions=True, shifted_tracker=True) if 0: #read_write tests
st[this_simname].find() do_supersets = True else: do_supersets = False import colors import core_proj reload(core_proj) if do_supersets: stuff = st[this_simname].supersets for nset, superset in enumerate(stuff): if nset != 1: continue core_list = list(superset) color_dict = colors.make_core_cmap(core_list, cmap='tab20c', seed=-1) frame_list = set_looper.tr.frames[::10] set_looper.out_prefix = '%s_full_S%02d' % (this_simname, nset) else: core_list = np.unique(set_looper.core_ids)[:2] frame_list = set_looper.tr.frames[::10] #frame_list=set_looper.tr.frames #[::10] if 1: import movie_frames reload(movie_frames) movie_mask = movie_frames.quantized_mask(set_looper) frame_list = set_looper.tr.frames[movie_mask] frame_list = frame_list[frame_list > 71] core_list = [323] frame_list = frame_list[-1:] color_dict = colors.make_core_cmap(core_list, cmap='tab20c', seed=-1)
# # get mountain tops # import three_loopers_mountain_top as TLM # # Project tracks # if 1: if 'this_simname' not in dir(): this_simname = 'u301' this_looper = TLM.loops[this_simname] if 1: import colors reload(colors) core_cmap = colors.make_core_cmap(this_looper.core_list) projections.proj_cores_annotate_zoom( this_looper, #core_list=[10], #frame_list=[0], axis_list=[0], annotate_particles=False, field='density', color='r', zoom_level=4, plot_dir="./plots_to_sort", )
def plot_watershed(htool, core_list=None, accumulate=False, frames=[0], all_plots=False, label_cores=[], prefix="", color_dict=None, axis_to_plot=[0]): thtr = htool.this_looper.tr all_cores = np.unique(thtr.core_ids) rm = rainbow_map(len(all_cores)) if frames is None: frames = thtr.frames if core_list is None: core_list = all_cores if -1 in axis_to_plot: fig_many, ax = plt.subplots(2, 2, figsize=(8, 8)) ax = ax.flatten() else: fig_many, ax = plt.subplots(1, 1, figsize=(8, 8)) x_min, x_max, y_min, y_max = [1, 0, 1, 0] import colors if color_dict is None: color_dict = colors.make_core_cmap(core_list) ms_dict = {} for ncore, core_id in enumerate(core_list): ms = trackage.mini_scrubber(thtr, core_id) ms.particle_pos(core_id) ms_dict[core_id] = ms vx1 = thtr.c(core_list[:1], 'velocity_x')[:, 0] vy1 = thtr.c(core_list[:1], 'velocity_y')[:, 0] vz1 = thtr.c(core_list[:1], 'velocity_z')[:, 0] vx2 = thtr.c(core_list[1:], 'velocity_x')[:, 0] vy2 = thtr.c(core_list[1:], 'velocity_y')[:, 0] vz2 = thtr.c(core_list[1:], 'velocity_z')[:, 0] gx1 = thtr.c(core_list[:1], 'grav_x')[:, 0] gy1 = thtr.c(core_list[:1], 'grav_y')[:, 0] gz1 = thtr.c(core_list[:1], 'grav_z')[:, 0] gx2 = thtr.c(core_list[1:], 'grav_x')[:, 0] gy2 = thtr.c(core_list[1:], 'grav_y')[:, 0] gz2 = thtr.c(core_list[1:], 'grav_z')[:, 0] dvx1 = thtr.c(core_list[:1], 'velocity_x')[:, 2] - thtr.c( core_list[:1], 'velocity_x')[:, 0] dvy1 = thtr.c(core_list[:1], 'velocity_y')[:, 2] - thtr.c( core_list[:1], 'velocity_y')[:, 0] dvz1 = thtr.c(core_list[:1], 'velocity_z')[:, 2] - thtr.c( core_list[:1], 'velocity_z')[:, 0] dvx2 = thtr.c(core_list[1:], 'velocity_x')[:, 2] - thtr.c( core_list[1:], 'velocity_x')[:, 0] dvy2 = thtr.c(core_list[1:], 'velocity_y')[:, 2] - thtr.c( core_list[1:], 'velocity_y')[:, 0] dvz2 = thtr.c(core_list[1:], 'velocity_z')[:, 2] - thtr.c( core_list[1:], 'velocity_z')[:, 0] if 0: VM1 = np.sqrt(vx1**2 + vy1**2 + vz1**2) VM2 = np.sqrt(vx2**2 + vy2**2 + vz2**2) vx1bar = np.mean(vx1) vy1bar = np.mean(vy1) vz1bar = np.mean(vz1) vmbar = np.sqrt(vx1bar**2 + vy1bar**2 + vz1bar**2) cosine1 = (vx1 * vx1bar + vy1 * vy1bar + vz1 * vz1bar) / (VM1 * vmbar) cosine2 = (vx2 * vx1bar + vy2 * vy1bar + vz2 * vz1bar) / (VM2 * vmbar) if 0: DVM1 = np.sqrt(dvx1**2 + dvy1**2 + dvz1**2) DVM2 = np.sqrt(dvx2**2 + dvy2**2 + dvz2**2) dvx1bar = np.mean(dvx1) dvy1bar = np.mean(dvy1) dvz1bar = np.mean(dvz1) dvmbar = np.sqrt(dvx1bar**2 + dvy1bar**2 + dvz1bar**2) cosine1 = (dvx1 * dvx1bar + dvy1 * dvy1bar + dvz1 * dvz1bar) / (DVM1 * dvmbar) cosine2 = (dvx2 * dvx1bar + dvy2 * dvy1bar + dvz2 * dvz1bar) / (DVM2 * dvmbar) if 1: GM1 = np.sqrt(gx1**2 + gy1**2 + gz1**2) GM2 = np.sqrt(gx2**2 + gy2**2 + gz2**2) gx1bar = np.mean(gx1) gy1bar = np.mean(gy1) gz1bar = np.mean(gz1) g1bar = np.sqrt(gx1bar**2 + gy1bar**2 + gz1bar**2) gx2bar = np.mean(gx2) gy2bar = np.mean(gy2) gz2bar = np.mean(gz2) g2bar = np.sqrt(gx2bar**2 + gy2bar**2 + gz2bar**2) cosine1 = (gx1 * gx1bar + gy1 * gy1bar + gz1 * gz1bar) / (GM1 * g1bar) cosine2 = (gx2 * gx2bar + gy2 * gy2bar + gz2 * gz2bar) / (GM2 * g2bar) colors = [cosine1, cosine2] rtmap = rainbow_trout(vmin=-1, vmax=1) for it, frame in enumerate(frames): #asort): nt = np.where(nar(thtr.frames) == frame)[0][0] if -1 in axis_to_plot: for aaa in ax: aaa.clear() else: ax.clear() ax[-1].hist(cosine1, label='c%04d' % core_list[0], histtype='step') ax[-1].hist(cosine2, label='c%04d' % core_list[1], histtype='step') ax[-1].legend(loc=0) ax[-1].set_yscale('log') for ncore, core_id in enumerate(core_list): ms = ms_dict[core_id] if ms.r.shape[0] <= 4: continue print('plot core %s %d' % (htool.this_looper.out_prefix, core_id)) delta = 0.1 mask = slice(None) if not accumulate: if -1 in axis_to_plot: for aaa in ax: aaa.clear() aaa.set_aspect('equal') aaa.plot([0, 1, 1, 0, 0], [0, 0, 1, 1, 0]) else: ax.clear() ax.set_aspect('equal') ax.plot([0, 1, 1, 0, 0], [0, 0, 1, 1, 0]) #this_x,this_y,this_z=ms.this_x[mask,nt],ms.this_y[mask,nt], ms.this_z[mask,nt] this_x, this_y, this_z = ms.particle_x[mask, nt], ms.particle_y[ mask, nt], ms.particle_z[mask, nt] all_x, all_y, all_z = ms.particle_x, ms.particle_y, ms.particle_z all_p = [all_x, all_y, all_z] do_hull = True if np.unique(this_x).size < 4 or\ np.unique(this_y).size < 4 or\ np.unique(this_z).size < 4 : print("Not enough degrees of freedom") do_hull = False this_p = [this_x, this_y, this_z] if -1 in axis_to_plot: axis_to_actually_plot = [0, 1, 2] else: axis_to_actually_plot = axis_to_plot for LOS in axis_to_actually_plot: x = [1, 0, 0][LOS] y = [2, 2, 1][LOS] xlab = r'$%s \rm(code\ length)$' % 'xyz'[x] ylab = r'$%s \rm(code\ length)$' % 'xyz'[y] if -1 in axis_to_plot: this_ax = ax[LOS] else: this_ax = ax n_particles = len(this_p[0]) # # the plot # this_ax.scatter(this_p[x], this_p[y], s=2, c=colors[ncore]) #streaks. Use with caution. #this_ax.plot(all_p[x].transpose(), all_p[y].transpose(), c=color_dict[core_id], linewidth=.1) if do_hull: points_2d = np.array(list(zip(this_p[x], this_p[y]))) hull_2d = ConvexHull(points_2d) vert_x = points_2d[hull_2d.vertices, 0] vert_y = points_2d[hull_2d.vertices, 1] vert_x = np.concatenate([vert_x, vert_x[0:1]]) vert_y = np.concatenate([vert_y, vert_y[0:1]]) this_ax.plot(vert_x, vert_y, 'k', linewidth=0.3) if core_id in label_cores or -1 in label_cores: this_ax.text(this_p[x].max(), this_p[y].max(), r'$%s$' % core_id) x_min = min([x_min, this_p[x].min(), -delta]) x_max = max([x_max, this_p[x].max(), 1 + delta]) y_min = min([y_min, this_p[y].min(), -delta]) y_max = max([y_max, this_p[y].max(), 1 + delta]) this_ax.plot([0, 1, 1, 0, 0], [0, 0, 1, 1, 0], c=[0.5] * 3) axbonk(this_ax, xlabel=xlab, ylabel=ylab, xlim=[x_min, x_max], ylim=[y_min, y_max]) #ax_many.set_title(title) cumltext = "" if accumulate: cumltext = "%04d" % ncore if all_plots: outname = '%s/%s_hull_3d_t_%sc%04d_n%04d.png' % ( dl.output_directory, htool.this_looper.out_prefix, cumltext, core_id, frame) fig_many.savefig(outname) print("Wrote " + outname) if accumulate: outname = '%s/%s_hull_3d_t_%scXXXX_n%04d.png' % ( dl.output_directory, htool.this_looper.out_prefix, prefix, frame) fig_many.savefig(outname) print("Wrote " + outname)
import supersets reload(supersets) if 'st' not in dir(): st = {} for this_simname in sim_list: st[this_simname] = supersets.superset(TL4.loops[this_simname], ht[this_simname]) st[this_simname].find() fig, ax = plt.subplots(1, 3) reload(CHT) if 1: for ns, this_simname in enumerate(sim_list): tool = ht[this_simname] color_dict = colors.make_core_cmap(tool.cores_used) for nc, core_id in enumerate(ht[this_simname].cores_used): o = nar(tool.overlaps[core_id]) od = overlap_numb[this_simname] in_me = od[nc, :] me_in = od[:, nc] yes_have_some = (in_me == 0) * (me_in > 0) butts = np.where(yes_have_some)[0] if yes_have_some.sum() == 0: continue parts = nar(particles[this_simname])[butts] print(core_id, parts) core_ids = nar(tool.cores_used)[butts] other_core = core_ids[np.argmax(parts)]
#import three_loopers_mountain_top as TLM if 'ht' not in dir(): ht = {} for sim in sim_list: ht[sim] = CHT.hull_tool(TL6.loops[sim]) cores_to_label = {'u601': [323], 'u602': [], 'u603': []} TL6.loops['u601'].sublabel = figure_sublabel.labs(1.15, -0.2, r'$1a$') TL6.loops['u602'].sublabel = figure_sublabel.labs(1.1, -0.1, r'$1d$') TL6.loops['u603'].sublabel = figure_sublabel.labs(1.15, -0.2, r'$1g$') for ns, sim in enumerate(sim_list): #print('KLUDGE core list') full_core_list = np.unique(ht[sim].this_looper.tr.core_ids) #core_list = np.concatenate([core_list,[323]]) core_list = None color_dict = colors.make_core_cmap( full_core_list) #, cmap = 'tab20', seed = -1) CHP.plot_2d(ht[sim], frames=[0], accumulate=True, label_cores=cores_to_label[sim], external_axis=[grid[ns]], core_list=core_list, color_dict=color_dict, axis_to_plot=[0], add_jitter=False, center_image=True) if 0: import image_centroid reload(image_centroid) #This is annoyingly manual; subfigure labels