quanta

class quanta[source]

quanta tool handles units and quantities

Methods Summary

abs

absolute value of quantity

acos

arccosine of quantity

add

add quantities

angle

show an angle as a formatted string

asin

arcsine of quantity

atan

arctangent of quantity

atan2

arctangent of two quantity

canon

get canonical value of quantity

canonical

get canonical value of quantity

ceil

ceil value of quantity

check

check for proper unit string

checkfreq

check for proper frequency unit

compare

compare dimensionality of units

constants

get a constant

convert

convert a quantity to another unit

convertdop

convert a doppler velocity quantity to another unit

convertfreq

convert a frequency quantity to another unit

cos

cosine of quantity

define

define a new unit name

div

divides quantities

done

Free resources used by tool. Current implementation

eq

compare quantities

exp

exponential of quantity

fits

define some FITS units

floor

floor value of quantity

formxxx

Format a quantity using given format, allowed are hms, dms, deg, rad, +deg.

ge

compare quantities

getformat

get current output format

getunit

get the internal unit of a quantity

getvalue

get the internal value of a quantity

gt

compare quantities

isangle

check if valid angle or time quantity

isquantity

Check if quantity

le

compare quantities

log

logarithm of quantity

log10

logarithm of quantity

lt

compare quantities

map

list known unit names and constants

maprec

create record containing list of known unit names and

mul

multiply quantities

ne

compare quantities

neg

negate quantities

norm

normalise angle

pow

raise quantity to power

quanta

Construct quanta tool

quantity

make a quantity from a string or from a numeric value

setformat

set format for output of numbers.

sin

sine of quantity

splitdate

split a date/time into a record

sqrt

square root of quantity

sub

subtract quantities

tan

tangent of quantity

time

show a time (or date) as a formatted string

toangle

convert a time (or an angle) to an angle

tos

convert quantity to string

totime

convert an angle (or a time) to a time

type

type of tool

unit

quantity from value v and unit string

abs(v='')[source]

absolute value of quantity

abs gives absolute value of quantity

Parameters

  • v (variant='') - value

acos(v='')[source]

arccosine of quantity

acos gives arccosine of non-dimensioned quantity

Parameters

  • v (variant='') - non-dimensioned quantity

add(v='', a='0')[source]

add quantities

add adds two quantities

Parameters

  • v (variant='') - value

  • a (variant='0') - value

angle(v='', prec=0, form=[''], showform=False)[source]

