Since this is a recurring question, here is a little script to change a single keyword in a set of FITS files:
/*
* Script to change a keyword value in a set of FITS files.
*/
var inputDirectory = "";
var outputDirectory = "";
var keywordName = "";
var oldKeywordValue = "";
var newKeywordValue = "";
// ----------------------------------------------------------------------------
if ( inputDirectory.length == 0 )
throw new Error( "Must specify an input directory" );
if ( outputDirectory.length == 0 )
throw new Error( "Must specify an output directory" );
if ( keywordName.length == 0 )
throw new Error( "Must specify a keyword name" );
if ( oldKeywordValue.length == 0 || newKeywordValue.length == 0 )
throw new Error( "Must specify old and new keyword values" );
if ( !inputDirectory.endsWith( '/' ) )
inputDirectory += '/';
if ( !outputDirectory.endsWith( '/' ) )
outputDirectory += '/';
for ( let D = searchDirectory( inputDirectory + "*.fit", false/*recursive*/ ), i = 0; i < D.length; ++i )
{
let w = ImageWindow.open( D[i] );
let k = w[0].keywords;
let found = false;
for ( let j = 0; j < k.length; ++j )
{
k[j].trim();
if ( k[j].name == keywordName )
if ( k[j].strippedValue == oldKeywordValue )
{
k[j].value = newKeywordValue;
found = true;
break;
}
}
if ( found )
{
console.writeln( "<end><cbr>" + D[i] );
w[0].keywords = k;
w[0].saveAs( outputDirectory + File.extractNameAndSuffix( D[i] ),
false/*queryOptions*/,
false/*allowMessages*/,
false/*strict*/,
true/*verifyOverwrite*/ );
}
w[0].forceClose();
}
Just enter the appropriate script parameters and run it from Script Editor. For example:
var inputDirectory = "/path/to/images";
var outputDirectory = "/path/to/images/test";
var keywordName = "OBJECT";
var oldKeywordValue = "M1";
var newKeywordValue = "XXX";
This would change all OBJECT keyword values from 'M1' to 'XXX' in all existing FITS files on a folder '/path/to/images' (replace it with the path to an actual folder on your system). The output directory must exist, and if it is the same as the input directory, existing files will be replaced (you will be asked for confirmation in such case). I have made a few tests and the script works well; however, use it at your own risk, of course. Everybody: feel free to improve it and/or adapt it to your specific needs.