NAME
PDL::IO::NDF - PDL Module for reading and writing Starlink N-dimensional data structures as PDLs.
SYNOPSIS
use PDL::IO::NDF;
$a = PDL->rndf($file);
$a = rndf('test_image');
$a = rndf('test_image', 1);
$a->wndf($file);
wndf($a, 'out_image');
propndfx($a, 'template', 'out_image');
DESCRIPTION
This module adds the ability to read and write Starlink N-dimensional data files as N-dimensional PDLs.
You must have the Starlink NDF library installed to use it. The library is distributed under the GPL and is available from "http://www.starlink.ac.uk".
FUNCTIONS
rndf()
Reads an ndarray from a NDF format data file.
$pdl = rndf('file.sdf');
$pdl = rndf('file.sdf',1);
The '.sdf' suffix is optional. The optional second argument turns off automatic quality masking and returns a quality array as well.
A hash options version of rndf() also exists
$pdl = rndf( 'file.sdf', nomask => 1, quickread => 1 );
where the supported options are (defaults in square brackets):
nomask => (boolean) Disable automatic quality masking. [false]
quickread => (boolean) If true, only read the primary data array and
FITS header [false]
Header information and NDF Extensions are stored in the ndarray as a hash which can be retreived with the $pdl->gethdr
command. Array extensions are stored in the header as follows:
$a - the base DATA_ARRAY
If $hdr = $a->gethdr
;
then:
%{$hdr} contains all the FITS headers plus:
$$hdr{Error} contains the Error/Variance PDL
$$hdr{Quality} The quality byte array (if reqeusted)
@{$$hdr{Axis}} Is an array of ndarrays containing the information
for axis 0, 1, etc.
$$hdr{NDF_EXT} Contains all the NDF extensions
$$hdr{Hist} Contains the history information
$$hdr{NDF_EXT}{_TYPES}
Data types for non-PDL NDF extensions so that
wndf can reconstruct a NDF.
All extension information is stored in the header hash array. Extension structures are preserved in hashes, so that the PROJ_PARS component of the IRAS.ASTROMETRY extension is stored in $$hdr{NDF_EXT}{IRAS}{ASTROMETRY}{'PROJ_PARS'}
. All array structures are stored as arrays in the Hdr: numeric arrays are stored as PDLs, logical and character arrays are stored as plain Perl arrays. FITS arrays are a special case and are expanded as scalars into the header.
PDL does not have a signed byte datatype, so any '_BYTE' data is read into a byte
(unsigned) ndarray and a warning is printed to STDOUT
.
If the starlink bad flag is set, then the bad flag on the output ndarray is also set. Starlink bad values are converted to the current bad value used by the ndarray type (if they are different).
wndf()
Writes an ndarray to a NDF format file:
$pdl->wndf($file);
wndf($pdl,$file);
wndf can be used for writing PDLs to NDF files. The '.sdf' suffix is optional. All the extensions created by rndf are supported by wndf. This means that error, axis and quality arrays will be written if they exist. Extensions are also reconstructed by using their name (ie FIGARO.TEST would be expanded as a FIGARO extension and a TEST component). Hdr keywords Label, Title and Units are treated as special cases and are written to the label, title and units fields of the NDF.
Header information is written to corresponding NDF extensions. NDF extensions can also be created in the {NDF} hash by using a key containing '.', ie {NDF}{'IRAS.DATA'} would write the information to an IRAS.DATA extension in the NDF. rndf stores this as $$hdr{NDF}{IRAS}{DATA}
and the two systems are interchangeable.
rndf stores type information in {NDF}{'_TYPES'} and below so that wndf can reconstruct the data type of non-PDL extensions. If no entry exists in _TYPES, wndf chooses between characters, integer and double on a best guess basis. Any perl arrays are written as CHAR array extensions (on the assumption that numeric arrays will exist as PDLs).
The bad flag is written to the file, if set.
propndfx()
Routine to write a PDL to an NDF by copying the extension information from an existing NDF and writing DATA,VARIANCE, QUALITY and AXIS info from a PDL (if they exist).
Extensions, labels and history are propogated from the old NDF. No new extension information is written.
This command has been superseded by wndf().
NOTES
The perl NDF module must be available. This is available from Starlink (http://www.starlink.ac.uk).
If an NDF is read which contains AST World Coordinate information (a .WCS component) this information is currently ignored. Currently WCS information can only be written and stored using standard FITS headers. See http://www.starlink.ac.uk/ast for more information on AST.
AUTHOR
This module was written by Tim Jenness <tjenness@cpan.org>.
PDL bad value support was added by Douglas Burke <dburke@cfa.harvard.edu>.
LICENSE
Copyright (C) 1998 - 2012 Tim Jenness. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
PDL::FAQ for general information on the Perl Data language, NDF for information on the NDF module.