Yes, an interesting project for sure.
Please note that in the above thread I had to write a workaround to a bug we had in late releases of PI version 1.5.
Here is an updated script that prints all FITS header keywords for a set of selectable FITS images:
#include <pjsr/DataType.jsh>
/**
* Opens a FITS file at the specified fitsFilePath path and reads all keywords
* from the primary HDU. Returns an array of FITSKeyword objects.
*
* Limitations:
* - HIERARCH convention not supported, i.e. all keyword names must
* be strings of (possibly padded with white spaces) eight characters.
* - Reads only the first HDU; extension HDUs are ignored.
*/
function LoadFITSKeywords( fitsFilePath )
{
function searchCommentSeparator( b )
{
var inString = false;
for ( var i = 9; i < 80; ++i )
switch ( b.at( i ) )
{
case 39: // single quote
inString ^= true;
break;
case 47: // slash
if ( !inString )
return i;
break;
}
return -1;
}
var f = new File;
f.openForReading( fitsFilePath );
var keywords = new Array;
for ( ;; )
{
var rawData = f.read( DataType_ByteArray, 80 );
var name = rawData.toString( 0, 8 );
if ( name.toUpperCase() == "END " ) // end of HDU keyword list?
break;
if ( f.isEOF )
throw new Error( "Unexpected end of file: " + fitsFilePath );
var value;
var comment;
if ( rawData.at( 8 ) == 61 ) // value separator (an equal sign at byte 8) present?
{
// This is a valued keyword
var cmtPos = searchCommentSeparator( rawData ); // find comment separator slash
if ( cmtPos < 0 ) // no comment separator?
cmtPos = 80;
value = rawData.toString( 9, cmtPos-9 ); // value substring
if ( cmtPos < 80 )
comment = rawData.toString( cmtPos+1, 80-cmtPos-1 ); // comment substring
else
comment = "";
}
else
{
// No value in this keyword
value = "";
comment = rawData.toString( 8, 80-8 );
}
// Perform a naive sanity check: a valid FITS file must begin with a SIMPLE=T keyword.
if ( keywords.length == 0 )
if ( name != "SIMPLE " && value.trim() != 'T' )
throw new Error( "File does not seem a valid FITS file: " + fitsFilePath );
// Add new keyword.
keywords.push( new FITSKeyword( name, value, comment ) );
}
f.close();
return keywords;
}
function main()
{
var ofd = new OpenFileDialog;
ofd.multipleSelections = true;
ofd.caption = "LoadFITSKeywords: Select FITS Files";
if ( ofd.execute() )
for ( var i in ofd.fileNames )
{
console.writeln( "<end><cbr><br><b>", ofd.fileNames[i], "</b>" );
var keywords = LoadFITSKeywords( ofd.fileNames[i] );
for ( var i in keywords )
console.writeln( keywords[i].name, ',', keywords[i].value, ',', keywords[i].comment );
}
}
main();
Regarding alignment, have you tried with DynamicAlignment? DA can align images with one, two, and >= three alignment points. For a single alignment point, a simple translation is applied to align the images. For two points, translation + rotation + scale change on the line joining both alignment points. For >= 3 points, DA uses thin plates (2D surface splines).