ArrayLattice imposes another layer of function calls on top of a an Array. As a result they should not be used for generic Array manipulation. They are useful if you have an Array that needs to use Lattice functions or needs to be used with PagedArrays or other Lattice derivatives (like LatticeExpr or SubLattice). For example the LatticeIterator class can iterate through an Array in more ways than any of the ArrayIterator classes can. The examples below illustrate some uses for ArrayLattices.
// make an Array and fill it with data.
Array<Float> myArray(IPosition(3, 64, 64, 2));
indgen(myArray); // fills the Array with 0,1,2,....,64*64*2-1
// construct the ArrayLattice
ArrayLattice<Float> myLattice(myArray);
// make a PagedArray to store the data on disk
PagedArray<Float> myPagedArray(myLattice.shape(), "myTestData.array");
// now copy the data onto disk
myPagedArray.copyData (myLattice);
Note that it could be done in a somewhat simpler way as:
// make an Array and fill it with data.
Array<Float> myArray(IPosition(3, 64, 64, 2));
indgen(myArray); // fills the Array with 0,1,2,....,64*64*2-1
// make a PagedArray to store the data on disk
PagedArray<Float> myPagedArray(myLattice.shape(), "myTestData.array");
// now put the data onto disk
myPagedArray.put (myArray);
Cube<Float> arr(64,64,128);
// assume that the data gets put into the cube somehow
// now construct an ArrayLattice from this cube.
ArrayLattice<Float> lat(arr);
// Construct an iterator that returns the 128-element spectra one at a time
ArrLatticeIter<Float> iter(lat, IPosition(3,1,1,128));
// construct a Matrix to hold the results
Matrix<Float> channelSum(64,64);
// and do the summation one spectrum at a time
for (iter.reset(); !iter.atEnd(); iter++)
channelSum(iter.position().getFirst(2)) = sum(iter.cursor());
There are more examples in the Lattice class and many of the examples in the PagedArray class will also be instructive.
Construct an ArrayLattice with the specified shape. It results in a writable lattice.
Construct an ArrayLattice that references the given Array. By default it results in a writable lattice.
Construct an ArrayLattice that references the given Array. It results in a non-writable lattice.
The copy constructor uses reference semantics.
The assignment operator uses copy semantics.
Make a copy of the object (reference semantics).
The lattice data can be referenced as an array section.
Is the lattice writable?
returns the shape of the ArrayLattice.
Set all of the elements in the Lattice to a value.
Return the Array of the data within this Lattice.
Return the value of the single element located at the argument IPosition. Note that operator() (defined in the base class) can also be used.
Put the value of a single element.
Check for internal consistency. Returns False if something nasty has happened to the ArrayLattice.
Returns the maximum recommended number of pixels for a cursor. For this class this is equal to the number of pixels in the lattice.
Get a slice in an optimized way (specifically for ArrLatticeIter). It returns in buffer a reference to the lattice array.
Do the actual putting of an array of values.