AHELP for CIAO 4.2 | copy_piximgvals |
Context: py.crates |
Synopsis
Copy the image values from a crate.
Syntax
copy_piximgvals(crate)
Description
- crate - input IMAGECrate
The copy_piximgvals command retrieves an array of the values of the specified image within the crate. The data values are copied into an array and that array is returned.
Example
>>> img = read_file("image.fits") >>> vals_cpy = copy_piximgvals(img) >>> print vals_cpy [[0 0 0 ..., 0 0 0] [0 0 0 ..., 0 0 0] [0 0 0 ..., 0 0 0] ..., [0 0 0 ..., 0 0 0] [0 0 0 ..., 0 0 0] [0 0 0 ..., 0 0 0]] >>> vals_cpy[0][0] = 99 >>> print vals_cpy [[99 0 0 ..., 0 0 0] [ 0 0 0 ..., 0 0 0] [ 0 0 0 ..., 0 0 0] ..., [ 0 0 0 ..., 0 0 0] [ 0 0 0 ..., 0 0 0] [ 0 0 0 ..., 0 0 0]]
Use copy_piximgvals to get the values of the image "image.fits" and print them to the screen. Change the first value to "99", then print the array again.
Should I use copy_piximgvals or get_piximgvals?
The copy_piximgvals routine was added to Crates in CIAO 4.2. It appears similar to get_piximgvals, so why was it added? The return value from get_piximgvals reflects the contents of the Crate, so that changes to the return value also change the crate, whereas copy_piximgvals returns a copy of this data.
It is generally going to be safer to use copy_piximgvals rather than get_piximgvals unless:
- you do want to be able to change values in the crate for either future processing or to write out to disk
- you have read in a large file and do not want to waste memory by creating another copy of the array
If the image being read in is a virtual one then the data is always going to be copied, so in this particular case there is no difference between copy_piximgvals and get_piximgvals.
Bugs
See the bug pages on the CIAO website for an up-to-date listing of known bugs.
See Also
- py.crates
- add_piximg, delete_piximg, get_piximg, get_piximg_shape, get_piximgvals, set_piximgvals