summaryrefslogtreecommitdiffstats
path: root/astro_params.py
blob: b3b733b48a3a64bbfbea78df5baf4f90c502b4ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- mode: python -*-
#
# Weitian LI
# Created: 2016-06-24
# Updated: 2016-06-24
#
# Change logs:
# 2016-06-24:
#   * Add class 'ChandraPixel', moved from 'deproject_sbp.py'
#

"""
This module contains the parameters/constants used in astronomy
and astrophysics.
"""

import astropy.units as au
from astropy.cosmology import FlatLambdaCDM


class AstroParams:
    """
    The parameters/constants used in astronomy.

    References:
    [1] ref. [4], eq.(9) below
    """
    # Hubble constant at z=0
    H0 = 71.0  # [ km/s/Mpc ]
    # density of non-relativistic matter in units of the critical density
    # at z=0
    OmegaM0 = 0.27
    # ratio of electron density (n_e) to proton density (n_p) [1]
    ratio_ne_np = 1.211
    # molecular weight per electron (0.3 solar abundance; grsa table) [1]
    mu_e = 1.155
    # atomic mass unit
    m_atom = au.u.to(au.g)  # [ g ]


class ChandraPixel:
    """
    Chandra pixel unit conversions.
    """
    angle = 0.492 * au.arcsec
    z = None
    # cosmology calculator
    cosmo = None
    # angular diameter distance
    D_A = None
    # length of one pixel at the given redshift
    length = None

    def __init__(self, z=None):
        self.z = z
        self.cosmo = FlatLambdaCDM(H0=AstroParams.H0,
                                   Om0=AstroParams.OmegaM0)
        if z is not None:
            self.D_A = self.cosmo.angular_diameter_distance(z)
            self.length = self.D_A * self.angle.to(au.radian).value

    def get_angle(self):
        return self.angle

    def get_length(self, z=None):
        if z is None:
            length = self.length
        else:
            D_A = self.cosmo.angular_diameter_distance(z)
            length = D_A * self.angle.to(au.radian).value
        return length