Exemplo n.º 1
0
def plot_orbits(ep, debris1, debris2):
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.set_aspect('equal')
    ax.set_xlim(-1e7, 1e7)
    ax.set_ylim(-1e7, 1e7)
    ax.set_zlim(-1e7, 1e7)
    for deb in debris1:
        try:
            kep.orbit_plots.plot_planet(deb,
                                        ax=ax,
                                        t0=kep.epoch(ep),
                                        s=0,
                                        color='r',
                                        alpha=0.2)
        except:
            pass

    for deb in debris2:
        try:
            kep.orbit_plots.plot_planet(deb,
                                        ax=ax,
                                        t0=kep.epoch(ep),
                                        s=0,
                                        color='b',
                                        alpha=0.2)
        except:
            pass

    plt.show()
Exemplo n.º 2
0
def write_output_vts(output_vts_format_file, trajectory, earth, mars):
    """ Function for generating the trajectory of the CubeSat by traj.xyzv 
	in the VTS format """
    def tab_write(value):
        output_vts_format_file.write('%s\t' % value)

    for value in trajectory:
        time = value[0]
        pos = value[1:4]
        time_integer_part = int(pk.epoch(time).mjd //
                                1)  # integer part of mjd time
        time_decimal_part = (
            pk.epoch(time).mjd % 1
        ) * pk.DAY2SEC  # converting the decimal part of mjd time to seconds
        tab_write(time_integer_part)
        tab_write(time_decimal_part)
        tab_write(
            pos[0] /
            1000.)  # the position of the CubeSat along the X axis (in km)
        tab_write(pos[1] / 1000.)
        tab_write(pos[2] / 1000.)
        tab_write(
            value[4])  # the velocity of the CubeSat along the X axis (in m/s)
        tab_write(value[5])
        tab_write(value[6])
        output_vts_format_file.write('\n')
Exemplo n.º 3
0
    def solve(self, *args, validate_barker=True, verbose=False, **kwargs):
        "Solves Lambert's problem for the requested transfer."

        # departure and arrival epochs
        dep_t = pk.epoch(self.dep_t, 'mjd')
        arr_t = pk.epoch(self.arr_t, 'mjd')

        # departure and arrival positions & velocities
        #		/-> (could obtain `dep_ast_eph` in `lambert_optimize_dt` and pass it as
        #		|   argument to avoid having it being repeatedly calculated here)
        #		r1, v1 = self.dep_ast.eph(dep_t) if dep_ast_eph is None else dep_ast_eph
        r1, v1 = self.dep_ast.eph(dep_t)
        r2, v2 = self.arr_ast.eph(arr_t)

        # Barker equation used to skip useless Lambert computations
        # https://en.wikipedia.org/wiki/Parabolic_trajectory#Barker.27s_equation
        if validate_barker and self.dT < pk.barker(r1, r2, MU_SUN) * SEC2DAY:
            if verbose:
                print(self.dT, 'Fails Barker:', self.dT,
                      pk.barker(r1, r2, MU_SUN) * SEC2DAY)
            self.fail()
            return None

        l = pk.lambert_problem(r1, r2, self.dT * DAY2SEC, MU_SUN)
        # don't compute any multi-rev solutions:
        #l = pk.lambert_problem(r1, r2, self.dT * DAY2SEC, MU_SUN, False, 0)

        return l, v1, v2
Exemplo n.º 4
0
def body_eph_gen_vts(output_vts_format_file, trajectory, body):
    """ Function for generating the ephemeris of a body by traj.xyzv
	in the VTS format """
    def tab_write(value):
        output_vts_format_file.write('%s\t' % value)

    def car2sph(car_pos):
        r = np.linalg.norm(car_pos)  # km
        lat = np.arcsin(car_pos[2] / r) * 180. / np.pi  # degree
        lon = np.arctan2(car_pos[1], car_pos[0]) * 180. / np.pi  # degree
        return np.array([lon, lat, r / 1000.])

    for value in trajectory:
        time = value[0]
        pos = value[1:4]
        sph_temp = car2sph(body.get_relative_position(time, pos))
        time_integer_part = int(pk.epoch(time).mjd //
                                1)  # integer part of mjd time
        time_decimal_part = (
            pk.epoch(time).mjd % 1
        ) * pk.DAY2SEC  # converting the decimal part of mjd time to seconds
        tab_write(time_integer_part)
        tab_write(time_decimal_part)
        tab_write(sph_temp[1])  # latitude
        tab_write(sph_temp[0])  # longitude
        tab_write(sph_temp[2])
        output_vts_format_file.write('\n')
