Image HDU Routines
CFITSIO.fits_get_img_dim
— Functionfits_get_img_dim(f::FITSFile)
Return the number of dimensions in the current image HDU.
See also fits_get_img_type
, fits_get_img_size
and fits_get_img_param
.
CFITSIO.fits_get_img_size
— Functionfits_get_img_size(f::FITSFile)
Return the size along each dimension in the current Image HDU.
See also fits_get_img_type
, fits_get_img_dim
and fits_get_img_param
.
CFITSIO.fits_get_img_type
— Functionfits_get_img_type(f::FITSFile)
Return the datatype (bitpix) of the current image HDU. This may be converted to a Julia type by using the function type_from_bitpix
.
CFITSIO.fits_get_img_param
— Functionfits_get_img_param(f::FITSFile)
Return the bitpix, number of dimensions and the size along each dimension of the current image HDU.
See also fits_get_img_type
, fits_get_img_dim
and fits_get_img_size
.
CFITSIO.fits_create_img
— Functionfits_create_img(f::FITSFile, T::Type, naxes::Vector{<:Integer})
Create a new primary array or IMAGE extension with the specified data type T
and size naxes
.
fits_create_img(f::FITSFile, A::AbstractArray)
Create a new primary array or IMAGE extension with the element type and size of A
, that is capable of storing the entire array A
.
CFITSIO.fits_create_empty_img
— Functionfits_create_empty_img(f::FITSFile)
Create an empty image HDU with no dimensions, and of type Int
. See fits_create_img
.
CFITSIO.fits_insert_img
— Functionfits_insert_img(f::FITSFile, T::Type,
naxes::Union{Vector{<:Integer}, Tuple{Vararg{Integer}}}; prepend_primary::Bool = false)
Insert a new image extension immediately following the current HDU (CHDU), or insert a new primary array at the beginning of the file.
A new primary array may be inserted at the beginning of the FITS file by calling fits_insert_img
with prepend_primary
set to true
. In this case, the existing primary HDU is converted to an image extension, and the new primary array will become the CHDU.
The inserted array has an eltype T
and size naxes
.
fits_insert_img(f::FITSFile, a::AbstractArray{<:Real}; prepend_primary::Bool = false)
Insert a new image HDU with an element type of eltype(a)
and a size of size(a)
that is capable of storing the array a
. The flag prepend_primary
may be specified to insert a new primary array at the beginning of the FITS file.
CFITSIO.fits_write_pix
— Functionfits_write_pix(f::FITSFile,
fpixel::Union{Vector{<:Integer}, Tuple{Vararg{Integer}}},
nelements::Integer, data::StridedArray)
Write nelements
pixels from data
into the FITS file starting from the pixel fpixel
.
The HDU must have been created previously, and its size must match the number of elements being written.
See also: fits_write_pixnull
fits_write_pix(f::FITSFile, data::StridedArray)
Write the entire array data
into the FITS file.
The HDU must have been created previously, and its size must match the number of elements being written.
See also: fits_write_pixnull
, fits_write_subset
CFITSIO.fits_write_pixnull
— Functionfits_write_pixnull(f::FITSFile,
fpixel::Union{Vector{<:Integer}, Tuple{Vararg{Integer}}},
nelements::Integer, data::StridedArray, nulval)
Write nelements
pixels from data
into the FITS file starting from the pixel fpixel
. The argument nulval
specifies the values that are to be considered as "null values", and replaced by appropriate numbers corresponding to the element type of data
.
The HDU must have been created previously, and its size must match the number of elements being written.
See also: fits_write_pix
fits_write_pixnull(f::FITSFile, data::StridedArray, nulval)
Write the entire array data
into the FITS file. The argument nulval
specifies the values that are to be considered as "null values", and replaced by appropriate numbers corresponding to the element type of data
.
See also: fits_write_pix
CFITSIO.fits_write_subset
— Functionfits_write_subset(f::FITSFile,
fpixel::V, lpixel::V,
data::StridedArray) where {V<:Union{Vector{<:Integer}, Tuple{Vararg{Integer}}}}
Write a rectangular section of the FITS image. The number of pixels to be written will be computed from the first and last pixels (specified as the fpixel
and lpixel
arguments respectively).
The section to be written out must be contiguous in memory, so all the dimensions aside from the last one must span the entire axis range. The arguments fpixel
and lpixel
must account for this.
See also: fits_write_pix
CFITSIO.fits_read_pix
— Functionfits_read_pix(f::FITSFile,
fpixel::NTuple{Vector{<:Integer}, Tuple{Vararg{Integer}}},
nelements::Integer, [nulval], data::StridedArray)
Read nelements
pixels from the FITS file into data
starting from the pixel fpixel
. If the optional argument nulval
is specified and is non-zero, any null value present in the array will be replaced by it.
See also: fits_read_pixnull
, fits_read_subset
fits_read_pix(f::FITSFile, data::StridedArray, [nulval])
Read length(data)
pixels from the FITS file into data
starting from the first pixel. The optional argument nulval
, if specified and non-zero, is used to replace any null value present in the array.
See also: fits_read_pixnull
CFITSIO.fits_read_pixnull
— Functionfits_read_pixnull(f::FITSFile,
fpixel::Union{Vector{<:Integer}, Tuple{Vararg{Integer}}},
nelements::Integer, data::StridedArray, nullarray::Array{UInt8})
Read nelements
pixels from the FITS file into data
starting from the pixel fpixel
. At output, the indices of nullarray
where data
has a corresponding null value are set to 1
.
See also: fits_read_pix
fits_read_pixnull(f::FITSFile, data::StridedArray, nullarray::Array{UInt8})
Read length(data)
pixels from the FITS file into data
starting from the first pixel. At output, the indices of nullarray
where data
has a corresponding null value are set to 1
.
See also: fits_read_pix
CFITSIO.fits_read_subset
— Functionfits_read_subset(f::FITSFile,
fpixel::V, lpixel::V, inc::V,
[nulval],
data::StridedArray) where {V<:Union{Vector{<:Integer}, Tuple{Vararg{Integer}}}}
Read a rectangular section of the FITS image. The number of pixels to be read will be computed from the first and last pixels (specified as the fpixel
and lpixel
arguments respectively). The argument inc
specifies the step-size in pixels along each dimension.
If the optional argument nulval
is specified and is non-zero, null values in data
will be replaced by it.
data
needs to be stored contiguously in memory, and will be populated contiguously with the pixels that are read in.
See also: fits_read_pix
CFITSIO.fits_read_imghdr
— Functionfits_read_imghdr(f::FITSFile, maxdim::Integer = 99)
Read the header of an image HDU, where maxdim
represents the maximum number of dimensions to read. By default, maxdim == 99
will read the size along every dimension of the image. The function returns the values of SIMPLE::Bool
, BITPIX::Int
, NAXIS::Int
, NAXES::Vector{Int}
, PCOUNT::Int
, GCOUNT::Int
, and EXTEND::Bool
. The length of NAXES
is set equal to min(NAXIS, maxdim)
.
The BITPIX
value indicates the data type of the image, and it may be converted to a Julia type using the type_from_bitpix
function.
CFITSIO.fits_copy_image_section
— Functionfits_copy_image_section(fin::FITSFile, fout::FITSFile, section::String)
Copy a rectangular section of an image from fin
and write it to a new FITS primary image or image extension in fout
. The section specifier is described on the CFITSIO website
.
CFITSIO.fits_write_null_img
— Functionfits_write_null_img(f::FITSFile, firstelem::Integer, nelements::Integer)
Set a stretch of elements to the appropriate null value, starting from the pixel number firstelem
and extending over nelements
pixels.
CFITSIO.fits_resize_img
— Functionfits_resize_img(f::FITSFile, T::Type, naxis::Integer,
sz::Union{Vector{<:Integer}, Tuple{Vararg{Integer}}})
Modify the size, dimensions and optionally the element type of the image in f
. The new image will have an element type T
, be a naxis
-dimensional image with size sz
. If the new image is larger than the existing one, it will be zero-padded at the end. If the new image is smaller, existing image data will be truncated.
Example
julia> f = fits_clobber_file(tempname());
julia> a = [1 2; 3 4];
julia> fits_create_img(f, a);
julia> fits_write_pix(f, a);
julia> fits_get_img_size(f)
2-element Vector{Int64}:
2
2
julia> fits_resize_img(f, [3,3]);
julia> fits_get_img_size(f)
2-element Vector{Int64}:
3
3
julia> b = similar(a, (3,3));
julia> fits_read_pix(f, b); b
3×3 Matrix{Int64}:
1 4 0
3 0 0
2 0 0
julia> fits_resize_img(f, [4]);
julia> b = similar(a, (4,));
julia> fits_read_pix(f, b); b
4-element Vector{Int64}:
1
3
2
4
fits_resize_img(f::FITSFile, sz::Union{Vector{<:Integer}, Tuple{Vararg{Integer}}})
Resize the image to the new size sz
. The element type is preserved, and the number of dimensions is set equal to length(sz)
.
fits_resize_img(f::FITSFile, T::Type)
Change the element type of the image to T
, leaving the size unchanged.