Question

I have written a function that i need to use for multiple files. when I use it for one file it works but when i try to use it for more i get errors. I have attached my code, can anybody tell me what is wrong with it?

#! /usr/bin/env python
#peice of code to find the information from a star catalog for the brightest star from each indiviual CCD

import os, sys, glob, pyfits, numpy

dr='/home/desar2.cosmology.illinois.edu+7443/DESFiles/desardata/OPS/red/20130321211637_20130106/red/DECam_00166306/catalogs/'

def meanarr(image, res=None):
 "costruct code which runs over a single ccd to get the means"
 a=pyfits.getdata(image).MAG_AUTO
 q=numpy.mean(a)
 s=pyfits.getdata(image).X2WIN_IMAGE
 j=numpy.mean(s)
 f=pyfits.getdata(image).Y2WIN_IMAGE
 z=numpy.mean(f)
 g=pyfits.getdata(image).XYWIN_IMAGE
 h= numpy.mean(g)
 a=[q,j,z,h]
 print a
 s0=''
 return res

#image=dr+'DECam_00166306_01_star_catalog.fits'
#s=meanarr(image)

for arg in (sys.argv):
 print arg
 s=meanarr(arg)

print '---done---' 

It should just print a list of four figures for each input files, but i think there is a problem in the last four lines.

Was it helpful?

Solution

The first element of sys.argv is always your script that you run, not the image. Could that be the error?

You should do

for arg in sys.argv[1:]:
    print arg
    s=meanarr(arg)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top