Source code for astronat.sc.core
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------
#
# TITLE : functions
# PROJECT : astronat
#
# ----------------------------------------------------------------------------
"""Astronomy functions.
.. todo::
incorporate astropy cosmology
"""
__author__ = "Nathaniel Starkman"
__all__ = [
"apparent_to_absolute_magnitude",
"absolute_to_apparent_magnitude",
"distanceModulus_magnitude",
"distanceModulus_distance",
"distanceModulus",
"parallax_angle",
"parallax_distance",
"parallax",
"max_angular_separation",
]
##############################################################################
# IMPORTS
import numpy as np
from ..units import AU
from ..units import deg as DEG
from ..units import m as METER
from ..units import mag as MAG
from ..units import pc as PC
from ..units import quantity_io
###############################################################################
# Distance Modulus
[docs]@quantity_io(m=MAG)
def apparent_to_absolute_magnitude(sc, m, **kw):
"""Calculate absolute magnitude.
M = m - 5 log10(d) + 5
Parameters
----------
sc: SkyCoord
gets sc.spherical.distance
.. todo::
check if skycoord frame centered on Earth
m: array_like
apparent magnitude
Returns
-------
M: array_like
absolute magnitudes
"""
M = m - 5.0 * np.log10(sc.spherical.distance) + 5.0
return M
# /def
[docs]@quantity_io(M=MAG)
def absolute_to_apparent_magnitude(sc, M, **kw):
"""Calculate apparent magnitude.
m = M + 5 log10(d) - 5
Parameters
----------
M: array_like
absolute magnitude
sc: SkyCoord
gets ``sc.spherical.distance``
.. todo::
check if skycoord frame centered on Earth
Returns
-------
m: ndarray
apparent magnitudes
"""
m = M + 5.0 * np.log10(sc.spherical.distance) - 5.0
return m
# /def
[docs]@quantity_io()
def distanceModulus_magnitude(sc, **kw):
"""Distance modulus from distance in Skycoord.
DM = 5 log10(d / 10) + A
the Skycoord already has the distance
equivalent to `sc.spherical.distance.distmod`
Parameters
----------
sc: SkyCoord
.. todo::
check if skycoord frame centered on Earth
Returns
-------
DM: scalar, array
default units: MAG
"""
return sc.spherical.distance.distmod
# /def
[docs]@quantity_io()
def distanceModulus_distance(sc, **kw):
"""Distance from distance modulus in Skycoord.
DM = 5 log10(d / 10) + A
the Skycoord already has the distance,
equivalent to `sc.spherical.distance`
Parameters
----------
sc: SkyCoord
.. todo::
check if skycoord frame centered on Earth
Returns
-------
DM: scalar, array
default units u.mag
"""
return sc.spherical.distance
# /def
[docs]@quantity_io()
def distanceModulus(sc, d2dm=True, **kw):
"""Distance Modulus.
DM = 5 log10(d / 10) + A
Parameters
----------
sc: SkyCoord
d2dm: bool
if true: distance -> DM
else: DM -> distance
Returns
-------
DM or distance: scalar, array
TODO
----
A, obs
"""
if d2dm:
distanceModulus_magnitude(sc)
else:
distanceModulus_distance(sc)
# /def
###############################################################################
# Parallax
[docs]@quantity_io()
def parallax_angle(sc, **kw) -> DEG:
"""Compute parallax angle from skycoord.
Parameters
----------
sc: SkyCoord
** warning: check if skycoord frame centered on Earth
Returns
-------
p: deg
parallax angle
"""
return np.arctan(1 * AU / sc.spherical.distance)
# /def
[docs]@quantity_io()
def parallax_distance(sc, **kw) -> PC:
"""Compute distance from parallax angle.
Parameters
----------
sc: SkyCoord
.. warning:: check if skycoord frame centered on Earth
"""
return np.arctan(1 * AU / sc.spherical.distance)
# return 1 * AU / np.tan(p)
# /def
[docs]def parallax(sc, d2p=True, **kw):
"""Parallax.
Parameters
----------
sc: SkyCoord
** warning: check if skycoord frame centered on Earth
d2p: bool
if true: arg = distance -> parallax_angle
else: arg = parallax_angle -> distance
Returns
-------
parallax_angle or distance: scalar, array
"""
if d2p:
return parallax_angle(sc)
else:
return parallax_distance(sc)
# /def
###############################################################################
# Angular Separation
[docs]@quantity_io()
def max_angular_separation(sc, doff: METER, **kw):
"""Maximum angular separation.
doff: distance
distance offset from coordinate
dto: distance
distance to original coordinate
the maximum angular separation comes from movint at right angle from current position
TODO
----
support zero point
"""
return np.fabs(np.arctan(np.divide(doff, sc.spherical.distance)))
# /def