In [1]:
%run -i '../Common.ipynb'

In [2]:
%load_ext autoreload
%autoreload 2
sys.path.append('home/goetz/local/lib64/python')
%aimport ksp

In [3]:
class Bunch(dict):
    def __contains__(self, k):
        try:
            return dict.__contains__(self, k) or hasattr(self, k)
        except:
            return False
    def __getattr__(self, k):
        try:
            return object.__getattribute__(self, k)
        except AttributeError:
            try:
                return self[k]
            except KeyError:
                raise AttributeError(k)
    def __setattr__(self, k, v):
        try:
            object.__getattribute__(self, k)
        except AttributeError:
            try:
                self[k] = v
            except:
                raise AttributeError(k)
        else:
            object.__setattr__(self, k, v)
    def __delattr__(self, k):
        try:
            object.__getattribute__(self, k)
        except AttributeError:
            try:
                del self[k]
            except KeyError:
                raise AttributeError(k)
        else:
            object.__delattr__(self, k)

In [4]:
π = np.pi
deg = 180/π

b = Bunch(
    name = 'Kerbin',
    gravitational_parameter = 3.5316e12,
    equatorial_radius = 600000,
    rotational_speed = 2*π / 21600)

oe = Bunch(
    eccentricity = 0.5,
    inclination = π/3,
    longitude_of_ascending_node = π+0.1,
    argument_of_periapsis = π-2,
    semi_major_axis = 3420030,
    mean_anomaly_at_epoch = π+0.1,
    epoch = 1000,
    body = b)

o = ksp.Orbit(oe)
eo = ksp.EllipticOrbit(oe)

assert o.true_anomaly_at_epoch == eo.true_anomaly_at_epoch
assert o.specific_angular_momentum == eo.specific_angular_momentum

oe.eccentricity = 1.4

ho = ksp.HyperbolicOrbit(oe)

assert o.true_anomaly_at_epoch == ho.true_anomaly_at_epoch
assert o.specific_angular_momentum == ho.specific_angular_momentum


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-38a8d712f850> in <module>()
     26 oe.eccentricity = 1.4
     27 
---> 28 ho = ksp.HyperbolicOrbit(oe)
     29 
     30 assert o.true_anomaly_at_epoch == ho.true_anomaly_at_epoch

/home/goetz/local/lib64/python/ksp/hyperbolic_orbit.py in __init__(self, orbit)
      7     def __init__(self,orbit):
      8         #super().__init__(orbit)
----> 9         BaseOrbit.__init__(self,orbit)
     10 
     11 

/home/goetz/local/lib64/python/ksp/base_orbit.py in __init__(self, orbit)
     65         for a in attrs:
     66             if hasattr(orbit,a):
---> 67                 setattr(self,a,getattr(orbit,a))
     68 
     69     def clear_attributes(self,attrs):

/home/goetz/local/lib64/python/ksp/base_orbit.py in __setattr__(self, name, value)
     88         elif name in BaseOrbit._state_vectors:
     89             self.clear_orbital_elements()
---> 90         super().__setattr__(name,value)
     91 
     92     @property

AttributeError: can't set attribute