项目作者: behrouzz

项目描述 :
A python package for astronomical calculations
高级语言: Python
项目地址: git://github.com/behrouzz/hypatie.git
创建时间: 2021-02-24T02:33:15Z
项目社区:https://github.com/behrouzz/hypatie

开源协议:MIT License

下载


Author: Behrouz Safari

License: MIT

hypatie

A python package for astronomical calculations

Installation

Install the latest version of hypatie from PyPI:

  1. pip install hypatie

Requirements are numpy, pandas and matplotlib.

NASA JPL’s Horizons

Let’s get the positions of the sun between two times:

  1. import hypatie as hp
  2. t1 = '2021-03-20 08:00:00'
  3. 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):

  1. obs = hp.Observer('sun', t1, t2, step=5)

Now you can access the time intervals with .time attribute:

  1. print(obs.time)
  2. [datetime.datetime(2021, 3, 20, 8, 0)
  3. datetime.datetime(2021, 3, 20, 8, 24)
  4. datetime.datetime(2021, 3, 20, 8, 48)
  5. datetime.datetime(2021, 3, 20, 9, 12)
  6. datetime.datetime(2021, 3, 20, 9, 36)
  7. datetime.datetime(2021, 3, 20, 10, 0)]

To acces the position you can use obs.pos, obs.ra, or obs.dec:

  1. print(obs.pos)
  2. [[ 3.59938235e+02 -2.66803120e-02]
  3. [ 3.59953431e+02 -2.00920520e-02]
  4. [ 3.59968627e+02 -1.35038600e-02]
  5. [ 3.59983823e+02 -6.91573600e-03]
  6. [ 3.59999018e+02 -3.27680000e-04]
  7. [ 1.42132560e-02 6.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 :

  1. 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 with Vector class.

  1. vec = hp.Vector('sun', t1, t2, step=5)

As with the Observer class, there are two attributes .time and .pos for Vector class.
Note that when creating a Vector class, you have .x, .y and .z attributes instead of .ra and .dec.

For both Vector and Observer classes you can pass a single time to get position/state of a body at a single time:

  1. vec = hp.Vector('sun', t1)

Both Vector and Observer classes have .plot() method.

  1. # plot polar coordinates
  2. obs.plot()
  3. # plot cartesian coordinates
  4. vec.plot()

Example: animating James Webb Space Telescope

In addition to .plot() method of Vector and Observer classes, there’s a play() function that you can pass it a list of Vector objects as well as some other lists as shown in the example below:

  1. import hypatie as hp
  2. import matplotlib.pyplot as plt
  3. t1 = '2018-10-01 14:18:00'
  4. t2 = '2024-12-31 12:18:00'
  5. # get positions with respect to the barycenter of earth-moon
  6. earth = hp.Vector('399', t1, t2, center='500@3', step=1000)
  7. moon = hp.Vector('301', t1, t2, center='500@3', step=1000)
  8. jwst = hp.Vector('-170', t1, t2, center='500@3', step=1000)
  9. bodies = [earth, moon, jwst]
  10. names = ['Earth', 'Moon', 'James Webb']
  11. colors = ['b','g','r']
  12. sizes = [20, 8, 3]
  13. # play the animation
  14. anim = hp.play(bodies, names, colors, sizes)
  15. plt.show()

Transformations

There are several functions in hypatie.transform module. As an example, let’s use the to_tete function which transforms the GCRS coordinates to True Equator True Equinox (of date):

  1. from hypatie.transform import to_tete
  2. import numpy as np
  3. from datetime import datetime
  4. t = datetime(2022, 3, 18)
  5. # GCRS coordinates
  6. pos = np.array([0.73859258, 0.13935437, 0.65959182])
  7. # True Equator and True equinox of t
  8. pos_tete = to_tete(pos, t)
  9. print(pos_tete)
  10. #[0.73649269 0.14295327 0.66116782]

Deep sky

You can download data from astronomical catalogues:

  1. from hypatie.catalogues import Catalogue
  2. cat = Catalogue('gaia3')
  3. data, meta = cat.download()

or, plot the star chart for your location:

  1. from hypatie.plots import star_chart
  2. fig, ax = star_chart(lon=2.2945, lat=48.8584)
  3. plt.show()

or, use a virtual telescope:

  1. from hypatie.plots import Telescope
  2. target = (10.6847,41.2687) # az,alt of a point in the sky
  3. paris = (2.2945, 48.8584) # location of observer
  4. # get image with 3 degrees field of view
  5. tel = Telescope(target_loc=target, obs_loc=paris, fov=3)
  6. tel.show()

Explore proper motion

Let’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.

  1. from hypatie.plots import explore_pm
  2. import matplotlib.pyplot as plt
  3. ra = 266.41681662499997
  4. dec = -29.00782497222222
  5. df, fig, ax = explore_pm(ra, dec, r=0.001, otype='star')
  6. plt.show()

alt text

See more examples at astrodatascience.net