Package: hypatie
Author:Behrouz SafariLicense:MIThypatieA python package for astronomical calculationsInstallationInstall the latest version ofhypatiefromPyPI:pip install hypatieRequirements arenumpy,pandasandmatplotlib.NASA JPL's HorizonsLet's get the positions of the sun between two times:importhypatieashpt1='2021-03-20 08:00:00't2='2021-03-20 10:00:00'If you want the apparent RA and DEC of the Sun with respect to Earth's center (geocentric):obs=hp.Observer('sun',t1,t2,step=5)Now you can access the time intervals with.timeattribute:print(obs.time)[datetime.datetime(2021,3,20,8,0)datetime.datetime(2021,3,20,8,24)datetime.datetime(2021,3,20,8,48)datetime.datetime(2021,3,20,9,12)datetime.datetime(2021,3,20,9,36)datetime.datetime(2021,3,20,10,0)]To acces the position you can useobs.pos,obs.ra, orobs.dec:print(obs.pos)[[3.59938235e+02-2.66803120e-02][3.59953431e+02-2.00920520e-02][3.59968627e+02-1.35038600e-02][3.59983823e+02-6.91573600e-03][3.59999018e+02-3.27680000e-04][1.42132560e-026.26030600e-03]]The first column in the above array is RA and the second column is DEC.It is possible to get the apparent RA & DEC of a targer with respect to a specified location on the surface of a body.
For example, if you want to get the apparent RA & DEC of the Sun for the Eiffel Tower :obs=hp.Observer('sun',t1,t2,step=5,center='2.2945,48.8584,300@399')Note that 2.2945 is the longtitude, 48.8584 is the latitude and 300 (meters) is the elevation of the Eiffel Tower.
We have specified '@399' at the end which means that this coordinates is situated on the Earth (399 is the Earth's code).You can request the cartesian positions (x,y,z) of a target withVectorclass.vec=hp.Vector('sun',t1,t2,step=5)As with theObserverclass, there are two attributes.timeand.posforVectorclass.
Note that when creating a Vector class, you have.x,.yand.zattributes instead of.raand.dec.For bothVectorandObserverclasses you can pass a single time to get position/state of a body at a single time:vec=hp.Vector('sun',t1)BothVectorandObserverclasses have.plot()method.# plot polar coordinatesobs.plot()# plot cartesian coordinatesvec.plot()Example: animating James Webb Space TelescopeIn addition to.plot()method ofVectorandObserverclasses, there's aplay()function that you can pass it a list of Vector objects as well as some other lists as shown in the example below:importhypatieashpimportmatplotlib.pyplotaspltt1='2018-10-01 14:18:00't2='2024-12-31 12:18:00'# get positions with respect to the barycenter of earth-moonearth=hp.Vector('399',t1,t2,center='500@3',step=1000)moon=hp.Vector('301',t1,t2,center='500@3',step=1000)jwst=hp.Vector('-170',t1,t2,center='500@3',step=1000)bodies=[earth,moon,jwst]names=['Earth','Moon','James Webb']colors=['b','g','r']sizes=[20,8,3]# play the animationanim=hp.play(bodies,names,colors,sizes)plt.show()TransformationsThere are several functions inhypatie.transformmodule. As an example, let's use theto_tetefunction which transforms the GCRS coordinates to True Equator True Equinox (of date):fromhypatie.transformimportto_teteimportnumpyasnpfromdatetimeimportdatetimet=datetime(2022,3,18)# GCRS coordinatespos=np.array([0.73859258,0.13935437,0.65959182])# True Equator and True equinox of tpos_tete=to_tete(pos,t)print(pos_tete)#[0.73649269 0.14295327 0.66116782]Deep skyYou can download data from astronomical catalogues:fromhypatie.cataloguesimportCataloguecat=Catalogue('gaia3')data,meta=cat.download()or, plot the star chart for your location:fromhypatie.plotsimportstar_chartfig,ax=star_chart(lon=2.2945,lat=48.8584)plt.show()or, use a virtual telescope:fromhypatie.plotsimportTelescopetarget=(10.6847,41.2687)# az,alt of a point in the skyparis=(2.2945,48.8584)# location of observer# get image with 3 degrees field of viewtel=Telescope(target_loc=target,obs_loc=paris,fov=3)tel.show()Explore proper motionLet's create a chart showing the proper motion of stars near the Sgr A* (Milky Way's central supermassive black hole). The coordinates of the black hole are given and shown with the red '+' in the chart.fromhypatie.plotsimportexplore_pmimportmatplotlib.pyplotaspltra=266.41681662499997dec=-29.00782497222222df,fig,ax=explore_pm(ra,dec,r=0.001,otype='star')plt.show()See more examples atastrodatascience.net