def __init__(self, Ls, idx): self.recordLines = Ls self.index = idx midpoint, radius = map(l2d, self.recordLines[:2]) self.window = stypes.SPICEDOUBLE_CELL(2) spice.scard(0, self.window) spice.wninsd(midpoint - radius, midpoint + radius, self.window)
def __init__(self, ephem_directory_in): #load SPICE try: import spiceypy as spice import spiceypy.utils.support_types as stypes except: print("spiceypy not available") self.mySPICEdriver = SpiceHandler(ephem_directory_in) self.mySPICEdriver.loadSpiceFiles() self.TDBFMT = 'DD-MON-YYYY HR:MN:SC.###### TDB ::TDB' self.start = 0 self.stop = 0 self.search_step_size = 120.0 self.SPICE_search_window = stypes.SPICEDOUBLE_CELL(1000000) self.results_window = stypes.SPICEDOUBLE_CELL(1000000) self.observer = 'EARTH' self.target = 'SUN' self.target_body_shape = 'ELLIPSOID' self.target_frame = 'IAU_SUN' self.occulting_bodies = [] self.aberration_correction = 'NONE' self.cumulative_results = {}
if "__main__" == __name__: # FURNSH the docstring above as a text kernel, # plus any other files on the command line, # and put values into kernel pool for arg in sys.argv: spice.furnsh(arg) # Get pairs of ET endpoints from kernel pool pts = list(spice.gdpool('PAIR_TIMES', 0, 100)) nPETs = len(pts) # Set or clear debug flag try: doDebug = True if spice.gcpool("DEBUG", 0, 1, 999)[0] else False except: doDebug = False # Allocate cell of SpiceDoubles pws = stypes.SPICEDOUBLE_CELL(nPETs) # Add ET endpoints to cell pts.reverse() while pts: spice.appndd(pts.pop(), pws) # Convert those pairs of ET endpoints into confinement window pws = spice.wnvald(nPETs, nPETs, pws) assert (spice.wncard(pws) << 1) == nPETs pts = list(spice.gdpool('PAIR_TIMES', 0, 100)) # Get the filename of, and read, the input XFR file filename = spice.gcpool("XPC_KERNEL", 0, 1, 999)[0] assert filename # Read transfer file as XpcFile object xpcFileIn = XpcFile(fnIn=filename) if doDebug: import pprint
def core(): class SpiceVariables: obs = '-74' # NAIF code for MEX target = 'MARS ODYSSEY' # NAIF code for TGO ['EARTH'/'SUN'/ a groundstation etc] obsfrm = 'IAU_MARS' abcorr = 'NONE' crdsys = 'LATITUDINAL' coord = 'LATITUDE' stepsz = 100.0 # Check every 300 seconds if there is an occultation MAXILV = 100000 #Max number of occultations that can be returned by gfoclt bshape = 'POINT' fshape = 'DSK/UNPRIORITIZED' front = 'MARS' fframe = 'IAU_MARS' TFMT = 'YYYY-MM-DD HR:MN:SC' # Format that Cosmographia understands sv = SpiceVariables() #-----------------------------------------------------<VALUES TO EDIT REGULARLY>---------------------------------------- # If you only wish to analysis mutual [cross-link] occultation between MEX and TGO, then this is the only section that # needs to be edited start = '2020 MAR 1' stop = '2020 MAR 3' OCCSELECTION = 17 # Which occultation do you wish to see in Cosmographia? [optional] here = path.abspath(path.dirname(__file__)) PathtoMetaKernel1 = here + '/TGO/krns/mk/em16_plan.tm' PathtoMetaKernel2 = here + '/MEX/krns/mk/MEX_OPS.tm' #----------------------------------------------------------------------------------------------------------------------- spice.furnsh(PathtoMetaKernel1) spice.furnsh(PathtoMetaKernel2) sv = SpiceVariables() # Setting Variables ingresslist = np.array([1.0], dtype=float) etbeg = spice.str2et(start) etend = spice.str2et(stop) # Form a windows that gfoclt can populate window = stypes.SPICEDOUBLE_CELL(2) spice.wninsd(etbeg, etend, window) occwindow = stypes.SPICEDOUBLE_CELL(sv.MAXILV) #find occultation windows between the dates listed above [ most comp cost in this function] spice.gfoclt('ANY', sv.front, sv.fshape, sv.fframe, sv.target, sv.bshape, 'J2000', sv.abcorr, sv.obs, sv.stepsz, window, occwindow) winsiz = spice.wncard(occwindow) # Find cardinality (number of windows) #initialize lists to form dataframe lon, lat, dist, sza, angle = (np.ones(winsiz - 1) for i in range(5)) # Enter the ingress epochs into a dataframe occlist = np.ones((winsiz, 3)) for i in range(winsiz): [ingress, egress ] = spice.wnfetd(occwindow, i) # extract the begining and ends of the windows if i == 1: ingresslist = ingress else: ingresslist = np.append(ingresslist, [ingress]) occs = pd.DataFrame(ingresslist, columns=['Time']) occ = occs.Time[OCCSELECTION] return occ # sv = main.SpiceVariables() # occ = core() #print("strange result:", occ) # #print(result) # #form the dataframe # length = 120 # occs = pd.DataFrame(ingresslist, columns=['Time']) # residualdoppler = np.zeros(length) # velocitydoppler = np.zeros(length) # RESIDUALSUM = np.zeros(length) # #Calculate the residual doppler as the sum of the neutral and ionosphere # tic = timer.perf_counter() # for time in tqdm(range(length)): #begin time at occultation epoch and go to 2 mins pior # ray, dist, totalperiods, remainingdistance = main.producegeometrylamda(occs.Time[OCCSELECTION], sv, time*8)# Produce geometry in wavelenghts to investigate electric distance # _,_,_,_, alt = main.Location(occs.Time[OCCSELECTION], sv, time*8) # ionoresidual = atmosphere.iono(ray[2,:],totalperiods) # neutralresidual = atmosphere.neutral(ray[2,:],totalperiods) # residual = 1 + (ionoresidual + neutralresidual) # # plt.plot(range(totalperiods),residual[0,:]) # # plt.title("Refractive Index through Propergation of Ray") # # plt.xlabel("MEX->TGO distance (km)") # # plt.ylabel("Refractive Index") # # plt.show() # #DO A TEST TO SEE IF THE NET REFRACTIVE INDEX CHANGES OVER TIME, THEN U CAN HONE IN ON THE ERRRO # # account for the plus 1 # [electricdistance, geometric, resdopplershift] = main.doppler(residual, totalperiods, dist, remainingdistance) # miss = electricdistance - dist + remainingdistance # a possitive number as electric distance is greater that geometric due to iono # howwrongurcodeis = geometric - dist # is this purly due to rounding of that 9945 (each 1 is ~685 m) # residualdoppler[time] = resdopplershift # #find the geometric doppler too UNTESTED MODULE # sc2scstates = spice.spkezr(sv.target, (occs.Time[OCCSELECTION] - time*8), sv.fframe, 'LT+S', sv.obs) # velocityvector = sc2scstates[0][3:6] # velocityvector = velocityvector[0:3] # positionalvector = sc2scstates[0][0:3] # positionalvector = positionalvector[0:3] # velocityangle = spice.vsep( positionalvector, velocityvector) #rads # relativevelocity = np.linalg.norm(velocityvector) * np.cos(velocityangle) # geometricdopplershift = -(relativevelocity/constants.c) * 437.1e6 # velocitydoppler[time] = geometricdopplershift *1000 # becuase spice is in km and c is in m # toc = timer.perf_counter() # passingtime = toc-tic # print('elapsed time in seconds:', passingtime) # noise = np.random.normal(0,50,velocitydoppler.shape) # RESIDUALSUM = residualdoppler + velocitydoppler + noise # fig, ax = plt.subplots(3) # ax[0].plot(range(-960,0,8),velocitydoppler[: : -1] ) # ax[0].set_title('Geometric', loc='left') # ax[0].set_xlabel('Time after Occ (s)') # ax[0].set_ylabel('Doppler Shift (Hz)') # ax[1].plot(range(-960,0,8),residualdoppler[: : -1] ) # ax[1].set_title('Residual', loc='left') # ax[1].set_xlabel('Time after Occ (s)') # ax[1].set_ylabel('Doppler Shift (Hz)') # ax[2].plot(range(-960,0,8),RESIDUALSUM[: : -1]) # ax[2].set_title('Product + Noise', loc='left') # ax[2].set_xlabel('Time to Horizon Epoch (s)') # ax[2].set_ylabel('Doppler Shift (Hz)') # plt.show() # #then add noise
def test_empty_spice_cell_slicing(): test_cell = stypes.SPICEDOUBLE_CELL(1) assert test_cell[0:1] == []
def spk_coverage(self, path, id=-5440): """Get start and end ephemeris times for a SPK file.""" coverage = stypes.SPICEDOUBLE_CELL(2) spice.spkcov(path, id, coverage) return spice.wnfetd(coverage, 0)
def test_EmptySpiceCellSlicing(): testCell = stypes.SPICEDOUBLE_CELL(1) assert testCell[0:1] == []
# positionalvector = positionalvector[0:3] # velocityangle = spice.vsep( positionalvector, velocityvector) #rads # relativevelocity = np.linalg.norm(velocityvector) * np.cos(velocityangle) # geometricdopplershift[time] = -(relativevelocity/constants.c) * 437.1e9 #conversion from km to m # pd.DataFrame(geometricdopplershift).to_csv("geometricdopplershift.csv") # Setting Variables ingresslist = np.array([1.0], dtype=float) egresslist = np.array([1.0], dtype=float) etbeg = spice.str2et(start) etend = spice.str2et(stop) # Form a windows that gfoclt can populate window = stypes.SPICEDOUBLE_CELL(2) spice.wninsd(etbeg, etend, window) occwindow = stypes.SPICEDOUBLE_CELL(sv.MAXILV) # find occultation windows between the dates listed above [ most comp cost in this function] spice.gfoclt('ANY', sv.front, sv.fshape, sv.fframe, sv.target, sv.bshape, '', sv.abcorr, sv.obs, sv.stepsz, window, occwindow) winsiz = spice.wncard(occwindow) # Find cardinality (number of windows) # initialize lists to form dataframe lon, lat, dist, sza, angle = (np.ones(winsiz - 1) for i in range(5)) # Enter the ingress epochs into a dataframe occlist = np.ones((winsiz, 3)) for i in range(winsiz):