PixInsight Forum (historical)
PixInsight => General => Topic started by: JeffSeivert on 2016 March 16 08:45:36
-
I have a bunch of darks that mistakenly have the OBJECT keyword as M1. Is there a way to batch edit the keyword for a group of files rather than one at a time?
Thanks,
Jeff
-
I use this one: <link removed>
EDITED BY THE FORUM ADMINISTRATOR
Please do not advertise other applications on this forum.
-
Hi Jeff!
No need to do software jumping and loose data precision if you have PI.
PI can cover all your processing needs.
Your solution:
Create an Image Container in wich you load the images with the OBJECT Name 'M1' in the Fits Header !!
Load ONLY one of the images with "M1" into your Workspace.
Select File / Fits Header
At the bottom set
Name: OBJECT
Value: Dark
Comment: Updated by me
Click the line with OBJECT 'M1'
Click the Replace button (on the bottom of the FITSHeader process window)
This changes the value of OBJECT in the FITSHeader process window to 'Dark'.
Move and drop the blue triangle of the FITSHeader process to your Workspace
this get you a FitsHeader process icon on the Workspace.
Finally move the blue triangle of the Image Container with all your M1 images and drop it
over the FitsHeader process icon
All now new created images will be replaced in the Fits Header with the text you entered.
Gerald
-
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.
-
For those having troubles with the script - like i do -
use the existing simple working solution
with
FitsHeader process
and Image Container.
Gerald
-
Gerald, wouldn't that overwrite the entire fits header of each image in the ImageContainer?
rob
-
In my first test it looked okay.
After your note i tried it again and got an overwrite
of all selected Image with the sam FitsHeader.
Have to check again - could be i was NOT precise enough...
Gerald
-
Hi Rob!
You are right. The ImageContainer trick would
overwrite all other data in the FITS Header including the OBJECT data also !!!
So, i have to apologize for not testing my advice 100% correct.
For the case to get the darks re named to dark in the "object" Fits Column it would be good enough,
but when the script will work it should be better.
Ash on my head.
Gerald
-
OK thanks for checking it - i was fairly certain it would all be overwritten but had not tried it in a long time. was not sure what would happen...
rob
-
What's the problem with the script? Have you tried it?
-
Hey! We are working on a (simple) friendly GUI based on Juan's script. Stay tuned ;)
-
What's the problem with the script? Have you tried it?
Hi Juan!
The issue was between chair and keyboard...
First didnt enter the pathname in script. After first run with error abend
i couldnot restart script with F9. Had to remove and reload.
You never can imagine how some users like me are ticking.
Sorry
Gerald
-
Hi, the script with the interface has been uploaded to PixInsight Resources repository. If you do not have it already configured see here (http://pixinsight.com.ar/en/docs/47/pixinsight-manage-repositories.html) how to add the repository and download the script.
Saludos, Alejandro.
-
Thank you all for the discussion and solutions! I will give them a try.
Thanks,
Jeff
-
Alejandro
Could you give a link to the new script with interface.
Thanks
Mike
-
Hi Mike,
You can download it (and others) by setting a new repository directly on PI (see Alejandro's link), or if you prefer, I'm attaching the zipped script for download.
By the way, script's credits are for Juan, I just added the GUI. To all: feel free to change the script to improve the GUI or add some features.
Greetings,
Enzo.
-
Thanks!
Very nice!!
Gerald
-
Hello All,
I have been following this closely with interest. I have a lot of flat files that don't have any filter type in the fits header so tonight I tried the script.
It failed as my entry for old keyword value is blank (see screen capture) and the net result it did not work.
I tried with another key word value like OBSERVER and this had a value already and I could change this successfully with the script.
So it wouldn't work with blank fields - any ideas gents
Thanks for the efforts all with this development.
Regards
Martin
-
Hi Martin, please test the script variation attached. I have removed the requirement of that value, but I'm not sure you have some unexpected behavior...
Greetings,
Enzo.
-
Hello Enzo,
Yes I can confirm that this latest version you have kindly posted works with blank entries as a value you need to change.
I have very quickly modified my collection of Flat file headers to now include the filter.
Thank you for your efforts, and indeed all who have contributed.
Martin
-
Apologies for raising an older thread, but thought it might be useful to provide some feedback.
I recently had cause to change the focal length in the FITS header for a series of shots taken back in 2017. I was just starting to use SGP and really had not much of an idea of what I was doing (a bit like I am with PI right now). Anyway, for some reason my focal length was set to 517mm in stead of 714mm per the ES ED102CF I have.
Anyway, after some reading and assistance from Rob for pointing me in the right direction, I eventually found and ran the script to change the focal length accordingly. I found some interesting results however.
Running the script on either my High Sierra iMac, or Win 10Pro PC, the script would append a . on the end of the digit so instead of getting 714 the value was 714. Given it is a digit, it may well treat 714. as 714.00 therefore making no difference at all, but still thought it might be worth pointing out.
Pete