Exemplo n.º 5
0
Arquivo: motion.py Projeto: tobspm/TSX
 def mjd_vts(self, time):
     """Method converting a MJD epoch to the vts format.
     Returns a tuple: the integer part of the MJD and the fractional
     part (converted to seconds) of the MJD. 
     """
     mjd_integer_part = int(pk.epoch(time).mjd // 1)
     mjd_decimal_part = (pk.epoch(time).mjd % 1) * pk.DAY2SEC
     return mjd_integer_part, mjd_decimal_part
Exemplo n.º 6
0
    def vts(self, dates):
        # pas compris, si un objet est de type "Date", sa méthode t.vts(...) utilise quoi et retourne quoi?
        """Method converting an epoch to the vts format.
	it returns the integer part of the MJD and
	the fractional part (converted to seconds) of the MJD. 
	"""
        self.time_integer_part = int(pk.epoch(dates).mjd // 1)
        self.time_decimal_part = (pk.epoch(dates).mjd % 1) * pk.DAY2SEC
        return self.time_integer_part, self.time_decimal_part
Exemplo n.º 7
0
    def vts(self, dates):
	# pas compris, si un objet est de type "Date", sa méthode t.vts(...) utilise quoi et retourne quoi?
	"""Method converting an epoch to the vts format.
	it returns the integer part of the MJD and
	the fractional part (converted to seconds) of the MJD. 
	"""
	self.time_integer_part = int(pk.epoch(dates).mjd // 1)
	self.time_decimal_part = (pk.epoch(dates).mjd % 1) * pk.DAY2SEC
	return self.time_integer_part, self.time_decimal_part
Exemplo n.º 8
0
    def _compute_constraints_impl(self, x):
        import PyKEP
        start = PyKEP.epoch(x[0])
        end = PyKEP.epoch(x[0] + x[1])

        # Computing starting spaceraft state
        r, v = self.__departure.eph(start)
        v_list = list(v)
        v_list[0] += x[3]
        v_list[1] += x[4]
        v_list[2] += x[5]
        x0 = PyKEP.sims_flanagan.sc_state(r, v_list, self.__sc.mass)

        # Computing ending spaceraft state
        r, v = self.__target.eph(end)
        v_list = list(v)
        v_list[0] += x[6]
        v_list[1] += x[7]
        v_list[2] += x[8]
        xe = PyKEP.sims_flanagan.sc_state(r, v_list, x[2])

        # Building the SF leg
        self.__leg.set(start, x0, x[-3 * self.__nseg:], end, xe)

        # Computing Vinf constraints (careful here, the weights do count). In case of a larger than constarint
        # a factor of 100 has been added
        if (self.__Vinf_0 >= 0):
            v_inf_con_0 = (x[3] * x[3] + x[4] * x[4] + x[5] * x[5] -
                           self.__Vinf_0 * self.__Vinf_0) / (
                               PyKEP.EARTH_VELOCITY * PyKEP.EARTH_VELOCITY)
        else:
            v_inf_con_0 = -100 * (
                x[3] * x[3] + x[4] * x[4] + x[5] * x[5] - self.__Vinf_0 *
                self.__Vinf_0) / (PyKEP.EARTH_VELOCITY * PyKEP.EARTH_VELOCITY)
        if (self.__Vinf_f >= 0):
            v_inf_con_f = (x[6] * x[6] + x[7] * x[7] + x[8] * x[8] -
                           self.__Vinf_f * self.__Vinf_f) / (
                               PyKEP.EARTH_VELOCITY * PyKEP.EARTH_VELOCITY)
        else:
            v_inf_con_f = -100 * (
                x[6] * x[6] + x[7] * x[7] + x[8] * x[8] - self.__Vinf_f *
                self.__Vinf_f) / (PyKEP.EARTH_VELOCITY * PyKEP.EARTH_VELOCITY)

        # Setting all constraints
        retval = list(self.__leg.mismatch_constraints() +
                      self.__leg.throttles_constraints()) + [v_inf_con_0
                                                             ] + [v_inf_con_f]
        retval[0] /= PyKEP.AU
        retval[1] /= PyKEP.AU
        retval[2] /= PyKEP.AU
        retval[3] /= PyKEP.EARTH_VELOCITY
        retval[4] /= PyKEP.EARTH_VELOCITY
        retval[5] /= PyKEP.EARTH_VELOCITY
        retval[6] /= self.__sc.mass
        return retval
Exemplo n.º 9
0
    def _compute_constraints_impl(self, x):
        import PyKEP
        start = PyKEP.epoch(x[0])
        end = PyKEP.epoch(x[0] + x[1])

        # Computing starting spaceraft state
        r, v = self.__departure.eph(start)
        v_list = list(v)
        v_list[0] += x[3]
        v_list[1] += x[4]
        v_list[2] += x[5]
        x0 = PyKEP.sims_flanagan.sc_state(r, v_list, self.__sc.mass)

        # Computing ending spaceraft state
        r, v = self.__target.eph(end)
        v_list = list(v)
        v_list[0] += x[6]
        v_list[1] += x[7]
        v_list[2] += x[8]
        xe = PyKEP.sims_flanagan.sc_state(r, v_list, x[2])

        # Building the SF leg
        self.__leg.set(start, x0, x[-3 * self.__nseg:], end, xe)

        # Computing Vinf constraints (careful here, the weights do count). In case of a larger than constarint
        # a factor of 100 has been added
        if (self.__Vinf_0 >= 0):
            v_inf_con_0 = (x[3] * x[3] + x[4] * x[4] + x[5] * x[5] - self.__Vinf_0 *
                           self.__Vinf_0) / (PyKEP.EARTH_VELOCITY * PyKEP.
                                             EARTH_VELOCITY)
        else:
            v_inf_con_0 = -100 * (x[3] * x[3] + x[4] * x[4] + x[5] * x[5] - self.
                                  __Vinf_0 * self.__Vinf_0) / (PyKEP.
                                                               EARTH_VELOCITY * PyKEP.EARTH_VELOCITY)
        if (self.__Vinf_f >= 0):
            v_inf_con_f = (x[6] * x[6] + x[7] * x[7] + x[8] * x[8] - self.__Vinf_f *
                           self.__Vinf_f) / (PyKEP.EARTH_VELOCITY * PyKEP.
                                             EARTH_VELOCITY)
        else:
            v_inf_con_f = -100 * (x[6] * x[6] + x[7] * x[7] + x[8] * x[8] - self.
                                  __Vinf_f * self.__Vinf_f) / (PyKEP.
                                                               EARTH_VELOCITY * PyKEP.EARTH_VELOCITY)

        # Setting all constraints
        retval = list(self.__leg.mismatch_constraints(
        ) + self.__leg.throttles_constraints()) + [v_inf_con_0] + [v_inf_con_f]
        retval[0] /= PyKEP.AU
        retval[1] /= PyKEP.AU
        retval[2] /= PyKEP.AU
        retval[3] /= PyKEP.EARTH_VELOCITY
        retval[4] /= PyKEP.EARTH_VELOCITY
        retval[5] /= PyKEP.EARTH_VELOCITY
        retval[6] /= self.__sc.mass
        return retval
Exemplo n.º 10
0
    def _compute_constraints_impl(self, x_full):
        import PyKEP
        sc_mass = self.__start_mass
        eqs = []
        ineqs = []

        for i in range(self.__num_legs):
            x = x_full[i * self.__dim_leg:(i + 1) * self.__dim_leg]

            start = PyKEP.epoch(x[0])
            end = PyKEP.epoch(x[0] + x[1])

            # Computing starting spaceraft state
            r, v = self.__seq[i].eph(start)
            x0 = PyKEP.sims_flanagan.sc_state(r, v, sc_mass)

            # Computing ending spaceraft state
            r, v = self.__seq[i + 1].eph(end)
            xe = PyKEP.sims_flanagan.sc_state(r, v, x[3])

            # Building the SF leg
            self.__legs[i].set_spacecraft(
                PyKEP.sims_flanagan.spacecraft(sc_mass, .3, 3000.))
            self.__legs[i].set(start, x0, x[-3 * self.__nseg:], end, xe)

            # Setting all constraints
            eqs.extend(self.__legs[i].mismatch_constraints())
            ineqs.extend(self.__legs[i].throttles_constraints())

            eqs[-7] /= PyKEP.AU
            eqs[-6] /= PyKEP.AU
            eqs[-5] /= PyKEP.AU
            eqs[-4] /= PyKEP.EARTH_VELOCITY
            eqs[-3] /= PyKEP.EARTH_VELOCITY
            eqs[-2] /= PyKEP.EARTH_VELOCITY
            eqs[-1] /= self.__start_mass

            sc_mass = x[3]  # update mass to final mass of leg

            if i < self.__num_legs - 1:
                x_next = x_full[(i + 1) * self.__dim_leg:(i + 2) *
                                self.__dim_leg]
                time_ineq = x[0] + x[1] + x[2] - x_next[0]
                ineqs.append(time_ineq / 365.25)
            else:
                final_time_ineq = x[0] + x[1] + x[2] - x_full[0] - x_full[
                    -1]  # <- total time
                ineqs.append(final_time_ineq / 365.25)

        retval = eqs + ineqs
        return retval
Exemplo n.º 11
0
    def _compute_constraints_impl(self, x_full):
        import PyKEP
        sc_mass = self.__start_mass
        eqs = []
        ineqs = []

        for i in range(self.__num_legs):
            x = x_full[i * self.__dim_leg:(i + 1) * self.__dim_leg]

            start = PyKEP.epoch(x[0])
            end = PyKEP.epoch(x[0] + x[1])

            # Computing starting spaceraft state
            r, v = self.__seq[i].eph(start)
            x0 = PyKEP.sims_flanagan.sc_state(r, v, sc_mass)

            # Computing ending spaceraft state
            r, v = self.__seq[i + 1].eph(end)
            xe = PyKEP.sims_flanagan.sc_state(r, v, x[3])

            # Building the SF leg
            self.__legs[i].set_spacecraft(PyKEP.sims_flanagan.spacecraft(sc_mass, .3, 3000.))
            self.__legs[i].set(start, x0, x[-3 * self.__nseg:], end, xe)

            # Setting all constraints
            eqs.extend(self.__legs[i].mismatch_constraints())
            ineqs.extend(self.__legs[i].throttles_constraints())

            eqs[-7] /= PyKEP.AU
            eqs[-6] /= PyKEP.AU
            eqs[-5] /= PyKEP.AU
            eqs[-4] /= PyKEP.EARTH_VELOCITY
            eqs[-3] /= PyKEP.EARTH_VELOCITY
            eqs[-2] /= PyKEP.EARTH_VELOCITY
            eqs[-1] /= self.__start_mass

            sc_mass = x[3]  # update mass to final mass of leg

            if i < self.__num_legs - 1:
                x_next = x_full[(i + 1) * self.__dim_leg:(i + 2) * self.__dim_leg]
                time_ineq = x[0] + x[1] + x[2] - x_next[0]
                ineqs.append(time_ineq / 365.25)
            else:
                final_time_ineq = x[0] + x[1] + x[2] - x_full[0] - x_full[-1]  # <- total time
                ineqs.append(final_time_ineq / 365.25)

        retval = eqs + ineqs
        return retval
Exemplo n.º 12
0
def write_output(output_file, trajectory, earth, mars):
    def tab_write(value):
        output_file.write('%s\t' % value)

    for value in trajectory:
        time = value[0]
        pos = value[1:4]
        tab_write(pk.epoch(time).jd)
        tab_write(
            pos[0] /
            1000.)  # the position of the CubeSat along the X axis (in km)
        tab_write(pos[1] / 1000.)
        tab_write(pos[2] / 1000.)
        tab_write(
            value[4])  # the velocity of the CubeSat along the X axis (in m/s)
        tab_write(value[5])
        tab_write(value[6])
        tab_write(np.linalg.norm(pos) /
                  1000.)  # the radii of the CubeSat from the Sun (in km)
        tab_write(
            np.linalg.norm(earth.get_relative_position(time, pos)) /
            1000.)  # the radii of the CubeSat from the Earth (in km)
        tab_write(
            np.linalg.norm(mars.get_relative_position(time, pos)) /
            1000.)  # the radii of the CubeSat from the Mars  (in km)
        tab_write(np.linalg.norm(earth.eph(time)) /
                  1000.)  # the radii of Earth from the Sun (in km)
        output_file.write('%s' %
                          (np.linalg.norm(mars.eph(time)) /
                           1000.))  # the radii of Mars from the Sun (in km)
        output_file.write('\n')
Exemplo n.º 13
0
def eph_matrix(asts, t, ref_ast=None):
    """
	Given a list `asts` of asteroids (either by IDs, or as PyKEP.planet objects)
	and an epoch `t` (either as an mjd int/float, or as a PyKEP.epoch object),
	produce the matrix with their normalized ephemerides.
	
	If a reference asteroid `ref_ast` is given, its ephemeris will be used
	as reference for the normalization. Otherwise, AU, EARTH_VELOCITY will
	be used instead.
	"""
    if type(asts[0]) is int:
        asts = [asteroids[ast] for a in asts]
    if type(t) in [float, int]:
        t = pk.epoch(t, 'mjd')

    if ref_ast is None:
        norm_ref = AU, EARTH_VELOCITY
    else:
        norm_ref = eph_reference(ref_ast, t)

    # obtain all asteroids' ephemerides
    eph = np.array([a.eph(t) for a in asts])
    # reshape matrix, so each asteroid's ephemeris will be represented by
    # a single 6 dimensional vector
    eph = eph.reshape((-1, 6))

    # normalize the full matrix
    return eph_normalize(eph, *norm_ref)
Exemplo n.º 14
0
    def cluster(self, t, with_velocity=True, scaling='astro', eps=0.125, min_samples=10):
        """
        USAGE: cl.cluster(self, t, with_velocity=True, scaling='astro', eps=0.125, min_samples=10)

        - t: epoch (in MJD2000)
        - with_velocity: when True clusters by position and velocity, otherwise only position is used
        - scaling: one of
          - None, or
          - 'standard' (removing mean and scale to standard variance), or
          - 'astro' (scaling by PyKEP.AU and PyKEP.EARTH_VELOCITY)
        - eps: max distance between points in a cluster
        - min_samples: minimum number of samples per cluster
        """
        import PyKEP
        import numpy
        from sklearn.preprocessing import StandardScaler
        from sklearn.cluster import DBSCAN

        self._scaling = scaling
        self._epoch = PyKEP.epoch(t)

        if with_velocity:
            self._X = [
                [elem for tupl in p.eph(self._epoch) for elem in tupl] for p in self._asteroids]
        else:
            self._X = [list(p.eph(self._epoch)[0]) for p in self._asteroids]
        self._X = numpy.array(self._X)

        self._scaler = None
        if self._scaling == 'standard':
            self._scaler = StandardScaler().fit(self._X)
            self._X = self._scaler.transform(self._X)
        elif self._scaling == 'astro':
            scaling_vector = [PyKEP.AU] * 3
            if with_velocity:
                scaling_vector += [PyKEP.EARTH_VELOCITY] * 3
            scaling_vector = numpy.array(scaling_vector)
            self._X = self._X / scaling_vector[None, :]

        self._db = DBSCAN(eps=eps, min_samples=min_samples).fit(self._X)
        self._core_samples = self._db.core_sample_indices_

        self.labels = self._db.labels_
        self.n_clusters = len(
            set(self.labels)) - (1 if -1 in self.labels else 0)

        self.members = {}
        self.core_members = {}
        for label in set(self.labels):
            if int(label) == -1:
                continue
            self.members[int(label)] = [index[0]
                                        for index in numpy.argwhere(self.labels == label)]
            self.core_members[int(label)] = [
                index for index in self._core_samples if self.labels[index] == label]

        if self._scaling == 'standard':
            self._X = self._scaler.inverse_transform(self._X)
        elif self._scaling == 'astro':
            self._X = self._X * scaling_vector[None, :]
Exemplo n.º 15
0
def lambert_leg(P1, P2, t0, tof):
    
    ast1 = ASTEROIDS[P1]
    ast2 = ASTEROIDS[P2]

    r1, v1 = ast1.eph(kep.epoch(t0))
    r2, v2 = ast2.eph(kep.epoch(t0 + tof))

    lambert = kep.lambert_problem(r1, r2, tof * kep.DAY2SEC, ast1.mu_central_body)

    vrel_in = tuple(map(lambda x, y: -x + y, lambert.get_v1()[0], v1))
    vrel_out = tuple(map(lambda x, y: -x + y, lambert.get_v2()[0], v2))

    dv_lambert = np.linalg.norm(vrel_out) + np.linalg.norm(vrel_in)

    a, _, _, dv_damon = kep.damon(vrel_in, vrel_out, tof*kep.DAY2SEC)
    m_star = kep.max_start_mass(np.linalg.norm(a), dv_damon, T_max, Isp)
    
    return dv_lambert, dv_damon, m_star
Exemplo n.º 16
0
def jde_mga_1dsm(seq, t0, tof, slack=5, pop_size=50, n_evolve=10, dv_launch=6127., verbose=False):
    """Runs jDE with mga_1dsm problem."""
    from PyGMO.problem import mga_1dsm_tof
    from PyGMO.algorithm import jde
    from PyGMO import population

    prob = mga_1dsm_tof(seq=[kep.planet_ss(name) for name in seq],
                                   t0=[kep.epoch(t0-slack), kep.epoch(t0+slack)],
                                   tof=[[t-slack, t+slack] for t in tof],
                                   vinf=[0., dv_launch/1000.],
                                   add_vinf_arr=False)
    algo = jde(gen=500, memory=True)
    pop = population(prob, pop_size)
    if verbose:
        print pop.champion.f[0]
    for i in xrange(n_evolve):
        pop = algo.evolve(pop)
        if verbose:
            print pop.champion.f
Exemplo n.º 17
0
 def pretty(self, x):
     """Decodes the decision vector x"""
     import PyKEP
     start = PyKEP.epoch(x[0])
     end = PyKEP.epoch(x[0] + x[1])
     r, v = self.__departure.eph(start)
     v_list = list(v)
     v_list[0] += x[3]
     v_list[1] += x[4]
     v_list[2] += x[5]
     x0 = PyKEP.sims_flanagan.sc_state(r, v_list, self.__sc.mass)
     r, v = self.__target.eph(end)
     xe = PyKEP.sims_flanagan.sc_state(r, v, x[2])
     self.__leg.set(start, x0, x[-3 * self.__nseg:], end, xe)
     print("A direct interplantary transfer\n")
     print("FROM:")
     print(self.__departure)
     print("TO:")
     print(self.__target)
     print(self.__leg)
Exemplo n.º 18
0
def J(t0, tof):
    ep1 = pk.epoch(t0)
    ep2 = pk.epoch(t0 + tof)
    r1, v1 = p1.eph(ep1)
    r2, v2 = p2.eph(ep2)
    resJ = []
    for lw in [False, True]:
        prob = pk.lambert_exposin(r1, r2, tof * pk.DAY2SEC, pk.MU_SUN, lw, n,
                                  k2)
        for i in range(prob.num_solutions()):
            exps = prob.get_exposins()[i]
            dv1 = Vector.mag(Vector.sub(prob.get_v1()[i], v1))
            dv2 = Vector.mag(Vector.sub(prob.get_v2()[i], v2))
            dvlt = exps.get_delta_v(pk.MU_SUN)
            resJ.append(1.0 - math.exp(-(dv1 + dv2) / 9.81 / isp_chem -
                                       dvlt / 9.81 / isp_lt))
    if len(resJ) == 0:
        return numpy.nan
    else:
        return numpy.nanmin(resJ)
Exemplo n.º 19
0
 def pretty(self, x):
     """Decodes the decision vector x"""
     import PyKEP
     start = PyKEP.epoch(x[0])
     end = PyKEP.epoch(x[0] + x[1])
     r, v = self.__departure.eph(start)
     v_list = list(v)
     v_list[0] += x[3]
     v_list[1] += x[4]
     v_list[2] += x[5]
     x0 = PyKEP.sims_flanagan.sc_state(r, v_list, self.__sc.mass)
     r, v = self.__target.eph(end)
     xe = PyKEP.sims_flanagan.sc_state(r, v, x[2])
     self.__leg.set(start, x0, x[-3 * self.__nseg:], end, xe)
     print("A direct interplantary transfer\n")
     print("FROM:")
     print(self.__departure)
     print("TO:")
     print(self.__target)
     print(self.__leg)
Exemplo n.º 20
0
def write_output_vts(output_vts_format_file, trajectory, earth, mars):
	""" Function for generating the trajectory of the CubeSat by traj.xyzv 
	in the VTS format """
	def tab_write(value):
        	output_vts_format_file.write('%s\t' % value)

	for value in trajectory:
        	time = value[0]
        	pos = value[1:4]
		time_integer_part = int(pk.epoch(time).mjd // 1) # integer part of mjd time 
		time_decimal_part = (pk.epoch(time).mjd % 1)*pk.DAY2SEC # converting the decimal part of mjd time to seconds
        	tab_write(time_integer_part)
		tab_write(time_decimal_part)
        	tab_write(pos[0]/1000.)  # the position of the CubeSat along the X axis (in km)
        	tab_write(pos[1]/1000.)
        	tab_write(pos[2]/1000.)
        	tab_write(value[4])      # the velocity of the CubeSat along the X axis (in m/s)
        	tab_write(value[5])
       		tab_write(value[6])
        	output_vts_format_file.write('\n')
Exemplo n.º 21
0
def plot_trajectory(dates, positions, flight_duration):
    earth = pk.planet.jpl_lp('earth')
    mars = pk.planet.jpl_lp('mars')

    fig = pyplot.figure()
    ax = fig.gca(projection='3d')
    unzip = zip(*positions)
    pk.orbit_plots.plot_planet(earth, ax=ax, t0=dates[0])
    mars_arrival = pk.epoch(dates[0].mjd2000 + flight_duration)
    pk.orbit_plots.plot_planet(mars, ax=ax, t0=mars_arrival)
    ax.plot(unzip[0], unzip[1], unzip[2], color='red')
    return ax
Exemplo n.º 22
0
    def cluster(self, t, eps=0.125, min_samples=10, metric='orbital', T=180, ref_r=AU, ref_v=EARTH_VELOCITY):
        """
        USAGE: cl.cluster(t, eps=0.125, min_samples=10, metric='orbital', T=180, ref_r=AU, ref_v=EARTH_VELOCITY):

        - t: epoch (in MJD2000)
        - eps: max distance between points in a cluster
        - min_samples: minimum number of samples per cluster
        - metric: one of 'euclidean', 'euclidean_r', orbital'
        - T: average transfer time (used in the definition of the 'orbital' metric)
        - ref_r         reference radius   (used as a scaling factor for r if the metric is 'euclidean' or 'euclidean_r')
        - ref_v         reference velocity (used as a scaling factor for v if the metric is 'euclidean')
        """
        import PyKEP
        import numpy
        from sklearn.cluster import DBSCAN

        self._epoch = PyKEP.epoch(t)

        if metric == 'euclidean':
            self._X = [
                [elem for tupl in p.eph(self._epoch) for elem in tupl] for p in self._asteroids]
            scaling_vector = [ref_r] * 3
            scaling_vector += [ref_v] * 3
        elif metric == 'euclidean_r':
            self._X = [list(p.eph(self._epoch)[0]) for p in self._asteroids]
            scaling_vector = [ref_r] * 3
        elif metric == 'orbital':
            self._T = T
            self._X = [self._orbital_metric(*p.eph(self._epoch)) for p in self._asteroids]
            scaling_vector = [1.] * 6  # no scaling
        self._X = numpy.array(self._X)

        scaling_vector = numpy.array(scaling_vector)
        self._X = self._X / scaling_vector[None, :]

        self._db = DBSCAN(eps=eps, min_samples=min_samples).fit(self._X)
        self._core_samples = self._db.core_sample_indices_

        self.labels = self._db.labels_
        self.n_clusters = len(
            set(self.labels)) - (1 if -1 in self.labels else 0)

        self.members = {}
        self.core_members = {}
        for label in set(self.labels):
            if int(label) == -1:
                continue
            self.members[int(label)] = [index[0]
                                        for index in numpy.argwhere(self.labels == label)]
            self.core_members[int(label)] = [
                index for index in self._core_samples if self.labels[index] == label]

        self._X = self._X * scaling_vector[None, :]
Exemplo n.º 23
0
def plot_trajectory(dates, positions, flight_duration):
    earth = pk.planet.jpl_lp('earth')
    mars = pk.planet.jpl_lp('mars')

    fig = pyplot.figure()
    ax = fig.gca(projection='3d')
    unzip = zip(*positions)
    pk.orbit_plots.plot_planet(earth, ax=ax, t0=dates[0])
    mars_arrival = pk.epoch(dates[0].mjd2000 + flight_duration)
    pk.orbit_plots.plot_planet(mars, ax=ax, t0=mars_arrival)
    ax.plot(unzip[0], unzip[1], unzip[2], color='red')
    return ax
Exemplo n.º 24
0
def parse_trajectory(trajectory_file):
    dates = []
    positions = []
    velocities = []
    for line in trajectory_file.read().splitlines():
        values = [float(element) for element in line.split(' ')]
        dates.append(pk.epoch(values[0], 'jd'))
        positions.append([values[1], values[2], values[3]])
        velocities.append([values[4], values[5], values[6]])
    positions = np.array(positions) * 1000
    velocities = np.array(velocities) * 1000
    return dates, positions, velocities
Exemplo n.º 25
0
def parse_trajectory(trajectory_file):
    dates = []
    positions = []
    velocities = []
    for line in trajectory_file.read().splitlines():
        values = [float(element) for element in line.split(' ')]
        dates.append(pk.epoch(values[0], 'jd'))
        positions.append([values[1], values[2], values[3]])
        velocities.append([values[4], values[5], values[6]])
    positions = np.array(positions)*1000
    velocities = np.array(velocities)*1000
    return dates, positions, velocities
Exemplo n.º 26
0
def lambert_leg(p1, p2, t0, tof, vrel=None, dv_launch=0., rendezvous=False):
    """Compute a lambert leg from planet to planet.

    Arguments:
    p1 -- starting planet (str or PyKEP.planet object)
    p2 -- final planet (str or PyKEP.planet object)
    t0 -- start time of leg in MJD2000
    tof -- time of flight in days
    
    Keyword arguments:
    vrel -- caresian coordinates of the relative velocity before the flyby at p1
    dv_launch -- dv discounted at lunch (i.e. if vrel is None)
    rendezvous -- add final dv

    Returns:
    dV, vrel_out, where vrel_out is the relative velocity at the end of the leg at p2
    """
    # check if planets are names or planet objects
    
    p1 = PLANETS[str(p1)]
    p2 = PLANETS[str(p2)]
    r1, v1 = p1.eph(kep.epoch(t0))
    r2, v2 = p2.eph(kep.epoch(t0 + tof))
    lambert = kep.lambert_problem(r1, r2, tof * kep.DAY2SEC, p1.mu_central_body, False, 0)
    
    vrel_in = tuple(map(lambda x, y: x - y, lambert.get_v1()[0], v1))
    vrel_out = tuple(map(lambda x, y: x - y, lambert.get_v2()[0], v2))

    if vrel is None:
        # launch
        dv = max(np.linalg.norm(vrel_in) - dv_launch, 0)
    else:
        # flyby
        #print p1.name, p2.name, np.linalg.norm(vrel_in), np.linalg.norm(vrel_out)
        dv = kep.fb_vel(vrel, vrel_in, p1)

    if rendezvous:
        dv += np.linalg.norm(vrel_out)
        
    return dv, vrel_out
Exemplo n.º 27
0
def plot_orbits(ep, debris1, debris2):
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.set_aspect('equal')
    ax.set_xlim(-1e7, 1e7)
    ax.set_ylim(-1e7, 1e7)
    ax.set_zlim(-1e7, 1e7)
    for deb in debris1:
        try:
            kep.orbit_plots.plot_planet(deb, ax=ax, t0=kep.epoch(ep), s=0, color='r', alpha=0.2)
        except:
            pass

    for deb in debris2:
        try:
            kep.orbit_plots.plot_planet(deb, ax=ax, t0=kep.epoch(ep), s=0, color='b', alpha=0.2)
        except:
            pass

    plt.show()
Exemplo n.º 28
0
def rate__orbital(dep_ast, dep_t, leg_dT, **kwargs):
    """
	Orbital Phasing Indicator.
	See: http://arxiv.org/pdf/1511.00821.pdf#page=12
	
	Estimates the cost of a `leg_dT` days transfer from departure asteroid
	`dep_ast` at epoch `dep_t`, towards each of the available asteroids.
	"""
    dep_t = pk.epoch(dep_t, 'mjd')
    leg_dT *= DAY2SEC
    orbi = [
        orbital_indicator(ast, dep_t, leg_dT, **kwargs) for ast in asteroids
    ]
    ast_orbi = np.array(orbi[dep_ast])
    return np.linalg.norm(ast_orbi - orbi, axis=1)
Exemplo n.º 29
0
def body_eph_gen_vts(output_vts_format_file, trajectory, body):
	""" Function for generating the ephemeris of a body by traj.xyzv
	in the VTS format """
	def tab_write(value):
		output_vts_format_file.write('%s\t' % value)

	def car2sph(car_pos):
		r = np.linalg.norm(car_pos)  # km
		lat = np.arcsin(car_pos[2]/r)*180./np.pi   # degree
		lon = np.arctan2(car_pos[1], car_pos[0])*180./np.pi  # degree
		return np.array([lon,lat,r/1000.])
	
	for value in trajectory:
		time = value[0]
		pos = value[1:4]
		sph_temp = car2sph( body.get_relative_position(time, pos) )
		time_integer_part = int(pk.epoch(time).mjd // 1) # integer part of mjd time 
		time_decimal_part = (pk.epoch(time).mjd % 1)*pk.DAY2SEC # converting the decimal part of mjd time to seconds
		tab_write(time_integer_part)
		tab_write(time_decimal_part)
		tab_write(sph_temp[1]) # latitude 
		tab_write(sph_temp[0]) # longitude  
		tab_write(sph_temp[2]) 
		output_vts_format_file.write('\n')
Exemplo n.º 30
0
def eph_reference(ref_ast, t):
    """
	Calculate reference r and v magnitudes for use in the normalization
	of asteroid ephemeris.
	
	Returns:
		(|r|, |v|)
	where (r,v) is the ephemeris of the given asteroid `ref_ast` (id, or object)
	at epoch `t` (int/float, or epoch object).
	"""
    if type(ref_ast) is int:
        ref_ast = asteroids[ref_ast]
    if type(t) in [float, int]:
        t = pk.epoch(t, 'mjd')

    r, v = ref_ast.eph(t)
    return np.linalg.norm(r), np.linalg.norm(v)
def plotOrbits(planets_tle):
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ep = kep.epoch(17)
    for pln in planets_tle:
        e = float("0." + pln.line2[26:32])
        i = float(pln.line2[8:15])
        W = float(pln.line2[17:24])
        w = float(pln.line2[34:41])
        M = 20
        # print e,i,W,w
        oe = [
            2000000 + 6378000, e, i * kep.DEG2RAD, W * kep.DEG2RAD,
            w * kep.DEG2RAD, M * kep.DEG2RAD
        ]
        pl = kep.planet.keplerian(ep, oe, earth.mu_self, 0, 0, 0, '')
        kep.orbit_plots.plot_planet(pl, ax=ax, alpha=0.2, s=0, color='red')
    plt.show()
Exemplo n.º 32
0
def jup_eph_gen(output_file, trajectory, jupiter):
	def tab_write(value):
		output_file.write('%s\t' % value)

	def car2sph(car_pos):
		r = np.linalg.norm(car_pos)  # km
		lat = np.arcsin(car_pos[2]/r)*180./np.pi   # degree
		lon = np.arctan2(car_pos[1], car_pos[0])*180./np.pi  # degree
		return np.array([lon,lat,r/1000.])
	
	for value in trajectory:
		time = value[0]
		pos = value[1:4]
		sph_temp = car2sph( jupiter.get_relative_position(time, pos) )
		tab_write(pk.epoch(time).jd)
		tab_write(sph_temp[1]) # latitude 
		tab_write(sph_temp[0]) # longitude  
		tab_write(sph_temp[2]) 
		output_file.write('\n')
Exemplo n.º 33
0
def jup_eph_gen(output_file, trajectory, jupiter):
    def tab_write(value):
        output_file.write('%s\t' % value)

    def car2sph(car_pos):
        r = np.linalg.norm(car_pos)  # km
        lat = np.arcsin(car_pos[2] / r) * 180. / np.pi  # degree
        lon = np.arctan2(car_pos[1], car_pos[0]) * 180. / np.pi  # degree
        return np.array([lon, lat, r / 1000.])

    for value in trajectory:
        time = value[0]
        pos = value[1:4]
        sph_temp = car2sph(jupiter.get_relative_position(time, pos))
        tab_write(pk.epoch(time).jd)
        tab_write(sph_temp[1])  # latitude
        tab_write(sph_temp[0])  # longitude
        tab_write(sph_temp[2])
        output_file.write('\n')
Exemplo n.º 34
0
def write_output(output_file, trajectory, earth, mars):
    def tab_write(value):
        output_file.write('%s\t' % value)

    for value in trajectory:
        time = value[0]
        pos = value[1:4]
        tab_write(pk.epoch(time).jd)
        tab_write(pos[0]/1000.)  # the position of the CubeSat along the X axis (in km)
        tab_write(pos[1]/1000.)
        tab_write(pos[2]/1000.)
        tab_write(value[4])      # the velocity of the CubeSat along the X axis (in m/s)
        tab_write(value[5])
        tab_write(value[6])
        tab_write(np.linalg.norm(pos)/1000.)  # the radii of the CubeSat from the Sun (in km)
        tab_write(np.linalg.norm(earth.get_relative_position(time, pos))/1000.)  # the radii of the CubeSat from the Earth (in km)
        tab_write(np.linalg.norm(mars.get_relative_position(time, pos))/1000.)   # the radii of the CubeSat from the Mars  (in km)
        tab_write(np.linalg.norm(earth.eph(time))/1000.) 			 # the radii of Earth from the Sun (in km)
        output_file.write('%s' % (np.linalg.norm(mars.eph(time))/1000.) )	 # the radii of Mars from the Sun (in km)
        output_file.write('\n')
Exemplo n.º 35
0
    def parse_traj(self, trajectory_file):
        """Method reading the contents of a specified trajectory file and 
        returning the data from last line of file as a tuple of an epoch, 
        an array of position vector and an array of velocity vector.
        Returns date (string format), position (m), velocity (km).
        """
        d = motion.Date()
        p = motion.Position()
        v = motion.Velocity()
        for line in trajectory_file.read().splitlines():
            values = [float(element) for element in line.split(' ')]
            d.date = pk.epoch(values[0], 'jd')
            p.x = values[1]
            p.y = values[2]
            p.z = values[3]
            v.vx = values[4]
            v.vy = values[5]
            v.vz = values[6]
	
        return d.date, p.xyz_array() * 1000, v.vxvyvz_array() * 1000
Exemplo n.º 36
0
def body_eph_gen(output_file, trajectory, body):
	""" Function for generating the ephemeris of a body by traj.xyzv """
	def tab_write(value):
		output_file.write('%s\t' % value)

	def car2sph(car_pos):
		r = np.linalg.norm(car_pos)  # km
		lat = np.arcsin(car_pos[2]/r)*180./np.pi   # degree
		lon = np.arctan2(car_pos[1], car_pos[0])*180./np.pi  # degree
		return np.array([lon,lat,r/1000.])
	
	for value in trajectory:
		time = value[0]
		pos = value[1:4]
		sph_temp = car2sph( body.get_relative_position(time, pos) )
		tab_write(pk.epoch(time).jd)
		tab_write(sph_temp[1]) # latitude 
		tab_write(sph_temp[0]) # longitude  
		tab_write(sph_temp[2]) 
		output_file.write('\n')
Exemplo n.º 37
0
def body_eph_gen(output_file, trajectory, body):
    """ Function for generating the ephemeris of a body by traj.xyzv """
    def tab_write(value):
        output_file.write('%s\t' % value)

    def car2sph(car_pos):
        r = np.linalg.norm(car_pos)  # km
        lat = np.arcsin(car_pos[2] / r) * 180. / np.pi  # degree
        lon = np.arctan2(car_pos[1], car_pos[0]) * 180. / np.pi  # degree
        return np.array([lon, lat, r / 1000.])

    for value in trajectory:
        time = value[0]
        pos = value[1:4]
        sph_temp = car2sph(body.get_relative_position(time, pos))
        tab_write(pk.epoch(time).jd)
        tab_write(sph_temp[1])  # latitude
        tab_write(sph_temp[0])  # longitude
        tab_write(sph_temp[2])
        output_file.write('\n')
Exemplo n.º 38
0
# "The weight of such a scientific equipment is set to be 40 kg at each
# asteroid. The second asteroid encounter (fly-by) corresponds to the delivery
# of a 1 kg penetrator."
MASS_EQUIPMENT = 40.0
MASS_PENETRATOR = 1.0

# constraint for the flyby to deliver the penetrator:
# "flyby asteroid with a velocity not less than dV_min = 0.4 km/s."
dV_fb_min = 400.0  # m/s

# "The flight time, measured from start to the end must not exceed 15 years"
TIME_MAX = 15 * YEAR2DAY  # 5478.75 days

# "The year of launch must lie in the range 2015 to 2025, inclusive:
# 57023 MJD <= t_s <= 61041 MJD."
TRAJ_START_MIN = pk.epoch(57023, 'mjd')
TRAJ_START_MAX = pk.epoch(61041, 'mjd')
# >>> TRAJ_START_MIN, TRAJ_START_MAX
# (2015-Jan-01 00:00:00, 2026-Jan-01 00:00:00)

TRAJ_END_MIN = pk.epoch(TRAJ_START_MIN.mjd + TIME_MAX, 'mjd')
TRAJ_END_MAX = pk.epoch(TRAJ_START_MAX.mjd + TIME_MAX, 'mjd')
# >>> TRAJ_END_MIN, TRAJ_END_MAX
# (2029-Dec-31 18:00:00, 2040-Dec-31 18:00:00)

# ==================================== # GTOC5 asteroids (body objects)

# Earth's Keplerian orbital parameters
# Source: http://dx.doi.org/10.2420/AF08.2014.9 (Table 1)
_earth_op = (
    pk.epoch(54000, 'mjd'),  # t
 def __init__(self, *args, **kwargs):
     super(BasePlanet, self).__init__(*args, **kwargs)
     self.semi_major_axis, self.eccentricity, self.inclination, self.longitude_asc_node, self.arg_periapsis, _ = self.osculating_elements(pk.epoch(0))
     self.soi = self.semi_major_axis*(self.mu_self/self.mu_central_body)**(2./5)
Exemplo n.º 40
0
	"""
	Return's the body's orbital period, in days.
	"""
	return 2 * pi * sqrt( self.orbital_elements[0]**3 / self.mu_central_body )
	# http://en.wikipedia.org/wiki/Orbital_period#Calculation

_planet = pk.planet
_planet.period = _period

# Instantiating PyKEP planet objects for each of the bodies (and making them indexable by body name)
# http://keptoolbox.sourceforge.net/documentation.html#PyKEP.planet
body_obj = OrderedDict( [
	( _b.body, _planet(
		# when
		# 	a PyKEP.epoch indicating the orbital elements epoch
		pk.epoch( _b.Epoch, pk.epoch.epoch_type.MJD ),
		
		# orbital_elements
		# 	a sequence of six containing a,e,i,W,w,M (SI units, i.e. meters and radiants)
		(	_b.a * 1000.,
			_b.e,
			radians( _b.i    ),
			radians( _b.Node ),
			radians( _b.w    ),
			radians( _b.M    ),
			),
		
		# mu_central_body
		# 	gravity parameter of the central body (SI units, i.e. m^2/s^3)
		pk.MU_SUN if _b.body == 'jupiter' else ( body_tuple['jupiter'].mu * 1000.**3 ),
		# pk.MU_SUN == 1.32712428e+20 m^2/s^3
Exemplo n.º 41
0
        else:
            newListOfCommonRiskPlanets.append([couple[1],couple[4]])

    return newListOfCommonRiskPlanets, tupleOfCollisions


# for cycle for multiple experiments - output file is marked with number of cycle
for qq in range(1,2):
    satcat = kep.util.read_satcat('satcat.txt')
    debris = kep.util.read_tle('full.tle', with_name=False)
    # list of all EU states and ESA and its bodies
    EU_list = ["ASRA","BEL","CZCH","DEN","ESA","ESRO","EST","EUME","EUTE","FGER","FR","FRIT","GER","GREC","HUN","IT","LTU","LUXE","NETH","NOR","POL","POR","SPN","SWED","SWTZ","UK"]

#  filtering only objects in LEO
    leo_debris = []
    ep = kep.epoch(16.*365.25)
    for p in debris:
        try:
            oe = p.osculating_elements(ep)
            if oe[0] * (1-oe[1]) < 6378000.0 + 2000000:
                leo_debris.append(p)
        except:
            pass
    debris = leo_debris
    # loading tle files of recent objects for relaunching sequence from 2005 to 2014
    # TLE files are downloaded from space-track based on NORAD number range from filtered satcat files
    recentPlanetsTLE = kep.util.read_tle('recentPlanetsTLE_2005_2014.tle', with_name=False)

    # alternative sequence for relaunching objects from 1995 to 2004
    # recentPlanetsTLE = kep.util.read_tle('recentPlanetsTLE_1995_2004.tle', with_name=False)
    beginningOfSequence = 2005
Exemplo n.º 42
0
'''
Plot an example transfer
'''
import PyKEP

earth = PyKEP.planet.jpl_lp('earth')
mars = PyKEP.planet.jpl_lp('mars')
k2 = 0.6
n = -1
t0 = 250.0
tof = 520.0
lw = False

r1, v1 = earth.eph(PyKEP.epoch(t0, "mjd2000"))
r2, v2 = mars.eph(PyKEP.epoch(t0 + tof, "mjd2000"))

prob = PyKEP.lambert_exposin(r1, r2, tof * PyKEP.DAY2SEC, PyKEP.MU_SUN, lw, n,
                             k2)
print prob

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

fig = plt.figure()
axis = fig.gca(projection='3d')

axis.scatter([0], [0], [0], color='y')

PyKEP.orbit_plots.plot_lambert_exposin(prob, axis)
PyKEP.orbit_plots.plot_planet(earth, PyKEP.epoch(t0, "mjd2000"), ax=axis)
Exemplo n.º 43
0
    def cluster(self,
                t,
                eps=0.125,
                min_samples=10,
                metric='orbital',
                T=180,
                ref_r=AU,
                ref_v=EARTH_VELOCITY):
        """
        USAGE: cl.cluster(t, eps=0.125, min_samples=10, metric='orbital', T=180, ref_r=AU, ref_v=EARTH_VELOCITY):

        - t: epoch (in MJD2000)
        - eps: max distance between points in a cluster
        - min_samples: minimum number of samples per cluster
        - metric: one of 'euclidean', 'euclidean_r', orbital'
        - T: average transfer time (used in the definition of the 'orbital' metric)
        - ref_r         reference radius   (used as a scaling factor for r if the metric is 'euclidean' or 'euclidean_r')
        - ref_v         reference velocity (used as a scaling factor for v if the metric is 'euclidean')
        """
        import PyKEP
        import numpy
        from sklearn.cluster import DBSCAN

        self._epoch = PyKEP.epoch(t)

        if metric == 'euclidean':
            self._X = [[elem for tupl in p.eph(self._epoch) for elem in tupl]
                       for p in self._asteroids]
            scaling_vector = [ref_r] * 3
            scaling_vector += [ref_v] * 3
        elif metric == 'euclidean_r':
            self._X = [list(p.eph(self._epoch)[0]) for p in self._asteroids]
            scaling_vector = [ref_r] * 3
        elif metric == 'orbital':
            self._T = T
            self._X = [
                self._orbital_metric(*p.eph(self._epoch))
                for p in self._asteroids
            ]
            scaling_vector = [1.] * 6  # no scaling
        self._X = numpy.array(self._X)

        scaling_vector = numpy.array(scaling_vector)
        self._X = self._X / scaling_vector[None, :]

        self._db = DBSCAN(eps=eps, min_samples=min_samples).fit(self._X)
        self._core_samples = self._db.core_sample_indices_

        self.labels = self._db.labels_
        self.n_clusters = len(set(
            self.labels)) - (1 if -1 in self.labels else 0)

        self.members = {}
        self.core_members = {}
        for label in set(self.labels):
            if int(label) == -1:
                continue
            self.members[int(label)] = [
                index[0] for index in numpy.argwhere(self.labels == label)
            ]
            self.core_members[int(label)] = [
                index for index in self._core_samples
                if self.labels[index] == label
            ]

        self._X = self._X * scaling_vector[None, :]
Exemplo n.º 44
0
for qq in range(1, numOfExperiments + 1):
    satcat = launch.loadData_satcat()
    debris = launch.loadData_tle()

    # list of all EU states and ESA and its bodies
    EU_list = [
        "EU", "ASRA", "BEL", "CZCH", "DEN", "ESA", "ESRO", "EST", "EUME",
        "EUTE", "FGER", "FR", "FRIT", "GER", "GREC", "HUN", "IT", "LTU",
        "LUXE", "NETH", "NOR", "POL", "POR", "SPN", "SWED", "SWTZ", "UK"
    ]
    agentList = ['CIS', 'US', 'PRC', 'EU']
    agentListWithEU = ['CIS', 'US', 'PRC', EU_list]
    #  filtering only objects in LEO
    debris_LEO = []
    ep = kep.epoch((START_YEAR - 2000.) * 365.25)
    for p in debris:
        try:
            oe = p.osculating_elements(ep)
            if oe[0] * (1 - oe[1]) < 6378000.0 + 2000000:
                debris_LEO.append(p)
        except:
            pass
    debris = debris_LEO
    debris_pom = copy.deepcopy(debris)
    satcat_pom = copy.deepcopy(satcat)
    # contains all satellites i.e. not debris, not R/B, and not decayed at the beginning of run
    satellites = launch.getSatellites(satcat_pom, debris_pom,
                                      spacecraft_classes, START_YEAR, 1)
    agentImportantAssetsAtStart = []
    for agentIndex in range(0, len(agentList)):
Exemplo n.º 45
0
'''
Check the state vector of an exposin for discrepancies
'''
import PyKEP

earth = PyKEP.planet.jpl_lp('earth')
mars = PyKEP.planet.jpl_lp('mars')
k2 = 0.6
n = 1
t0 = 250.0
tof = 520.0
lw = True

r1, v1 = earth.eph(PyKEP.epoch(t0, "mjd2000"))
r2, v2 = mars.eph(PyKEP.epoch(t0 + tof, "mjd2000"))

prob = PyKEP.lambert_exposin(r1, r2, tof * PyKEP.DAY2SEC, PyKEP.MU_SUN, lw, n,
                             k2)
print prob
'''
To look for discrepancies in propagated state, we find v by propagation as well as the implemented analytical v
'''
import random
import Vector

exps = prob.get_exposins()[0]

# any random progress into the trajectory
rand_psi = random.uniform(0.0, exps.get_psi())
r, v, a = exps.get_state(rand_psi, PyKEP.MU_SUN)
Exemplo n.º 46
0
PLANET_TOF[('venus', 'jupiter')] = (400., 1600.)
PLANET_TOF[('venus', '67p')] = (500., 3000.)

PLANET_TOF[('mars', 'mars')] = (780., 1600.)
PLANET_TOF[('mars', 'jupiter')] = (400., 1600.)
PLANET_TOF[('mars', '67p')] = (500., 3000.)

PLANET_TOF[('jupiter', 'jupiter')] = (4332., 9000.)
PLANET_TOF[('jupiter', '67p')] = (500., 3000.)

#TOF the same coming and going
for (p1, p2) in PLANET_TOF.keys():
    PLANET_TOF[(p2, p1)] = PLANET_TOF[(p1, p2)]

#Comet = Final Destination
chury = kep.planet.keplerian(kep.epoch(2456879.5, 'jd'),
                   (
                       3.4630 * kep.AU, # a
                       0.64102, # e
                       7.0405 * kep.DEG2RAD, # i
                       50.147 * kep.DEG2RAD, # W
                       12.780 * kep.DEG2RAD, # w
                       303.71 * kep.DEG2RAD # M
                   ),
                   kep.MU_SUN,
                   1e-10, # mu_self
                   5.e3, # radius
                   100.e3, # save_radius
                   '67p'
)
tools.PLANETS[chury.name] = chury
Exemplo n.º 47
0
 def __init__(self, *args, **kwargs):
     super(BasePlanet, self).__init__(*args, **kwargs)
     self.semi_major_axis, self.eccentricity, self.inclination, self.longitude_asc_node, self.arg_periapsis, _ = self.osculating_elements(
         pk.epoch(0))
     self.soi = self.semi_major_axis * (self.mu_self /
                                        self.mu_central_body)**(2. / 5)
Exemplo n.º 48
0
    def plot_track(self,data,predict=True,longplot=False):
        UT = data[0]
        shippids = data[1]
        
        fig = plt.figure(figsize=(20,10))
        kmap = mpl_toolkits.basemap.Basemap(rsphere=600000,celestial=True,resolution=None)
        im = plt.imread("Kerbin_elevation.png")
        #implot = plt.imshow(im)
        kmap.imshow(im,origin="upper")


        #UT = float(ss["UT"]) / 60 / 60 / 24
        #ships = ss["VESSELS"]
        #colors = ["red","green","white","cyan","orange","yellow","purple","brown"]
        nearest=lambda a,l:min(l,key=lambda x:abs(x-a)) # Thanks stackexchange
        if longplot:
            steps = 720 #Minutes
        else:
            steps = 30 #Minutes
        trackTime = steps/60/24 #  30 minutes
        stepTime = 1.0/60.0/24.0 # 1 minute
        reserved = []
        for ship in shippids.values():
            last_rascension = None
            last_declination = None
            if "debris" in ship.name.lower():
                continue
            XY = []
            for i in xrange(steps):
                stepEpoch = UT - i*stepTime
                if stepEpoch<ship.min and not predict: #TODO: predictorbits
                    stepEpoch = ship.min #This is to ensure that no orbits are drawn which have unsure stuff
                nt = nearest(stepEpoch,ship.datapoints.keys())
                print "Epoch ",stepEpoch,"using datapoint",nt
                dp = ship.datapoints[nt]
                
                if len(dp) == 2:
                    XY.append([dp[0],dp[1]])
                elif len(dp) == 7:
                    E = PyKEP.epoch(dp[0])
                    KepShip = PyKEP.planet(E,[dp[1],dp[2],dp[3],dp[4],dp[5],dp[6]],3531600000000,1,1,1)
                    r,v = KepShip.eph(PyKEP.epoch(stepEpoch))
                    r = np.array(r)
                    theta = -0.000290888209 * stepEpoch * 60 * 60 * 24
                    rmatrix = np.array([[np.cos(theta),np.sin(theta),0],[-np.sin(theta),np.cos(theta),0],[0,0,1]])
                    rr=np.dot(r,rmatrix)
                    ur = rr / np.linalg.norm(rr)
                    declination = np.arcsin(ur[2])
                    if ur[1] > 0:
                        rascension = np.degrees(np.arccos(ur[0] / np.cos(declination)))
                    elif ur[1] <= 0:
                        rascension = - np.degrees(np.arccos(ur[0]/ np.cos(declination)))
                       # print "360-",np.degrees(np.arccos(ur[0]/ np.cos(declination)))
                    declination = np.degrees(declination)

                    # Insert NaN if crossing 180 or -180
                    if last_rascension != None:
                        dif = rascension - last_rascension
                        if dif > 180 or dif < -180:
                            if dif < -180: # Going from 180 to -180
                                k = (declination - last_declination) / ((rascension - 180) + (180-last_rascension))
                                d = (180 - last_rascension)*k + last_declination
                                XY.append([180,d])
                                XY.append([np.NaN,np.NaN])
                                XY.append([-180,d])
                            else: # Going from -180 to 180
                                k = (declination - last_declination) / ((180-rascension) + (last_rascension-180))
                                d = (last_rascension-180)*k + last_declination
                                XY.append([-180,d])
                                XY.append([np.NaN,np.NaN])
                                XY.append([180,d])
                                
                            XY.append([np.NaN,np.NaN]) #FLIP
                    last_rascension = rascension
                    last_declination = declination
                    XY.append([rascension,declination])
                    
                else:
                    print "Error"
                    sys.exit(1)
            
            lastx = None
            lasty = None
            #color = random.choice(colors)
            r = random.randint(100,255) / 255.0
            g = random.randint(100,255)/ 255.0
            b = random.randint(100,255)/ 255.0
            color = (r,g,b)
            #colors.remove(color)
            alphafade = 1.0 / len(XY)
            for i,point in enumerate(XY):
                if i == 0:
                    lastx = point[0]
                    lasty = point[1]
                    continue
                    
                x = point[0]
                y = point[1]
                if lastx and lasty:
                    kmap.plot([x,lastx],[y,lasty],color=color,alpha=1-i*alphafade)
                lastx = x
                lasty = y
                    
            kmap.plot(XY[0][0],XY[0][1],marker="x",markersize=10,color=color)
            kmap.plot(XY[0][0],XY[0][1],marker="+",markersize=10,color=color)
            
            if XY[0][0] > 0:
                mx = -4*len(ship.name)
            else:
                mx = 2*len(ship.name)
            if XY[0][1] >= 0:
                my = -20+XY[0][1]
                while int(my/5) in reserved:
                    my-=5
                reserved.append(int(my/5))
            elif XY[0][1] < 0:
                my = 20+XY[0][1]
                while int(my/5) in reserved:
                    my+=5
                reserved.append(int(my/5))
          
            print "ship:",ship.name,mx,my
            print "reserved",reserved
            plt.annotate(ship.name,xy=(XY[0][0],XY[0][1]), xycoords="data",xytext=(mx+XY[0][0],my),textcoords="data",color=color,arrowprops=dict(arrowstyle="->",color=color))
            
            
            
        days = int(UT) 
        years = days / 365 + 1
        days %= 365
        days += 1

        plt.title("Kerbin satellite ground track - Year %i, Day %i"%(years,days))
        print ("Track.py completed succesfully")
        return plt
Exemplo n.º 49
0

# for cycle for multiple experiments - output file is marked with number of cycle
for qq in range(1, 2):
    satcat = kep.util.read_satcat('satcat.txt')
    debris = kep.util.read_tle('full.tle', with_name=False)
    # list of all EU states and ESA and its bodies
    EU_list = [
        "ASRA", "BEL", "CZCH", "DEN", "ESA", "ESRO", "EST", "EUME", "EUTE",
        "FGER", "FR", "FRIT", "GER", "GREC", "HUN", "IT", "LTU", "LUXE",
        "NETH", "NOR", "POL", "POR", "SPN", "SWED", "SWTZ", "UK"
    ]

    #  filtering only objects in LEO
    leo_debris = []
    ep = kep.epoch(16. * 365.25)
    for p in debris:
        try:
            oe = p.osculating_elements(ep)
            if oe[0] * (1 - oe[1]) < 6378000.0 + 2000000:
                leo_debris.append(p)
        except:
            pass
    debris = leo_debris
    # loading tle files of recent objects for relaunching sequence from 2005 to 2014
    # TLE files are downloaded from space-track based on NORAD number range from filtered satcat files
    recentPlanetsTLE = kep.util.read_tle('recentPlanetsTLE_2005_2014.tle',
                                         with_name=False)

    # alternative sequence for relaunching objects from 1995 to 2004
    # recentPlanetsTLE = kep.util.read_tle('recentPlanetsTLE_1995_2004.tle', with_name=False)
Exemplo n.º 50
0
def rate__edelbaum(dep_ast, dep_t, **kwargs):
    dep_ast = asteroids[dep_ast]
    dep_t = pk.epoch(dep_t, 'mjd')
    return [edelbaum_dv(dep_ast, arr_ast, dep_t) for arr_ast in asteroids]
Exemplo n.º 51
0
    return 2 * pi * sqrt(self.orbital_elements[0]**3 / self.mu_central_body)
    # http://en.wikipedia.org/wiki/Orbital_period#Calculation


_planet = pk.planet
_planet.period = _period

# Instantiating PyKEP planet objects for each of the bodies (and making them indexable by body name)
# http://keptoolbox.sourceforge.net/documentation.html#PyKEP.planet
body_obj = OrderedDict([
    (
        _b.body,
        _planet(
            # when
            # 	a PyKEP.epoch indicating the orbital elements epoch
            pk.epoch(_b.Epoch, pk.epoch.epoch_type.MJD),

            # orbital_elements
            # 	a sequence of six containing a,e,i,W,w,M (SI units, i.e. meters and radiants)
            (
                _b.a * 1000.,
                _b.e,
                radians(_b.i),
                radians(_b.Node),
                radians(_b.w),
                radians(_b.M),
            ),

            # mu_central_body
            # 	gravity parameter of the central body (SI units, i.e. m^2/s^3)
            pk.MU_SUN if _b.body == 'jupiter' else
Exemplo n.º 52
0
def set_t_res(t_res):
    global T_RES
    global T_SCALE
    T_RES = t_res
    T_SCALE = {name: np.arange(T_MIN, T_MAX, tools.PLANETS[name].compute_period(kep.epoch(0))/+
kep.DAY2SEC/T_RES) for name in PLANET_NAMES}