def _ssacc(self, td, y, kernel):
     # comupte acceleration of Solar Sail
     pos = y[0:3]
     vel = y[3:6]
     sunpos, sunvel = kernel[0, 10].compute_and_differentiate(td)
     sunpos = common.eqn2ecl(sunpos) * 1000.0
     sunvel = common.eqn2ecl(sunvel) * 1000.0 / common.secofday
     scpos = pos - sunpos
     r2 = np.dot(scpos, scpos)
     p0 = common.solark1 / 4.0 / np.pi / r2 / common.c
     nv = np.array([
         np.cos(self._sstheta) * np.cos(self._sselv),
         np.sin(self._sstheta) * np.cos(self._sselv),
         np.sin(self._sselv)
     ])
     xax = np.array([
         1.0,
         0.,
         0.,
     ])
     costheta = np.dot(xax, nv)
     cos2theta = costheta**2
     f = 2.0 * cos2theta * p0 * self._ssarea
     acc = nv * (f / self._pmass)
     if costheta < 0.0:
         acc = acc * (-1.0)
     return common.sodv2ecldv(acc, pos, vel, sunpos, sunvel)
 def planets_ephem(self, jd):
     pos, vel = self.kernel[self.idx1a,
                            self.idx1b].compute_and_differentiate(jd)
     if self.idx2a != 0:
         pos2, vel2 = self.kernel[self.idx2a,
                                  self.idx2b].compute_and_differentiate(jd)
         pos = pos + pos2
         vel = vel + vel2
     pos = common.eqn2ecl(pos) * 1000.0
     vel = common.eqn2ecl(vel) / common.secofday * 1000.0
     return pos, vel
 def _epacc(self, td, y, kernel):
     # comupte acceleration of Electric Propulsion System
     acc = np.array([
         self._epdv * np.cos(self._epelv) * np.cos(self._epphi),
         self._epdv * np.cos(self._epelv) * np.sin(self._epphi),
         self._epdv * np.sin(self._epelv)
     ])
     pos = y[0:3]
     vel = y[3:6]
     sunpos, sunvel = kernel[0, 10].compute_and_differentiate(td)
     sunpos = common.eqn2ecl(sunpos) * 1000.0
     sunvel = common.eqn2ecl(sunvel) * 1000.0 / common.secofday
     return common.ldv2ecldv(acc, pos, vel, sunpos, sunvel)
 def _ssnv(self, td, y, kernel):
     # compute normal vector of Solar Sail
     pos = y[0:3]
     vel = y[3:6]
     sunpos, sunvel = kernel[0, 10].compute_and_differentiate(td)
     sunpos = common.eqn2ecl(sunpos) * 1000.0
     sunvel = common.eqn2ecl(sunvel) * 1000.0 / common.secofday
     nv = np.array([
         np.cos(self._sstheta) * np.cos(self._sselv),
         np.sin(self._sstheta) * np.cos(self._sselv),
         np.sin(self._sselv)
     ])
     return common.sodv2ecldv(nv, pos, vel, sunpos, sunvel)
 def _sseclacc(self, td, y, kernel):
     # compute acceleration of Solar Sail when tvmode='E'
     pos = y[0:3]
     sunpos = kernel[0, 10].compute(td)
     sunpos = common.eqn2ecl(sunpos) * 1000.0
     scpos = pos - sunpos
     r2 = np.dot(scpos, scpos)
     p0 = common.solark1 / 4.0 / np.pi / r2 / common.c
     xax = scpos / np.sqrt(r2)
     costheta = np.dot(xax, self._sseclnv)
     cos2theta = costheta**2
     f = 2.0 * cos2theta * p0 * self._ssarea
     acc = self._sseclnv * (f / self._pmass)
     if costheta < 0.0:
         acc = acc * (-1.0)
     return acc
    def _func(self, t, y, kernel, body_f, body_mu):
        # t: JD by seconds
        # y: position and velocity, origin=solar system barycenter, ecliptic.
        # kernel: kernel of SPK
        # body_f: source of grav. [0]Mercury~[8]Pluto,[9]Sun  True or False
        # body_mu: mu of the body
        yd = np.zeros(6)
        yd[0] = y[3]
        yd[1] = y[4]
        yd[2] = y[5]

        td = t / common.secofday
        #        print(td)
        for i in range(12):
            if body_f[i]:
                n = common.planets_id[i][0]
                if n > 300:
                    pos = (kernel[0,3].compute(td) + kernel[3,n].compute(td)) \
                        * 1000.0
                else:
                    pos = kernel[0, n].compute(td) * 1000.0
                delta = common.eqn2ecl(pos) - y[0:3]
                r = np.sqrt(np.dot(delta, delta))
                yd[3:6] += delta * (body_mu[i] / r**3)
