Synopsis
Provides a Python interface to the CXC stk library
Syntax
import stk
Description
The stk module provides a routine that will read in the contents of a CIAO stack file.
It is suggested that the module is always loaded with the explicit form:
import stk
The build routine
The module provides a single routine, build, which takes a stack and returns the contents as a list. The stack can either be given directly (where spaces and commas separate values) or with the "@" value to indicate a file.
>>> stk.build("a1, a2.dat, a3.fits")
['a1', 'a2.dat', 'a3.fits']Reading from a file
If the file "in.stk" contains
a1 a2.dat a3.fits[cols x, y]
then it can be read in with:
>>> stk.build("@in.stk")
['a1', 'a2.dat', 'a3.fits[cols x, y]']If a path is included to the file then this path will be included, as it follows the stack behaviour for parameter values (the examples below assume the file has been copied to the requested locations):
>>> stk.build("@/tmp/in.stk")
['/tmp/a1', '/tmp/a2.dat', '/tmp/a3.fits[cols x, y]']
>>> stk.build("@../other/in.stk")
['../other/a1', '../other/a2.dat', '../other/a3.fits[cols x, y]']The "+" and "-" modifiers control the behaviour, and also note that individual stack entries behave differently if they start with the "!" character.
>>> stk.build("@-/tmp/in.stk")
['a1', 'a2.dat', 'a3.fits[cols x, y]']Grid special forms
The "igrid", "lgrid", "rgrid", and "pgrid" special forms create a grid of string values.
>>> stk.build("igrid(1:5:2")
['1', '3', '5']
>>> stk.build("lgrid(1.1:5.2:0.8")
['1.1', '1.9', '2.7', '3.5', '4.3', '5.1']
>>> for reg in stk.build("rgrid(10:20:3,120:160:20)"):
... print(reg)
...
rectangle(10,120,13,140)
rectangle(10,140,13,160)
rectangle(13,120,16,140)
rectangle(13,140,16,160)
rectangle(16,120,19,140)
rectangle(16,140,19,160)
>>> for reg in stk.build("pgrid(4123,3950,0:40:10,0:360:180)"):
... print(reg)
...
pie(4123,3950,0,10,0,180)
pie(4123,3950,0,10,180,360)
pie(4123,3950,10,20,0,180)
pie(4123,3950,10,20,180,360)
pie(4123,3950,20,30,0,180)
pie(4123,3950,20,30,180,360)
pie(4123,3950,30,40,0,180)
pie(4123,3950,30,40,180,360)Bugs
See the bugs page for the stack library on the CIAO website for an up-to-date listing of known bugs.
Refer to the CIAO bug pages for an up-to-date listing of known issues.
See Also
- concept
- stack
- tools::stacks
- stk_build, stk_count, stk_read_num, stk_where