Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem updating FITS header using pyfits 3.4 #44

Open
dgroenewald opened this issue Nov 18, 2016 · 7 comments
Open

Problem updating FITS header using pyfits 3.4 #44

dgroenewald opened this issue Nov 18, 2016 · 7 comments
Assignees
Labels

Comments

@dgroenewald
Copy link
Collaborator

Ran reducepoldata.py using pyfits 3.4.
Got the following error.

Traceback (most recent call last):
  File "scripts/reducepoldata.py", line 43, in <module>
    specpolwavmap(infile_list, linelistlib=linelistlib, logfile=logfile)
  File "/home/dviljoen/.conda/envs/iraf27/lib/python2.7/site-packages/polsalt/specpolwavmap.py", line 108, in specpolwavmap
    for f in ('SCI','VAR','BPM','WAV'): hdu[f].header.update('CTYPE3','O,E')
  File "/home/dviljoen/.conda/envs/iraf27/lib/python2.7/site-packages/pyfits/header.py", line 1017, in update
    'value, and comment string.' % idx)
ValueError: Header update sequence item #0 is invalid; the item must either be a 2-tuple containing a keyword and value, or a 3-tuple containing a keyword, value, and comment string.
Segmentation fault (core dumped)

Cause: syntax used in script to update header of FITS is based on pyfits 3.3 and has since been deprecated.
The above syntax in the script should be updated for the latest pyfits version (v3.4).

@crawfordsm
Copy link
Contributor

Thanks @dgroenewald ! Yes, the syntax will need to be updated. One other update that we should consider making is switching from pyfits to astropy as pyfits is no longer in active development as well.

Once you have confirmed this is the problem, this would be a great thing for you to fix @dgroenewald to learn how to submit an update and bug report, so I'm assigning you to it.

@knordsieck
Copy link
Collaborator

I’m glad to see there are others now using polsalt. I have been switching to astropy as I go, but I see specpolwavmap is still on old pyfits. Steve, am I right that switching to astropy would not have fixed the problem seen here, and it is still necessary to update the syntax in all uses of header.update? So, like in this case it should have been:
for f in ('SCI','VAR','BPM','WAV'): hdu[f].header.update(('CTYPE3','O,E'))

(with the extra parens)?

Ken

From: Steve Crawford [mailto:[email protected]]
Sent: Friday, November 18, 2016 4:19 AM
To: saltastro/polsalt
Subject: Re: [saltastro/polsalt] Problem updating FITS header using pyfits 3.4 (#44)

Thanks @dgroenewaldhttps://github.com/dgroenewald ! Yes, the syntax will need to be updated. One other update that we should consider making is switching from pyfits to astropy as pyfits is no longer in active development as well.

Once you have confirmed this is the problem, this would be a great thing for you to fix @dgroenewaldhttps://github.com/dgroenewald to learn how to submit an update and bug report, so I'm assigning you to it.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://github.com//issues/44#issuecomment-261497112, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADRf7eqNgliUaW_buIy6ybEC60bY-99kks5q_XuHgaJpZM4K2Ukq.

@crawfordsm
Copy link
Contributor

Correct--adding the extra parenthesis would be the necessary fix (there is one other spot in the code that needs to be fixed as well).

@knordsieck
Copy link
Collaborator

Actually, this seems to be related to deprecation warnings I get whenever we are using astropy, like in specpolfinalstokes:

WARNING: AstropyDeprecationWarning: The use of header.update() to add new keywords to a header is
deprecated. Instead, use either header.set() or simply header[keyword] = value or
header[keyword] = (value, comment). header.set() is only necessary to use if you also
want to use the before/after keyword arguments. [pyfits.core]

If I use their advice, and change all uses of update in this way, it works fine and the warning goes away. So I would propose to do this in all cases where update is used (there are a lot of them).

Ken

From: Steve Crawford [mailto:[email protected]]
Sent: Friday, November 18, 2016 11:54 AM
To: saltastro/polsalt
Cc: KENNETH H NORDSIECK; Comment
Subject: Re: [saltastro/polsalt] Problem updating FITS header using pyfits 3.4 (#44)

Correct--adding the extra parenthesis would be the necessary fix (there is one other spot in the code that needs to be fixed as well).


You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com//issues/44#issuecomment-261596831, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADRf7YZouunaQNta-dHwKarTFI7IzZExks5q_eZMgaJpZM4K2Ukq.

@knordsieck
Copy link
Collaborator

I’ve uploaded a new version, knnov16_2, which fixes this issue in all the routines used in specpolreduce, and upgrades pyfits to astropy where it wasn’t. Also, I uploaded a new version of polsalt/data/wppaterns.txt, which I noticed was still the old version on github.

Ken

From: Steve Crawford [mailto:[email protected]]
Sent: Friday, November 18, 2016 11:54 AM
To: saltastro/polsalt
Cc: KENNETH H NORDSIECK; Comment
Subject: Re: [saltastro/polsalt] Problem updating FITS header using pyfits 3.4 (#44)

Correct--adding the extra parenthesis would be the necessary fix (there is one other spot in the code that needs to be fixed as well).


You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com//issues/44#issuecomment-261596831, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADRf7YZouunaQNta-dHwKarTFI7IzZExks5q_eZMgaJpZM4K2Ukq.

@dgroenewald
Copy link
Collaborator Author

To check whether the above-mentioned error was caused by using the latest version of pyfits, I first downgraded pyfits to version 3.3 and ran the script again. It compiled successfully, however I also received a deprecation warning (see below)

/home/dviljoen/.conda/envs/iraf27/lib/python2.7/site-packages/pyfits/header.py:1108: PyfitsDeprecationWarning: The use of header.update() to add new keywords to a header is deprecated. Instead, use either header.set() or simply header[keyword] = valueorheader[keyword] = (value, comment). header.set() is only necessary to use if you also want to use the before/after keyword arguments. "keyword arguments.", PyfitsDeprecationWarning)

Secondly, the warning was solved by updating the header.update syntax to be compatible with pyfits 3.4. I did this in 3 places in the specpolwavmap.py script. Just as Ken suggested above, the fix is implemented by adding an extra parenthesis, however the extra parenthesis should be "{}" and not round brackets.
For example, in the case of pyfits 3.3 the command to update the header will be:
for f in ('SCI','VAR','BPM','WAV'): hdu[f].header.update('CTYPE3','O,E')
and in pyfits 3.4 it is:
for f in ('SCI','VAR','BPM','WAV'): hdu[f].header.update({'CTYPE3': 'O,E'})

With these changes made, I ran the code again (using pyfits 3.4) and it compiled successfully.
I am still working towards updating the code using astropy (instead of pyfits).

@knordsieck
Copy link
Collaborator

knordsieck commented Nov 24, 2016 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants