What is DeLaFits?
DeLaFits is a pure Delphi and Lazarus library for working with data in the FITS format.
DeLaFits features:
- parsing a byte stream to an HDU container
- creating and deleting an HDU in a container
- reading, writing, adding, and deleting HDU header keyword records
- reading and writing HDU data array
- reading, writing, and rendering physical values (pixels) of an IMAGE extension
- reading and writing records and fields of a TABLE extension
How to use?
Add the DeLaFits directory “source” to your project’s search path. Add references to DeLaFits units. Open the FITS file and create a FITS container from it. Select an HDU from the container and get a pointer to its header and data. Read and write HDU header keyword records. Read and write HDU data byte array. To work with the physical values of an HDU’s data, set its class according to the extension type.
uses
..., DeLaFitsCommon, DeLaFitsCard, DeLaFitsClasses, DeLaFitsImage;
// Open the FITS file
LStream := TFileStream.Create('demo-image.fits', fmOpenRead);
// Create a FITS container
LContainer := TFitsContainer.Create(LStream);
// Get the first HDU from the container, its header and data
LItem := LContainer.Items[0];
LHead := LItem.Head;
LData := LItem.Data;
// Read the HDU header keyword records. Get the date and time
// of the observation specified by the keyword "DATE-OBS"
if LHead.LocateCard('DATE-OBS') then
begin
LCard := TFitsDateTimeCard.Create;
LCard.Card := LHead.Card;
LDateTime := LCard.ValueAsDateTime;
LCard.Free;
end;
// Read the HDU data byte array
var LBuffer: array of Byte;
SetLength(LBuffer, LData.InternalSize);
LData.ReadChunk({AInternalOffset:} 0, Length(LBuffer), {var} LBuffer[0]);
// Set the HDU class as TFitsImage and read its pixel values
if LContainer.ItemExtensionTypeIs({AIndex:} 0, TFitsImage) then
begin
LContainer.ItemClasses[0] := TFitsImage;
LImage := LContainer.Items[0] as TFitsImage;
var LPixels: array of Integer;
SetLength(LPixels, LImage.Data.ValueCount);
LImage.Data.ReadValues({AIndex:} 0, Length(LPixels), {var} TA32c(LPixels));
end;
// Free objects
LContainer.Free;
LStream.Free;
Summary
Test environment
DeLaFits is successfully compiled in Delphi 7/2010/12.1 and Lazarus 1.8.4/3.4.0
Unit tests pass successfully on 32- and 64-bit Windows 10 and Linux Mint 19.3/20.3