示例#1
0
def inter_bokeh():
    epoch2000=datetime.datetime.strptime("01-01-2000 00:00","%d-%m-%Y %H:%M")
    epoch2000=time.mktime(epoch2000.timetuple())
    lat=request.args.get('lat')
    long=request.args.get('lon')
    spkid=request.args.get('spkid')
    inicio=request.args.get('start')
    neo=spkid+".bsp"
    N=200
    spi.kclear()
    spi.furnsh("/home/cristobal/horizons_iterface/github/neo-challege-2016/spice/meta.fgl")
    spi.furnsh("/home/cristobal/horizons_iterface/github/neo-challege-2016/spice/kernels/neos/"+neo)
    inicio=inicio.replace("Z","").replace("T"," ")
    final= dateutil.parser.parse(inicio)+datetime.timedelta(days=0.5)
    final=str(final.year)+"-"+str(final.month).zfill(2)+"-"+str(final.day).zfill(2)+" "+str(final.hour).zfill(2)+":"+str(final.minute).zfill(2)+":"+str(final.second).zfill(2)+"."+str(final.microsecond)
    tiempos=spi.str2et([inicio,final])
    tiempos=np.linspace(tiempos[0],tiempos[1],N)
    ar=list()
    dec=list()
    times_list=list()
    for k in tiempos:
            temp=spi.spkez(int(neo.split(".")[0]),k,"J2000","LT+S",399)
            temp2=spi.recrad(temp[0][0:3])
            ar.append(temp2[1]*(180/np.pi))
            dec.append(temp2[2]*(180/np.pi))
            times_list.append(datetime.datetime.utcfromtimestamp(k+epoch2000))
    [altura,times_list]=conversion(ar,dec,times_list,lat,long)
    json.dumps(altura)
    bokeh_pinta(altura,list,neo)
    return app.send_static_file('spice.html')
def calc_spice(initi,final,neo,puntos,db):
	N=puntos#2880 #Precision 
	spi.kclear() #Limpiamos el pool de los kernels.
	#MetaKernel con los datos genericos menos el neo.
	spi.furnsh("./meta.fgl")
	spi.furnsh("./kernels/neos/"+neo)
	#tiempos=spi.str2et(["Jun 20 2004","Dec 1, 2005"])
	ini=initi#"Apr 24 2016 0:00:00"
	fin=final#"Jun 20 2016 0:00:00"
        #Fran: It would be better to directly put the number of seconds of J2000 instead of this shit...
        epoch2000=datetime.datetime.strptime("01-01-2000 00:00","%d-%m-%Y %H:%M")
	epoch2000=time.mktime(epoch2000.timetuple())
        tiempos=spi.str2et([ini,fin])
	tiempos=np.linspace(tiempos[0],tiempos[1],N) 
	ar=list()
	dec=list()
        #pdb.set_trace()
	for k in tiempos:
		temp=spi.spkez(int(neo.split(".")[0]),k,"J2000","LT+S",399)
                temp2=spi.recrad(temp[0][0:3])
		ar.append(temp2[1]*(180/np.pi))
		dec.append(temp2[2]*(180/np.pi))
        for k in range(len(tiempos)):
            document={"spkid":neo.split(".")[0],"name":neo.split(".")[0],"ra":ar[k],"dec":dec[k],"date":datetime.datetime.fromtimestamp(int(tiempos[k])+epoch2000)}
            day=str(document["date"].day).zfill(2)+str(document["date"].month).zfill(2)+str(document["date"].year)
            day="d"+day
            exec("db.%s.insert_one(document)"%day)
def main():
	neo="2000433.bsp"
        N=200
	ini="Apr 24 2016 0:00:00"
	fin="Apr 25 2016 0:00:00"
        ALT=390	
	LAT=40.123
	LONG=-3.70
        obser=EarthLocation(lat=LAT*u.deg,lon=LONG*u.deg,height=ALT*u.m)
#===================================================
        epoch2000=datetime.datetime.strptime("01-01-2000 00:00","%d-%m-%Y %H:%M")
        epoch2000=time.mktime(epoch2000.timetuple())
