|
|||
NRAO Home > CASA > CASA Toolkit Reference Manual |
|
1.5 quanta - Module
quanta.convertfreq - Function
quanta.convertdop - Function
quanta.quantity - Function
quanta.getvalue - Function
quanta.getunit - Function
quanta.canonical - Function
quanta.canon - Function
quanta.convert - Function
quanta.define - Function
quanta.map - Function
quanta.maprec - Function
quanta.fits - Function
quanta.angle - Function
quanta.time - Function
quanta.add - Function
quanta.sub - Function
quanta.mul - Function
quanta.div - Function
quanta.neg - Function
quanta.norm - Function
quanta.le - Function
quanta.lt - Function
quanta.eq - Function
quanta.ne - Function
quanta.gt - Function
quanta.ge - Function
quanta.sin - Function
quanta.cos - Function
quanta.tan - Function
quanta.asin - Function
quanta.acos - Function
quanta.atan - Function
quanta.atan2 - Function
quanta.abs - Function
quanta.ceil - Function
quanta.floor - Function
quanta.log - Function
quanta.log10 - Function
quanta.exp - Function
quanta.sqrt - Function
quanta.compare - Function
quanta.check - Function
quanta.checkfreq - Function
quanta.pow - Function
quanta.constants - Function
quanta.isangle - Function
quanta.totime - Function
quanta.toangle - Function
quanta.splitdate - Function
quanta.tos - Function
quanta.type - Function
quanta.done - Function
quanta.unit - Function
quanta.isquantity - Function
quanta.setformat - Function
quanta.getformat - Function
quanta.formxxx - Function
A quantity is a value with a unit. For example, ’5km/s’, or ’20Jy/pc2’. This module (the quanta module) enables you to create and manipulate such quantities. The types of functionality provided are:
- Conversion - Conversion of quantities to different units
- Calculation - Calculations with quantities
The Quanta tool manipulates quantities. A quantity is stored as a record with two fields. These fields are named ‘value’ and ‘unit’. As well as simple scalar quantites, one can also create quantities as vectors or arrays. For example, you may have a vector of values, which all have the same unit - there is no need to store a copy of the unit for each value. Access to the individual fields of a quantum should always be by using the getvalue and getunit methods, especially since the internal names can change or be not accessable at some stage.
#
print "\t----\t Module Ex 1 \t----"
print qa.quantity(5.4, ’km/s’)
#{’value’: 5.4000000000000004, ’unit’: ’km/s’}
q1 = qa.quantity([8.57132661e+09, 1.71426532e+10], ’km/s’)
print qa.convert(q1, ’pc/h’);
#{’value’: array([ 1., 2.]), ’unit’: ’pc/h’}
#
"""
In the first example, we make a simple scalar quantity. You can see that the quantity (which is actually a record) has fields ‘value’ and ‘unit’.
In the second example, we make a vector quantity and then convert it from units of km/s to pc/h.
#
print "\t----\t Module Ex 2 \t----"
print qa.quantity(’5.4km/s’)
#{’value’: 5.4000000000000004, ’unit’: ’km/s’}
print qa.quantity(qa.unit(’5.4km/s’))
#{’value’: 5.4000000000000004, ’unit’: ’km/s’}
#
"""
In the first example, the value and unit were combined into one string (just saves a bit of typing). The second example shows that the function unit is an alias for quantity, and that you can create a quantity from another quantity.
#
print "\t----\t Module Ex 3 \t----"
q1 = qa.unit("5s 5.4km/s")
print len(q1)
#2
print q1[’*0’]
# {’unit’: ’s’, ’value’: 5.0}
print q1[’*1’]
# {’unit’: ’km/s’, ’value’: 5.4000000000000004}
#
Here we make a vector quantity by using the string vector. You can see that the resultant quantity record is of length 2 and that each field of that vector quantity is a scalar quantity. So you see that ’q1’ itself does not have fields ‘value’ and ‘unit’, only the elements of ’q1’ have that.
#
print "\t----\t Module Ex 4 \t----"
q1 = qa.unit(’5km’);
q2 = qa.unit(’200m’);
print qa.canonical(qa.add(q1,q2))
#{’value’: 5200.0, ’unit’: ’m’}
#
"""
Here we make two quantities with consistent but different units, add them together and then convert the result to canonical units.
#
print "\t----\t Module Ex 5 \t----"
q1 = qa.quantity(’6rad’);
q2 = qa.quantity(’3deg’);
print qa.compare(q1,q2)
#True
print qa.compare(q1,qa.unit(’3km’))
#False
#
"""
Here we compare the dimensionality of the units of two quantities.
Constants, time and angle formatting
If you would like to see all the possible constants known to the Quanta tool you can issue the command print qa.map(’const’). You can get the value of any constant in that list with a command such as
#
print "\t----\t Module Ex 6 \t----"
boltzmann = qa.constants(’k’)
print ’Boltzmann constant is ’, boltzmann
#Boltzmann constant is {’value’: 1.3806577987510647e-23, ’unit’: ’J/K’}
#
"""
There are some extra handy ways you can manipulate strings when you are dealing with times or angles. The following list shows special strings and string formats which you can input to the quantity function. Something in square brackets is optional. There are examples after the list.
- time: [+-]hh:mm:ss.t... – This is the preferred time format (trailing fields can be omitted)
- time: [+-]hhHmmMss.t..[S] – This is an alternative time format (HMS case insensitive, trailing second fields can be omitted)
- angle: [+-]dd.mm.ss.t.. – This is the preferred angle format (trailing fields after second priod can be omitted; dd.. is valid)
- angle: [+-]ddDmmMss.t...[S] – This is an alternative angle format (DMS case insensitive, trailing fields can be omitted after M)
- today – The special string “today” gives the UTC time at the instant the command was issued.
- today/time – The special string “today” plus the specified time string gives the UTC time at the specified instant
- yyyy/mm/dd[/time] – gives the UTC time at the specified instant
- dd[-]mmm[-][cc]yy[/time] – gives the UTC time at the specified instant in calendat style notation (23-jun-1999)
Note that the standard unit for degrees is ’deg’, and for days ’d’. Formatting is done in such a way that it interprets a ’d’ as degrees if preceded by a value without a period and if any value following it is terminated with an ’m’. In other cases ’days’ are assumed. Here are some examples.
#
print "\t----\t Module Ex 7 \t----"
print qa.quantity(’today’)
#{’value’: 54178.87156457176, ’unit’: ’d’}
print qa.quantity(’5jul1998’)
#{’value’: 50999.0, ’unit’: ’d’}
print qa.quantity(’5jul1998/12:’)
#{’value’: 50999.5, ’unit’: ’d’}
print qa.quantity(’-30.12.2’)
#{’value’: -30.200555555555557, ’unit’: ’deg’}
print qa.quantity(’2:2:10’)
#{’value’: 30.541666666666668, ’unit’: ’deg’}
print qa.unit(’23h3m2.2s’)
#{’value’: 345.75916666666666, ’unit’: ’deg’}
#
"""
Angles and times can often be used interchangeably. Special functions (qa.totime() and qa.toangle()) are available to make them in the right units for the purpose. E.g. qa.sin(time) gives an error, whereas qa.sin(qa.toangle(time)) works ok. See the map function for pre-defined units.
#
print "\t----\t Module Ex 8 \t----"
a = qa.quantity(’today’); # 1
print a
#{’value’: 54178.871564641202, ’unit’: ’d’}
b = qa.toangle(a); # 2
print b
#{’value’: 340415.88977452344, ’unit’: ’rad’}
print qa.angle(qa.norm(qa.toangle(a))); # 3
#-046.14.12
print qa.angle(qa.norm(qa.toangle(a), 0)); # 4
#+313.45.48
print qa.sub(’today’,a); # 5
#{’value’: 1.1576048564165831e-08, ’unit’: ’d’}
#
print "Last example! Exiting ..."
exit()
"""
- Get the time now
- Get the time as an angle
- Get the time as a normalised angle (-pi to +pi) and show as dms
- Get the time as a normalised angle (0 to 2pi) and show as dms
- Get time since creation of a
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