hypatie


Namehypatie JSON
Version 2.20.2 PyPI version JSON
download
home_pagehttps://github.com/behrouzz/hypatie
SummaryA python package for astronomical calculations
upload_time2024-02-17 10:55:35
maintainer
docs_urlNone
authorBehrouz Safari
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            **Author:** [Behrouz Safari](https://behrouzz.github.io/)<br/>
**License:** [MIT](https://opensource.org/licenses/MIT)<br/>

# hypatie
*A python package for astronomical calculations*


## Installation

Install the latest version of *hypatie* from [PyPI](https://pypi.org/project/hypatie/):

    pip install hypatie

Requirements are *numpy*, *pandas* and *matplotlib*.


## NASA JPL's Horizons

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

```python
import hypatie as hp

t1 = '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):

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

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

```python
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 use *obs.pos*, *obs.ra*, or *obs.dec*:

```python
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-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 :

```python
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.

```python
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:
```python
vec = hp.Vector('sun', t1)
```

Both *Vector* and *Observer* classes have *.plot()* method.
```python
# plot polar coordinates
obs.plot()
# plot cartesian coordinates
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:

```python
import hypatie as hp
import matplotlib.pyplot as plt

t1 = '2018-10-01 14:18:00'
t2 = '2024-12-31 12:18:00'

# get positions with respect to the barycenter of earth-moon
earth = 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 animation
anim = hp.play(bodies, names, colors, sizes)
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):

```python
from hypatie.transform import to_tete
import numpy as np
from datetime import datetime

t = datetime(2022, 3, 18)

# GCRS coordinates
pos = np.array([0.73859258, 0.13935437, 0.65959182])

# True Equator and True equinox of t
pos_tete = to_tete(pos, t)

print(pos_tete)
#[0.73649269 0.14295327 0.66116782]
```

## Deep sky

You can download data from astronomical catalogues:
```python
from hypatie.catalogues import Catalogue

cat = Catalogue('gaia3')
data, meta = cat.download()
```

or, plot the star chart for your location:
```python
from hypatie.plots import star_chart

fig, ax = star_chart(lon=2.2945, lat=48.8584)
plt.show()
```

or, use a virtual telescope:
```python
from hypatie.plots import Telescope

target = (10.6847,41.2687) # az,alt of a point in the sky
paris = (2.2945, 48.8584)  # location of observer

# get image with 3 degrees field of view
tel = Telescope(target_loc=target, obs_loc=paris, fov=3)
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.

```python
from hypatie.plots import explore_pm
import matplotlib.pyplot as plt

ra = 266.41681662499997
dec = -29.00782497222222

df, fig, ax = explore_pm(ra, dec, r=0.001, otype='star')
plt.show()
```

![alt text](https://raw.githubusercontent.com/behrouzz/astronomy/main/images/sgr_A_pm.png)

See more examples at [astrodatascience.net](https://astrodatascience.net/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/behrouzz/hypatie",
    "name": "hypatie",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "Behrouz Safari",
    "author_email": "behrouz.safari@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cf/db/7124ee21c439f63586914fbbc67ae1711ec0fa0eb4a91ebc2c93e6207393/hypatie-2.20.2.tar.gz",
    "platform": null,
    "description": "**Author:** [Behrouz Safari](https://behrouzz.github.io/)<br/>\r\n**License:** [MIT](https://opensource.org/licenses/MIT)<br/>\r\n\r\n# hypatie\r\n*A python package for astronomical calculations*\r\n\r\n\r\n## Installation\r\n\r\nInstall the latest version of *hypatie* from [PyPI](https://pypi.org/project/hypatie/):\r\n\r\n    pip install hypatie\r\n\r\nRequirements are *numpy*, *pandas* and *matplotlib*.\r\n\r\n\r\n## NASA JPL's Horizons\r\n\r\nLet's get the positions of the sun between two times:\r\n\r\n```python\r\nimport hypatie as hp\r\n\r\nt1 = '2021-03-20 08:00:00'\r\nt2 = '2021-03-20 10:00:00'\r\n```\r\n\r\nIf you want the apparent RA and DEC of the Sun with respect to Earth's center (geocentric):\r\n\r\n```python\r\nobs = hp.Observer('sun', t1, t2, step=5)\r\n```\r\n\r\nNow you can access the time intervals with *.time* attribute:\r\n\r\n```python\r\nprint(obs.time)\r\n\r\n[datetime.datetime(2021, 3, 20, 8, 0)\r\n datetime.datetime(2021, 3, 20, 8, 24)\r\n datetime.datetime(2021, 3, 20, 8, 48)\r\n datetime.datetime(2021, 3, 20, 9, 12)\r\n datetime.datetime(2021, 3, 20, 9, 36)\r\n datetime.datetime(2021, 3, 20, 10, 0)]\r\n```\r\n\r\nTo acces the position you can use *obs.pos*, *obs.ra*, or *obs.dec*:\r\n\r\n```python\r\nprint(obs.pos)\r\n\r\n[[ 3.59938235e+02 -2.66803120e-02]\r\n [ 3.59953431e+02 -2.00920520e-02]\r\n [ 3.59968627e+02 -1.35038600e-02]\r\n [ 3.59983823e+02 -6.91573600e-03]\r\n [ 3.59999018e+02 -3.27680000e-04]\r\n [ 1.42132560e-02  6.26030600e-03]]\r\n```\r\n\r\nThe first column in the above array is RA and the second column is DEC.\r\n\r\nIt is possible to get the apparent RA & DEC of a targer with respect to a specified location on the surface of a body.\r\nFor example, if you want to get the apparent RA & DEC of the Sun for the Eiffel Tower :\r\n\r\n```python\r\nobs = hp.Observer('sun', t1, t2, step=5, center='2.2945,48.8584,300@399')\r\n```\r\n\r\nNote that 2.2945 is the longtitude, 48.8584 is the latitude and 300 (meters) is the elevation of the Eiffel Tower.\r\nWe have specified '@399' at the end which means that this coordinates is situated on the Earth (399 is the Earth's code).                                                                                           \r\n\r\nYou can request the cartesian positions (x,y,z) of a target with *Vector* class.\r\n\r\n```python\r\nvec = hp.Vector('sun', t1, t2, step=5)\r\n```\r\n\r\nAs with the *Observer* class, there are two attributes *.time* and *.pos* for *Vector* class.\r\nNote that when creating a Vector class, you have *.x*, *.y* and *.z* attributes instead of *.ra* and *.dec*.\r\n\r\nFor both *Vector* and *Observer* classes you can pass a single time to get position/state of a body at a single time:\r\n```python\r\nvec = hp.Vector('sun', t1)\r\n```\r\n\r\nBoth *Vector* and *Observer* classes have *.plot()* method.\r\n```python\r\n# plot polar coordinates\r\nobs.plot()\r\n# plot cartesian coordinates\r\nvec.plot()\r\n```\r\n\r\n## Example: animating James Webb Space Telescope\r\n\r\nIn 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:\r\n\r\n```python\r\nimport hypatie as hp\r\nimport matplotlib.pyplot as plt\r\n\r\nt1 = '2018-10-01 14:18:00'\r\nt2 = '2024-12-31 12:18:00'\r\n\r\n# get positions with respect to the barycenter of earth-moon\r\nearth = hp.Vector('399', t1, t2, center='500@3', step=1000)\r\nmoon = hp.Vector('301', t1, t2, center='500@3', step=1000)\r\njwst = hp.Vector('-170', t1, t2, center='500@3', step=1000)\r\n\r\nbodies = [earth, moon, jwst]\r\nnames = ['Earth', 'Moon', 'James Webb']\r\ncolors = ['b','g','r']\r\nsizes = [20, 8, 3]\r\n\r\n# play the animation\r\nanim = hp.play(bodies, names, colors, sizes)\r\nplt.show()\r\n```\r\n\r\n## Transformations\r\n\r\nThere 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):\r\n\r\n```python\r\nfrom hypatie.transform import to_tete\r\nimport numpy as np\r\nfrom datetime import datetime\r\n\r\nt = datetime(2022, 3, 18)\r\n\r\n# GCRS coordinates\r\npos = np.array([0.73859258, 0.13935437, 0.65959182])\r\n\r\n# True Equator and True equinox of t\r\npos_tete = to_tete(pos, t)\r\n\r\nprint(pos_tete)\r\n#[0.73649269 0.14295327 0.66116782]\r\n```\r\n\r\n## Deep sky\r\n\r\nYou can download data from astronomical catalogues:\r\n```python\r\nfrom hypatie.catalogues import Catalogue\r\n\r\ncat = Catalogue('gaia3')\r\ndata, meta = cat.download()\r\n```\r\n\r\nor, plot the star chart for your location:\r\n```python\r\nfrom hypatie.plots import star_chart\r\n\r\nfig, ax = star_chart(lon=2.2945, lat=48.8584)\r\nplt.show()\r\n```\r\n\r\nor, use a virtual telescope:\r\n```python\r\nfrom hypatie.plots import Telescope\r\n\r\ntarget = (10.6847,41.2687) # az,alt of a point in the sky\r\nparis = (2.2945, 48.8584)  # location of observer\r\n\r\n# get image with 3 degrees field of view\r\ntel = Telescope(target_loc=target, obs_loc=paris, fov=3)\r\ntel.show()\r\n```\r\n\r\n## Explore proper motion\r\n\r\nLet'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.\r\n\r\n```python\r\nfrom hypatie.plots import explore_pm\r\nimport matplotlib.pyplot as plt\r\n\r\nra = 266.41681662499997\r\ndec = -29.00782497222222\r\n\r\ndf, fig, ax = explore_pm(ra, dec, r=0.001, otype='star')\r\nplt.show()\r\n```\r\n\r\n![alt text](https://raw.githubusercontent.com/behrouzz/astronomy/main/images/sgr_A_pm.png)\r\n\r\nSee more examples at [astrodatascience.net](https://astrodatascience.net/)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A python package for astronomical calculations",
    "version": "2.20.2",
    "project_urls": {
        "Homepage": "https://github.com/behrouzz/hypatie"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ca7aef8440d7c546cb910f431d28f7beddf3c56c03d011995af992cf8308a19d",
                "md5": "745a339e7c652e01e51a5c8f83962614",
                "sha256": "831b80e3d0212dc9f1160c7be4aaa4072402bf4588b1051e9451875d7191e24e"
            },
            "downloads": -1,
            "filename": "hypatie-2.20.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "745a339e7c652e01e51a5c8f83962614",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 70384,
            "upload_time": "2024-02-17T10:55:32",
            "upload_time_iso_8601": "2024-02-17T10:55:32.249471Z",
            "url": "https://files.pythonhosted.org/packages/ca/7a/ef8440d7c546cb910f431d28f7beddf3c56c03d011995af992cf8308a19d/hypatie-2.20.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cfdb7124ee21c439f63586914fbbc67ae1711ec0fa0eb4a91ebc2c93e6207393",
                "md5": "88dc8dbe861464a88ba05426493c652a",
                "sha256": "4a910776bd96a610a9763363d360ef1d3c4577c9555262ec89ad08c64b21b9e1"
            },
            "downloads": -1,
            "filename": "hypatie-2.20.2.tar.gz",
            "has_sig": false,
            "md5_digest": "88dc8dbe861464a88ba05426493c652a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 68823,
            "upload_time": "2024-02-17T10:55:35",
            "upload_time_iso_8601": "2024-02-17T10:55:35.408012Z",
            "url": "https://files.pythonhosted.org/packages/cf/db/7124ee21c439f63586914fbbc67ae1711ec0fa0eb4a91ebc2c93e6207393/hypatie-2.20.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-17 10:55:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "behrouzz",
    "github_project": "hypatie",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "hypatie"
}
        
Elapsed time: 0.50832s