quanta
- class quanta[source]
quanta tool handles units and quantities
Methods Summary
abs gives absolute value of quantity
acos gives arccosine of non-dimensioned quantity
add adds two quantities
angle converts an angle quantity to a formatted string.
asin gives arcsine of non-dimensioned quantity
atan gives arctangent of non-dimensioned quantity
atan gives arctangent of two non-dimensioned quantity
canon gets the canonical value of a quantity
canonical (with alias canon) gets the canonical value of a quantity
ceil gives ceiling value of quantity
check checks if the argument has a properly defined unit string
checkfreq checks if the argument has a properly defined frequency interpretable unit string
compare compares the dimensionality of units of two qauntities
constants gets a named constant quantity.
convert converts a quantity to another unit.
convertfreq converts a velocity quantity to another unit.
convertfreq converts a frequency quantity to another unit.
cos gives cosine of angle quantity
define defines the name and value of a user defined unit
div divides two quantities
Currently, this method is an NOP.
eq compares two quantities for equality.
exp gives exponential value of dimensionless quantity
fits defines some unit names used in reading and writing FITS files.
floor gives flooring value of quantity
form.xxx (xxx can be lat, long, len, vel, freq, dtime, unit) will format the input into a string using the global format information set by setformat().
ge compares two quantities for greater than or equal.
getformat returns the current format value set for the different format possibilities.
getunit returns the internal unit string of a quantity.
getvalue returns the internal value of a quantity.
gt compares two quantities for greater than.
isangle checks if the argument is a valid angle/time quantity.
Checks if the operand is a correct quantity
le compares two quantities for less than or equal.
log gives natural logarithm of dimensionless quantity
log10 gives logarithm of dimensionless quantity
lt compares two quantities for less than.
map lists the known mapping of units and constants.
maprec returns a record with the known mapping of units and constants.
mul multiplies two quantities
ne compares two quantities for non equality.
neg negates a quantity
norm normalise angles in interval of \(2\pi\) radians.
pow raises a quantity to an integer power
Create a quanta tool on the specified host (or by default the host you are running on).
quantity makes a quantity from a string, or from a value and a string.
set format for output of numbers.
sin gives sine of angle quantity
splitdate splits a date/time quantity into a record with constituent fields like year, yearday, month etc.
sqrt gives square root of quantity with only even powered dimensions
sub subtracts two quantities
tan gives tangent of angle quantity
time converts a time quantity to a formatted string.
toangle converts a time quantity (or an angle) to an angle quantity
tos converts a quantity to a string with the precision defined with the setformat(’prec’) (which defaults to 9).
totime converts an angle quantity (or a time) to a time quantity
type will return the tool name.
unit makes a quantity from a string, or from a value and a string.
- abs(v='')[source]
abs gives absolute value of quantity
Parameters
v (variant='')
- value
Returns
record
Examples
# print "\t----\t abs Ex 1 \t----" print qa.abs('-5km/s') #{'value': 5.0, 'unit': 'km/s'} #
- acos(v='')[source]
acos gives arccosine of non-dimensioned quantity
Parameters
v (variant='')
- non-dimensioned quantity
Returns
record
Examples
# print "\t----\t acos Ex 1 \t----" print qa.convert(qa.acos(qa.cos('7deg')), 'deg') #{'value': 7.0000000000000249, 'unit': 'deg'} #
- add(v='', a='0')[source]
add adds two quantities
Parameters
v (variant='')
- valuea (variant='0')
- value
Returns
record
Examples
# print "\t----\t add Ex 1 \t----" print qa.add('5m', '2yd') #{'value': 6.8288000000000002, 'unit': 'm'} #
- angle(v='', prec=0, form='', showform=False)[source]
angle converts an angle quantity to a formatted string. The formatting information is a precision (0 is default, 6 includes +-ddd.mm.ss) and a string array of codes (no-case, minimax match): Codes include:
- clean
delete leading/trailing superfluous separators
- no_d
do not show degrees part
- no_dm
do not show degrees and minutes part
- dig2
show only 2 digits of degrees in angle format
- time
show as time (hh:mm:ss.ttt) rather than as angle
If a multi-dimensional value is given for the value \(v\), the returned value is a string vector of a length equal to last dimension. Each string has a number of fields equal to the number of elements in all earlier dimensions. If the showform is \(T\), each vector element is surrounded by a pair of square brackets if there is more than one entry, and fields are separated by a ’,’.
Parameters
v (variant='')
- angle quantity value to outputprec (int=0)
- number of digits shownform (stringVec='')
- formatting information in coded string arrayshowform (bool=False)
- show square brackets and separating ,
Returns
stringVec
Examples
# print "\t----\t angle Ex 1 \t----" tu = qa.quantity('5.7.12.345678') # define an angle print tu #{'value': 5.1200960216666669, 'unit': 'deg'} print qa.angle(tu) # default output #+005.07.12 print qa.angle(tu, prec=7) # 7 digits #+005.07.12.3 print qa.angle(tu, prec=4) # 4 digits #+005.07. print qa.angle(tu, form=["tim","no_d"]) # as time, no hours shown #:20:29 #
- asin(v='')[source]
asin gives arcsine of non-dimensioned quantity
Parameters
v (variant='')
- non-dimensioned quantity
Returns
record
Examples
# print "\t----\t asin Ex 1 \t----" print qa.convert(qa.asin(qa.sin('7deg')), 'deg') #{'value': 7.0, 'unit': 'deg'} #
- atan(v='')[source]
atan gives arctangent of non-dimensioned quantity
Parameters
v (variant='')
- non-dimensioned quantity
Returns
record
Examples
# print "\t----\t atan Ex 1 \t----" print qa.convert(qa.atan(qa.tan('7deg')), 'deg') #{'value': 7.0, 'unit': 'deg'} #
- atan2(v='', a='')[source]
atan gives arctangent of two non-dimensioned quantity
Parameters
v (variant='')
- non-dimensioned quantitya (variant='')
- non-dimensioned quantity
Returns
record
Examples
# print "\t----\t atan2 Ex 1 \t----" print qa.convert(qa.atan2(qa.sin('7deg'), qa.cos('7deg')), 'deg') #{'value': 7.0, 'unit': 'deg'} #
- canon(v='')[source]
canon gets the canonical value of a quantity
Parameters
v (variant='')
- value to convert
Returns
record
Examples
# print "\t----\t canon Ex 1 \t----" print qa.canon('1Jy') # canonical value of a string #{'value': 1e-26, 'unit': 'kg.s-2'} print qa.canonical(qa.quantity('1Jy')) # canonical value of a unit #{'value': 1e-26, 'unit': 'kg.s-2'} #
- canonical(v='1.0')[source]
canonical (with alias canon) gets the canonical value of a quantity
Parameters
v (variant='1.0')
- value to convert
Returns
record
Examples
# print "\t----\t canonical Ex 1 \t----" print qa.canonical('1Jy') # canonical value of a string #{'value': 1e-26, 'unit': 'kg.s-2'} print qa.canon(qa.quantity('1Jy')) # canonical value of a unit #{'value': 1e-26, 'unit': 'kg.s-2'} #
- ceil(v='')[source]
ceil gives ceiling value of quantity
Parameters
v (variant='')
- value
Returns
record
Examples
# print "\t----\t ceil Ex 1 \t----" print qa.ceil('5.1AU') #{'value': 6.0, 'unit': 'AU'} #
- check(v='')[source]
check checks if the argument has a properly defined unit string
Parameters
v (string='')
- value
Returns
bool
Examples
# print "\t----\t check Ex 1 \t----" print qa.check('5AE/Jy.pc5/s') #True print qa.check('7MYs') #False #
- checkfreq(cm='')[source]
checkfreq checks if the argument has a properly defined frequency interpretable unit string
Parameters
cm (variant='')
- value
Returns
bool
Examples
# print "\t----\t checkfreq Ex 1 \t----" print qa.checkfreq('5GHz') #True print qa.checkfreq('5cm') #True print qa.checkfreq('5cm/s2') #False #
- compare(v='', a='')[source]
compare compares the dimensionality of units of two qauntities
Parameters
v (variant='')
- valuea (variant='')
- value
Returns
bool
Examples
# print "\t----\t compare Ex 1 \t----" print qa.compare('5yd/a', '6m/s') # equal dimensions #True print qa.compare('5yd', '5s') # unequal dimensions #False #
- constants(v='pi')[source]
constants gets a named constant quantity. Names (no-case, minimax) are:
pi 3.14.. 3.14159 ee 2.71.. 2.71828 c light vel. 2.99792e+08 m/s G grav. const 6.67259e-11 N.m2/kg2 h Planck const 6.62608e-34 J.s HI HI line 1420.41 MHz R gas const 8.31451 J/K/mol NA Avogadro number 6.02214e+23 mol-1 e electron charge 1.60218e-19 C mp proton mass 1.67262e-27 kg mp_me mp/me 1836.15 mu0 permeability vac. 1.25664e-06 H/m eps0 permittivity vac. 1.60218e-19 C k Boltzmann const 1.38066e-23 J/K F Faraday const 96485.3 C/mol me electron mass 9.10939e-31 kg re electron radius 2.8179e-15 m a0 Bohr’s radius 5.2918e-11 m R0 solar radius 6.9599e+08 m k2 IAU grav. const2̂ 0.000295912 AU3/d2/S0
Parameters
v (string='pi')
- name
Returns
record
Examples
# print "\t----\t constants Ex 1 \t----" print qa.constants() #{'unit': '', 'value': 3.1415926535897931} #
- convert(v='', outunit='')[source]
convert converts a quantity to another unit. If no output unit given, conversion is to canonical units
Parameters
v (variant='')
- quantity to convertoutunit (variant='')
- unit to convert to
Returns
record
Examples
# print "\t----\t convert Ex 1 \t----" tu = qa.quantity('5Mm/s') # specify a quantity print tu #{'value': 5.0, 'unit': 'Mm/s'} print qa.convert(tu, 'pc/a') # convert it to parsec per year #{'value': 0.0051135608266237404, 'unit': 'pc/a'} print qa.convert(tu) # convert to canonical units #{'value': 5000000.0, 'unit': 'm.s-1'} #
- convertdop(v='0.0', outunit='km/s')[source]
convertfreq converts a velocity quantity to another unit. Units are either velocity or dimensionless.
Parameters
v (variant='0.0')
- quantity to convertoutunit (string='km/s')
- unit to convert to
Returns
record
Examples
# print "\t----\t convertdop Ex 1 \t----" print qa.convertdop('1','km/s') #{'value': 299792.45799999998, 'unit': 'km/s'} print qa.convertdop('10km/s','1') #{'value': 3.3356409519815205e-05, 'unit': '1'} #
- convertfreq(v='1.0', outunit='Hz')[source]
convertfreq converts a frequency quantity to another unit.
Parameters
v (variant='1.0')
- quantity to convertoutunit (string='Hz')
- unit to convert to
Returns
record
Examples
# print "\t----\t convertfreq Ex 1 \t----" print qa.convertfreq('5GHz','cm') #{'value': 5.9958491599999997, 'unit': 'cm'} print qa.convertfreq('5cm','GHz') #{'value': 5.9958491599999997, 'unit': 'GHz'} #
- cos(v='')[source]
cos gives cosine of angle quantity
Parameters
v (variant='')
- angle quantity
Returns
record
Examples
# print "\t----\t cos Ex 1 \t----" print qa.cos('7deg') #{'value': 0.99254615164132198, 'unit': ''} #
- define(name='', v='1')[source]
define defines the name and value of a user defined unit
Parameters
name (string='')
- name of unit to definev (variant='1')
- quantity value of new unit
Returns
bool
Examples
# print "\t----\t define Ex 1 \t----" print qa.define('JY','1Jy') # your misspelling #True print qa.define('VLAunit', '0.898 JY') # a special unit using it #True print qa.quantity('5 VLAunit') # check its use #{'value': 5.0, 'unit': 'VLAunit'} print qa.convert('5 VLAunit','Jy') #{'value': 4.4900000000000002, 'unit': 'Jy'} #
- div(v='', a='1')[source]
div divides two quantities
Parameters
v (variant='')
- valuea (variant='1')
- value
Returns
record
Examples
# print "\t----\t div Ex 1 \t----" print qa.div('5m', '3s') #{'value': 1.6666666666666667, 'unit': 'm/(s)'} #
- done(kill=False)[source]
Currently, this method is an NOP.
Parameters
kill (bool=False)
- force kill of the default tool (ignored)
Returns
bool
Examples
# print "\t----\t done Ex 1 \t----" print qa.done() #True print qa.done() #True print qa.done(kill=T) #True #
- eq(v='', a='0')[source]
eq compares two quantities for equality.
Parameters
v (variant='')
- valuea (variant='0')
- value
Returns
bool
Examples
# print "\t----\t eq Ex 1 \t----" print qa.eq('5m', '2yd') #False #
- exp(v='')[source]
exp gives exponential value of dimensionless quantity
Parameters
v (variant='')
- dimensionless quantity
Returns
record
Examples
# print "\t----\t exp Ex 1 \t----" print qa.exp('2') #{'value': 7.3890560989306504, 'unit': ''} try: print qa.exp('2m') except Exception, e: print "Caught an expected exception", e #Caught an expected exception Quantum::exp illegal unit type 'm' #
- floor(v='')[source]
floor gives flooring value of quantity
Parameters
v (variant='')
- value
Returns
record
Examples
# print "\t----\t floor Ex 1 \t----" print qa.floor('-5.1AU') #{'value': -6.0, 'unit': 'AU'} #
- formxxx(v='', format='dms', prec=2)[source]
form.xxx (xxx can be lat, long, len, vel, freq, dtime, unit) will format the input into a string using the global format information set by setformat().
Parameters
v (variant='')
- value to be convertedformat (string='dms')
- xxx can be hms, dms, deg, rad or +degprec (int=2)
- digits in fractional part of output string for dms,hms
Returns
string
Examples
# print "\t----\t formxxx Ex 1 \t----" #qa.setformat('freq','cm') #T #qa.formxxx('freq',qa.quantity('5GHz')) #form_xxx NOT IMPLEMENTED YET! #5.99584916 cm print "Last example, exiting! ..." exit() #
- ge(v='', a='0')[source]
ge compares two quantities for greater than or equal.
Parameters
v (variant='')
- valuea (variant='0')
- value
Returns
bool
Examples
# print "\t----\t ge Ex 1 \t----" print qa.ge('5m', '2yd') #True #
- getformat(t='')[source]
getformat returns the current format value set for the different format possibilities. See the setformat function for the different format type descriptions. The known types are: prec, aprec, tprec, long, lat, len, dtime, elev, auto, vel, freq, dop, unit.
Parameters
t (string='')
- type - coded string
Returns
string
Examples
# print "\t----\t getformat Ex 1 \t----" print qa.getformat('prec') #6 #setformat is NOT IMPLEMENTED YET! #qa.setformat('prec', 12) # set precision to 12 significant digits #T #print qa.getformat('prec') #12 print qa.getformat('long') #hms #
- getunit(v='')[source]
getunit returns the internal unit string of a quantity. Note that 1-D arrays are supported, but multi-dimensional arrays are not.
Parameters
v (variant='')
- quantity
Returns
string
Examples
# print "\t----\t getunit Ex 1 \t----" tu = qa.quantity(-1.3, 'Jy') # make quantity print tu #{'value': -1.3, 'unit': 'Jy'} print qa.getvalue(tu) #-1.3 print qa.getunit(tu) #Jy #
- getvalue(v='')[source]
getvalue returns the internal value of a quantity. It also can handle a 1-D array of quantities, but multi-dimensional arrays are not supported.
Parameters
v (variant='')
- quantity
Returns
doubleVec
Examples
# print "\t----\t getvalue Ex 1 \t----" tu = qa.quantity(-1.3, 'Jy') # make quantity print tu #{'value': -1.3, 'unit': 'Jy'} print qa.getvalue(tu) #-1.3 print qa.getunit(tu) #Jy a = qa.quantity([3,5],'cm') print a #{'value': array([ 3., 5.]), 'unit': 'cm'} print qa.getvalue(a) #[3.0, 5.0] #
- gt(v='', a='0')[source]
gt compares two quantities for greater than.
Parameters
v (variant='')
- valuea (variant='0')
- value
Returns
bool
Examples
# print "\t----\t gt Ex 1 \t----" print qa.gt('5m', '2yd') #True #
- isangle(v='')[source]
isangle checks if the argument is a valid angle/time quantity.
Parameters
v (variant='')
- angle/time quantity
Returns
bool
Examples
# print "\t----\t isangle Ex 1 \t----" print qa.isangle(qa.constants('pi')) #False #
- isquantity(v='')[source]
Checks if the operand is a correct quantity
Parameters
v (variant='')
- value to be tested
Returns
bool
Examples
# print "\t----\t isQuantity Ex 1 \t----" a = qa.quantity("5Jy") # make a quantity print a #{'value': 5.0, 'unit': 'Jy'} print qa.isquantity(a) # is it one? #True print qa.isquantity("5Jy") # and this string? #True #
- le(v='', a='0')[source]
le compares two quantities for less than or equal.
Parameters
v (variant='')
- valuea (variant='0')
- value
Returns
bool
Examples
# print "\t----\t le Ex 1 \t----" print qa.le('5m', '2yd') #False #
- log(v='')[source]
log gives natural logarithm of dimensionless quantity
Parameters
v (variant='')
- dimensionless quantity
Returns
record
Examples
# print "\t----\t log Ex 1 \t----" print qa.log('2') #{'value': 0.69314718055994529, 'unit': ''} #
- log10(v='')[source]
log10 gives logarithm of dimensionless quantity
Parameters
v (variant='')
- dimensionless quantity
Returns
record
Examples
# print "\t----\t log10 Ex 1 \t----" print qa.log10('2') #{'value': 0.3010299956639812, 'unit': ''} #
- lt(v='', a='0')[source]
lt compares two quantities for less than.
Parameters
v (variant='')
- valuea (variant='0')
- value
Returns
bool
Examples
# print "\t----\t lt Ex 1 \t----" print qa.lt('5m', '2yd') #False #
- map(v='all')[source]
map lists the known mapping of units and constants. It has a single argument, which can be a coded string (no-case, minimax match):
- all
all of the following units (not constants): also the default
- Prefix
known decimal prefixes
- SI
known SI units
- Customary
a set of customary units known to programs
- User
units defined by the user
- Constants
known constants (note: only ’const’, ’Const’, ’constants’ and ’Constants’ recognised).
Parameters
v (string='all')
- type of information to list - coded string
Returns
string
Examples
# print "\t----\t map Ex 1 \t----" print qa.map('pre') # list decimal prefixes # == Prefix ==== 20 ==== # E (exa) 1e+18 # G (giga) 1000000000 # M (mega) 1000000 # P (peta) 1e+15 # T (tera) 1e+12 # Y (yotta) 1e+24 # Z (zetta) 1e+21 # a (atto) 1e-18 # c (centi) 0.01 # d (deci) 0.1 # da (deka) 10 # f (femto) 1e-15 # h (hecto) 100 # k (kilo) 1000 # m (milli) 0.001 # n (nano) 1e-09 # p (pico) 1e-12 # u (micro) 1e-06 # y (yocto) 1e-24 # z (zepto) 1e-21 print qa.map('Constants') # list known constants # == Constants ==== # pi 3.14.. 3.14159 # ee 2.71.. 2.71828 # c light vel. 2.99792e+08 m/s # G grav. const 6.67259e-11 N.m2/kg2 # h Planck const 6.62608e-34 J.s # HI HI line 1420.41 MHz # R gas const 8.31451 J/K/mol # NA Avogadro # 6.02214e+23 mol-1 # e electron charge 1.60218e-19 C # mp proton mass 1.67262e-27 kg # mp_me mp/me 1836.15 # mu0 permeability vac. 1.25664e-06 H/m # eps0 permittivity vac. 1.60218e-19 C # k Boltzmann const 1.38066e-23 J/K # F Faraday const 96485.3 C/mol # me electron mass 9.10939e-31 kg # re electron radius 2.8179e-15 m # a0 Bohr's radius 5.2918e-11 m # R0 solar radius 6.9599e+08 m # k2 IAU grav. const^2 0.000295912 AU3/d2/S0 #
- maprec(v='all')[source]
maprec returns a record with the known mapping of units and constants. It has a single argument, which can be a coded string (no-case, minimax match):
- all
all of the following units (not constants): also the default
- Prefix
known decimal prefixes
- SI
known SI units
- Customary
a set of customary units known to programs
- User
units defined by the user
Parameters
v (string='all')
- type of information to list - coded string
Returns
record
Examples
# print "\t----\t maprec Ex 1 \t----" p = qa.maprec('pre') # list decimal prefixes print p['Prefix_G'] # G (giga) 1000000000 s = qa.maprec('SI') # list SI units print s['SI_Jy'] #Jy (jansky) 1e-26 kg.s-2 #
- mul(v='', a='1')[source]
mul multiplies two quantities
Parameters
v (variant='')
- valuea (variant='1')
- value
Returns
record
Examples
# print "\t----\t mul Ex 1 \t----" print qa.mul('5m', '3s') #{'value': 15.0, 'unit': 'm.s'} #
- ne(v='', a='0')[source]
ne compares two quantities for non equality.
Parameters
v (variant='')
- valuea (variant='0')
- value
Returns
bool
Examples
# print "\t----\t ne Ex 1 \t----" print qa.ne('5m', '2yd') #True #
- neg(v='1')[source]
neg negates a quantity
Parameters
v (variant='1')
- value
Returns
record
Examples
# print "\t----\t neg Ex 1 \t----" print qa.neg('5m') #{'value': -5.0, 'unit': 'm'} #
- norm(v='', a=-0.5)[source]
norm normalise angles in interval of \(2\pi\) radians. The default interval is from -0.5 to +0.5 of a full interval (i.e. from -180 to +180 degrees). The lower end of the interval can be set as a fraction of \(2\pi\)
Parameters
v (variant='')
- angle quantitya (double=-0.5)
- lower interval boundary
Returns
record
Examples
# print "\t----\t norm Ex 1 \t----" print qa.norm('713deg') #default normalisation #{'value': -6.9999999999999716, 'unit': 'deg'} print qa.norm('713deg', -2.5) # normalise to interval -900 - -540 deg #{'value': -727.0, 'unit': 'deg'} #
- pow(v='', a=1)[source]
pow raises a quantity to an integer power
Parameters
v (variant='')
- valuea (int=1)
- power
Returns
record
Examples
# print "\t----\t pow Ex 1 \t----" print qa.pow('7.2km/s', -3) #{'value': 0.0026791838134430724, 'unit': '(km/s)-3'} #
- quanta()[source]
Create a quanta tool on the specified host (or by default the host you are running on).
- quantity(v='', unitname='', keepshape=False)[source]
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).
The keepshape input parameter is only relevant if v is a multi-dimensional array. In this case, if True, the output value array will have the same shape as v. If False, a one-dimensional array is returned with length equal to the number of elements in v. The default value is False in order to preserve backward compatibility with previous versions.
Parameters
v (variant='')
- quantity or numeric or string to convert to quantityunitname (string='')
- unit string if v numerickeepshape (bool=False)
- Only used if input parameter v is a multi-dimensional array. Output array will have the same shape as v.
Returns
record
Examples
# 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}
- setformat(t='', v='F')[source]
- set format for output of numbers.
(NOT IMPLEMENTED YET!)
Parameters
t (string='')
- type -coded string indicating which format parameter to setv (string='F')
- format parameter value - numeric or coded string, depending on format type to be set
Returns
bool
- sin(v='')[source]
sin gives sine of angle quantity
Parameters
v (variant='')
- angle quantity
Returns
record
Examples
# print "\t----\t sin Ex 1 \t----" print qa.sin('7deg') #{'value': 0.12186934340514748, 'unit': ''} #
- splitdate(v='')[source]
splitdate splits a date/time quantity into a record with constituent fields like year, yearday, month etc. All fields will be integer (to enable use as index and easy personal formatting), with the exception of the s field which is a double float. See the example for the fields returned.
Parameters
v (variant='')
- angle/time quantity
Returns
record
Examples
# print "\t----\t splitdate Ex 1 \t----" print qa.splitdate('today') #{'mjd': 54175.752367291658, 'week': 11, 'usec': 533999, 'hour': 18, # 'min': 3, 'yearday': 75, 'msec': 533, 'month': 3, 's': # 24.533999226987362, 'sec': 24, 'weekday': 5, 'year': 2007, 'monthday': # 16} print qa.splitdate('183.33333333deg') #{'mjd': 0.50925925925000004, 'week': 46, 'usec': 999999, 'hour': 12, # 'min': 13, 'yearday': 321, 'msec': 999, 'month': 11, 's': # 19.999999200003487, 'sec': 19, 'weekday': 3, 'year': 1858, # 'monthday': 17} #
- sqrt(v='')[source]
sqrt gives square root of quantity with only even powered dimensions
Parameters
v (variant='')
- dimensionless quantity
Returns
record
Examples
# print "\t----\t sqrt Ex 1 \t----" print qa.sqrt('2m2') #{'value': 1.4142135623730951, 'unit': 'm'} try: print qa.sqrt('2s') except Exception, e: print "Caught an expected exception", e #Caught an expected exception UnitVal::UnitVal Illegal unit dimensions for root #
- sub(v='', a='0')[source]
sub subtracts two quantities
Parameters
v (variant='')
- valuea (variant='0')
- value
Returns
record
Examples
# print "\t----\t sub Ex 1 \t----" print qa.sub('5m', '2yd') #{'value': 3.1712000000000002, 'unit': 'm'} #
- tan(v='')[source]
tan gives tangent of angle quantity
Parameters
v (variant='')
- angle quantity
Returns
record
Examples
# print "\t----\t tan Ex 1 \t----" print qa.tan('7deg') #{'value': 0.1227845609029046, 'unit': ''} #
- time(v='', prec=0, form='', showform=False)[source]
time converts a time quantity to a formatted string. The formatting information is a precision (0 is default, 6 includes hh.mm.ss) and a string array of codes (no-case, minimax match): Codes include:
- clean
delete leading/trailing superfluous separators
- no_d
do not show hours part
- no_dm
do not show hours and minutes part
- ymd
include a date as yyyy/mm/dd (date is by default not shown)
- dmy
include a date as ddMMMyyyy (date is by default not shown)
- mjd
include a date as Modified Julian Day (date is by default not shown)
- fits
include a date and show time in FITS format: le from OS
- angle
show in angle (dd.mm.ss.ttt) rather than time format
- day
prefix day-of-week to output
- local
show local time rather than UTC (add timezone offset)
- no_time
suppress printing of time part
If a multi-dimensional value is given for the value \(v\), the returned value is a string vector of a length equal to last dimension. Each string has a number of fields equal to the number of elements in all earlier dimensions. If the showform is \(T\), each vector element is surrounded by a pair of square brackets if there is more than one entry, and fields are separated by a ’,’.
Parameters
v (variant='')
- time quantity value to outputprec (int=0)
- number of digits shownform (stringVec='')
- formatting information in coded string arrayshowform (bool=False)
- show square brackets and separating ,
Returns
stringVec
Examples
# print "\t----\t time Ex 1 \t----" tu = qa.quantity('today') # a time print tu #{'value': 54175.708981504627, 'unit': 'd'} print qa.time(tu) # default format #17:00:56 print qa.time(tu,form="dmy") # show date #16-Mar-2007/17:00:56 print qa.time(tu,form=["ymd","day"]) # and day #Fri-2007/03/16/17:00:56 print qa.time(tu,form="fits") # FITS format #2007-03-16T17:00:56 print qa.time(tu,form=["fits","local"]) # local FITS format #2007-03-16T10:00:56-07:00 print qa.time(tu,form=["ymd","local"]) # local time #2007/03/16/10:00:56 #
- toangle(v='')[source]
toangle converts a time quantity (or an angle) to an angle quantity
Parameters
v (variant='')
- angle/time quantity
Returns
record
Examples
# print "\t----\t toangle Ex 1 \t----" print qa.toangle('5h30m12.6') #{'value': 82.552499999999995, 'unit': 'deg'} #
- tos(v='', prec=9)[source]
tos converts a quantity to a string with the precision defined with the setformat(’prec’) (which defaults to 9). If the optional prec argument is set to an integer value greater than 1, that precision is used in the conversion
Parameters
v (variant='')
- valueprec (int=9)
- convert precision of value
Returns
string
Examples
# print "\t----\t tos Ex 1 \t----" a = qa.quantity('2.56 yd/s') print a #{'value': 2.5600000000000001, 'unit': 'yd/s'} print qa.tos(a) #2.560000000yd/s a=qa.quantity(1./7, 'km/s') print qa.tos(a) #0.142857143km/s print qa.tos(a,2) #0.14km/s print qa.tos(a,20) #0.14285714285714284921km/s print qa.tos(a) #0.142857143km/s #