NRAO Home > CASA > CASA Toolkit Reference Manual
image.fromarray - Function

1.1.1 Construct a CASA image from a numerical (integer or float) array


Description

This function converts a numerical (integer or float) numpy array of any size and dimensionality into a CASA image. It will create both float and complex valued images.

The image analysis tool on which this method is called will reference the created image; if this tool referenced another image before this call, that image will no longer be referenced by the tool after the creation of the new image. If you would rather have a new image analysis tool returned, keeping the one on which this method is called unaltered, use newimagefromarray() instead. If outfile is given, the image is written to disk, if not, the image tool on which this method was called will reference a temporary image (either in memory or on disk, depending on its size) that will be deleted when the tool is closed.

Float valued images are produced from real-valued arrays. Complex-valued images are produced from complex-valued arrays.

The coordinate system, provided as a coordsys toolconverted to a record is optional. If you provide it, it must have the same number of dimensions as the pixels array (see also coordsys). Call the naxes() method on the coordinate system tool to see how many dimensions the coordinate system has. A coordinate system can be created from scratch using the coordinate system (cs) tool and methods therein, but often users prefer to use a coordinate system from an already existing image. This can be gotten using ia.coordsys() which returns a coordinate system tool. A torecord() call on that tool will result in a python dictionary describing the coordinate system which is the necessary format for the csys input parameter of ia.fromarray().

If csys is not specified, a default coordinate system is created. If linear=F (the default) the created coordinate system will have standard RA/DEC/Stokes/Spectral Coordinate axes depending upon the shape of the pixels array (Stokes axis must be no longer than 4 pixels and you may find the spectral axis preceding the Stokes axis if say, shape=[64,64,32,4]). Extra dimensions are given linear coordinates. If linear=T, then all the resulting coordinates are linear with the axes represent lengths. In this case each axis will have a value of 0.0 at its center pixel. The increment of each axis will be 1.0 km.

The method returns True if creation of the image was successful, False otherwise, so you can check programmatically if the image creation was successful.

Arguments





Inputs

outfile

Output image file name. Default is unset.

allowed:

string

Default:

pixels

Numeric array

allowed:

any

Default:

variant

csys

Coordinate System. Default is unset.

allowed:

record

Default:

linear

Make a linear Coordinate System if csys not given

allowed:

bool

Default:

false

overwrite

Overwrite (unprompted) pre-existing output file?

allowed:

bool

Default:

false

log

Write image creation messages to logger

allowed:

bool

Default:

true

Returns
bool

Example

 
 
"""  
# make an image with a default RA/Dec/Stokes/Frequency coordinate system  
# having all pixels set to 2.5.  
ary = ia.makearray(v=2.5, shape=[64, 64, 4, 128])  
# the ia tool does not need to reference an image in this case (ie open()  
# need not have been called), if it does reference another image, that reference  
# will be lost and replaced with a reference to the newly created image.  
res = ia.fromarray(outfile=’test.data’, pixels=ary, overwrite=true)  
if res:  
    # perform operations on the newly created image if desired and make sure  
    # to close it when done to free up system resources (eg memory)  
    ia.shape()  
ia.done()  
"""  
 

Example

 
"""  
 
# create an image using the coordinate system from another image  
ia.open("myexistingimage.im")  
 
mycs = ia.coordsys()  
# the number of dimensions in the array and the coordinate system must  
# be the same. For this example to work, mycs.naxes() must return 4.  
ia.done()  
ary = ia.makearray(v=2.5, shape=[64, 64, 4, 128])  
res = ia.fromarray(pixels=ary, csys=mycs.torecord())  
mycs.done()  
if (res):  
    # do things with the newly created temporary image before closing it  
    ia.shape()  
ia.done()  
 
"""  
 

__________________________________________________________________


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