Package ComboCode :: Package cc :: Package tools :: Package units :: Module Equivalency
[hide private]
[frames] | no frames]

Source Code for Module ComboCode.cc.tools.units.Equivalency

 1  # -*- coding: utf-8 -*- 
 2   
 3  """ 
 4  Equivalencies for the astropy.units module for converting several quantities in 
 5  both directions. 
 6   
 7  Author: R. Lombaert 
 8   
 9  """ 
10   
11  from astropy import units as u 
12  from astropy import constants as cst 
13  import numpy as np 
14   
15   
16 -def Tmb(diameter):
17 18 ''' 19 Converting main-beam temperature in K to Fnu in cgs and vice versa. 20 21 Requires the diameter to be given in m. 22 23 >>> equiv = Tmb(12.) 24 >>> Fnu = (1*u.K).to(u.W/u.m/u.m/u.Hz,equivalencies=equiv) 25 gives the length in astronomical units. 26 27 Note that you don't have to give arcsec or au. You can also ask for u.cm, 28 u.arcminute, etc. The astropy unit conversion module takes care of these 29 conversions as long as no equivalency is needed. 30 31 @param diameter: The telescope dish size (diameter in m) 32 @type diameter: float 33 34 @return: list of (unit in, unit out, forward conversion, reverse conversion) 35 @rtype: list(tuple) 36 37 ''' 38 39 d = float(diameter)*u.m 40 factor = np.pi*d**2/8./cst.k_B 41 return [(u.K,u.W/u.m/u.m/u.Hz, lambda x: x/factor, lambda x: x*factor)]
42 43 44
45 -def angularSize(distance):
46 47 ''' 48 Equivalency for the astropy.units module for converting angular size to 49 physical length and vice versa. 50 51 Requires the distance to be given in pc. 52 53 Can be used to convert angular sizes and lengths using the units module. 54 >>> equiv = angularSize(1000.) 55 >>> rad = (0.001*u.arcsec).to(u.au,equivalencies=equiv) 56 gives the length in astronomical units. 57 58 Note that you don't have to give arcsec or au. You can also ask for u.cm, 59 u.arcminute, etc. The astropy unit conversion module takes care of these 60 conversions as long as no equivalency is needed. 61 62 @param distance: The distance to the object in parsec 63 @type distance: float 64 65 @return: list of (unit in, unit out, forward conversion, reverse conversion) 66 @rtype: list(tuple) 67 68 ''' 69 70 #- 1 AU at 1 pc is 1 as on the sky, hence 1 AU at x pc is 1/x as on the sky 71 #- hence [real_rad/1 AU] = [angrad/1 as] * [distance/1 pc] 72 distance = float(distance) 73 return [(u.arcsec,u.au, lambda x: x*distance, lambda x: x/distance)] 74