#                print(delta * (body_mu[i] / r ** 3))
        if self._epon:
            if self._epmode == 'L':
                yd[3:6] += self._epacc(td, y, kernel)
            else:
                yd[3:6] += self._epeclacc
        if self._sson:
            if self._ssmode == 'L':
                yd[3:6] += self._ssacc(td, y, kernel)
            else:
                yd[3:6] += self._sseclacc(td, y, kernel)
        return yd
    def _redrawmark(self):
        tempjd = self.jd + self.delta_jd
        self.ui.preddate.setText(common.jd2isot(tempjd))

        if self.artist_of_probe is not None:
            self.artist_of_probe.remove()
            self.artist_of_probe = None

        if self.artist_of_target is not None:
            self.artist_of_target.remove()
            self.artist_of_target = None

        if self.artist_of_sun is not None:
            self.artist_of_sun.remove()
            self.artist_of_sun = None

        remove_planets()
        remove_time()

        # Check time
        tsjd, tejd = g.mytarget.getsejd()
        if tempjd < tsjd or tempjd >= tejd:
            self.dispSysMes(self.sysMes04)
            self.unableDrawMark = True
            return False

        try:
            probe_pos, probe_vel = self.tbpred.posvelatt(tempjd)
        except RuntimeError:
            self.dispSysMes(self.sysMes05)
            self.unableDrawMark = True
            return False

        if self.unableDrawMark:
            self.dispSysMes(self.sysMes06)
            self.unableDrawMark = False

        self.target_pos, target_vel = g.mytarget.posvel(tempjd)

        sunpos = common.SPKkernel[0, 10].compute(tempjd)
        self.sun_pos = common.eqn2ecl(sunpos) * 1000.0

        xlim = g.ax.get_xlim3d()
        hw = (xlim[1] - xlim[0]) * 0.5
        if self.ui.tobarycenter.isChecked():
            cent = [0.0, 0.0, 0.0]
        elif self.ui.toprobe.isChecked():
            cent = probe_pos
        else:
            cent = self.target_pos

        g.ax.set_xlim3d(cent[0] - hw, cent[0] + hw)
        g.ax.set_ylim3d(cent[1] - hw, cent[1] + hw)
        g.ax.set_zlim3d(cent[2] - hw, cent[2] + hw)

        self.artist_of_probe = g.ax.scatter(*probe_pos,
                                            s=40,
                                            c='r',
                                            depthshade=False,
                                            marker='x')

        self.artist_of_target = g.ax.scatter(*self.target_pos,
                                             s=50,
                                             c='g',
                                             depthshade=False,
                                             marker='+')

        self.artist_of_sun = g.ax.scatter(*self.sun_pos,
                                          s=50,
                                          c='#FFAF00',
                                          depthshade=False,
                                          marker='o')

        # redraw planets
        if self.ui.showplanets.isChecked():
            replot_planets(tempjd)

        if self.delta_jd == 0.0:
            replot_time(tempjd, self.timecap_Real)
        else:
            replot_time(tempjd, self.timecap_Pred)

        if g.fig is not None: plt.draw()

        # display relative position and velocity
        rel_pos = self.target_pos - probe_pos
        rel_pos = common.eclv2lv(rel_pos, probe_pos, probe_vel,
                                 self.tbpred.sunpos, self.tbpred.sunvel)
        trange, tphi, telv = common.rect2polar(rel_pos)
        rel_vel = target_vel - probe_vel
        rel_vel = common.eclv2lv(rel_vel, probe_pos, probe_vel,
                                 self.tbpred.sunpos, self.tbpred.sunvel)
        relabsvel, tvphi, tvelv = common.rect2polar(rel_vel)
        losvel = np.dot(rel_vel, rel_pos) / trange
        self.ui.RPTrange.setText('{:.3f}'.format(trange / 1000.0))
        self.ui.RPTphi.setText('{:.2f}'.format(tphi))
        self.ui.RPTelv.setText('{:.2f}'.format(telv))
        self.ui.RVTvel.setText('{:.3f}'.format(relabsvel))
        self.ui.RVTphi.setText('{:.2f}'.format(tvphi))
        self.ui.RVTelv.setText('{:.2f}'.format(tvelv))
        self.ui.LoSVvel.setText('{:.3f}'.format(losvel))

        return True
 def nasa_sb_type21(self, jd):
     pos, vel = self.sbkernel.compute_type21(self.idx1a, self.idx1b, jd)
     pos = common.eqn2ecl(pos) * 1000.0
     vel = common.eqn2ecl(vel) * 1000.0
     return pos, vel