def calcMeanComparison(self,ccdGain=1):
        """
        Take the regression-weighted mean of some of the comparison stars
        to produce one comparison star flux to compare to the target to
        produce a light curve.

        The comparison stars used are those whose chi-squareds calculated by
        self.calcChiSq() are less than 2*sigma away from the other chi-squareds.
        This condition removes outliers.
        """

        ## Check whether chi-squared has been calculated already. If not, compute it.
        chisq = []
        for star in self.allStarsDict: chisq.append(self.allStarsDict[star]['chisq'])
        chisq = np.array(chisq)
        if all(chisq == 0): self.calcChiSq()

        ## Begin regression technique
        numCompStars =  len(self.allStarsDict) - 1
        targetFullLength = len(self.getScaledFluxes(self.targetKey))
        target = self.getFluxes(self.targetKey)[self.outOfTransit()]
        compStars = np.zeros([targetFullLength,numCompStars])
        compStarsOOT = np.zeros([len(target),numCompStars])
        compErrors = np.copy(compStars)
        columnCounter = 0
        compStarKeys = []
        for star in self.allStarsDict:
            if star != self.targetKey and (np.abs(self.meanChisq - self.allStarsDict[star]['chisq']) < 2*self.stdChisq):
                compStars[:,columnCounter] = self.getScaledFluxes(star).astype(np.float64)
                compStarsOOT[:,columnCounter] = self.getScaledFluxes(star)[self.outOfTransit()].astype(np.float64)
                compErrors[:,columnCounter] = self.getScaledErrors(star).astype(np.float64)
                compStarKeys.append(int(star))
                columnCounter += 1
            elif star != self.targetKey and (np.abs(self.meanChisq - self.allStarsDict[star]['chisq']) > 2*self.stdChisq):
                print 'Star '+str(star)+' excluded from regression'
                compStarKeys.append(int(star))
                columnCounter += 1
        initP = np.zeros([numCompStars])+ 1./numCompStars
        def errfunc(p,target):
            if all(p >=0.0): return np.dot(p,compStarsOOT.T) - target ## Find only positive coefficients
        #return np.dot(p,compStarsOOT.T) - target

        bestFitP = optimize.leastsq(errfunc,initP[:],args=(target.astype(np.float64)),maxfev=10000000,epsfcn=np.finfo(np.float32).eps)[0]
        print '\nBest fit regression coefficients:',bestFitP
        print 'Default weight:',1./numCompStars

        self.comparisonStarWeights = np.vstack([compStarKeys,bestFitP])
        self.meanComparisonStar = np.dot(bestFitP,compStars.T)
        self.meanComparisonStarError = np.sqrt(np.dot(bestFitP**2,compErrors.T**2))
        return self.meanComparisonStar, self.meanComparisonStarError
dataset/ETHPy150Open OSCAAR/OSCAAR/oscaar/dataBank.py/dataBank.calcMeanComparison/original