pythonimagepixelfitsiraf

variable limits when cutting pixels from a fits image with imcopy (IRAF) in python (pyraf)


I am trying to use pyraf to use the iraf's task imcopy in one code in python. My problem is that you have to specify the range in x and y in which you want to cut the image, but I want those limits to be variables, since everything is within a loop and I have to copy a several regions.

For example, I have this:

img_seg =raw_input('Name of the segmentation image? ')
iraf.imcopy(input=img_seg+'[200:220,300:400]',output='out')

But if I try with for example:

x1 = 200
x2 = 220
y1 = 300
y2 = 400
iraf.imcopy(input=img_seg+'[x1:x2,y1:y2]',output='out'),

that does not work. It gives me a syntax error and the message ERROR (1, "Number of input and output images not the same")

I have been trying for a while but I have not been able to make it. So it would me nice if someone can explain me how to do this, and thanks in advance!

ps. My anwer is similar to this one How to run a function on a list of objects in python/pyraf?, but the answer there is basically what is not working for me.


Solution

  • Ok, so the point was that IRAF needs to see only the interval, but you can use python to build the interval as is needed for IRAF. So all one needs to do is:

    iraf.imcopy(input=img_seg+'['+str(x1)+':'+str(x2)+','+str(y1)+':'+str(y2)+']',output='out')