FITS header support for COMMENT and HISTORY

Started by sbklb1, February 18, 2021, 12:03:44 PM

Previous topic - Next topic

sbklb1

ExifTool supports .FIT files and returns the header information for keyword/values

However, does not return the COMMENT and HISTORY keyword or values

I presume this is because COMMENT and HISTORY are commentary tags that do not follow standard key/value pairs, but instead are given as shown


COMMENT   This is a comments and is upto line of 80 characters
COMMENT   There can be multiple rows for comment
COMMENT   does not have a equals sign and is not quoted
HISTORY   A History tag has the same behavior as COMMENT above
HISTORY   and can have multiple rows


The spec also has the capability to CONTINUE a tag using a & at the end.  I do not have any examples of this other than reading in the spec.

I would guess this is not supported by default as does not match key/value pair and also is not enumerated for each repeat row.  I guess you need to decide on whether to enumerate this or not as will squash value if not combined into a single result.

a standard FITS tag would use something like

FOCALLEN=              214.382 / Camera focal length   
INSTRUME= 'ZWO CCD ASI290MC'   / instrument name       
DATE    = '2021-02-03T16:28:06' / UTC date that FITS file was created


ExifTool version 12.18 running on Windows 10

Thanks,

Scott

Phil Harvey

ExifTool should already support CONTINUE lines.

But I'll add support for reading COMMENT and HISTORY lines.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

sbklb1

Excellent!  and Thanks Phil.

For completeness may want to also add the "BLANK" field, although not sure this is commonly used or what you would map it to other than an empty value with key blank.  From the spec, Columns 1-8 contain the string, `BLANK   ' (ASCII blanks in columns 6-8).

also,

For documentation, my use case for the COMMENT and HISTORY is as follows:

Most astronomy tools generate and read FITS files as the default, and editors to add COMMENT and HISTORY data exist as these are the only freeform keywords for FITS files with SIMPLE headers.  Given that most of my images will start as FITS files, I am appending additional information that is not part of the generic tags to these fields, possibly with keyword/value pairs.  For example, LIGHTCT = 50 or LIGHTSUB = 30 as an indicator of the count and length of the subexposures or GUIDER = Orion 9x50  that is some additional information about the equipment [INSTRUM tag], that I want to maintain for my records.

In my processing of images the FITS file is converted to JPG or PNG files, and my plan is to use ExifTool to tag them.

Your ExifTool provides the conduit to extract the additional tags for HISTORY/COMMENT as listed so they can be pushed into new tags in JPG/PNG files.

Phil Harvey

ExifTool 12.19 with this new ability was released yesterday.  Note that each line in the COMMENT and HISTORY is extracted as a separate tag.  You need to add the -a option to see them all.  This may complicate matters for you when copying the tags to another format, but I didn't like the alternative of joining them all together.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

sbklb1

Phil,

Tested, and slight issue.  The COMMENT and HISTORY can start at column "9" for the FITS card, and it appears that you are assuming some other delimiter to and start at character 11 to start the value.  so a legal HISTORY tag is

HISTORY This starts at column 9


ExifTool 12.19 will return

History        : is starts at column 9


Note this removes "Th" from the beginning of the value

Further, agree that -a option is "best" method to generate the result for items that are "duplicate tags".

Regards, Scott

Phil Harvey

Yup.  Bug.  I'll fix it in the next release.  All my testing samples had extra spaces so I didn't see this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

Question: Should I preserve leading whitespace in comments/history?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

sbklb1

Personally, I would say "it depends".   for me it is more natural to squash all leading and trailing white space and would be my default.  However, I was researching FITS files and saw examples like the below, that would be better to preserve leading spaces.  Trailing can be squashed.  However, I am a hobbyist and not a professional for this use case.

note this example from page 152 of https://fits.gsfc.nasa.gov/users_guide/usersguide.pdf, approximated below:

COMMENT -------------------------------------------------------------------
COMMENT     Cumulative weighted average of the 140. micron photometry.
COMMENT      This average is calculated using the weighted number of
COMMENT      observations from each Weekly Averaged Map ( WtNumObs from
COMMENT      the Weekly Averaged Map) as the weight, such that
COMMENT      annual_average =
COMMENT         sum( weekly_average * weekly_weight )/ sum( weekly_weight)
COMMENT
COMMENT      The photometric measurement is given as a
COMMENT      spectral intensity, I(nu) in MJy/sr, and

Phil Harvey

Ah. (lightbulb turning on)  I will remove leading whitespace in the print conversion, so you can preserve it with the -n option.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

sbklb1

Verified it is working as expected.  Thanks.