def __init__(self, df: pd.DataFrame):
        self.figure = ipv.figure(animation=0.,
                                 animation_exponent=0,
                                 width=800,
                                 height=800)
        #self.figure.camera_control = 'orbit'

        self.lpp = lpp = 1

        x_min = np.min([-lpp, df['x0'].min()])
        x_max = np.max([lpp, df['x0'].max()])
        y_min = np.min([-lpp, df['y0'].min()])
        y_max = np.max([lpp, df['y0'].max()])
        z_min = np.min([-lpp, df['z0'].min()])
        z_max = np.max([lpp, df['z0'].max()])

        ipv.xlim(x_min, x_max)
        ipv.ylim(y_min, y_max)
        ipv.zlim(z_min, x_max)
        ipv.style.box_off()

        self.track = ipv.pylab.plot(df['x0'].values, df['y0'].values,
                                    df['z0'].values)

        self.load_ship_geometry()
        self.port = ipv.plot_mesh(self.X, self.Y_port, self.Z, wireframe=False)
        self.stbd = ipv.plot_mesh(self.X,
                                  self.Y_starboard,
                                  self.Z,
                                  wireframe=False)

        ipv.pylab.view(azimuth=180, elevation=60, distance=1)
        ipv.show()

        self.df = df

        min = df.index[0]
        max = df.index[-1]
        step = (max - min) / 100
        self.ui = widgets.interact(self.update,
                                   t=widgets.FloatSlider(value=0,
                                                         min=min,
                                                         max=max,
                                                         step=step))
Example #2
0
def plot_milkyway(R_sun=8, size=100):
    mw_image = PIL.Image.open(milkyway_image.fetch())
    rescale = 40
    t = np.linspace(0, 1, 100)
    xmw = np.linspace(0, 1, 10)
    ymw = np.linspace(0, 1, 10)
    xmw, ymw = np.meshgrid(xmw, ymw)
    zmw = xmw * 0 + 0.01
    mw = mesh = ipv.plot_mesh((xmw-0.5)*rescale, (ymw-0.5)*rescale+R_sun, zmw, u=xmw, v=ymw, texture=mw_image, wireframe=False)
    mw.material.blending = pythreejs.BlendingMode.CustomBlending
    mw.material.blendSrc = pythreejs.BlendFactors.SrcColorFactor
    mw.material.blendDst = pythreejs.BlendFactors.OneFactor
    mw.material.blendEquation = 'AddEquation'
    mw.material.transparent = True
    mw.material.depthWrite = False
    mw.material.alphaTest = 0.1
    ipv.xyzlim(size)
    return mesh
Example #3
0
    def plot(self, **kwargs):
        """
        
        plot the sphere
        

        :returns: 
        :rtype: 

        """

        # u = np.linspace(0, 2 * np.pi, self._detail_level)
        # v = np.linspace(0, np.pi, self._detail_level)

        # x_unit = np.outer(np.cos(u), np.sin(v))
        # y_unit = np.outer(np.sin(u), np.sin(v))
        # z_unit = np.outer(np.ones(np.size(u)), np.cos(v))

        u = np.linspace(0, 1, self._detail_level)
        v = np.linspace(0, 1, self._detail_level)
        u, v = np.meshgrid(u, v)
        phi = u * 2 * np.pi
        theta = v * np.pi

        x_unit = np.cos(phi) * np.sin(theta)
        y_unit = np.sin(theta) * np.sin(phi)
        z_unit = np.cos(theta)

        if self._transform_matrix is not None:

            xyz = np.array([x_unit, y_unit, z_unit]).T

            if self._time_dep_transform:

                # new_xyz = compute_multiple_rotation(xyz, self._transform_matrix, self._detail_level, self._n_steps)

                x_unit_rot = np.zeros(
                    (self._n_steps, self._detail_level, self._detail_level))
                y_unit_rot = np.zeros(
                    (self._n_steps, self._detail_level, self._detail_level))
                z_unit_rot = np.zeros(
                    (self._n_steps, self._detail_level, self._detail_level))

                for i in range(self._n_steps):

                    this_xyz = compute_single_rotation(
                        xyz, self._transform_matrix[i], self._detail_level)

                    x_unit_rot[i] = this_xyz[0]
                    y_unit_rot[i] = this_xyz[1]
                    z_unit_rot[i] = this_xyz[2]

            else:

                xyz = compute_single_rotation(xyz, self._transform_matrix,
                                              self._detail_level)

                x_unit_rot = xyz[0]
                y_unit_rot = xyz[1]
                z_unit_rot = xyz[2]

        if np.atleast_1d(self._x).shape[0] == 1:

            if self._time_dep_transform:
                # if False:
                X = np.array([
                    self._x + self._radius * x_unit
                    for _ in range(self._n_steps)
                ])

                Y = np.array([
                    self._y + self._radius * y_unit
                    for _ in range(self._n_steps)
                ])

                Z = np.array([
                    self._z + self._radius * z_unit
                    for _ in range(self._n_steps)
                ])

            else:

                X = self._x + self._radius * x_unit

                Y = self._y + self._radius * y_unit

                Z = self._z + self._radius * z_unit

        else:

            X = np.array([x + self._radius * x_unit for x in self._x])

            Y = np.array([y + self._radius * y_unit for y in self._y])

            Z = np.array([z + self._radius * z_unit for z in self._z])

        if self._image is None:

            return ipv.plot_surface(X, Y, Z, color=self._color, **kwargs)

        else:

            if self._transform_matrix is None:

                lon = np.arctan2(y_unit, x_unit)
                lat = np.arcsin(z_unit)

            else:

                lon = np.arctan2(y_unit_rot, x_unit_rot)
                lat = np.arcsin(z_unit_rot)

            u = 0.5 + lon / (2 * np.pi)
            v = 0.5 + lat / (np.pi)

            return ipv.plot_mesh(X,
                                 Y,
                                 Z,
                                 u=u,
                                 v=v,
                                 texture=self._image,
                                 wireframe=False)