def eqHistograms(data): import matplotlib.pyplot as plt import numpy as np import cartopy.crs as ccrs import spiceypy as spice from matplotlib.backends.backend_pdf import PdfPages #Turn the ephemeris time into Universal Time. calet = spice.etcal(data[0][0]) #Get the data for the Earthquake magnitude, Earthquake latitude #and Earthquake longitude. mag = data[:, 1].copy() lat = data[:, 2].copy() lon = data[:, 3].copy() #Plot a histogram of the magnitude of the earthquakes. outfilepath = '/home/jdw/UM2019Autumn/M561/Project/' outfile = outfilepath + 'Plots/EQMagHist.pdf' n, bins, patches = plt.hist(mag, 25, density=1, facecolor='g') plt.xlabel('Magnitude') plt.ylabel('Probability') plt.title('Histogram of Earthquake Magnitude') plt.grid(True) #Save the plot to a file. plt.savefig(outfile) #Plot a histogram of the latitude of the earthquakes. outfile = outfilepath + 'Plots/EQLatHist.pdf' n, bins, patches = plt.hist(lat, 50, density=1, facecolor='g', alpha=0.75) plt.xlabel('Latitude') plt.ylabel('Probability') plt.title('Histogram of Earthquake Latitude') plt.axis([-90, 90, 0, 0.03]) plt.grid(True) #Save the plot to a file. plt.savefig(outfile) #Plot a histogram of the longitude of the earthquakes. outfile = outfilepath + 'Plots/EQLongHist.pdf' n, bins, patches = plt.hist(lon, 50, density=1, facecolor='g', alpha=0.75) plt.xlabel('Longitude') plt.ylabel('Probability') plt.title('Histogram of Earthquake Longitude') plt.axis([-180, 180, 0, 0.02]) plt.grid(True) #Save the plot to a file. plt.savefig(outfile)
def UTC2PCKKernelDate(time,target): #UTC is: YYYY - MM - DD T hr:min:sec #PCK kernel is: DDMonthYYYY - ex: 11Jun2004 et = UTC2ET(time, target) date = spice.etcal(et) YYYY = date[0:4] Month = date[5:8].lower() DD = date[9:11] mon = Month.capitalize() kernelDate = DD+mon+YYYY return kernelDate
### Find ET of spring equinox wrt Solar System Barycenter (SSB) & earth cnfine = sp.utils.support_types.SPICEDOUBLE_CELL(2) result = sp.utils.support_types.SPICEDOUBLE_CELL(200) sp.wninsd(0., sp.pi() * .5e7, cnfine) r = sp.gfposc(ssb, j2000, none, earth, ra_dec, declination, equals, 0., 0., 10 * sp.spd(), 200, cnfine, result) ### Get SSB->Earth and Earth->SSB vectors at that time et = sp.wnfetd(result, 0)[0] ssb2e = sp.spkezr(earth, et, j2000, none, ssb)[0] e2ssblt = sp.spkezr(ssb, et, j2000, LT, earth)[0] if do_debug: ### N.B. Light-time correction on Earth->SSB will have no effect print( dict( etcal=sp.etcal(et, 99), ssb2earth_au=sp.vscl(aupkm, ssb2e[:3]), earth2ssb_au=sp.vscl(aupkm, e2ssblt[:3]), )) assert 0.0 == sp.vnormg(sp.vaddg(ssb2e, e2ssblt, 6), 6) ### Get a star (ra,dec,parallax) near the pole with parallax > 10mas/y cn = sl3.connect(gaia_db) cu = cn.cursor() cu.execute(""" SELECT gr.idoffset ,gl.ra ,gl.dec ,gl.parallax FROM gaiartree as gr INNER JOIN gaialight as gl
etStart, etStop = et0 - 10e-3, et0 + spd - 10e-3 sp.wninsd(etStart, etStop, cnfine) ### Find local minima using SPICE Geometry Finder sp.gfpa(sClock, sMinute, "NONE", sHour, "LOCMIN", 1e-6, 0.0, spm, 6000, cnfine, result) ### Confirm that 22 minima were found assert 22 == sp.wncard(result) print('SP-Kernel passed [{}-alignments per day] test'.format( sp.wncard(result))) ### Optional logging if doDebug: print('Alignments between {} and {}:'.format( sp.etcal(etStart + 0.0005, 99), sp.etcal(etStop + 0.0005, 99))) for iWin in range(sp.wncard(result)): left, right = sp.wnfetd(result, iWin) print(' {}: {}'.format(iWin, sp.etcal(left + 0.0005, 99))) ### Repeat with extra time cnfine = sp.stypes.SPICEDOUBLE_CELL(2) etStop = et0 + spd + 10e-3 sp.wninsd(etStart, etStop, cnfine) ### Find local minima sp.gfpa(sClock, sMinute, "NONE", sHour, "LOCMIN", 1e-6, 0.0, spm, 6000, cnfine, result) ### Confirm that 23 minima were found assert 23 == sp.wncard(result)
lastEt = d[bn][target][-1][1] if et == lastEt: continue assert et > lastEt delEt = et - lastEt if delEt > ninetyDaysPlus: d[bn][target].append([et, et, 0]) continue d[bn][target][-1][1] = et d[bn][target][-1][2] = (et - d[bn][target][-1][0]) / 864e3 if doDebug: pprint.pprint(d, stream=sys.stderr) print('LEAPSECONDS_KERNEL = naif0012.tls') print('SPK_KERNEL = allspk.bsp') for bn in d: dbn = d[bn] path = dbn['path'] for target in dbn: if target == 'path': continue for dbntn in dbn[target]: print(' SOURCE_SPK_KERNEL = {}'.format(bn)) print(' BODIES = {}'.format(target)) print(' BEGIN_TIME = {} TDB'.format(sp.etcal(dbntn[0] - 600))) print(' END_TIME = {} TDB'.format(sp.etcal(dbntn[1] + 600)))
def ET2Date(ET): #At the end for readability in plots, may not be needed date = spice.etcal(ET) return(date)
def polarplot(data): import matplotlib.pyplot as plt import numpy as np import math import cartopy.crs as ccrs import spiceypy as spice from matplotlib.backends.backend_pdf import PdfPages #Get the data for the Earthquake magnitude, Earthquake latitude #and Earthquake longitude. mag = data[:, 1].copy() lat = data[:, 2].copy() lon = data[:, 3].copy() #Plot a histogram of the magnitude of the earthquakes. outfilepath = '/home/jdw/UM2019Autumn/M561/Project/' outfile = outfilepath + 'Plots/GlobalEqPlanetLocation.png' #Find the number of rows in the data matrix. nRows = data.shape[0] print(nRows) #Allocate an array of distances for each planet for each earthquake. LatPlanet = np.zeros((nRows, 10), dtype='float64') LonPlanet = np.zeros((nRows, 10), dtype='float64') #Allocate vectors of earthquake latitudes and longitudes. EQLat = np.zeros((nRows), dtype='float64') EQLon = np.zeros((nRows), dtype='float64') calet = [0] * nRows for i in range(nRows): #Turn the ephemeris time into Universal Time. calet[i] = spice.etcal(data[i][0]) EQLat[i] = data[i, 2] #given in degrees. EQLon[i] = data[i, 3] #given in degrees. for j in range(10): index = 25 + j * 28 LatPlanet[i, j] = data[i, index] #given in degrees. LonPlanet[i, j] = data[i, index + 1] #given in degrees. #Choose some times to look at earthquakes. time_vec = [300, 900, 1500, 2100, 2700] plt.figure() # plt.gcf() ax = plt.axes(projection=ccrs.Mollweide()) ax.coastlines() ax.stock_img() titlestr = (r"Earthquake and Planet Locations for " + "\n" + "M = " + str(data[300, 1]) + " Earthquake on " + "\n" + calet[300]) #Plot the location of the earthquake. plt.scatter(EQLon[300], EQLat[300], color='red', marker='o', transform=ccrs.Geodetic()) plt.title(titlestr) #Plot the locations of the planets. plt.scatter(LatPlanet[300, -10:], LonPlanet[300, -10:], color='blue', marker='o', transform=ccrs.Geodetic()) #Enter some text plt.text(EQLon[300] - 1, EQLat[300] - 10, 'Earthquake', horizontalalignment='right', color='red', transform=ccrs.Geodetic()) plt.text(LatPlanet[300, 0] - 6, LonPlanet[300, 0] - 12, 'Sun', horizontalalignment='left', transform=ccrs.Geodetic()) plt.text(LatPlanet[300, 1] + 2, LonPlanet[300, 1] + 4, 'Mercury', horizontalalignment='left', transform=ccrs.Geodetic()) plt.text(LatPlanet[300, 2] + 1, LonPlanet[300, 2] - 6, 'Venus', horizontalalignment='left', transform=ccrs.Geodetic()) plt.text(LatPlanet[300, 3] + 3, LonPlanet[300, 3] - 12, 'Moon', horizontalalignment='left', transform=ccrs.Geodetic()) plt.text(LatPlanet[300, 4] + 3, LonPlanet[300, 4] + 4, 'Mars', horizontalalignment='left', transform=ccrs.Geodetic()) plt.text(LatPlanet[300, 5] - 3, LonPlanet[300, 5] - 12, 'Jupiter', horizontalalignment='left', transform=ccrs.Geodetic()) plt.text(LatPlanet[300, 6] + 2, LonPlanet[300, 6] + 3, 'Saturn', horizontalalignment='left', transform=ccrs.Geodetic()) plt.text(LatPlanet[300, 7] + 3, LonPlanet[300, 7] - 12, 'Uranus', horizontalalignment='left', transform=ccrs.Geodetic()) plt.text(LatPlanet[300, 8] + 3, LonPlanet[300, 8] - 12, 'Neptune', horizontalalignment='left', transform=ccrs.Geodetic()) plt.text(LatPlanet[300, 9] + 3, LonPlanet[300, 9] - 12, 'Pluto', horizontalalignment='left', transform=ccrs.Geodetic()) #Save the plot to a file. plt.savefig(outfile)
def do_main(argv): sp.kclear() halfpi, dpr = sp.halfpi(), sp.dpr() fnck = 'out.bc' target = 'TEMPEL 1' frame = 'DIF_SPACECRAFT' for arg in argv: if arg.startswith('--ck='): fnck = arg[5:] elif arg.startswith('--target='): target = arg[9:] elif arg.startswith('--k='): sp.furnsh(arg[4:]) else: assert False, 'Unknown argument [{0}]'.format(arg) frameid = sp.gipool('FRAME_{0}'.format(frame), 0, 1)[0] scid = sp.gipool('CK_{0}_SPK'.format(frameid), 0, 1)[0] scname = sp.bodc2s(scid, 99) cover = sp.stypes.SPICEDOUBLE_CELL(200) sp.scard(0, cover) cover = sp.ckcov(fnck, frameid, False, "INTERVAL", 0.0, "TDB") sp.furnsh(fnck) vbore = sp.vpack(-1, 0, 0) vorbitnorm = sp.vpack(0, 1, 0) for ipair in range(sp.wncard(cover)): et0, etend = sp.wnfetd(cover, 0) etlast, ettca, niter = et0, (et0 + etend) * 0.5, 0 while ettca != etlast and niter < 20: etlast = ettca state6 = sp.spkezr(target, ettca, "j2000", "none", scname)[0] vpos, vvel = state6[:3], state6[3:] det = sp.vdot(vvel, vpos) / sp.vdot(vvel, vvel) ettca -= det niter += 1 print(dict( TCAtdb=sp.etcal(ettca, 99), niter=niter, )) et = et0 ets, boreerrs, orbitnormerrs = list(), list(), list() while et <= etend: state6 = sp.spkezr(target, et, frame, "none", scname)[0] vpos, vvel = state6[:3], state6[3:] ets.append(et - et0) boreerrs.append(dpr * sp.vsep(vbore, vpos)) orbitnormerrs.append(dpr * (sp.vsep(vbore, vorbitnorm) - halfpi)) et += max([0.01, 0.1 * abs(cos(sp.vsep(vpos, vvel)))]) try: plt.plot(ets, orbitnormerrs, 'o', label='Orbit normal error') plt.plot(ets, boreerrs, 'o', label='Boresight error') plt.axvline(ettca - et0, label='TCA') plt.xlabel('Time, s past {0} TDB'.format(sp.etcal(et0, 99))) plt.ylabel('Error, deg') plt.legend(loc='best') plt.show() except: if do_debug: import traceback as tb tb.print_exc() print(boreerrs[::1000]) print(orbitnormerrs[::1000])