pythonbashiraf

Pyraf rspectext RuntimeError: dictionary keys changed during iteration


I have to convert a classic ascii file with two columns (wavelength and flux) into a fits file and I used rspectext from pyraf (with dtype=interp) in a python script but I get this error message:

Traceback (innermost last):
File "<CL script CL1>", line 1, in <module>
File "<CL script onedspec.rspectext>", line 54, in rspectext
    iraf.hedit(Vars.specout, 'title', Vars.title, add=yes, 
    addonly=no,PYdel=no,update=yes,verify=no,show=no)
RuntimeError: dictionary keys changed during iteration

I cannot understand what is wrong. I updated everything, followed guides to install both iraf and pyraf and on iraf, rspectext works. In other python scripts I use other commands like continuum, splot etc. and they work.

My script for a test is simply:

from pyraf.iraf import onedspec,rspectext
onedspec
rspectext(input='test.dat',output='spectrum',dtype='interp')

A very short version of the spectrum with which i am testing is:

5530.01708984375 0.9749500155448914
5530.0498046875 0.9674800038337708
5530.0830078125 0.9679499864578247
5530.1162109375 0.968280017375946
5530.1474609375 0.9703999757766724
5530.18115234375 0.9549300074577332
5530.21435546875 0.9670699834823608
5530.2470703125 0.9639800190925598
5530.2802734375 0.953029990196228
5530.31298828125 0.9535700082778931
5530.34619140625 0.9583899974822998
5530.37890625 0.9467300176620483
5530.412109375 0.9565500020980835

python version 3.10.6 pyraf version 2.2.0 iraf 2.17 OS Ubuntu 22.04.1 LTS 64bit

It is ok also if you have suggestions for alternative ways to normalise a spectrum using python. Thanks in advance.


Solution

  • That is actually a bug in PyRAF 2.2.0, which is fixed in 2.2.1. See iraf-community/pyraf#146 for details. So the way to fix this is to upgrade to 2.2.1.