astrogo / fitsio

fitsio is a pure-Go package to read and write `FITS` files
BSD 3-Clause "New" or "Revised" License
53 stars 24 forks source link

Panic on Duplicate Keys #38

Closed rickbassham closed 6 years ago

rickbassham commented 6 years ago

This is obviously by design.

Some of my images saved by Sequence Generator Pro have DEWPOINT specified twice. Since this library panics on duplicate keywords, I can't use this to parse my fits files. I've sent them a request to fix it on their end.

I'm not sure doing a panic is the right thing to do here, although short of just logging it out or silently ignoring it, neither of which are good options, I'm not sure what the best approach to handle this is. I'll probably fork and silently ignore for my own work, but I'm not sure what the rest of the community would prefer on this.

Thanks for the awesome lib!

sbinet commented 6 years ago

when I wrote this, I wanted to be very strict at first and maybe loosen the grip on a few things once I'd gained more experience (and more data about files in the wild.)

IIRC, the FITS standard is silent on what is required to do in the case of duplicate keywords: https://fits.gsfc.nasa.gov/standard40/fits_standard40aa.pdf

I guess I could just piggy back on what C-FITSIO or astropy.io.fits does.

what do you think ?

rickbassham commented 6 years ago

I agree this lib should probably do the same as the other libs, just to have consistency in the community. I haven't tested my image against those yet, but can this weekend.

sbinet commented 6 years ago

great! please update this thread with your findings.

sbinet commented 6 years ago

tunrs out fitshdr (the C equivalent of ./cmd/go-fitsio-listhead) ignores the duplicate card keys and returns the last occurence of such duplicates.

astrogo/fitsio#39 does the same.

astrogo/fitsio still returns an error when somebody tries to create a FITS file with duplicate cards, though.