def main():
  iso25D = 40 / 0.396
  #band = Settings.setBand()

 # dataDir = '/media/46F4A27FF4A2713B_/work2/data'
  fitsdir = Settings.getConstants().dataDir+'SDSS'+Settings.getConstants().band
  #  fitsDir = '../data/SDSS/'
  #  dataDir = '../data'
  band = Settings.getConstants().band
  
  #missing = np.genfromtxt('u_wrong_skies.csv', delimiter = ',', dtype = object)[:, 0]
  #print missing
  #missing = np.genfromtxt('wrong_tsfield.csv', delimiter = ',', dtype = int)
  #missing = np.genfromtxt("susp_z.csv", dtype = int, delimiter = "\n")
  #print missing
  #for x, i in enumerate(missing):
  for i in range(Settings.getConstants().lim_lo, Settings.getConstants().lim_hi):
    
    #print i, lim_lo, lim_hi, setBand()

    i = int(i) - 1

    try:
      print Settings.getSkyFitValues(str(i + 1)).sky, Settings.getSkyFitValues(str(i + 1)).isoA      
      print 'filename', GalaxyParameters.getSDSSUrl(i)
      print 'filledFilename', GalaxyParameters.getFilledUrl(i, band)
      print i, 'i'
      output = Photometry.calculateGrowthCurve(i)
      #utils.writeOut(output, band+'_flux'+str(Settings.getConstants().lim_lo)+'.csv')
    except IOError as err:
      print 'err', err
      output = [str(i+1), 'File not found', err]
      utils.writeOut(output, band+'_fluxErrors.csv')
      pass   
  def calculateGrowthCurve(i):
    CALIFA_ID = str(i+1)

    dbDir = '../db/'
    imgDir = 'img/'+Settings.getConstants().band+'/'
    center = Photometry.getCenter(i)
    distances = Photometry.createDistanceArray(i)

    pa = db.dbUtils.getFromDB('pa', Settings.getConstants().dbDir+'CALIFA.sqlite', 'nadine', ' where califa_id = '+ CALIFA_ID)[0]
    ba = db.dbUtils.getFromDB('ba', Settings.getConstants().dbDir+'CALIFA.sqlite', 'bestBA', ' where califa_id = '+ CALIFA_ID)[0]
    
    #print CALIFA_ID, pa
    #pa = -1*(90 - pa)
    
    # --------------------------------------- starting ellipse GC photometry

    print 'ELLIPTICAL APERTURE'
    try:
      #returns np.mean(y), fluxSlope, np.mean(yM), fluxSlopeM, fluxData[-1, 0]
      sky, slope, skyM, slopeM, isoA  = Photometry.fitSky(center, distances, pa, ba, CALIFA_ID)
    except IndexError:
      sky = 'nan'
      slope = 'nan'
      isoA = 'nan'
      print 'aaaa'
    out = (CALIFA_ID, sky, slope, skyM, slopeM, isoA)
    utils.writeOut(out, "gc2_"+Settings.getConstants().band+"_sky.csv")
def checkOutput(dataDir, ID, run, rerun, camcol, runstr, band, field_str, fitsDir, filledDir):
	outputFilename = dataDir+'/'+filledDir+'fpC-'+runstr+'-'+band+camcol+'-'+field_str+'.fits'
	print outputFilename
	try:
	  f = open(outputFilename)
	  #print 'musu', ID
	except IOError as e:
	  
	  out = [ID]
	  utils.writeOut(out, 'missing_'+setBand()+'.csv')
	  pass
 def calculateGrowthCurve(i):
   CALIFA_ID = str(i+1)
   band = Settings.getConstants().band
   dbDir = '../db/'
   imgDir = 'img/2/'+Settings.getConstants().band+'/'
   center = Photometry.getCenter(i)
   distances = Photometry.createDistanceArray(i)
   
   e = Photometry.findClosestEdge(distances, center)
   pa = db.dbUtils.getFromDB('pa', Settings.getConstants().dbDir+'CALIFA.sqlite', 'nadine', ' where califa_id = '+ CALIFA_ID)[0]
   ba = db.dbUtils.getFromDB('ba', Settings.getConstants().dbDir+'CALIFA.sqlite', 'bestBA', ' where califa_id = '+ CALIFA_ID)[0]
   utils.writeOut([CALIFA_ID, e], 'closest_edge.csv')
def measure(galaxyList):
  band = Settings.getConstants().band        
  for i in galaxyList:
      i = int(i) - 1
      try:
	  print 'filename', GalaxyParameters.getSDSSUrl(i)
	  print 'filledFilename', GalaxyParameters.getFilledUrl(i, band)
	  
	  Photometry.calculateGrowthCurve(i)
      except IOError as err:
	print 'err', err
	output = [str(i+1), 'File not found', err]
	utils.writeOut(output, "ellipseErrors_new.csv")
	pass   
def measureFluxInOtherBands(galaxyList):
    band = Settings.getConstants().band
    out = []
    for i in galaxyList:
	i = int(i) - 1
	try:	    
	    print 'filledFilename', GalaxyParameters.getFilledUrl(i, band)
	    mag, sky = getFluxUnderMask(i)
	    out.append((i+1, mag, sky))
	except IOError as err:
	  print 'err', err
	  output = [str(i+1), 'File not found', err]
	  utils.writeOut(output, "ellipseErrors.csv")
	  pass   
    np.savetxt("gc_ellmask_"+band+".csv", out, fmt="%s, %f, %f")
def doFitting(galaxyList):
    for i in galaxyList:
      i = int(i) - 1
      band = Settings.getConstants().band      
      try:
	  print 'filename', GalaxyParameters.getSDSSUrl(i)
	  print 'filledFilename', GalaxyParameters.getFilledUrl(i, band)
	  print i, 'i'
	  output = Photometry.calculateGrowthCurve(i)
	  #utils.writeOut(output, band+'_log'+str(Settings.getConstants().lim_lo)+'.csv')
      except IOError as err:
	  print 'err', err
	  output = [str(i+1), 'File not found', err]
	  utils.writeOut(output, band+'_skyFitErrors.csv')
	  pass   
  def calculateGrowthCurve(name, ba, pa):
    imgName = 'vimos/sdss/SDSS/'+name+"/galaxy_"+Settings.getConstants().band+'_large.fits'
    dataFile = pyfits.open(imgName)
    img = dataFile[0].data
    try:
    	mask = pyfits.open('vimos/sdss/SDSS/'+name+"/mask_large.fits")[0].data
    	print mask.shape, img.shape
 	if mask.shape != img.shape:
		print mask.shape, img.shape, 'ALERT'
		pass

	#mask = mask/255
    except IOError:
     	mask = np.zeros(img.shape)
    center = Photometry.getCenter(img)
    distances = Astrometry.makeDistanceArray(img, center)

    
    
    # --------------------------------------- starting ellipse GC photometry
    
    print 'ELLIPTICAL APERTURE'
    try:
      #returns np.mean(y), fluxSlope, np.mean(yM), fluxSlopeM, fluxData[-1, 0]
      sky, slope, skyM, slopeM, isoA  = Photometry.fitSky(center, distances, pa, ba, img, mask, name)
    except IndexError:
      print 'aaa'
      sky = 'nan'
      slope = 'nan'
      isoA = 'nan'
      print 'aaaa'
    out = (name, sky, slope, skyM, slopeM, isoA)
    utils.writeOut(out, "vimos_sky_new_"+Settings.getConstants().band+"_ell.csv")
    
    print 'Circular APERTURE --------------------------'
    try:
      #returns np.mean(y), fluxSlope, np.mean(yM), fluxSlopeM, fluxData[-1, 0]
      sky, slope, skyM, slopeM, isoA  = Photometry.fitSky(center, distances, 0, 1, img, mask, name)
    except IndexError:
      print 'aaa'
      sky = 'nan'
      slope = 'nan'
      isoA = 'nan'
      print 'aaaa'
    out = (name, sky, slope, skyM, slopeM, isoA)
    utils.writeOut(out, "vimos_sky_new_"+Settings.getConstants().band+"_circ.csv")
