NRAO Home > CASA > CASA Toolkit Reference Manual
quanta.quantity - Function

1.5.1 make a quantity from a string or from a numeric value and a unit string


Description

quantity makes a quantity from a string, or from a value and a string. Note that a function unit exists which is a synonym for quantity. If only a string is given, it can be a scalar string. The result will be a scalar quantity.

If a numeric value and a unit string are given, the numeric value can be any numeric type, and can also be a vector of numeric values. print qa.map() to get a list of recognized units. ’d’ is usually days, but can be degrees (see example).

Arguments





Inputs

v

quantity or numeric or string to convert to quantity

allowed:

variant

Default:

unitname

unit string if v numeric

allowed:

string

Default:

Returns
record

Example

 
 
"""  
#  
print "\t----\t quantity Ex 1 \t----"  
tu = qa.quantity(’1Jy’) # make quantity  
print tu  
#{’value’: 1.0, ’unit’: ’Jy’}  
print qa.quantity(tu) # also accepts a quantity  
#{’value’: 1.0, ’unit’: ’Jy’}  
tu = qa.unit(’1Jy’) # make quantity with synonym  
print tu  
#{’value’: 1.0, ’unit’: ’Jy’}  
print qa.quantity(-1.3, ’Jy’) # make quantity with separate value  
#{’value’: -1.3, ’unit’: ’Jy’}  
q1 = qa.quantity([8.57132661e+09, 1.71426532e+10], ’km/s’) # Composite unit  
print q1  
#{’value’: array([  8.57132661e+09,   1.71426532e+10]), ’unit’: ’km/s’}  
q = qa.quantity(’5d’); print q  
#{’value’: 5.0, ’unit’: ’d’}            # d = days  
q = qa.quantity(’5 d’); print q  
#{’value’: 5.0, ’unit’: ’d’}            # even if there’s a space, as of 5/28/09  
q = qa.quantity(’5d30m’); print q  
#{’value’: 5.5, ’unit’: ’deg’}          # Unless followed by an m!  
qa.quantity(’5d30s’)                    # WRONG  
# {’unit’: ’d30s’, ’value’: 5.0}        # I told you...  
qa.quantity(’5d0m30s’)                  # OK  
# {’unit’: ’deg’, ’value’: 5.0083333333333337}  
"""  
 

__________________________________________________________________


More information about CASA may be found at the CASA web page

Copyright 2016 Associated Universities Inc., Washington, D.C.

This code is available under the terms of the GNU General Public Lincense


Home | Contact Us | Directories | Site Map | Help | Privacy Policy | Search