"""Compare results of spktype01 and spktype21. @author: Shushi Uetsuki (whiskie14142) """ from spktype01 import SPKType01 from spktype21 import SPKType21 import numpy as np oname = 'Ryugu' spkid = 2162173 path01 = oname + '-01.bsp' path21 = oname + '-21.bsp' k01 = SPKType01.open(path01) k21 = SPKType21.open(path21) print('\nspktype01') print(k01) print('\nspktype21') print(k21) print() while (True): jd = float(input('Enter JD, or 999 to exit >> ')) if jd == 999.0: break else: print('\nspktype01') pos01, vel01 = k01.compute_type01(0, spkid, jd) print(pos01)
os.makedirs(fp_load) load = sf.Loader(fp_load, verbose=True) #load timescale object ts = load.timescale() #load almanac e = load('de421.bsp') earth = e['earth'] sun = e['sun'] print('Earth:', earth) print(' Sun:', sun) fp_bsp = '/'.join([cwd, cfg['data_path'], cfg['bsp_file']]) if not os.path.isfile(fp_bsp) == True: print('ERROR: Invalid BSP File: {:s}'.format(fp_bsp)) sys.exit() k21 = SPKType21.open(fp_bsp) spkid = k21.segments[0].target print(k21, type(k21)) print("Target ID:", spkid) #sys.exit() #setup ground station gs = sf.Topos(latitude_degrees=cfg['gs']['latitude'], longitude_degrees=cfg['gs']['longitude'], elevation_m=cfg['gs']['altitude']) print(cfg['gs']['name'], gs) t = ts.utc(datetime.datetime.now(datetime.timezone.utc)) #Now pos21, vel21 = k21.compute_type21(0, spkid, t.tt) #pos - km, vel km/s #pos21 = pos21 *u.km pos21 = pos21 / au2km #Convert poistion from km to AU
def spkfileselectclicked(self): ans = QFileDialog.getOpenFileName( parent=self, caption=self.winTtl_SPK, directory=os.path.join(common.bspdir), filter='SPK Files (*.bsp);;All Files (*.*)') ans = ans[0] if ans == '': return try: filename = os.path.relpath(ans, start=common.bspdir) except ValueError: filename = ans filepath = ans else: filepath = os.path.join(common.bspdir, filename) try: tempk = SPKType21.open(filepath) except ValueError: QMessageBox.critical(self, self.mbTtl01, self.mbMes01, QMessageBox.Ok) return self.ui.spkfilepath.setText(filename) self.ui.targetname.setText( os.path.splitext(os.path.basename(filename))[0]) # Check center of coordinates. it should be 0 center0 = tempk.segments[0].center if center0 != 0: mes = self.mbMes02.format(center0) QMessageBox.critical(self, self.mbTtl01, mes, QMessageBox.Ok) tempk.close() return self.center = center0 # Check data_type. it should be 1 or 21, and all segments has same type datatype0 = tempk.segments[0].data_type if datatype0 != 1 and datatype0 != 21: mes = self.mbMes03.format(datatype0) QMessageBox.critical(self, self.mbTtl01, mes, QMessageBox.Ok) tempk.close() return for seg in tempk.segments: if datatype0 != seg.data_type: QMessageBox.critical(self, self.mbTtl01, self.mbMes04, QMessageBox.Ok) tempk.close() return g.data_type = datatype0 # Prepare the combo-box of SPKID # idlist is a list of [SPKID] idlist = [tempk.segments[0].target] for seg in tempk.segments: found = False for i in range(len(idlist)): if idlist[i] == seg.target: found = True break if not found: idlist.append(seg.target) idlist.sort() combo = self.ui.spkid_list combo.clear() for spkid in idlist: combo.addItem(str(spkid)) combo.setCurrentIndex(0) tempk.close()
def __init__(self, parent=None, manplan=None): super().__init__(parent) self.manplan = manplan probe = self.manplan['probe'] target = self.manplan['target'] self.ui.probename.setText(probe['name']) self.ui.probemass.setText('{:.3f}'.format(probe['pmass'])) for ix in range(16): if common.bases[ix][0] == probe['base']: index = ix break self.ui.spacebase.setCurrentIndex(index) if target['file'] != '': self.ui.planetbutton.setChecked(False) self.ui.smallbodybutton.setChecked(True) self.ui.planets.setEnabled(False) self.ui.targetgroupbox.setEnabled(True) self.ui.targetname.setText(target['name']) self.ui.spkfilepath.setText(target['file']) temppath = target['file'] fname = os.path.basename(temppath) if temppath != '': if os.path.isabs(temppath): try: tempk = SPKType21.open(temppath) except FileNotFoundError: try: tempk = SPKType21.open( os.path.join(common.bspdir, fname)) except FileNotFoundError: QMessageBox.critical(self, self.mbTtl09, self.mbMes09.format(fname), QMessageBox.Ok) return else: temppath = os.path.join(common.bspdir, temppath) try: tempk = SPKType21.open(temppath) except FileNotFoundError: try: tempk = SPKType21.open( os.path.join(common.bspdir, fname)) except FileNotFoundError: QMessageBox.critical(self, self.mbTtl09, self.mbMes09.format(fname), QMessageBox.Ok) return idlist = [tempk.segments[0].target] for seg in tempk.segments: found = False for i in range(len(idlist)): if idlist[i] == seg.target: found = True break if not found: idlist.append(seg.target) idlist.sort() combo = self.ui.spkid_list combo.clear() for spkid in idlist: combo.addItem(str(spkid)) index = combo.findText(str(target['SPKID1B'])) combo.setCurrentIndex(index) tempk.close() else: for ix in range(12): if target['name'] == common.planets_id[ix][1]: for iy in range(10): if g.i_planetnames[iy][1] == ix: index = iy break break self.ui.planets.setCurrentIndex(index) self.center = target['SPKID1A'] self.setWindowTitle(self.winTtl_ET) self.ui.probe_box.setEnabled(False)
def __init__(self, name='Mars', file='', SPKID1A=0, SPKID1B=4, SPKID2A=0, SPKID2B=0): self.sbkernel = None if file == '': self.kernel = common.SPKkernel self.ephem = self.planets_ephem self.startjd = common.SPKstart self.endjd = common.SPKend else: filename = os.path.basename(file) mes = "Target's SPK file {0} is not found. Store it in 'SSVG_data' folder".format( filename) if g.data_type == 1: if os.path.isabs(file): try: self.sbkernel = SPKType01.open(file) except FileNotFoundError: try: self.sbkernel = SPKType01.open( os.path.join(common.bspdir, filename)) except FileNotFoundError: raise RuntimeError(mes) else: file = os.path.join(common.bspdir, file) try: self.sbkernel = SPKType01.open(file) except FileNotFoundError: try: self.sbkernel = SPKType01.open( os.path.join(common.bspdir, filename)) except FileNotFoundError: raise RuntimeError(mes) self.ephem = self.nasa_sb_type01 elif g.data_type == 21: if os.path.isabs(file): try: self.sbkernel = SPKType21.open(file) except FileNotFoundError: try: self.sbkernel = SPKType21.open( os.path.join(common.bspdir, filename)) except FileNotFoundError: raise RuntimeError(mes) else: file = os.path.join(common.bspdir, file) try: self.sbkernel = SPKType21.open(file) except FileNotFoundError: try: self.sbkernel = SPKType21.open( os.path.join(common.bspdir, filename)) except FileNotFoundError: raise RuntimeError(mes) self.ephem = self.nasa_sb_type21 else: raise RuntimeError("Illegal data_type: " + str(g.data_type)) # start time and end time of Target's SPK file # self.startjd is inclusive # self.endjd is exclusive self.startjd = common.SPKend self.endjd = common.SPKstart for seg in self.sbkernel.segments: if seg.center == SPKID1A and seg.target == SPKID1B: if self.startjd > seg.start_jd: self.startjd = seg.start_jd if self.endjd < seg.end_jd: self.endjd = seg.end_jd self.name = name self.idx1a = SPKID1A self.idx1b = SPKID1B self.idx2a = SPKID2A self.idx2b = SPKID2B return
#! /usr/bin/python3 from spktype01 import SPKType01 from spktype21 import SPKType21 import csv import numpy as np import datetime from skyfield import api as sf import time bspfiles = 'Ceres_Vesta.bsp' csvfiles = ['Ceres_jpl.csv', 'Vesta_jpl.csv'] testnames = ['Ceres', 'Vesta'] bodyids = [2000001, 2000004] dposlim = 1.0 # position difference limit = 1.0 kilometer dvellim = 1e-7 # velocity difference limit = 0.0001 m/s k21 = SPKType21.open('L1_2020_2021-21.bsp') spkid = k21.segments[0].target print(k21) print(spkid) ts = sf.load.timescale() while True: t = ts.utc(datetime.datetime.now(datetime.timezone.utc)) #Now print(t.tt) pos21, vel21 = k21.compute_type21(0, spkid, t.tt) print(pos21, vel21) time.sleep(1)
@author: Shushi Uetsuki (whiskie14142) """ from spktype21 import SPKType21 import csv import numpy as np bspfile = 'Ryugu-21.bsp' csvfile = 'RyuguEPH.csv' spkid = 2162173 dposlim = 1.0 # position difference limit = 1.0 kilometer dvellim = 1e-7 # velocity difference limit = 0.0001 m/s kernel = SPKType21.open(bspfile) print() print(kernel) csvfile = open(csvfile) print() print('No. JD p_dist(km) v_dist(km/s)\n') count = 0 for row in csv.reader(csvfile): count += 1 refjd = float(row[0]) refpos = np.array([float(row[2]), float(row[3]), float(row[4])]) refvel = np.array([float(row[5]), float(row[6]), float(row[7])]) spkpos, spkvel = kernel.compute_type21(0, spkid, refjd)