def main():
  iso25D = 40 / 0.396
  #dataDir = '/media/46F4A27FF4A2713B_/work2/data/'
  dataDir = '../data'
  band = setBand()
  #outputFile = dataDir+'/growthCurvePhotometry.csv'
  listFile = dataDir+'/SDSS_photo_match.csv'
  fitsDir = dataDir+'/SDSS/'
  #filledDir = 'filled_'+band+'/'
  filledDir = 'filled2/'
  imgDir = 'img/'+band
  simpleFile = dataDir+'/CALIFA_mother_simple.csv'
  maskFile = dataDir+'/maskFilenames.csv'  
  dataFile = 'list.txt'
  
  for ID in range(1, 940):
  
	  	    print 'id,', int(ID)
		    ra = GalaxyParameters.SDSS(listFile, int(ID)).ra
		    dec = GalaxyParameters.SDSS(listFile, int(ID)).dec
		    run = GalaxyParameters.SDSS(listFile, int(ID)).run
		    rerun = GalaxyParameters.SDSS(listFile, int(ID)).rerun
		    camcol = GalaxyParameters.SDSS(listFile, int(ID)).camcol		    
		    field = GalaxyParameters.SDSS(listFile, int(ID)).field
		    runstr = GalaxyParameters.SDSS(listFile, int(ID)).runstr
		    field_str = sdss.field2string(field)

		    print 'getting header info...'
		    rFile = fitsDir+'r/fpC-'+runstr+'-r'+camcol+'-'+field_str+'.fit.gz'

		    WCS=astWCS.WCS(rFile)	
		    pa = utils.convert(db.dbUtils.getFromDB('pa', dbDir+'CALIFA.sqlite', 'nadine', ' where califa_id = '+str(ID)))[0][0]
		    pa_align = utils.convert(db.dbUtils.getFromDB('pa_align', dbDir+'CALIFA.sqlite', 'nadine', ' where califa_id = '+str(ID)))[0][0]
		    ang = WCS.getRotationDeg() 
		    print ang
		    
		    pa_align2 = (360 - ang) - 90 + pa
		    #if pa_align2 >= 180:
		#	    pa_align2 = pa_align2 - 180
		 #   if pa_align2 <= 0:
		#	    pa_align2 = pa_align2 + 180
		    out = int(ID), pa, pa_align2
		    print out
		    utils.writeOut(out, "align_pa.csv")
Beispiel #10
0
def solve(filename):
    pizzas, teams = readIn(filename)
    num_pizzas = len(pizzas)

    # compute how many number of deliveries
    # 2a+3b+4c<=M
    candidates = getDeliveries(num_pizzas, teams)

    # for each a,b,c, diliver pizza
    # calculate 2D table
    max_score = 0
    best_delivers = []
    # O(n*m*4)
    for candidate in candidates:
        picked_pizza = []
        delivers = [[] for _ in range(len(candidate))]
        score = []

        for i, team_size in enumerate(candidate):
            for _ in range(team_size):
                value_table = computeTable(pizzas, picked_pizza, delivers[i])

                if len(value_table) > 1:
                    max_val = 0
                    for (key, val) in value_table.items():
                        if val > max_val:
                            max_val = val
                            max_val_pizza = key
                    picked_pizza.append(max_val_pizza)
                    delivers[i].append(max_val_pizza)
                else:
                    picked_pizza.append(list(value_table.keys())[0])
                    delivers[i].append(list(value_table.keys())[0])
            unique_ingre, _ = compare(pizzas, delivers[i])
            score.append(unique_ingre)

        score = np.sum(np.array(score)**2)
        if score > max_score:
            max_score = score
            best_delivers = delivers

    writeOut(filename, best_delivers)
