Batch edit fits headers

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
 
Use the script as attached in #19, but is may need modifying in a similar vein to that below

OR

try changing this line in Juan's script
for ( let D = searchDirectory( inputDirectory + "*.fit", false/*recursive*/ ), i = 0; i < D.length; ++i )

to this
for ( let D = searchDirectory( inputDirectory + "*.xisf", false/*recursive*/ ), i = 0; i < D.length; ++i )

I don't know the exact format of xisf files so it may not work
 
Last edited:
I had a few problems with this script. Although the v1.0.1 script does not require input of the old keyword value, it still tests for it (so you still have to specify it anyway). Worse, the search strips the common FITS single quotes off the old value before comparing, so the specified old value must be without quotes, but the new value must include the quotes. It took me a while to figure this out. If you just want to ignore the old value and write a new value the attached script should do this. This version also replaces the ".fit" extension with ".xisf" (i.e. it looks for and changes ".xisf" files).
 

Attachments

  • BatchEditFITSSingleKeywordXisf.zip
    2.5 KB · Views: 128
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


I have the exact same case scenario but unfortunately it is not working for my FITS files. Since this is an old thread, is there any new way of doing that? My flats have no filter value and I wanna add it.


Thanks!
 
Hello,

Sometime ago the original script has been modified to open XISF files only. Please check the new attached edited version. I have added the ability to select the file type (xisf, fits, fit; lowercase only)

Today I noticed that I'm a bit rusty in PI scripting ?

Greetings,

Enzo.
 

Attachments

  • BatchEditFITSSingleKeyword.zip
    2.8 KB · Views: 119
Thanks for that! I now understand what the script can do, and I can understand that is not what I need exactly. I need to add a Filter value that does not exist (Flats through SharpCap).

Despite that, I've just run the script, trying to edit the SWCREATE value and change it to "Ha", but there is no such value on the new file.
 

Attachments

  • Before.png
    Before.png
    566.1 KB · Views: 111
  • script.png
    script.png
    308.8 KB · Views: 124
  • After.png
    After.png
    807.9 KB · Views: 106
After some hours of looking into this, I discover that you have just been unlucky with your choice of keyword. Everything works fine up to the final "saveAs" file output call. Somewhere inside this call PixInsight inserts eight FITS header records immediately following the BSCALE record. One of these is a PROGRAM keyword record, identifying PI as the originating program. The SWCREATE keyword (which identifies the original creating program) appears to be deleted (I guess to avoid ambiguity - or something ...). So you need to pick a different keyword to repurpose.
... if you get the impression that PI really doesn't like FITS headers, you may have a point.
 
A further note ...
This interference with FITS header keywords does not happen if the file is saved as .xisf (the SWCREATE keyword is retained - and modified, and the additional lines are not inserted).
Inserting PI content is fine, but unsolicited, undocumented and completely unneccessary deletion of an unrelated keyword is unacceptable.
It seems that PI have decided that the keywords "SWCREATE" and "CREATOR" "don't make sense" (comment on line 2394 of FITS.cpp), and so should not be propagated when a FITS file is saved. They make perfectly good sense to me...
... maybe PI think that if they assert PROGRAM authorship, nobody else can possibly have been involved in creating the file. This seems to completely go against the model adopted everywhere else of maintaining an audit trail of the processing.
 
Hello,

Maybe this will help. I have added the option to change the output file type, so you can select FITS as input and XISF as output.

I have not tested it extensively. It could be extended, for example to add the keyword if not exist.

Greetings,

Enzo.
 

Attachments

  • BatchEditFITSSingleKeyword.zip
    2.9 KB · Views: 223
Thanks for that! I now understand what the script can do, and I can understand that is not what I need exactly. I need to add a Filter value that does not exist (Flats through SharpCap).

Despite that, I've just run the script, trying to edit the SWCREATE value and change it to "Ha", but there is no such value on the new file.

Moin

Same to me.
I'm using an AsiAir, which automatically inserts a fits keyword FILTER, if you have a filter wheel. But I don't have (I'm using OSC).
Nevertheless I would like to have the informations about the used filter(s) used that night.
So I want to insert FILTER to the fit files so that I can see later in WBPP wether the subs are taken with a UHC or narrowband or what else.
In fact, a try with the latest file from saturday did show an error:

** Warning [156]: C:/Program Files/PixInsight/src/scripts/BatchEditFITSSingleKeyword.js, line 149: assignment to undeclared variable index

And the log has an entry for reading the fit file, but not for writing.
The log file has the following entries, when I try to insert the keyword FILTER:

** Warning: The FITS format does not define an unambiguous orientation of pixel data. The coordinates read on the image may be wrong.
Reading image:
F:/ASTROFOTO/Nebel/IC 410 - Kaulquappen/SESSION_20210224 , Apo72, Asi2600, 900s, 51, Optolong, -10C/Lights/Light_IC410_900.0s_Bin1_gain51_20210224-225726_-10C_0010.fit
** Warning: Deprecated format: FITS
73 FITS keywords extracted.
Reading FITS image: 16-bit integers, 1 channel(s), 6248x4176 pixels: done
* Loaded astrometric solution:
Referentiation matrix (world[ra,dec] = matrix * image[x,y]):

+1.22142098e-03 -1.50394439e-03 +5.20670552e+00
-1.51122298e-03 -1.22207998e-03 +5.19085121e+00
.
.
.
Image bounds:
top-left .............. RA: 5 48 28.457 Dec: +38 38 55.35
top-right ............. RA: 6 19 30.917 Dec: +28 38 29.04
bottom-left ........... RA: 5 16 48.018 Dec: +33 44 24.81
bottom-right .......... RA: 5 50 14.661 Dec: +24 13 21.39

** Warning: The FITS format does not define an unambiguous orientation of pixel data. The coordinates read on the image may be wrong.
Reading image:

and so on....

When I tried to edit keyword COMMENT, nothing happened at all, the script finished execution immediately.
 
This script can only edit keyword values, it can't add keywords. The "COMMENT" keyword does not have a value (only a comment), so this script will have no effect if you try to change a "COMMENT" keyword.
 
Does this script still work? For me it doesn't do anything. Terminal window closes after a few seconds. Nothing in output directory.
 
Yes, version 1.0.4. Found th problem. My OS is linux, which is case sensitive. Changing line 36 to:

fileTypes[2] = "FIT";

solved my problem. For the non-Windows case, you could make the search looks for both lower and upper cases, for the three file types options.

Thank you for the script!

-Kevin
 
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
Thanks, Gerald. The procedure you outlined made it very easy for me to add a FILTER keyword and value to 42 lights.
 
I am in the same position as RolWinde (post #34). Is the position that there is no way to add a new keyword?
 
Back
Top