def __init__(self): self.jpv=[ ( 'JD %s TDT' % (jdtt,) , ( spice.convrt(float(x),'AU','KM'), spice.convrt(float(y),'AU','KM'), spice.convrt(float(z),'AU','KM'), ) , ( spice.convrt(float(xdot),'AU','KM')/spice.spd(), spice.convrt(float(ydot),'AU','KM')/spice.spd(), spice.convrt(float(zdot),'AU','KM')/spice.spd(), ) , ) for nm,jdtt,x,y,z,xdot,ydot,zdot in [ i.strip().split() for i in self.__doc__.split('\n') if i[:9]=='CK12S010 ' ] ]
def ITRF2GEO(posITRF): '''Converts from earth rectangular coordinate to Geodetic coordinate. Input will be the rectangular three coordinates [x,y,z]. Kernel file PCK is required. ''' load_kernels() _, value = spice.bodvcd(399, "RADII", 3) # Reuturns Earh radii [larger equatorial radius, smaller # equatorial radius, polar radius] dim is the dimension of # returned values Value is the returned values rEquatr = value[0] rPolar = value[2] # Calculate the flattening factor for earth f = (rEquatr - rPolar) / rEquatr # Calculate the geodetic coordinate on earth. lon,lat are in # radius. alt is the same unit with in put posITRF lon, lat, alt = spice.recgeo(posITRF, rEquatr, f) # Return longitude and latitude in degree lonDeg = spice.convrt(lon, "RADIANS", "DEGREES") latDeg = spice.convrt(lat, "RADIANS", "DEGREES") return lon, lonDeg, lat, latDeg, alt
def setUp(self): ### Load the kernel spice.furnsh( __file__ ) ### Convert MPC constants to CONICS_C elements ison = MPC_ISON_C_2012_S1() self.rpKM = spice.convrt( ison.qAU, 'AU', 'KM') self.ecc = ison.e self.incRAD = spice.convrt( ison.InclDEG, 'DEGREES', 'RADIANS') self.lnodeRAD = spice.convrt( ison.NodeDEG, 'DEGREES', 'RADIANS') self.argpRAD = spice.convrt( ison.PeriDEG, 'DEGREES', 'RADIANS') self.m0RAD = spice.convrt( ison.M0, 'DEGREES', 'RADIANS') self.t0 = spice.str2et( ison.T0_TDT[0] ) + spice.convrt( ison.T0_TDT[1], 'DAYS', 'SECONDS' ) self.mu = ison.MuM3S2 * 1e-9 self.elts = ( self.rpKM, self.ecc, self.incRAD, self.lnodeRAD, self.argpRAD, self.m0RAD, self.t0, self.mu ) self.ditime = spice.utc2et( '2013-01-16 12:00:00' )
def test_horizons(self): import horizons target = 'C/2013 S1' target = 'C/2011 L4' spkFilename,spiceId,status = horizons.gomain(target) spice.furnsh( spkFilename ) self.kernels += [spkFilename] target_ = '_'.join( target.split() ) et0 = spice.utc2et( '2013-01-10T12:00:00' ) ls2au = spice.convrt( spice.clight(), 'KM', 'AU' ) dpr = spice.dpr() spd = spice.spd() deltatime = None while deltatime is None or abs(deltatime) > 5e-7: stS2I,lsS2I = spice.spkgeo( spiceId, et0, 'J2000', 10 ) posn, veloc = stS2I[:3], stS2I[3:] deltatime = - spice.vdot( posn, veloc ) / spice.vdot( veloc, veloc ) et0 += deltatime valarrs = [ ] print( (deltatime,spice.et2utc(et0,'ISOC',3),) ) deltatime = 1.0 sixmonths = spice.pi() * 1e7 while deltatime < sixmonths: for pmdet in (-deltatime,deltatime): et = et0 + pmdet utc = spice.et2utc(et,'ISOC',1) stD2I,lsD2I = spice.spkgeo( spiceId, et, 'J2000', -140) stI2S,lsI2S = spice.spkgeo( 10, et, 'J2000', spiceId ) stD2S,lsD2S = spice.spkgeo( 10, et, 'J2000', -140 ) rD2I, rI2S = [ ls * ls2au for ls in [lsD2I,lsI2S] ] aDIS, aSDI = [ ang * dpr for ang in [ spice.vsep( spice.vminus(stD2I[:3]), stI2S[:-3] ) , spice.vsep( stD2S[:3], stD2I[:-3] ) ] ] valarrs += [ (et,pmdet,rD2I,rI2S,aDIS,aSDI,utc,) ] deltatime *= 1.2 valarrs.sort() for valarr in valarrs: print( '%12.1f %9.3f %9.3f %7.2f %7.2f %s' % valarr[1:] ) days = [i[1]/spd for i in valarrs] titles = [ i % (target_,) for i in """ Range, %s-DI, AU Range, %s-Sun, AU Phase, DI-%s-Sun, deg Elongation, Sun-DI-%s, deg """.strip().split('\n')] try: ### Moved matplotlib import to here so test runs to here at least from matplotlib import pyplot as plt plt.figure(1) for idx in range(len(titles)): ordinate = [i[idx+2] for i in valarrs] plt.subplot( 221+idx ) plt.plot( days, ordinate ) plt.plot( days, ordinate, '.') plt.title( titles[idx] ) plt.ylabel( titles[idx] ) if idx>1: plt.xlabel( 'T-Tperi, d' ) plt.show() except: print( "Bypassed, or failed, matplotlib tests" )
def test_horizons(self): import horizons target = 'C/2013 S1' target = 'C/2011 L4' spkFilename, spiceId, status = horizons.gomain(target) spice.furnsh(spkFilename) self.kernels += [spkFilename] target_ = '_'.join(target.split()) et0 = spice.utc2et('2013-01-10T12:00:00') ls2au = spice.convrt(spice.clight(), 'KM', 'AU') dpr = spice.dpr() spd = spice.spd() deltatime = None while deltatime is None or abs(deltatime) > 5e-7: stS2I, lsS2I = spice.spkgeo(spiceId, et0, 'J2000', 10) posn, veloc = stS2I[:3], stS2I[3:] deltatime = -spice.vdot(posn, veloc) / spice.vdot(veloc, veloc) et0 += deltatime valarrs = [] print(( deltatime, spice.et2utc(et0, 'ISOC', 3), )) deltatime = 1.0 sixmonths = spice.pi() * 1e7 while deltatime < sixmonths: for pmdet in (-deltatime, deltatime): et = et0 + pmdet utc = spice.et2utc(et, 'ISOC', 1) stD2I, lsD2I = spice.spkgeo(spiceId, et, 'J2000', -140) stI2S, lsI2S = spice.spkgeo(10, et, 'J2000', spiceId) stD2S, lsD2S = spice.spkgeo(10, et, 'J2000', -140) rD2I, rI2S = [ls * ls2au for ls in [lsD2I, lsI2S]] aDIS, aSDI = [ ang * dpr for ang in [ spice.vsep(spice.vminus(stD2I[:3]), stI2S[:-3]), spice.vsep(stD2S[:3], stD2I[:-3]) ] ] valarrs += [( et, pmdet, rD2I, rI2S, aDIS, aSDI, utc, )] deltatime *= 1.2 valarrs.sort() for valarr in valarrs: print('%12.1f %9.3f %9.3f %7.2f %7.2f %s' % valarr[1:]) days = [i[1] / spd for i in valarrs] titles = [ i % (target_, ) for i in """ Range, %s-DI, AU Range, %s-Sun, AU Phase, DI-%s-Sun, deg Elongation, Sun-DI-%s, deg """.strip().split('\n') ] try: ### Moved matplotlib import to here so test runs to here at least from matplotlib import pyplot as plt plt.figure(1) for idx in range(len(titles)): ordinate = [i[idx + 2] for i in valarrs] plt.subplot(221 + idx) plt.plot(days, ordinate) plt.plot(days, ordinate, '.') plt.title(titles[idx]) plt.ylabel(titles[idx]) if idx > 1: plt.xlabel('T-Tperi, d') plt.show() except: print("Bypassed, or failed, matplotlib tests")