indices = [10, 43, 104, 146, 156, 176, 194, 251, 265, 272, 302, 342, 418, 429, 431, 448, 525, 533, 566, 577, 638, 659, 721, 787, 878, 902, 938, 939]
for i, x in enumerate(indices):
	indices[i] = x - 1
data[indices, 1] = 1

#flag: 2 denotes off-center galaxies:
center = [246, 428, 679]
data[center, 2] = 2
print data[center].shape, data.shape

#flag: 4 marks galaxies that are closer to the edge of the frame than 2 HLSMA (in r band):
#select g.califa_id, (0.396*c.closest_edge)/g.elhlr from gc2_r as g, closest_edge as c where (c.closest_edge)/g.elhlr < 2 and g.califa_id = c.califa_id
indices = [126, 244, 258, 260, 273, 304, 417, 434, 545, 696, 741, 763, 809, 841, 880] 
for i, x in enumerate(indices):
	indices[i] = x - 1
data[indices, 3] = 4

#flag: 8 denotes galaxies that have suspicious/unreliable measurements (heavily masked)

indices = [10, 22, 46, 53, 63, 86, 135, 154, 156, 161, 162, 175, 185, 223, 233, 245, 248, 255, 266, 267, 271, 355, 390, 426, 444, 457, 460, 491, 541, 577, 592, 617, 670, 680, 684, 699, 710, 714, 781, 784, 785, 801, 806, 819, 824, 827, 852, 858, 870, 874, 880, 881, 882, 883, 888, 893, 897, 908, 911, 924, 928, 932, 938, 939]
for i, x in enumerate(indices):
	indices[i] = x - 1
data[indices, 4] = 8


for i in range(0, 939):
	data[i, 5]  = np.sum(data[i, 1:5])
	out = data[i, :]
	print 'did you delete the file?'
	utils.writeOut(out, 'gc2_flags.txt')		
Beispiel #12
0
    logger.info(' Finish building Haar-like features ... >')

    ##################
    #####
    ##################
    logger.info('< F : {0} , D : {1} , Ftarget : {2} >'.format(
        constants.F, constants.D, constants.Ftarget))
    logger.info('< Start training cascade classifer ... >')
    cascade = trainCascade.train(constants.F, constants.D, constants.Ftarget,
                                 faces, non_faces, features)
    logger.info('< Finish training cascade classifer ... >')

    ##################
    #####
    ##################
    logger.info('< Exporting final model ... >')
    run_name = strftime("%Y%m%d-%H%M%S", time.localtime()).replace('-', '')
    filename = '../result/' + run_name + '/cascade.txt'
    utils.writeOut(cascade, filename)
    logger.info('< Finish exporting final model ... >')

    ##################
    #####
    ##################
    end = time.time()
    m, s = divmod((end - start), 60)
    h, m = divmod(m, 60)
    logger.info(
        '< Elasped {0} hour(s) : {1} minute(s) : {2} second(s) >'.format(
            h, m, s))
Beispiel #13
0
                    old_time = intersection.TL[street_id]
                    new_time = [
                        min(timestamp, old_time[0]),
                        max(timestamp, old_time[1]),
                    ]

                    if not intersection.isConflict(
                            new_time[0]) and not intersection.isConflict(
                                new_time[1]):
                        intersection.TL[street_id] = new_time
                else:
                    if not intersection.isConflict(timestamp):
                        intersection.TL[street_id] = [timestamp, timestamp + 1]
            else:
                intersection = Intersection(intersection_id)
                intersection.TL[street_id] = [timestamp, timestamp + 1]
                result[intersection_id] = intersection

    return result


if __name__ == "__main__":
    directory = "quali/"
    for file in os.listdir(directory):
        basic_info, street_list, car_list = readIn(directory + file)
        sim_time = basic_info[0]
        bonus = basic_info[-1]

        result = solve(sim_time, bonus, street_list, car_list)
        writeOut("output/" + file[0], result)
# -*- coding: utf-8 -*-
import numpy as np
import db
import utils
dbDir = '../db/'

data = np.empty((939, 3), dtype = object)