show an angle as a formatted string

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: egin{description} item[clean] delete leading/trailing superfluous separators item[no_d] do not show degrees part item[no_dm] do not show degrees and minutes part item[dig2] show only 2 digits of degrees in angle format item[time] show as time (hh:mm:ss.ttt) rather than as angle end{description} 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 {em 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 output

  • prec (int=0) - number of digits shown

  • form (stringArray=['']) - formatting information in coded string array

  • showform (bool=False) - show square brackets and separating ,

asin(v='')[source]

arcsine of quantity

asin gives arcsine of non-dimensioned quantity

Parameters

  • v (variant='') - non-dimensioned quantity

atan(v='')[source]

arctangent of quantity

atan gives arctangent of non-dimensioned quantity

Parameters

  • v (variant='') - non-dimensioned quantity

atan2(v='', a='')[source]

arctangent of two quantity

atan gives arctangent of two non-dimensioned quantity

Parameters

  • v (variant='') - non-dimensioned quantity

  • a (variant='') - non-dimensioned quantity

canon(v='')[source]

get canonical value of quantity

canon gets the canonical value of a quantity

Parameters

  • v (variant='') - value to convert

canonical(v='1.0')[source]

get canonical value of quantity

canonical (with alias canon) gets the canonical value of a quantity

Parameters

  • v (variant='1.0') - value to convert

ceil(v='')[source]

ceil value of quantity

ceil gives ceiling value of quantity

Parameters

  • v (variant='') - value

check(v='')[source]

check for proper unit string

check checks if the argument has a properly defined unit string

Parameters

  • v (string='') - value

checkfreq(cm='')[source]

check for proper frequency unit

checkfreq checks if the argument has a properly defined frequency interpretable unit string

Parameters

  • cm (variant='') - value

compare(v='', a='')[source]

compare dimensionality of units

compare compares the dimensionality of units of two qauntities

Parameters

  • v (variant='') - value

  • a (variant='') - value

constants(v='pi')[source]

get a constant

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. const^2 0.000295912 AU3/d2/S0

Parameters

  • v (string='pi') - name

convert(v='', outunit='')[source]

convert a quantity to another unit

convert converts a quantity to another unit. If no output unit given, conversion is to canonical units

Parameters

  • v (variant='') - quantity to convert

  • outunit (variant='') - unit to convert to

convertdop(v='0.0', outunit='km/s')[source]

convert a doppler velocity quantity to another unit

convertfreq converts a velocity quantity to another unit. Units are either

velocity or dimensionless.

Parameters

  • v (variant='0.0') - quantity to convert

  • outunit (string='km/s') - unit to convert to

convertfreq(v='1.0', outunit='Hz')[source]

convert a frequency quantity to another unit

convertfreq converts a frequency quantity to another unit.

Parameters

  • v (variant='1.0') - quantity to convert

  • outunit (string='Hz') - unit to convert to

cos(v='')[source]

cosine of quantity

cos gives cosine of angle quantity

Parameters

  • v (variant='') - angle quantity

define(name='', v='1')[source]

define a new unit name

define defines the name and value of a user defined unit

Parameters

  • name (string='') - name of unit to define

  • v (variant='1') - quantity value of new unit

div(v='', a='1')[source]

divides quantities

div divides two quantities

Parameters

  • v (variant='') - value

  • a (variant='1') - value

done(kill=False)[source]
Free resources used by tool. Current implementation

ignores input parameter, does nothing and returns true

Currently, this method is an NOP.

Parameters

  • kill (bool=False) - force kill of the default tool (ignored)

eq(v='', a='0')[source]

compare quantities

eq compares two quantities for equality.

Parameters

  • v (variant='') - value

  • a (variant='0') - value

exp(v='')[source]

exponential of quantity

exp gives exponential value of dimensionless quantity

Parameters

  • v (variant='') - dimensionless quantity

fits()[source]

define some FITS units

fits defines some unit names used in reading and writing FITS files.

floor(v='')[source]

floor value of quantity

floor gives flooring value of quantity

Parameters

  • v (variant='') - value

formxxx(v='', format='dms', prec=2)[source]

Format a quantity using given format, allowed are hms, dms, deg, rad, +deg.

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 converted

  • format (string='dms') - xxx can be hms, dms, deg, rad or +deg

  • prec (int=2) - digits in fractional part of output string for dms,hms

ge(v='', a='0')[source]

compare quantities

ge compares two quantities for greater than or equal.

Parameters

  • v (variant='') - value

  • a (variant='0') - value

getformat(t='')[source]
get current output format

(NOT IMPLEMENTED YET!)

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

getunit(v='')[source]

get the internal unit of a quantity

getunit returns the internal unit string of a quantity

Parameters

  • v (variant='') - quantity

getvalue(v='')[source]

get the internal value of a quantity

getvalue returns the internal value of a quantity. It also can handle an array of quantities.

Parameters

  • v (variant='') - quantity

gt(v='', a='0')[source]

compare quantities

gt compares two quantities for greater than.

Parameters

  • v (variant='') - value

  • a (variant='0') - value

isangle(v='')[source]

check if valid angle or time quantity

isangle checks if the argument is a valid angle/time quantity.

Parameters

  • v (variant='') - angle/time quantity

isquantity(v='')[source]

Check if quantity

Checks if the operand is a correct quantity

Parameters

  • v (variant='') - value to be tested

le(v='', a='0')[source]

compare quantities

le compares two quantities for less than or equal.

Parameters

  • v (variant='') - value

  • a (variant='0') - value

log(v='')[source]

logarithm of quantity

log gives natural logarithm of dimensionless quantity

Parameters

  • v (variant='') - dimensionless quantity

log10(v='')[source]

logarithm of quantity

log10 gives logarithm of dimensionless quantity

Parameters

  • v (variant='') - dimensionless quantity

lt(v='', a='0')[source]

compare quantities

lt compares two quantities for less than.

Parameters

  • v (variant='') - value

  • a (variant='0') - value

map(v='all')[source]

list known unit names and constants

map lists the known mapping of units and constants. It has a single argument, which can be a coded string (no-case, minimax match): egin{description} item[all] all of the following units (not constants): also the default item[Prefix] known decimal prefixes item[SI] known SI units item[Customary] a set of customary units known to programs item[User] units defined by the user item[Constants] known constants (note: only ‘const’, ‘Const’, ‘constants’ and ‘Constants’ recognised). end{description}

Parameters

  • v (string='all') - type of information to list - coded string

maprec(v='all')[source]
create record containing list of known unit names and

constants

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): egin{description} item[all] all of the following units (not constants): also the default item[Prefix] known decimal prefixes item[SI] known SI units item[Customary] a set of customary units known to programs item[User] units defined by the user end{description}