#===================================================
	spi.kclear() 
	spi.furnsh("./meta.fgl")
	spi.furnsh("./../kernels/neos/"+neo)
	tiempos=spi.str2et([ini,fin])
	tiempos=np.linspace(tiempos[0],tiempos[1],N) 
	alt_list=list()
        times_list=list()
        for k in tiempos:
		temp=spi.spkez(int(neo.split(".")[0]),k,"J2000","LT+S",399)
                temp2=spi.recrad(temp[0][0:3])
		ar=(temp2[1]*(180/np.pi))
		dec=(temp2[2]*(180/np.pi))
                aux=datetime.datetime.utcfromtimestamp(k+epoch2000)
                fechas_aux=((str(aux.year)+"-"+str(aux.month).zfill(2)+"-"+str(aux.day).zfill(2)+" "+str(aux.hour).zfill(2)+":"+str(aux.minute).zfill(2)+":"+str(aux.second).zfill(2)+"."+str(aux.microsecond)))
                times_list.append(aux)
                fechas_aux=Time(fechas_aux)
                frames_loc=AltAz(obstime=fechas_aux,location=obser)
                #pdb.set_trace()
                alt_list.append((SkyCoord(ra=ar*u.deg,dec=dec*u.deg,frame='icrs')).transform_to(frames_loc).alt.value)

        #pdb.set_trace()
        
	output_file("spice.html",title="NEO SOURCE")
        p=figure(title="NEO Visual",x_axis_label="Time",tools="pan,box_zoom,reset,save,hover",y_axis_label="Elevation (deg)")
	p.line(times_list,alt_list,legend=neo)
        hover=p.select_one(HoverTool)
        hover.point_policy="follow_mouse"

	show(p)
def main():
	N=1000#1000 #Precision 
	spi.kclear() #Limpiamos el pool de los kernels.
	#MetaKernel con los datos.
	spi.furnsh("./meta.fgl")
	#tiempos=spi.str2et(["Jun 20 2004","Dec 1, 2005"])
	tiempos=spi.str2et(["Jun 20 2004","Feb 1, 2005"])	
	tiempos=np.linspace(tiempos[0],tiempos[1],N) 

	#pdb.set_trace() #Esto es lo mas fino que he llegado: 
	#try:
	a=list()
	#Chapuza metida tras sacar velocidad
	#=====================================
	x=list()
	y=list()
	z=list()
	dx=list()
	dy=list()
	dz=list()
	#=============
	for k in tiempos:
		#temp=spi.spkez(-82,k,"IAU_EARTH","None",399)
		temp=spi.spkez(2000433,k,"IAU_EARTH","None",399)
		x.append(temp[0][0]) #Este ya devuelve el vector completo
		y.append(temp[0][1])
		z.append(temp[0][2])		
		dx.append(temp[0][3]) #Este ya devuelve el vector completo
		dy.append(temp[0][4])
		dz.append(temp[0][5])

	x=np.array(x)
	y=np.array(y)
	z=np.array(z)
	dx=np.array(dx)
	dy=np.array(dy)
	dz=np.array(dz)
	mdscc=station(0)
	#===========================	====	
	print "Geocentric position for MDSCC:"	
	print "----------------------------------"
	print mdscc
	print "----------------------------------"
	if False:
		a=np.array(a)
		x=list()
		y=list()
		z=list()
		for k in a[0]:
			x.append(k[0])
			y.append(k[1])
			z.append(k[2])

	#Tenia el dato referedio al centro de masas de la Tierra. Ahora lo refiero a MDSCC.
	x=x-mdscc[0]
	y=y-mdscc[1]
	z=z-mdscc[2]

	plt.figure()
	plt.subplot(211)
	plt.plot(x,y)
	plt.xlabel("x [Km]")
	plt.ylabel("y [Km]")
	plt.subplot(212)
	plt.plot(y,z)
	plt.xlabel("y Km")
	plt.ylabel("z Km")
	plt.figure()
	plt.plot(dist(dx,dy,dz))
	plt.title("Relative speed as seen from Robledo to Eros")
	plt.ylabel("Kilometers")
	plt.xlabel("Samples")
	plt.grid()
	fig=plt.figure()
	ax=fig.add_subplot(111,projection='3d')
	ax.plot(x,y,z,label="Eros to Robledo de Chavela")
	plt.legend()
	plt.show()
