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

1.1.1 This function converts a pre-existing ascii file into a CASA image.


Description

This function is used to create a CASA image from a pre-existing ASCII file. You might want to use this if you just want to create a quick image to use to see what various image analysis methods do. The image analysis tool on which the method is called will always reference the created image if this method is successful. Thus, calling open() on that tool is not necessary, but if the tool is already open, referencing another image, that reference will be silently destroyed and replaced with a reference to the image created by fromascii(). If outfile is given, the image is also written to the specified disk file. If outfile is unset, the image analysis tool on which this method was called references a temporary image. This temporary image may be in memory or on disk, depending on its size. When you close the image analysis tool (with the close function) the temporary image is deleted.

You must specify the shape of the image. The image must be stored in the ascii file. If the shape of the image having N axes is to be [s_0, s_1, s_2, ..., s_(N-1)], where s_i is the integral number of pixels along axis number i, the file must have (s_1 * s_2 * ... * s_(N-1)) rows and each row must have s_0 numerical values delimited by the value specified by the sep parameter. Pixel locations are incremented by row number in such a way that the second axis changes fastest. As an example, say we want to create an image with shape=[3,4,2]. There must be 4*2 = 8 rows in the ascii file, and each row must have 3 space-delimited numerical values. The first row represents values of pixels [0, 0, 0], [1, 0, 0], and [2, 0, 0]. The second row represents values of pixels [0, 1, 0], [1, 1, 0], and [2, 1, 0]. The fifth row represents values of pixels [0, 0, 1], [1, 0, 1], and [2, 0, 1]. The sixth values of pixels [0, 1, 1], [1, 1, 1], and [2, 1, 1,]. And so on.

To further illustrate, say this is our file:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

When read with ia.fromascii(), ary = ia.getchunk() would return the following array: ary[0, 0, 0] = 1 ary[1, 0, 0] = 2 ary[2, 0, 0] = 3 ary[0, 1, 0] = 4 ary[1, 1, 0] = 5 ary[2, 1, 0] = 6 ary[0, 2, 0] = 7 ary[1, 2, 0] = 8 ary[2, 2, 0] = 9 ary[0, 3, 0] = 10 ary[1, 3, 0] = 11 ary[2, 3, 0] = 12 ary[0, 0, 1] = 13 ary[1, 0, 1] = 14 ary[2, 0, 1] = 15 ary[0, 1, 1] = 16 ary[1, 1, 1] = 17 ary[2, 1, 1] = 18 ary[0, 2, 1] = 19 ary[1, 2, 1] = 20 ary[2, 2, 1] = 21 ary[0, 3, 1] = 22 ary[1, 3, 1] = 23 ary[2, 3, 1] = 24

The coordinate system, provided as a coordsys tool converted to a record with coordsys torecord, is optional. If you provide it, it must be dimensionally consistent with the pixels array you give (see also coordsys).

If you don’t provide the coordinate system, a default coordinate system is made for you. If linear=F (the default) then it is a standard RA/DEC/Stokes/Spectral Coordinate System depending exactly upon the shape of the pixels array (Stokes axis must be no longer than 4 pixels and you may find the spectral axis coming out before the Stokes axis if say, shape=[64,64,32,4]). Extra dimensions are given linear coordinates. If linear=T, then all axes are linear in the resulting coordinate system.

Arguments





Inputs

outfile

Output image file name. Default is unset.

allowed:

string

Default:

infile

Input ascii disk file name. Must be specified..

allowed:

string

Default:

shape

Shape of image. Must be specified.

allowed:

intArray

Default:

-1

sep

Separator in ascii file. Default is space character.

allowed:

string

Default:

:

csys

Coordinate System record from coordsys torecord(). 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

Returns
bool

Example

 
 
"""  
# say the above file presented above is stored in a file  
# named image.txt  
ia.fromascii(outfile="myimage.im", infile=’image.txt’, shape=[3,4,2], sep=" ", overwrite=true)  
# should return [3, 4, 2]  
ia.shape()  
# call other ia methods then close the tool  
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