Parameters

  • v (string='all') - type of information to list - coded string

mul(v='', a='1')[source]

multiply quantities

mul multiplies two quantities

Parameters

  • v (variant='') - value

  • a (variant='1') - value

ne(v='', a='0')[source]

compare quantities

ne compares two quantities for non equality.

Parameters

  • v (variant='') - value

  • a (variant='0') - value

neg(v='1')[source]

negate quantities

neg negates a quantity

Parameters

  • v (variant='1') - value

norm(v='', a=- 0.5)[source]

normalise angle

norm normalise angles in interval of $2pi$ 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 $2pi$

Parameters

  • v (variant='') - angle quantity

  • a (double=-0.5) - lower interval boundary

pow(v='', a=1)[source]

raise quantity to power

pow raises a quantity to an integer power

Parameters

  • v (variant='') - value

  • a (int=1) - power

quanta()[source]

Construct quanta tool

Create a quanta tool on the specified host (or by default the host you are running on).

quantity(v='', unitname='')[source]
make a quantity from a string or from a numeric value

and a unit string

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).

Parameters

  • v (variant='') - quantity or numeric or string to convert to quantity

  • unitname (string='') - unit string if v numeric

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 set - v (string='F') - format parameter value - numeric or coded string, depending on format type to be set

sin(v='')[source]

sine of quantity

sin gives sine of angle quantity

Parameters

  • v (variant='') - angle quantity

splitdate(v='')[source]

split a date/time into a record

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 {em s} field which is a double float. See the example for the fields returned.

Parameters

  • v (variant='') - angle/time quantity

sqrt(v='')[source]

square root of quantity

sqrt gives square root of quantity with only even powered dimensions

Parameters

  • v (variant='') - dimensionless quantity

sub(v='', a='0')[source]

subtract quantities

sub subtracts two quantities

Parameters

  • v (variant='') - value

  • a (variant='0') - value

tan(v='')[source]

tangent of quantity

tan gives tangent of angle quantity

Parameters

  • v (variant='') - angle quantity

time(v='', prec=0, form=[''], showform=False)[source]

show a time (or date) as a formatted string

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: egin{description} item[clean] delete leading/trailing superfluous separators item[no_d] do not show hours part item[no_dm] do not show hours and minutes part item[ymd] include a date as yyyy/mm/dd (date is by default not shown) item[dmy] include a date as ddMMMyyyy (date is by default not shown) item[mjd] include a date as Modified Julian Day (date is by default not shown) item[fits] include a date and show time in FITS format: le from OS item[angle] show in angle (dd.mm.ss.ttt) rather than time format item[day] prefix day-of-week to output item[local] show local time rather than UTC (add timezone offset) item[no_time] suppress printing of time part end{description} 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 {em 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 output

  • prec (int=0) - number of digits shown

  • form (stringArray=['']) - formatting information in coded string array

  • showform (bool=False) - show square brackets and separating ,

toangle(v='')[source]

convert a time (or an angle) to an angle

toangle converts a time quantity (or an angle) to an angle quantity

Parameters

  • v (variant='') - angle/time quantity

tos(v='', prec=9)[source]

convert quantity to string

tos converts a quantity to a string with the precision defined with the {em setformat(‘prec’)} (which defaults to 9). If the optional {em prec} argument is set to an integer value greater than 1, that precision is used in the conversion

Parameters

  • v (variant='') - value

  • prec (int=9) - convert precision of value

totime(v='')[source]

convert an angle (or a time) to a time

totime converts an angle quantity (or a time) to a time quantity

Parameters

  • v (variant='') - angle/time quantity

type()[source]

type of tool

type will return the tool name.

unit(v='', unitname='')[source]

quantity from value v and unit string

unit makes a quantity from a string, or from a value and a string. Note that unit is a synonym for quantity (see example there).

Parameters

  • v (variant='')

  • unitname (string='')