def main():
	antes=datetime.datetime.now()
	N=100 #Precision 
	spi.kclear() #Limpiamos el pool de los kernels.
	#MetaKernel con los datos.
	spi.furnsh("./meta.fgl")
	#tiempos=spi.str2et(["Jun 20 2004","Dec 1, 2005"])
	ini="Apr 20 2016 0:00:00"
	fin="Apr 20 2017 0:00:00"
	
	tiempos=spi.str2et([ini,fin])
	
	tiempos=np.linspace(tiempos[0],tiempos[1],N) 
	#tiempos=spi.str2et(["Apr 20 2016 0:00:00"])
	#pdb.set_trace()		
	#pdb.set_trace() #Esto es lo mas fino que he llegado: 
	#try:
	a=list()
	#Chapuza metida tras sacar velocidad
	#=====================================
	x=list()
	y=list()
	z=list()
	dx=list()
	dy=list()
	dz=list()
	#=============
	#Test para spaceapps
	#colat=list()
	#longi=list()
	#radio=list()
	ar=list()
	dec=list()
	radio=list()
	ayuda=list()
	#Test para spaceapps (end)
	for k in tiempos:
		#temp=spi.spkez(2000433,k,"IAU_EARTH","LT+S",399)
		temp=spi.spkez(2000433,k,"J2000","LT+S",399)
		#temp2=spi.xfmsta(temp[0],'RECTANGULAR','SPHERICAL',399)
		temp2=spi.recrad(temp[0][0:3])

		#radio.append(temp2[0])
		#colat.append(temp2[1])
		#longi.append(temp2[2])
		radio.append(temp2[0])
		ayuda.append(temp2)
		ar.append(temp2[1]*(180/np.pi))
		dec.append(temp2[2]*(180/np.pi))
		x.append(temp[0][0]) #Este ya devuelve el vector completo
		y.append(temp[0][1])
		z.append(temp[0][2])		
		dx.append(temp[0][3]) #Este ya devuelve el vector completo
		dy.append(temp[0][4])
		dz.append(temp[0][5])
		
	despues=datetime.datetime.now()
	
	#spi.xfmtsta(temp[0],'RECTANGULAR','SPHERICAL',399)
	pdb.set_trace() # despues-antes
	x=np.array(x)
	y=np.array(y)
	z=np.array(z)
	dx=np.array(dx)
	dy=np.array(dy)
	dz=np.array(dz)
	mdscc=station(0)
	#===========================	====	
	print "Geocentric position for MDSCC:"	
	print "----------------------------------"
	print mdscc
	print "----------------------------------"
	if False:
		a=np.array(a)
		x=list()
		y=list()
		z=list()
		for k in a[0]:
			x.append(k[0])
			y.append(k[1])
			z.append(k[2])

	#Tenia el dato referedio al centro de masas de la Tierra. Ahora lo refiero a MDSCC.
	x=x-mdscc[0]
	y=y-mdscc[1]
	z=z-mdscc[2]

	#data2=list()	
	#for k in range(len(x)):
	#	data2.append(spi.recrad([x[k],y[k],z[k]]))
	#data2=np.array(data2)
	pdb.set_trace()
	plt.figure()
	plt.subplot(211)
	plt.plot(x,y)
	plt.xlabel("x [Km]")
	plt.ylabel("y [Km]")
	plt.subplot(212)
	plt.plot(y,z)
	plt.xlabel("y Km")
	plt.ylabel("z Km")
	plt.figure()
	plt.plot(dist(dx,dy,dz))
	frase="Relative speed as seen from Robledo to Eros from %s to %s"%(ini,fin)
	plt.title(frase)
	plt.ylabel("Kilometers")
	plt.xlabel("Samples")
	plt.grid()
	fig=plt.figure()
	ax=fig.add_subplot(111,projection='3d')
	frase="Distance from Eros to Robledo. Starting: %s End: %s"%(ini,fin)
	ax.plot(x,y,z,label=frase)
	plt.legend()
	plt.show()