Exemplo n.º 1
0
    def do_3d_projection(self, renderer):
        xs, ys, zs = self._offsets3d
        vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs, renderer.M)

        fcs = (_zalpha(self._facecolor3d, vzs) if self._depthshade else
               self._facecolor3d)
        fcs = mcolors.to_rgba_array(fcs, self._alpha)
        self.set_facecolors(fcs)

        ecs = (_zalpha(self._edgecolor3d, vzs) if self._depthshade else
               self._edgecolor3d)

        # Sort the points based on z coordinates
        # Performance optimization: Create a sorted index array and reorder
        # points and point properties according to the index array
        z_markers_idx = np.argsort(vzs)[::-1]

        # Re-order items
        vzs = vzs[z_markers_idx]
        vxs = vxs[z_markers_idx]
        vys = vys[z_markers_idx]
        fcs = fcs[z_markers_idx]
        ecs = ecs[z_markers_idx]
        vps = np.column_stack((vxs, vys))

        fcs = mcolors.to_rgba_array(fcs, self._alpha)
        ecs = mcolors.to_rgba_array(ecs, self._alpha)

        self.set_edgecolors(ecs)
        self.set_facecolors(fcs)

        PathCollection.set_offsets(self, vps)

        return np.min(vzs) if vzs.size else np.nan
Exemplo n.º 2
0
    def do_3d_projection(self, renderer=None):
        xs, ys, zs = self._offsets3d
        vxs, vys, vzs, vis = proj3d.proj_transform_clip(
            xs, ys, zs, self.axes.M)
        # Sort the points based on z coordinates
        # Performance optimization: Create a sorted index array and reorder
        # points and point properties according to the index array
        z_markers_idx = self._z_markers_idx = np.argsort(vzs)[::-1]
        self._vzs = vzs

        # we have to special case the sizes because of code in collections.py
        # as the draw method does
        #      self.set_sizes(self._sizes, self.figure.dpi)
        # so we can not rely on doing the sorting on the way out via get_*

        if len(self._sizes3d) > 1:
            self._sizes = self._sizes3d[z_markers_idx]

        if len(self._linewidths3d) > 1:
            self._linewidths = self._linewidths3d[z_markers_idx]

        # Re-order items
        vzs = vzs[z_markers_idx]
        vxs = vxs[z_markers_idx]
        vys = vys[z_markers_idx]

        PathCollection.set_offsets(self, np.column_stack((vxs, vys)))

        return np.min(vzs) if vzs.size else np.nan
Exemplo n.º 3
0
def update_plot(num: int, args: MyProgramArgs, sa: SimulationArchive,
                ed: ExtraData, dots: PathCollection, title: Text):
    global mean_mass
    total_frames = args.fps * args.duration
    if args.log_time:
        log_timestep = (log10(ed.meta.current_time) -
                        log10(50000)) / total_frames
        time = 10**((num + log10(50000) / log_timestep) * log_timestep)
    else:
        timestep = ed.meta.current_time / total_frames
        print(num / total_frames)
        time = num * timestep
    print(f"{num / total_frames:.2f}, {time:.0f}")
    sim = sa.getSimulation(t=time)
    if time < 1e3:
        timestr = f"{time:.0f}"
    elif time < 1e6:
        timestr = f"{time / 1e3:.2f}K"
    else:
        timestr = f"{time / 1e6:.2f}M"
    title.set_text(f"({len(sim.particles)}) {timestr} Years")

    p: Particle

    water_fractions = []
    for p in sim.particles[1:]:
        pd: ParticleData = ed.pd(p)
        wf = pd.water_mass_fraction
        water_fractions.append(wf)
    # a, e, i, M, M_rat = data[line]
    # title.set_text(f"({len(a)}) {ages[line]:.2f}K Years")
    a = [p.a for p in sim.particles[1:]]
    m = np.array([p.m for p in sim.particles[1:]])
    m[:2] /= 1e2

    if args.y_axis == "e":
        bla = np.array([a, [p.e for p in sim.particles[1:]]])
    elif args.y_axis == "i":
        bla = np.array([a, [degrees(p.inc) for p in sim.particles[1:]]])
    elif args.y_axis == "Omega":
        bla = np.array([a, [degrees(p.Omega) for p in sim.particles[1:]]])
    else:
        raise ValueError("invalid y-axis")
    dots.set_offsets(bla.T)
    with np.errstate(divide='ignore'):  # allow 0 water (becomes -inf)
        color_val = (np.log10(water_fractions) + 5) / 5
    colors = cmap(color_val)
    if not mean_mass:
        mean_mass = np.mean(m[3:])
    dots.set_sizes(size_factor * m / mean_mass)
    dots.set_color(colors)
    if output_plots:
        plt.savefig(f"tmp/{num}_{time / mega}.pdf", transparent=True)
    return dots, title