#califa_id = utils.convert(db.dbUtils.getFromDB('CALIFA_ID', dbDir+'CALIFA.sqlite', 'gc_r'))
ra = utils.convert(db.dbUtils.getFromDB('ra', dbDir+'CALIFA.sqlite', 'mothersample'))
dec = utils.convert(db.dbUtils.getFromDB('dec', dbDir+'CALIFA.sqlite', 'mothersample'))

print ra.shape
for i in range(0, 939):


  data[i, 0] = str(ra[i, 0])+'d'
  data[i, 1] = str(dec[i, 0])+'d'
  data[i, 2] = 0.05
  print i, data[i]
  utils.writeOut(data[i, 0:3], "ned_query_coords.csv", ";")

#np.savetxt("ned_query_coords.csv", data, delimiter = ';')

def main():
    iso25D = 40 / 0.396
    # dataDir = '/media/46F4A27FF4A2713B_/work2/data/'
    dataDir = "../data"
    band = setBand()
    outputFile = dataDir + "/growthCurvePhotometry.csv"
    listFile = dataDir + "/SDSS_photo_match.csv"
    fitsDir = dataDir + "/SDSS/"
    filledDir = "filled_" + band + "/"

    imgDir = "img/" + band
    simpleFile = dataDir + "/CALIFA_mother_simple.csv"
    maskFile = dataDir + "/maskFilenames.csv"
    dataFile = "list.txt"

    csvReader = csv.reader(open(dataFile, "rU"), delimiter=",")

    """
  for row in csvReader:

	ID = int(string.strip(row[0]))
	ra = string.strip(row[1])
	dec = string.strip(row[2])
	run = string.strip(row[3])
	rerun = string.strip(row[4])
	camcol = string.strip(row[5])
	field = string.strip(row[6])
	runstr = sdss.run2string(run)
	field_str = sdss.field2string(field)
	outputFilename = dataDir+'/'+filledDir+'fpC-'+runstr+'-'+band+camcol+'-'+field_str+'.fits'

	try:
	  f = open(GalaxyParameters.getSDSSUrl(listFile, dataDir, ID-1))
	  print 'it is here', ID - 1
	  pass
	except IOError as e: 
	  print e, ID - 1
	  os.system('wget -P '+fitsDir+band+' http://das.sdss.org/imaging/'+run+'/'+rerun+'/corr/'+camcol+'/fpC-'+runstr+'-'+band+camcol+'-'+field_str+'.fit.gz')     
	  pass

	try:
	  f = open(fitsDir+'r/fpC-'+runstr+'-r'+camcol+'-'+field_str+'.fit.gz')
	  print 'it is here', 'r', ID - 1
	  pass
	except IOError as e:  
	  print e, 'r', ID - 1
	  os.system('wget -P '+fitsDir+'r/ http://das.sdss.org/imaging/'+run+'/'+rerun+'/corr/'+camcol+'/fpC-'+runstr+'-r'+camcol+'-'+field_str+'.fit.gz')
	  pass

   #checking output file
	try:
	  f = open(outputFilename)
	  print 'musu', ID
	except IOError as e:
	  utils.writeOut(str(ID))
	  pass
	  """
    missing = np.genfromtxt("missing.csv")
    for row in csvReader:

        # print '********************************', row[0]
        ID = string.strip(row[0])
        # CHECK THE DELIMITERS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        if (ID in x for x in missing):

            print ID, "did you check the delimiters?"
            if int(ID) >= 250:
                ra = string.strip(row[1])
                dec = string.strip(row[2])
                run = string.strip(row[3])
                rerun = string.strip(row[4])
                camcol = string.strip(row[5])
                field = string.strip(row[6])
                runstr = sdss.run2string(run)
                field_str = sdss.field2string(field)
                print ID
                inFile = fitsDir + band + "/fpC-" + runstr + "-" + band + camcol + "-" + field_str + ".fit.gz"
                gz = gzip.open(inFile)
                imgFile = pyfits.open(gz)
                img = imgFile[0].data
                head = imgFile[0].header

                print "getting header info..."
                rFile = fitsDir + "r/fpC-" + runstr + "-r" + camcol + "-" + field_str + ".fit.gz"
                rgz = gzip.open(rFile)
                imgFiler = pyfits.open(rgz)
                try:
                    maskFile = pyfits.open(GalaxyParameters.getMaskUrl(listFile, dataDir, simpleFile, int(ID) - 1))
                    mask = maskFile[0].data
                    print mask.shape
                    WCSr = astWCS.WCS(rFile)
                    WCS = astWCS.WCS(inFile)
                    band_center = WCS.wcs2pix(
                        WCS.getCentreWCSCoords()[0], WCS.getCentreWCSCoords()[1]
                    )  #'other band image center coords in r image coordinate system'
                    r_center = WCS.wcs2pix(
                        WCSr.getCentreWCSCoords()[0], WCSr.getCentreWCSCoords()[1]
                    )  #'r center coords in r image coordinate system'
                    shift = [band_center[0] - r_center[0], band_center[1] - r_center[1]]
                    print type(shift)
                    # note the swap!
                    shift = [ceil(shift[1]), ceil(shift[0])]
                    print shift, img.shape
                    img = sdss.getShiftedImage(img, shift)
                    mask = sdss.getShiftedImage(mask, [-1 * shift[0], -1 * shift[1]])
                    outputFilename = (
                        dataDir + "/" + filledDir + "fpC-" + runstr + "-" + band + camcol + "-" + field_str + ".fits"
                    )
                    print outputFilename

                    info = (ID, shift, outputFilename)
                    utils.writeOut(info)
                    Interpolation.callInpaint(img, mask, outputFilename, ID)
                    utils.writeOut(info)

                except IOError as e:
                    utils.writeOut((ID, e))
                    pass
            else:
                print "passing", ID
                pass
