#from numarray import * ## Changed to numpy Aug 2007
from numpy import *
import pyfits
from simpler_skymap_datons import *

insumfilestuples = [
('ModelFlux64x64BremICPion1-1000GeV.060529.fits','ModelFlux64x64RSe8BremICPion1-1000GeV.060529.fits',0),
('ExposrTim64x64IntTime806.0.060529.fits','ExposrTim64x64RSe8IntTime806.0.060529.fits',1)
]

WantRescale = 1.00000000e+08
isexp = 0
which3rdbin = 0

for this_tuple in insumfilestuples:
#   1.1/ Get input file to be summed (assumed 128x128):
    this_infitsfile, thisoutrebinfile,isexp = this_tuple
    model_dat_HDUList = pyfits.open(this_infitsfile)
#   "touch" them to make sure -32 format read in:
    print 'model_dat_HDUList[0].header: ', model_dat_HDUList[0].header
    print 'model_dat_HDUList[0].data: ', model_dat_HDUList[0].data
#   1.2/ Rescale:
    if(isexp==0):
        model_dat_rebinned_hdu_data = model_dat_HDUList[0].data*WantRescale
    elif(isexp==1):
        model_dat_rebinned_hdu_data = model_dat_HDUList[0].data/WantRescale
    else:
        print 'Fatal Error: only recognizes isexp of 0 or 1 but you typed:', isexp
        
#   "Touching" the data to make sure it is read in properly:
    print 'Sample of rescaled data: ' , model_dat_rebinned_hdu_data

    model_dat_rebinned_HDU = pyfits.PrimaryHDU(data=model_dat_rebinned_hdu_data)

    model_dat_rebinned_HDU.writeto(thisoutrebinfile)

    model_dat_HDUList.close()