Exemplo n.º 4
0
    def do_3d_projection(self, renderer):
        xs, ys, zs = self._offsets3d
        vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs, renderer.M)

        fcs = (_zalpha(self._facecolor3d, vzs)
               if self._depthshade else self._facecolor3d)
        fcs = mcolors.to_rgba_array(fcs, self._alpha)
        self.set_facecolors(fcs)

        ecs = (_zalpha(self._edgecolor3d, vzs)
               if self._depthshade else self._edgecolor3d)
        ecs = mcolors.to_rgba_array(ecs, self._alpha)
        self.set_edgecolors(ecs)
        PathCollection.set_offsets(self, np.column_stack([vxs, vys]))

        return np.min(vzs) if vzs.size else np.nan
Exemplo n.º 5
0
    def do_3d_projection(self, renderer):
        xs, ys, zs = self._offsets3d
        vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs, renderer.M)

        fcs = (zalpha(self._facecolor3d, vzs) if self._depthshade else
               self._facecolor3d)
        fcs = mcolors.to_rgba_array(fcs, self._alpha)
        self.set_facecolors(fcs)

        ecs = (zalpha(self._edgecolor3d, vzs) if self._depthshade else
               self._edgecolor3d)
        ecs = mcolors.to_rgba_array(ecs, self._alpha)
        self.set_edgecolors(ecs)
        PathCollection.set_offsets(self, np.column_stack([vxs, vys]))

        return np.min(vzs) if vzs.size else np.nan
Exemplo n.º 6
0
    def do_3d_projection(self, renderer):
        xs, ys, zs = self._offsets3d
        vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs, renderer.M)

        fcs = zalpha(self._facecolor3d, vzs) if self._depthshade else self._facecolor3d
        fcs = mcolors.colorConverter.to_rgba_array(fcs, self._alpha)
        self.set_facecolors(fcs)

        ecs = zalpha(self._edgecolor3d, vzs) if self._depthshade else self._edgecolor3d
        ecs = mcolors.colorConverter.to_rgba_array(ecs, self._alpha)
        self.set_edgecolors(ecs)
        PathCollection.set_offsets(self, list(zip(vxs, vys)))

        if vzs.size > 0:
            return min(vzs)
        else:
            return np.nan
Exemplo n.º 7
0
    def do_3d_projection(self, renderer=None):
        # see _update_scalarmappable docstring for why this must be here
        _update_scalarmappable(self)
        xs, ys, zs = self._offsets3d
        vxs, vys, vzs, vis = proj3d.proj_transform_clip(
            xs, ys, zs, self.axes.M)

        fcs = (_zalpha(self._facecolor3d, vzs)
               if self._depthshade else self._facecolor3d)
        ecs = (_zalpha(self._edgecolor3d, vzs)
               if self._depthshade else self._edgecolor3d)
        sizes = self._sizes3d
        lws = self._linewidth3d

        # Sort the points based on z coordinates
        # Performance optimization: Create a sorted index array and reorder
        # points and point properties according to the index array
        z_markers_idx = np.argsort(vzs)[::-1]

        # Re-order items
        vzs = vzs[z_markers_idx]
        vxs = vxs[z_markers_idx]
        vys = vys[z_markers_idx]
        if len(fcs) > 1:
            fcs = fcs[z_markers_idx]
        if len(ecs) > 1:
            ecs = ecs[z_markers_idx]
        if len(sizes) > 1:
            sizes = sizes[z_markers_idx]
        if len(lws) > 1:
            lws = lws[z_markers_idx]
        vps = np.column_stack((vxs, vys))

        fcs = mcolors.to_rgba_array(fcs, self._alpha)
        ecs = mcolors.to_rgba_array(ecs, self._alpha)

        super().set_edgecolor(ecs)
        super().set_facecolor(fcs)
        super().set_sizes(sizes)
        super().set_linewidth(lws)

        PathCollection.set_offsets(self, vps)

        return np.min(vzs) if vzs.size else np.nan
Exemplo n.º 8
0
    def do_3d_projection(self, renderer):
        xs, ys, zs = self._offsets3d
        vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs, renderer.M)

        fcs = (zalpha(self._facecolor3d, vzs) if self._depthshade else
               self._facecolor3d)
        fcs = mcolors.colorConverter.to_rgba_array(fcs, self._alpha)
        self.set_facecolors(fcs)

        ecs = (zalpha(self._edgecolor3d, vzs) if self._depthshade else
               self._edgecolor3d)
        ecs = mcolors.colorConverter.to_rgba_array(ecs, self._alpha)
        self.set_edgecolors(ecs)
        PathCollection.set_offsets(self, list(zip(vxs, vys)))

        if vzs.size > 0 :
            return min(vzs)
        else :
            return np.nan
Exemplo n.º 9
0
 def update_scatter(scatter: PathCollection, ptrs: List[np.ndarray]):
     scatter.set_offsets(ptrs)