def main():
  iso25D = 40 / 0.396
  #dataDir = '/media/46F4A27FF4A2713B_/work2/data/'
  dataDir = '../data'
  band = setBand()
  outputFile = dataDir+'/growthCurvePhotometry.csv'
  listFile = dataDir+'/SDSS_photo_match.csv'
  fitsDir = dataDir+'/SDSS/'
  #filledDir = 'filled_'+band+'/'
  filledDir = 'filled2/'
  imgDir = 'img/'+band
  simpleFile = dataDir+'/CALIFA_mother_simple.csv'
  maskFile = dataDir+'/maskFilenames.csv'  
  dataFile = 'list.txt'
  
  csvReader = csv.reader(open(dataFile, "rU"), delimiter=',')
  
  
  for row in csvReader:
	
	ID = int(string.strip(row[0]))
	ra = string.strip(row[1])
	dec = string.strip(row[2])
	run = string.strip(row[3])
	rerun = string.strip(row[4])
	camcol = string.strip(row[5])
	field = string.strip(row[6])
	runstr = sdss.run2string(run)
	field_str = sdss.field2string(field)

	#checkInput(listFile, dataDir, ID, run, rerun, camcol, runstr, band, field_str, fitsDir)
	#checkOutput(dataDir, ID, run, rerun, camcol, runstr, band, field_str, fitsDir, filledDir)
  
  
 
  #missing = np.genfromtxt('missing_'+setBand()+'.csv')
  #print missing, 'missing'  
  #ID = missing
  #csvReader = csv.reader(open(dataFile, "rU"), delimiter=',')
  #for row in csvReader:  	
  #	ID = string.strip(row[0])
	#CHECK THE DELIMITERS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	
  #	if (int(ID) in x for x in missing):
  
  #	  print ID, 'did you check the delimiters?'
  #for i, ID in enumerate(missing):
  	if ID == 577:
	  	    print 'id,', int(ID) - 1	
		    ra = GalaxyParameters.SDSS(listFile, int(ID) - 1).ra
		    dec = GalaxyParameters.SDSS(listFile, int(ID) - 1).dec
		    run = GalaxyParameters.SDSS(listFile, int(ID) - 1).run
		    rerun = GalaxyParameters.SDSS(listFile, int(ID) - 1).rerun
		    camcol = GalaxyParameters.SDSS(listFile, int(ID) - 1).camcol		    
		    field = GalaxyParameters.SDSS(listFile, int(ID) - 1).field
		    runstr = GalaxyParameters.SDSS(listFile, int(ID) - 1).runstr
		    field_str = sdss.field2string(field)
		    print ID
		    inFile = fitsDir+band+'/fpC-'+runstr+'-'+band+camcol+'-'+field_str+'.fit.gz'
		    
		    print inFile, 'input'
		    
		    gz = gzip.open(inFile)
		    imgFile = pyfits.open(gz)
		    img = imgFile[0].data
		    head = imgFile[0].header

		    print 'getting header info...'
		    rFile = fitsDir+'r/fpC-'+runstr+'-r'+camcol+'-'+field_str+'.fit.gz'
		    rgz = gzip.open(rFile)
		    imgFiler = pyfits.open(rgz)
		    try:
		      maskFile = pyfits.open(GalaxyParameters.getMaskUrl(listFile, dataDir, simpleFile, int(ID)-1))
		      mask = maskFile[0].data
		      print mask.shape
		      WCSr=astWCS.WCS(rFile)	
		      WCS=astWCS.WCS(inFile)
		      band_center = WCS.wcs2pix(WCS.getCentreWCSCoords()[0], WCS.getCentreWCSCoords()[1]) #'other band image center coords in r image coordinate system'		
		      r_center = WCS.wcs2pix(WCSr.getCentreWCSCoords()[0], WCSr.getCentreWCSCoords()[1]) #'r center coords in r image coordinate system'		  
		      shift = [band_center[0] - r_center[0], band_center[1] - r_center[1]]
		      print shift, 'shift'
		      #print type(shift)
		      #note the swap!
		      shift = [ceil(shift[1]), ceil(shift[0])]
		      print shift, img.shape
		      img = sdss.getShiftedImage(img, shift)
		      mask = sdss.getShiftedImage(mask, [-1*shift[0], -1*shift[1]])
		      outputFilename = dataDir+'/'+filledDir+'fpC-'+runstr+'-'+band+camcol+'-'+field_str+'.fits'
		      print outputFilename

		      info = (ID, shift, outputFilename)
		      Interpolation.callInpaint(img, mask, outputFilename, int(ID - 1))
		      utils.writeOut(info, band+'_interp_log.csv')
		    
		    except IOError as e:
		      utils.writeOut((ID, e), band+'_fill_errors.csv')
		      pass
  def calculateGrowthCurve(listFile, dataDir, i):
    CALIFA_ID = str(i+1)
    inputImage = Photometry.getInputFile(listFile, dataDir, i)
    dbDir = '../db/'
    imgDir = 'img/'+setBand()+'/'
    center = Photometry.getCenter(listFile, i, dataDir)
    distances = Photometry.createDistanceArray(listFile, i, dataDir)
    #hdu = pyfits.PrimaryHDU(distances)
    #hdu.writeto('distances.fits')
    sky = inputImage[np.where(distances > int(round(Photometry.iso25D)))]
    skyMean = np.mean(sky)   
    skySD = np.std(sky)
    #i+1 in the next line reflects the fact that CALIFA id's start with 1
    pa = db.dbUtils.getFromDB('PA', dbDir+'CALIFA.sqlite', 'nadine', ' where califa_id = '+ CALIFA_ID)[0][0]  #parsing tuples
    ba = db.dbUtils.getFromDB('ba', dbDir+'CALIFA.sqlite', 'nadine', ' where califa_id = '+ CALIFA_ID)[0][0]#parsing tuples
    #ba = 1
    #r_mag = db.dbUtils.getFromDB('r_mag', dbDir+'CALIFA.sqlite', 'nadine', ' where califa_id = '+ CALIFA_ID)[0][0]#parsing tuples
    #r_e = db.dbUtils.getFromDB('re', dbDir+'CALIFA.sqlite', 'nadine', ' where califa_id = '+ CALIFA_ID)[0][0]#parsing tuples
    #lucy_re = db.dbUtils.getFromDB('re', dbDir+'CALIFA.sqlite', 'lucie', ' where id = '+ CALIFA_ID)[0][0]#parsing tuples
    #l_SkyMean = db.dbUtils.getFromDB('sky', dbDir+'CALIFA.sqlite', 'lucie', ' where id = '+ CALIFA_ID)[0][0] - 1000#parsing tuples
 #   print 'ba', ba
    
    #fluxData = Photometry.buildGrowthCurve(inputImage, center, distances, skyMean, pa, ba)
    #isoA = fluxData.shape[0]

  
    # --------------------------------------- starting GC photometry in circular annuli
    print 'CIRCULAR APERTURE'
    #circFlux, circFluxData = Photometry.circularFlux(inputImage, center,  distances, skyMean)  
    circFlux, circFluxData, gc_sky = Photometry.buildGrowthCurve(inputImage, center, distances, skyMean, pa, 1, str(i+1))
    circRadius = circFluxData.shape[0]
    #print circRadius, 'circle radius'
    #otherFlux = circFluxData[-1, 1]   
    #print 'fluxes: mask:', circFlux, 'sum', otherFlux    
    try:
    	    circHLR = circFluxData[np.where(np.floor(circFlux/circFluxData[:,1]) == 1)][0][0] - 1 #Floor() -1 -- last element where the ratio is 2
    except IndexError as e:
    	    circHLR = str(e)
	    
    circMag = Photometry.calculateFlux(circFlux, listFile, i)
    
    
    # --------------------------------------- starting ellipse GC photometry

    print 'ELLIPTICAL APERTURE'
    totalFlux, fluxData, gc_sky = Photometry.buildGrowthCurve(inputImage, center, distances, skyMean, pa, ba, CALIFA_ID, e=True)  
    
    otherFlux = fluxData[fluxData.shape[0]-1, 6]   
   
    elMajAxis = fluxData.shape[0]
    #print totalFlux - otherFlux, 'flux diff'
    #print 't', totalFlux, 'o', otherFlux
    diff = [CALIFA_ID, totalFlux - otherFlux]
    utils.writeOut(diff, 'fluxdiff.txt')
    elMag = Photometry.calculateFlux(totalFlux, listFile, i)
    
    try:
	elHLR = fluxData[np.where(np.floor(totalFlux/fluxData[:, 1]) == 1)][0][0] - 1 #Floor() -1 -- last element where the ratio is 2
	print elHLR  
    except IndexError as e:
        print 'err'
	elHLR = e
    
    plotGrowthCurve.plotGrowthCurve(fluxData, CALIFA_ID)
 	
    
    # --------------------- writing output jpg file with both outermost annuli  
    outputImage = inputImage
    circpix = ellipse.draw_ellipse(inputImage.shape, center[0], center[1], pa, circRadius, 1)
    elPix = ellipse.draw_ellipse(inputImage.shape, center[0], center[1], pa, elMajAxis, ba)    
    outputImage[circpix] = 0
    outputImage[elPix] = 0
    
    outputImage, cdf = imtools.histeq(outputImage)
        
    #scipy.misc.imsave('img/output/'+CALIFA_ID+'.jpg', outputImage)    
    scipy.misc.imsave(imgDir+'snapshots/'+CALIFA_ID+'_gc.jpg', outputImage)

    #hdu = pyfits.PrimaryHDU(outputImage)
    #outputName = 'CALIFA'+CALIFA_ID+'.fits'
    #hdu.writeto(outputName) 
    

    
    # ------------------------------------- formatting output row
    output = [CALIFA_ID, elMag, elHLR, circMag, circHLR, np.mean(sky),  gc_sky] 
    print output
    #print skyMean, oldSky, 'sky'
    return output