# 震级和其他对数单位¶

## 创建对数量¶

### 例子¶

>>> import astropy.units as u, astropy.constants as c, numpy as np
>>> u.Magnitude(-10.)
<Magnitude -10. mag>
>>> u.Magnitude(10 * u.ct / u.s)
<Magnitude -2.5 mag(ct / s)>
>>> u.Magnitude(-2.5, "mag(ct/s)")
<Magnitude -2.5 mag(ct / s)>
>>> -2.5 * u.mag(u.ct / u.s)
<Magnitude -2.5 mag(ct / s)>
>>> u.Dex((c.G * u.M_sun / u.R_sun**2).cgs)
<Dex 4.438067627303133 dex(cm / s2)>
>>> np.linspace(2., 5., 7) * u.Unit("dex(cm/s2)")
<Dex [2. , 2.5, 3. , 3.5, 4. , 4.5, 5. ] dex(cm / s2)>


>>> logg = 5. * u.dex(u.cm / u.s**2)
>>> logg.value
5.0
>>> logg.physical
<Quantity 100000. cm / s2>


## 转换为不同单位¶

### 例子¶

>>> logg = 5. * u.dex(u.cm / u.s**2)
>>> logg.to(u.m / u.s**2)
<Quantity 1000. m / s2>
>>> logg.to('dex(m/s2)')
<Dex 3. dex(m / s2)>


>>> logg.si
<Dex 3. dex(m / s2)>


## 算术和光度应用¶

### 例子¶

>>> tint = 1000.*u.s
>>> cr_b = ([3000., 100., 15.] * u.ct) / tint
>>> cr_v = ([4000., 90., 25.] * u.ct) / tint
>>> b_i, v_i = u.Magnitude(cr_b), u.Magnitude(cr_v)
>>> b_i, v_i
(<Magnitude [-1.19280314,  2.5       ,  4.55977185] mag(ct / s)>,
<Magnitude [-1.50514998,  2.61439373,  4.00514998] mag(ct / s)>)


>>> b_i - v_i
<Magnitude [ 0.31234684, -0.11439373,  0.55462187] mag>


>>> atm_ext_b, atm_ext_v = 0.12 * u.mag, 0.08 * u.mag
>>> secz = 1./np.cos(45 * u.deg)
>>> b_i0 = b_i - atm_ext_b * secz
>>> v_i0 = v_i - atm_ext_b * secz
>>> b_i0, v_i0
(<Magnitude [-1.36250876,  2.33029437,  4.39006622] mag(ct / s)>,
<Magnitude [-1.67485561,  2.4446881 ,  3.83544435] mag(ct / s)>)


>>> b_ref, v_ref = 17.2 * u.STmag, 17.0 * u.STmag
>>> b_ref, v_ref
(<Magnitude 17.2 mag(ST)>, <Magnitude 17. mag(ST)>)
>>> zp_b, zp_v = b_ref - b_i0[0], v_ref - v_i0[0]
>>> zp_b, zp_v
(<Magnitude 18.56250876 mag(s ST / ct)>,
<Magnitude 18.67485561 mag(s ST / ct)>)


>>> (0. * u.STmag).to(u.erg/u.s/u.cm**2/u.AA)
<Quantity 3.63078055e-09 erg / (Angstrom cm2 s)>
>>> (-21.1 * u.STmag).to(u.erg/u.s/u.cm**2/u.AA)
<Quantity 1. erg / (Angstrom cm2 s)>


>>> B, V = b_i0 + zp_b, v_i0 + zp_v
>>> B, V
(<Magnitude [17.2       , 20.89280314, 22.95257499] mag(ST)>,
<Magnitude [17.        , 21.1195437 , 22.51029996] mag(ST)>)


>>> V.to(u.ABmag, u.spectral_density(5500.*u.AA))
<Magnitude [16.99023831, 21.10978201, 22.50053827] mag(AB)>


>>> flam = V.to(u.erg/u.s/u.cm**2/u.AA)
>>> flam
<Quantity [5.75439937e-16, 1.29473986e-17, 3.59649961e-18] erg / (Angstrom cm2 s)>


>>> lam = 5500 * u.AA
>>> fnu = V.to(u.erg/u.s/u.cm**2/u.Hz, u.spectral_density(lam))
>>> fnu
<Quantity [5.80636959e-27, 1.30643316e-28, 3.62898099e-29] erg / (cm2 Hz s)>


>>> nu = 5.45077196e+14 * u.Hz
>>> fnu = V.to(u.erg/u.s/u.cm**2/u.Hz, u.spectral_density(nu))
>>> fnu
<Quantity [5.80636959e-27, 1.30643316e-28, 3.62898099e-29] erg / (cm2 Hz s)>


>>> B_V0 = -0.2 * u.mag
>>> EB_V = (B - V)[0] - B_V0
>>> R_V = 3.1
>>> A_V = R_V * EB_V
>>> A_B = (R_V+1) * EB_V
>>> EB_V, A_V, A_B
(<Magnitude 0.4 mag>, <Quantity 1.24 mag>, <Quantity 1.64 mag>)


>>> BC_V = -0.3 * (u.m_bol - u.STmag)
>>> M_bol = 5.46 * u.M_bol
>>> DM = V[0] - A_V + BC_V - M_bol
>>> BC_V, M_bol, DM
(<Magnitude -0.3 mag(bol / ST)>,
<Magnitude 5.46 mag(Bol)>,
<Magnitude 10. mag(bol / Bol)>)


>>> radius_and_inverse_area = [(u.pc, u.pc**-2,
...                            lambda x: 1./(4.*np.pi*x**2),
...                            lambda x: np.sqrt(1./(4.*np.pi*x)))]
<Quantity 1000. pc>


## NumPy函数¶

>>> np.max(v_i)
<Magnitude 4.00514998 mag(ct / s)>
>>> np.std(v_i)
<Magnitude 2.33971149 mag>


## 无量纲对数量¶

>>> dBm = u.dB(u.mW)
>>> signal_in, signal_out = 100. * dBm, 50 * dBm
>>> cable_loss = (signal_in - signal_out) / (100. * u.m)
>>> signal_in, signal_out, cable_loss
(<Decibel 100. dB(mW)>, <Decibel 50. dB(mW)>, <Quantity 0.5 dB / m>)
>>> better_cable_loss = 0.2 * u.dB / u.m
>>> signal_in - better_cable_loss * 100. * u.m
<Decibel 80. dB(mW)>

M15

Mamajek等人，2015年， arXiv:1510.06262

H95

E、 g.，Holtzman等人，1995年， PASP 107, 1065

OG83

Oke，J.B.和Gunn，J.E.，1983年， ApJ 266, 713