nraonrao
 
 NRAO Home > CASA > CasaDocument
image.fromascii - Function

1.1.1 Construct a CASA image by conversion from an ascii file
Description

This function is used to convert an ascii disk file to a CASA image file. If outfile is given, the image is written to the specified disk file. If outfile is unset, the Image tool is associated with a temporary image. This temporary image may be in memory or on disk, depending on its size. When you close the Image tool (with the close function) this temporary image is deleted.

You must specify the shape of the image. The image must be stored in the ascii file, one row at a time. This row must be of the correct length and there must be the correct number of rows. For example, let us say the shape of your image is [nx,ny,nz] = [3,4,2], then the image should be stored as

1 1 1                   # row 1; y = 1, z = 1  
2 2 2                   # row 2; y = 2, z = 1  
3 3 3                   # row 3; y = 3, z = 1  
4 4 4                   # row 4; y = 4, z = 1  
1.5 1.5 1.5             # row 5; y = 1, z = 2  
2.5 2.5 2.5             # row 6; y = 2, z = 2  
3.5 3.5 3.5             # row 7; y = 3, z = 2  
4.5 4.5 4.5             # row 8; y = 4, z = 2

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 (unset), 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 you get a linear 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:

any

Default:

record

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

The ascii image file shown above can be read as an image this way:

"""  
#  
print "\t----\t fromascii Ex 1 \t----"  
a = [[[ 1. ,  1.5],  
      [ 2. ,  2.5],  
      [ 3. ,  3.5],  
      [ 4. ,  4.5]],  
     [[ 1. ,  1.5],  
      [ 2. ,  2.5],  
      [ 3. ,  3.5],  
      [ 4. ,  4.5]],  
     [[ 1. ,  1.5],  
      [ 2. ,  2.5],  
      [ 3. ,  3.5],  
      [ 4. ,  4.5]]]  
ia.fromarray(’outimage.im’,a,overwrite=true)  
ia.toASCII(’myimage.ascii’,overwrite=true)     # write ascii image file  
ia.close()                                     # then read ascii image file  
ia.fromascii(’myimage.app’, ’myimage.ascii’, shape=[3,4,2], overwrite=true)  
ia.toASCII(’myimage2.ascii’,overwrite=true)  
ia.close()  
#!diff myimage.ascii myimage2.ascii  
#  
"""

Please send any comments or questions about CASA or AIPS++ to aips2-requests@nrao.edu

Copyright © 2007 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

Updated daily during alpha development.