<s> '''<STR_LIT>''' <EOL> import numpy as np <EOL> import pyfits <EOL> from matplotlib import pyplot as plt <EOL> from scipy import optimize <EOL> from glob import glob <EOL> import os <EOL> import re <EOL> import oscaar <EOL> import mathMethods <EOL> import sys <EOL> import systematics <EOL> oscaarpath = os . path . dirname ( os . path . abspath ( oscaar . __file__ ) ) <EOL> oscaarpathplus = os . path . join ( oscaarpath , '<STR_LIT>' ) <EOL> class dataBank : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , initParFilePath = None ) : <EOL> """<STR_LIT>""" <EOL> self . dict = { } <EOL> self . parseInit ( initParFilePath ) <EOL> self . flatPath = self . dict [ "<STR_LIT>" ] <EOL> self . rawRegionsList = self . dict [ "<STR_LIT>" ] <EOL> self . ingress = self . dict [ "<STR_LIT>" ] <EOL> self . egress = self . dict [ "<STR_LIT>" ] <EOL> self . apertureRadii = self . dict [ "<STR_LIT>" ] <EOL> self . trackingZoom = self . dict [ "<STR_LIT>" ] <EOL> self . ccdGain = self . dict [ "<STR_LIT>" ] <EOL> self . trackPlots = self . dict [ "<STR_LIT>" ] <EOL> self . photPlots = self . dict [ "<STR_LIT>" ] <EOL> self . smoothConst = self . dict [ "<STR_LIT>" ] <EOL> self . darksPath = self . dict [ "<STR_LIT>" ] <EOL> self . imagesPaths = self . dict [ "<STR_LIT>" ] <EOL> self . timeKeyword = self . dict [ "<STR_LIT>" ] <EOL> if self . timeKeyword == '<STR_LIT>' : <EOL> self . convertToJD = lambda x : x <EOL> elif self . timeKeyword == '<STR_LIT>' : <EOL> self . convertToJD = mathMethods . ut2jdSplitAtT <EOL> if not hasattr ( sys , '<STR_LIT>' ) : <EOL> self . masterFlat = np . ones_like ( pyfits . getdata ( self . imagesPaths [ <NUM_LIT:0> ] ) ) <EOL> elif self . flatPath != '<STR_LIT>' : <EOL> self . masterFlat = pyfits . getdata ( self . flatPath ) <EOL> self . masterFlatPath = self . flatPath <EOL> elif self . flatPath == '<STR_LIT>' : <EOL> self . masterFlat = np . ones_like ( pyfits . getdata ( self . imagesPaths [ <NUM_LIT:0> ] ) ) <EOL> self . allStarsDict = { } <EOL> self . regionsFileList , self . regionsFITSrefsList = self . parseRawRegionsList ( self . rawRegionsList ) <EOL> init_x_list , init_y_list = self . parseRegionsFile ( self . regionsFileList [ <NUM_LIT:0> ] ) <EOL> zeroArray = np . zeros_like ( self . imagesPaths , dtype = np . float32 ) <EOL> self . times = np . zeros_like ( self . imagesPaths , dtype = np . float64 ) <EOL> self . keys = [ ] <EOL> self . targetKey = '<STR_LIT>' <EOL> Nradii = len ( self . apertureRadii ) <EOL> for i in range ( <NUM_LIT:0> , len ( init_x_list ) ) : <EOL> self . allStarsDict [ str ( i ) . zfill ( <NUM_LIT:3> ) ] = { '<STR_LIT>' : np . copy ( zeroArray ) , '<STR_LIT>' : np . copy ( zeroArray ) , '<STR_LIT>' : [ np . copy ( zeroArray ) for j in range ( Nradii ) ] , '<STR_LIT>' : [ np . copy ( zeroArray ) for j in range ( Nradii ) ] , '<STR_LIT>' : False , '<STR_LIT>' : [ np . copy ( zeroArray ) for j in range ( Nradii ) ] , '<STR_LIT>' : [ np . copy ( zeroArray ) for j in range ( Nradii ) ] , '<STR_LIT>' : np . zeros_like ( self . apertureRadii ) } <EOL> self . allStarsDict [ str ( i ) . zfill ( <NUM_LIT:3> ) ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] = init_x_list [ i ] <EOL> self . allStarsDict [ str ( i ) . zfill ( <NUM_LIT:3> ) ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] = init_y_list [ i ] <EOL> self . keys . append ( str ( i ) . zfill ( <NUM_LIT:3> ) ) <EOL> def getDict ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . allStarsDict <EOL> def getMeanDarkFrame ( self ) : <EOL> if type ( self . darksPath ) == str and self . darksPath == "<STR_LIT>" : <EOL> return np . zeros_like ( pyfits . getdata ( self . imagesPaths [ <NUM_LIT:0> ] ) ) <EOL> else : <EOL> return systematics . meanDarkFrame ( self . darksPath ) <EOL> def centroidInitialGuess ( self , expNumber , star ) : <EOL> '''<STR_LIT>''' <EOL> if expNumber == <NUM_LIT:0> : <EOL> est_x = self . allStarsDict [ star ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> est_y = self . allStarsDict [ star ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> elif self . imagesPaths [ expNumber ] in self . regionsFITSrefsList : <EOL> refIndex = self . regionsFITSrefsList . index ( self . imagesPaths [ expNumber ] ) <EOL> init_x_list , init_y_list = self . parseRegionsFile ( self . regionsFileList [ refIndex ] ) <EOL> est_x = init_x_list [ int ( star ) ] <EOL> est_y = init_y_list [ int ( star ) ] <EOL> else : <EOL> est_x = self . allStarsDict [ star ] [ '<STR_LIT>' ] [ expNumber - <NUM_LIT:1> ] <EOL> est_y = self . allStarsDict [ star ] [ '<STR_LIT>' ] [ expNumber - <NUM_LIT:1> ] <EOL> return est_x , est_y <EOL> def storeCentroid ( self , star , exposureNumber , xCentroid , yCentroid ) : <EOL> '''<STR_LIT>''' <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ exposureNumber ] = xCentroid <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ exposureNumber ] = yCentroid <EOL> def storeFlux ( self , star , exposureNumber , rawFlux , rawError ) : <EOL> '''<STR_LIT>''' <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ exposureNumber ] = rawFlux <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ exposureNumber ] = rawError <EOL> def storeFluxes ( self , star , exposureNumber , rawFluxes , rawErrors ) : <EOL> '''<STR_LIT>''' <EOL> for apertureRadiusIndex in range ( len ( self . apertureRadii ) ) : <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] [ exposureNumber ] = rawFluxes [ apertureRadiusIndex ] <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] [ exposureNumber ] = rawErrors [ apertureRadiusIndex ] <EOL> def getPaths ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . imagesPaths <EOL> def getFluxes ( self , star ) : <EOL> '''<STR_LIT>''' <EOL> return self . allStarsDict [ star ] [ '<STR_LIT>' ] <EOL> def getErrors ( self , star ) : <EOL> '''<STR_LIT>''' <EOL> return self . allStarsDict [ star ] [ '<STR_LIT>' ] <EOL> def storeTime ( self , expNumber ) : <EOL> '''<STR_LIT>''' <EOL> timeStamp = pyfits . getheader ( self . getPaths ( ) [ expNumber ] ) [ self . timeKeyword ] <EOL> self . times [ expNumber ] = self . convertToJD ( timeStamp ) <EOL> def getTimes ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . times <EOL> def getFlag ( self , star ) : <EOL> '''<STR_LIT>''' <EOL> return self . allStarsDict [ star ] [ '<STR_LIT>' ] <EOL> def getAllFlags ( self ) : <EOL> '''<STR_LIT>''' <EOL> flags = [ ] <EOL> for star in self . allStarsDict : <EOL> flags . append ( self . allStarsDict [ star ] [ '<STR_LIT>' ] ) <EOL> self . flags = flags <EOL> return flags <EOL> def setFlag ( self , star , setting ) : <EOL> '''<STR_LIT>''' <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] = setting <EOL> def getKeys ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . keys <EOL> def scaleFluxes ( self ) : <EOL> '''<STR_LIT>''' <EOL> for star in self . allStarsDict : <EOL> if star != self . targetKey : <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] , m = mathMethods . regressionScale ( self . getFluxes ( star ) , self . getFluxes ( self . targetKey ) , self . getTimes ( ) , self . ingress , self . egress , returncoeffs = True ) <EOL> print m <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] = np . abs ( m ) * self . getErrors ( star ) <EOL> if star == self . targetKey : <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] = self . allStarsDict [ star ] [ '<STR_LIT>' ] <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] = self . allStarsDict [ star ] [ '<STR_LIT>' ] <EOL> def getFluxes_multirad ( self , star , apertureRadiusIndex ) : <EOL> '''<STR_LIT>''' <EOL> return self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] <EOL> def getErrors_multirad ( self , star , apertureRadiusIndex ) : <EOL> '''<STR_LIT>''' <EOL> return self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] <EOL> def scaleFluxes_multirad ( self ) : <EOL> '''<STR_LIT>''' <EOL> for star in self . allStarsDict : <EOL> for apertureRadiusIndex in range ( len ( self . apertureRadii ) ) : <EOL> if star != self . targetKey : <EOL> print self . getFluxes_multirad ( star , apertureRadiusIndex ) [ <NUM_LIT:0> ] <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] , m = mathMethods . regressionScale ( self . getFluxes_multirad ( star , apertureRadiusIndex ) , self . getFluxes_multirad ( self . targetKey , apertureRadiusIndex ) , self . getTimes ( ) , self . ingress , self . egress , returncoeffs = True ) <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] = np . abs ( m ) * self . getErrors_multirad ( star , apertureRadiusIndex ) <EOL> if star == self . targetKey : <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] = self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] = self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] <EOL> def getScaledFluxes ( self , star ) : <EOL> '''<STR_LIT>''' <EOL> return np . array ( self . allStarsDict [ star ] [ '<STR_LIT>' ] ) <EOL> def getScaledErrors ( self , star ) : <EOL> '''<STR_LIT>''' <EOL> return np . array ( self . allStarsDict [ star ] [ '<STR_LIT>' ] ) <EOL> def getScaledFluxes_multirad ( self , star , apertureRadiusIndex ) : <EOL> '''<STR_LIT>''' <EOL> return np . array ( self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] ) <EOL> def getScaledErrors_multirad ( self , star , apertureRadiusIndex ) : <EOL> '''<STR_LIT>''' <EOL> return np . array ( self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] ) <EOL> def calcChiSq ( self ) : <EOL> """<STR_LIT>""" <EOL> for star in self . allStarsDict : <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] = mathMethods . chiSquared ( self . getFluxes ( self . targetKey ) , self . getFluxes ( star ) ) <EOL> chisq = [ ] <EOL> for star in self . allStarsDict : <EOL> chisq . append ( self . allStarsDict [ star ] [ '<STR_LIT>' ] ) <EOL> self . chisq = np . array ( chisq ) <EOL> self . meanChisq = np . mean ( chisq ) <EOL> self . stdChisq = np . std ( chisq ) <EOL> def calcChiSq_multirad ( self , apertureRadiusIndex ) : <EOL> """<STR_LIT>""" <EOL> for star in self . allStarsDict : <EOL> print self . getFluxes_multirad ( self . targetKey , apertureRadiusIndex ) , self . getFluxes_multirad ( star , apertureRadiusIndex ) <EOL> self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] = mathMethods . chiSquared ( self . getFluxes_multirad ( self . targetKey , apertureRadiusIndex ) , self . getFluxes_multirad ( star , apertureRadiusIndex ) ) <EOL> chisq = [ ] <EOL> for star in self . allStarsDict : <EOL> chisq . append ( self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] ) <EOL> self . chisq = np . array ( chisq ) <EOL> self . meanChisq = np . mean ( chisq ) <EOL> self . stdChisq = np . std ( chisq ) <EOL> def calcMeanComparison_multirad ( self , ccdGain = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> self . meanComparisonStars = [ ] <EOL> self . meanComparisonStarErrors = [ ] <EOL> self . comparisonStarWeights = [ ] <EOL> for apertureRadiusIndex in range ( len ( self . apertureRadii ) ) : <EOL> chisq = [ ] <EOL> for star in self . allStarsDict : chisq . append ( self . allStarsDict [ star ] [ '<STR_LIT>' ] ) <EOL> chisq = np . array ( chisq ) <EOL> if ( chisq == <NUM_LIT:0> ) . all ( ) : self . calcChiSq_multirad ( apertureRadiusIndex ) <EOL> numCompStars = len ( self . allStarsDict ) - <NUM_LIT:1> <EOL> targetFullLength = len ( self . getScaledFluxes_multirad ( self . targetKey , apertureRadiusIndex ) ) <EOL> print "<STR_LIT>" , apertureRadiusIndex <EOL> print "<STR_LIT>" , self . getFluxes_multirad ( self . targetKey , apertureRadiusIndex ) <EOL> print "<STR_LIT>" , self . getScaledFluxes_multirad ( self . targetKey , apertureRadiusIndex ) <EOL> target = self . getFluxes_multirad ( self . targetKey , apertureRadiusIndex ) [ self . outOfTransit ( ) ] <EOL> compStars = np . zeros ( [ targetFullLength , numCompStars ] ) <EOL> compStarsOOT = np . zeros ( [ len ( target ) , numCompStars ] ) <EOL> compErrors = np . copy ( compStars ) <EOL> columnCounter = <NUM_LIT:0> <EOL> acceptedCompStarKeys = [ ] <EOL> compStarKeys = [ ] <EOL> for star in self . allStarsDict : <EOL> if star != self . targetKey and ( np . abs ( self . meanChisq - self . allStarsDict [ star ] [ '<STR_LIT>' ] ) < <NUM_LIT:2> * self . stdChisq ) . any ( ) : <EOL> compStars [ : , columnCounter ] = self . getScaledFluxes_multirad ( star , apertureRadiusIndex ) . astype ( np . float64 ) <EOL> compStarsOOT [ : , columnCounter ] = self . getScaledFluxes_multirad ( star , apertureRadiusIndex ) [ self . outOfTransit ( ) ] . astype ( np . float64 ) <EOL> compErrors [ : , columnCounter ] = self . getScaledErrors_multirad ( star , apertureRadiusIndex ) . astype ( np . float64 ) <EOL> compStarKeys . append ( int ( star ) ) <EOL> columnCounter += <NUM_LIT:1> <EOL> elif star != self . targetKey and ( np . abs ( self . meanChisq - self . allStarsDict [ star ] [ '<STR_LIT>' ] ) > <NUM_LIT:2> * self . stdChisq ) : <EOL> print '<STR_LIT>' + str ( star ) + '<STR_LIT>' <EOL> compStarKeys . append ( int ( star ) ) <EOL> columnCounter += <NUM_LIT:1> <EOL> initP = np . zeros ( [ numCompStars ] ) + <NUM_LIT:1.> / numCompStars <EOL> def errfunc ( p , target ) : <EOL> if all ( p >= <NUM_LIT:0.0> ) : return np . dot ( p , compStarsOOT . T ) - target <EOL> bestFitP = optimize . leastsq ( errfunc , initP [ : ] , args = ( target . astype ( np . float64 ) ) , maxfev = <NUM_LIT> , epsfcn = np . finfo ( np . float32 ) . eps ) [ <NUM_LIT:0> ] <EOL> print '<STR_LIT>' , bestFitP <EOL> print '<STR_LIT>' , <NUM_LIT:1.> / numCompStars <EOL> self . comparisonStarWeights_i = np . vstack ( [ compStarKeys , bestFitP ] ) <EOL> self . meanComparisonStar = np . dot ( bestFitP , compStars . T ) <EOL> self . meanComparisonStarError = np . sqrt ( np . dot ( bestFitP ** <NUM_LIT:2> , compErrors . T ** <NUM_LIT:2> ) ) <EOL> self . meanComparisonStars . append ( self . meanComparisonStar ) <EOL> self . meanComparisonStarErrors . append ( self . meanComparisonStarError ) <EOL> self . comparisonStarWeights . append ( self . comparisonStarWeights_i ) <EOL> return self . meanComparisonStars , self . meanComparisonStarErrors <EOL> def getAllChiSq ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . chisq <EOL> def outOfTransit ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( self . getTimes ( ) < self . ingress ) + ( self . getTimes ( ) > self . egress ) <EOL> def calcMeanComparison ( self , ccdGain = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> chisq = [ ] <EOL> for star in self . allStarsDict : chisq . append ( self . allStarsDict [ star ] [ '<STR_LIT>' ] ) <EOL> chisq = np . array ( chisq ) <EOL> if all ( chisq == <NUM_LIT:0> ) : self . calcChiSq ( ) <EOL> numCompStars = len ( self . allStarsDict ) - <NUM_LIT:1> <EOL> targetFullLength = len ( self . getScaledFluxes ( self . targetKey ) ) <EOL> target = self . getFluxes ( self . targetKey ) [ self . outOfTransit ( ) ] <EOL> compStars = np . zeros ( [ targetFullLength , numCompStars ] ) <EOL> compStarsOOT = np . zeros ( [ len ( target ) , numCompStars ] ) <EOL> compErrors = np . copy ( compStars ) <EOL> columnCounter = <NUM_LIT:0> <EOL> compStarKeys = [ ] <EOL> for star in self . allStarsDict : <EOL> if star != self . targetKey and ( np . abs ( self . meanChisq - self . allStarsDict [ star ] [ '<STR_LIT>' ] ) < <NUM_LIT:2> * self . stdChisq ) : <EOL> compStars [ : , columnCounter ] = self . getScaledFluxes ( star ) . astype ( np . float64 ) <EOL> compStarsOOT [ : , columnCounter ] = self . getScaledFluxes ( star ) [ self . outOfTransit ( ) ] . astype ( np . float64 ) <EOL> compErrors [ : , columnCounter ] = self . getScaledErrors ( star ) . astype ( np . float64 ) <EOL> compStarKeys . append ( int ( star ) ) <EOL> columnCounter += <NUM_LIT:1> <EOL> elif star != self . targetKey and ( np . abs ( self . meanChisq - self . allStarsDict [ star ] [ '<STR_LIT>' ] ) > <NUM_LIT:2> * self . stdChisq ) : <EOL> print '<STR_LIT>' + str ( star ) + '<STR_LIT>' <EOL> compStarKeys . append ( int ( star ) ) <EOL> columnCounter += <NUM_LIT:1> <EOL> initP = np . zeros ( [ numCompStars ] ) + <NUM_LIT:1.> / numCompStars <EOL> def errfunc ( p , target ) : <EOL> if all ( p >= <NUM_LIT:0.0> ) : return np . dot ( p , compStarsOOT . T ) - target <EOL> bestFitP = optimize . leastsq ( errfunc , initP [ : ] , args = ( target . astype ( np . float64 ) ) , maxfev = <NUM_LIT> , epsfcn = np . finfo ( np . float32 ) . eps ) [ <NUM_LIT:0> ] <EOL> print '<STR_LIT>' , bestFitP <EOL> print '<STR_LIT>' , <NUM_LIT:1.> / numCompStars <EOL> self . comparisonStarWeights = np . vstack ( [ compStarKeys , bestFitP ] ) <EOL> self . meanComparisonStar = np . dot ( bestFitP , compStars . T ) <EOL> self . meanComparisonStarError = np . sqrt ( np . dot ( bestFitP ** <NUM_LIT:2> , compErrors . T ** <NUM_LIT:2> ) ) <EOL> return self . meanComparisonStar , self . meanComparisonStarError <EOL> def computeLightCurve ( self , meanComparisonStar , meanComparisonStarError ) : <EOL> '''<STR_LIT>''' <EOL> self . lightCurve = self . getFluxes ( self . targetKey ) / meanComparisonStar <EOL> self . lightCurveError = np . sqrt ( self . lightCurve ** <NUM_LIT:2> * ( ( self . getErrors ( self . targetKey ) / self . getFluxes ( self . targetKey ) ) ** <NUM_LIT:2> + ( meanComparisonStarError / meanComparisonStar ) ** <NUM_LIT:2> ) ) <EOL> return self . lightCurve , self . lightCurveError <EOL> def computeLightCurve_multirad ( self , meanComparisonStars , meanComparisonStarErrors ) : <EOL> '''<STR_LIT>''' <EOL> self . lightCurves = [ ] <EOL> self . lightCurveErrors = [ ] <EOL> for apertureRadiusIndex in range ( len ( self . apertureRadii ) ) : <EOL> lightCurve = self . getFluxes_multirad ( self . targetKey , apertureRadiusIndex ) / meanComparisonStars [ apertureRadiusIndex ] <EOL> self . lightCurves . append ( lightCurve ) <EOL> self . lightCurveErrors . append ( np . sqrt ( lightCurve ** <NUM_LIT:2> * ( ( self . getErrors_multirad ( self . targetKey , apertureRadiusIndex ) / self . getFluxes_multirad ( self . targetKey , apertureRadiusIndex ) ) ** <NUM_LIT:2> + ( meanComparisonStarErrors [ apertureRadiusIndex ] / meanComparisonStars [ apertureRadiusIndex ] ) ** <NUM_LIT:2> ) ) ) <EOL> return self . lightCurves , self . lightCurveErrors <EOL> def getPhotonNoise ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . photonNoise = self . lightCurve * self . meanComparisonStarError <EOL> return self . photonNoise <EOL> def parseInit ( self , initParFilePath = None ) : <EOL> """<STR_LIT>""" <EOL> if initParFilePath is None : <EOL> init = open ( os . path . join ( <EOL> os . path . dirname ( os . path . abspath ( oscaar . __file__ ) ) , <EOL> '<STR_LIT>' ) , '<STR_LIT:r>' ) . read ( ) . splitlines ( ) <EOL> else : <EOL> if os . path . exists ( initParFilePath ) : <EOL> init = open ( os . path . abspath ( initParFilePath ) , '<STR_LIT:r>' ) . read ( ) . splitlines ( ) <EOL> else : <EOL> raise ValueError , ( <EOL> "<STR_LIT>" . format ( initParFilePath ) ) <EOL> for line in init : <EOL> if len ( line . split ( ) ) > <NUM_LIT:1> : <EOL> inline = line . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> name = inline [ <NUM_LIT:0> ] . strip ( ) <EOL> value = str ( inline [ <NUM_LIT:1> ] . strip ( ) ) <EOL> list = [ ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> for string , save in list : <EOL> if string == name : <EOL> if name == "<STR_LIT>" or name == "<STR_LIT>" or name == "<STR_LIT>" : <EOL> self . dict [ save ] = float ( value ) <EOL> elif name == "<STR_LIT>" or name == "<STR_LIT>" : <EOL> self . dict [ save ] = mathMethods . ut2jd ( value ) <EOL> elif name == "<STR_LIT>" or name == "<STR_LIT>" : <EOL> if value == "<STR_LIT>" : <EOL> self . dict [ save ] = True <EOL> else : <EOL> self . dict [ save ] = False <EOL> elif name == "<STR_LIT>" or name == "<STR_LIT>" : <EOL> value = inline [ <NUM_LIT:1> ] . strip ( ) <EOL> if len ( glob ( value ) ) > <NUM_LIT:0> : <EOL> self . dict [ save ] = np . sort ( glob ( value ) ) <EOL> elif value == "<STR_LIT>" : <EOL> self . dict [ save ] = "<STR_LIT>" <EOL> else : <EOL> tempArr = [ ] <EOL> for path in str ( inline [ <NUM_LIT:1> ] ) . split ( '<STR_LIT:U+002C>' ) : <EOL> path = path . strip ( ) <EOL> path = os . path . join ( oscaarpathplus , os . path . abspath ( path ) ) <EOL> tempArr . append ( path ) <EOL> self . dict [ save ] = np . sort ( tempArr ) <EOL> elif name == "<STR_LIT>" : <EOL> if len ( value . split ( '<STR_LIT:U+002C>' ) ) == <NUM_LIT:3> : <EOL> apertureRadiusMin , apertureRadiusMax , apertureRadiusStep = map ( float , value . split ( '<STR_LIT:U+002C>' ) ) <EOL> if ( apertureRadiusMax - apertureRadiusMin ) % apertureRadiusStep == <NUM_LIT:0> : <EOL> apertureRadii = np . arange ( apertureRadiusMin , apertureRadiusMax + apertureRadiusStep , apertureRadiusStep ) <EOL> else : <EOL> apertureRadii = np . arange ( apertureRadiusMin , apertureRadiusMax , apertureRadiusStep ) <EOL> self . dict [ save ] = apertureRadii <EOL> elif len ( value . split ( '<STR_LIT:U+002C>' ) ) == <NUM_LIT:1> : <EOL> self . dict [ save ] = [ float ( value ) ] <EOL> else : <EOL> self . dict [ save ] = [ float ( i ) for i in value . split ( '<STR_LIT:U+002C>' ) ] <EOL> elif name == "<STR_LIT>" : <EOL> self . outputPath = os . path . join ( oscaarpathplus , os . path . abspath ( value ) ) <EOL> else : <EOL> self . dict [ save ] = value <EOL> def parseRegionsFile ( self , regPath ) : <EOL> """<STR_LIT>""" <EOL> regionsData = open ( regPath , '<STR_LIT:r>' ) . read ( ) . splitlines ( ) <EOL> init_x_list = [ ] <EOL> init_y_list = [ ] <EOL> for i in range ( <NUM_LIT:0> , len ( regionsData ) ) : <EOL> if regionsData [ i ] [ <NUM_LIT:0> : <NUM_LIT:6> ] == '<STR_LIT>' : <EOL> y , x = re . split ( "<STR_LIT>" , re . split ( "<STR_LIT>" , regionsData [ i ] ) [ <NUM_LIT:1> ] ) [ <NUM_LIT:0> : <NUM_LIT:2> ] <EOL> init_y_list . append ( float ( y ) ) <EOL> init_x_list . append ( float ( x ) ) <EOL> return init_x_list , init_y_list <EOL> def parseRawRegionsList ( self , rawRegionsList ) : <EOL> """<STR_LIT>""" <EOL> regionsFiles = [ ] <EOL> refFITSFiles = [ ] <EOL> for pair in rawRegionsList . split ( '<STR_LIT:;>' ) : <EOL> if len ( pair . split ( "<STR_LIT:U+002C>" ) ) == <NUM_LIT:2> : <EOL> regionsFile , refFITSFile = pair . split ( '<STR_LIT:U+002C>' ) <EOL> regionsFiles . append ( regionsFile ) <EOL> refFITSFiles . append ( refFITSFile ) <EOL> return regionsFiles , refFITSFiles <EOL> def plot ( self , pointsPerBin = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> plt . close ( ) <EOL> times = self . getTimes ( ) <EOL> meanComparisonStar , meanComparisonStarError = self . calcMeanComparison ( ccdGain = self . ccdGain ) <EOL> lightCurve , lightCurveErr = self . computeLightCurve ( meanComparisonStar , meanComparisonStarError ) <EOL> binnedTime , binnedFlux , binnedStd = mathMethods . medianBin ( times , lightCurve , pointsPerBin ) <EOL> fig = plt . figure ( num = None , figsize = ( <NUM_LIT:10> , <NUM_LIT:8> ) , facecolor = '<STR_LIT:w>' , edgecolor = '<STR_LIT:k>' ) <EOL> fig . canvas . set_window_title ( '<STR_LIT>' ) <EOL> axis = fig . add_subplot ( <NUM_LIT> ) <EOL> def format_coord ( x , y ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' % ( x , y ) <EOL> axis . format_coord = format_coord <EOL> axis . errorbar ( times , lightCurve , yerr = lightCurveErr , fmt = '<STR_LIT>' , ecolor = '<STR_LIT>' ) <EOL> axis . errorbar ( binnedTime , binnedFlux , yerr = binnedStd , fmt = '<STR_LIT>' , linewidth = <NUM_LIT:2> ) <EOL> axis . axvline ( ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , x = self . ingress , color = '<STR_LIT:k>' , ls = '<STR_LIT::>' ) <EOL> axis . axvline ( ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , x = self . egress , color = '<STR_LIT:k>' , ls = '<STR_LIT::>' ) <EOL> axis . set_title ( '<STR_LIT>' ) <EOL> axis . set_xlabel ( '<STR_LIT>' ) <EOL> axis . set_ylabel ( '<STR_LIT>' ) <EOL> plt . ioff ( ) <EOL> plt . show ( ) <EOL> def plotLightCurve ( self , pointsPerBin = <NUM_LIT:10> , apertureRadiusIndex = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> binnedTime , binnedFlux , binnedStd = mathMethods . medianBin ( self . times , self . lightCurves [ apertureRadiusIndex ] , pointsPerBin ) <EOL> fig = plt . figure ( num = None , figsize = ( <NUM_LIT:10> , <NUM_LIT:8> ) , facecolor = '<STR_LIT:w>' , edgecolor = '<STR_LIT:k>' ) <EOL> fig . canvas . set_window_title ( '<STR_LIT>' ) <EOL> axis = fig . add_subplot ( <NUM_LIT> ) <EOL> def format_coord ( x , y ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' % ( x , y ) <EOL> axis . format_coord = format_coord <EOL> axis . errorbar ( self . times , self . lightCurves [ apertureRadiusIndex ] , yerr = self . lightCurveErrors [ apertureRadiusIndex ] , fmt = '<STR_LIT>' , ecolor = '<STR_LIT>' ) <EOL> axis . errorbar ( binnedTime , binnedFlux , yerr = binnedStd , fmt = '<STR_LIT>' , linewidth = <NUM_LIT:2> ) <EOL> axis . axvline ( ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , x = self . ingress , color = '<STR_LIT:k>' , ls = '<STR_LIT::>' ) <EOL> axis . axvline ( ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , x = self . egress , color = '<STR_LIT:k>' , ls = '<STR_LIT::>' ) <EOL> axis . set_title ( ( '<STR_LIT>' % self . apertureRadii [ apertureRadiusIndex ] ) ) <EOL> axis . set_xlabel ( '<STR_LIT>' ) <EOL> axis . set_ylabel ( '<STR_LIT>' ) <EOL> plt . ioff ( ) <EOL> plt . show ( ) <EOL> def plotRawFluxes ( self , apertureRadiusIndex = <NUM_LIT:0> , pointsPerBin = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> plt . ion ( ) <EOL> fig = plt . figure ( num = None , figsize = ( <NUM_LIT:10> , <NUM_LIT:8> ) , facecolor = '<STR_LIT:w>' , edgecolor = '<STR_LIT:k>' ) <EOL> fig . canvas . set_window_title ( '<STR_LIT>' ) <EOL> axis = fig . add_subplot ( <NUM_LIT> ) <EOL> def format_coord ( x , y ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' % ( x , y ) <EOL> axis . format_coord = format_coord <EOL> for star in self . allStarsDict : <EOL> axis . errorbar ( self . times , self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] , yerr = self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] , fmt = '<STR_LIT:o>' ) <EOL> axis . axvline ( ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , x = self . ingress , color = '<STR_LIT:k>' , ls = '<STR_LIT::>' ) <EOL> axis . axvline ( ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , x = self . egress , color = '<STR_LIT:k>' , ls = '<STR_LIT::>' ) <EOL> axis . set_title ( ( '<STR_LIT>' % self . apertureRadii [ apertureRadiusIndex ] ) ) <EOL> axis . set_xlabel ( '<STR_LIT>' ) <EOL> axis . set_ylabel ( '<STR_LIT>' ) <EOL> plt . ioff ( ) <EOL> plt . show ( ) <EOL> def plotScaledFluxes ( self , apertureRadiusIndex = <NUM_LIT:0> , pointsPerBin = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> plt . ion ( ) <EOL> fig = plt . figure ( num = None , figsize = ( <NUM_LIT:10> , <NUM_LIT:8> ) , facecolor = '<STR_LIT:w>' , edgecolor = '<STR_LIT:k>' ) <EOL> fig . canvas . set_window_title ( '<STR_LIT>' ) <EOL> axis = fig . add_subplot ( <NUM_LIT> ) <EOL> def format_coord ( x , y ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' % ( x , y ) <EOL> axis . format_coord = format_coord <EOL> for star in self . allStarsDict : <EOL> axis . errorbar ( self . times , self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] , yerr = self . allStarsDict [ star ] [ '<STR_LIT>' ] [ apertureRadiusIndex ] , fmt = '<STR_LIT:o>' ) <EOL> axis . axvline ( ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , x = self . ingress , color = '<STR_LIT:k>' , ls = '<STR_LIT::>' ) <EOL> axis . axvline ( ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , x = self . egress , color = '<STR_LIT:k>' , ls = '<STR_LIT::>' ) <EOL> axis . set_title ( ( '<STR_LIT>' % self . apertureRadii [ apertureRadiusIndex ] ) ) <EOL> axis . set_xlabel ( '<STR_LIT>' ) <EOL> axis . set_ylabel ( '<STR_LIT>' ) <EOL> plt . ioff ( ) <EOL> plt . show ( ) <EOL> def plotCentroidsTrace ( self , pointsPerBin = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> fig = plt . figure ( num = None , figsize = ( <NUM_LIT:10> , <NUM_LIT:8> ) , facecolor = '<STR_LIT:w>' , edgecolor = '<STR_LIT:k>' ) <EOL> fig . canvas . set_window_title ( '<STR_LIT>' ) <EOL> axis = fig . add_subplot ( <NUM_LIT> ) <EOL> def format_coord ( x , y ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' % ( x , y ) <EOL> axis . format_coord = format_coord <EOL> for star in self . allStarsDict : <EOL> axis . plot ( self . allStarsDict [ star ] [ '<STR_LIT>' ] , self . allStarsDict [ star ] [ '<STR_LIT>' ] ) <EOL> axis . set_title ( '<STR_LIT>' ) <EOL> axis . set_xlabel ( '<STR_LIT:X>' ) <EOL> axis . set_ylabel ( '<STR_LIT:Y>' ) <EOL> plt . ioff ( ) <EOL> plt . show ( ) <EOL> def plotComparisonWeightings ( self , apertureRadiusIndex = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> plt . ion ( ) <EOL> weights = self . comparisonStarWeights [ apertureRadiusIndex ] <EOL> weights = np . sort ( weights , axis = <NUM_LIT:1> ) <EOL> width = <NUM_LIT:0.5> <EOL> indices = weights [ <NUM_LIT:0> , : ] <EOL> coefficients = weights [ <NUM_LIT:1> , : ] <EOL> fig = plt . figure ( num = None , figsize = ( <NUM_LIT:10> , <NUM_LIT:8> ) , facecolor = '<STR_LIT:w>' , edgecolor = '<STR_LIT:k>' ) <EOL> fig . canvas . set_window_title ( '<STR_LIT>' ) <EOL> ax = fig . add_subplot ( <NUM_LIT> ) <EOL> ax . set_xlim ( [ <NUM_LIT:0> , len ( indices ) + <NUM_LIT:1> ] ) <EOL> ax . set_xticks ( indices + width / <NUM_LIT:2> ) <EOL> ax . set_xticklabels ( [ "<STR_LIT>" + str ( i ) for i in range ( len ( indices ) ) ] ) <EOL> ax . set_xlabel ( '<STR_LIT>' ) <EOL> ax . set_ylabel ( '<STR_LIT>' ) <EOL> ax . set_title ( '<STR_LIT>' % self . apertureRadii [ apertureRadiusIndex ] ) <EOL> ax . axhline ( xmin = <NUM_LIT:0> , xmax = <NUM_LIT:1> , y = <NUM_LIT:1.0> / len ( indices ) , linestyle = '<STR_LIT::>' , color = '<STR_LIT:k>' ) <EOL> ax . bar ( indices , coefficients , width , color = '<STR_LIT:w>' ) <EOL> plt . ioff ( ) <EOL> plt . show ( ) <EOL> def updateMCMC ( self , bestp , allparams , acceptanceRate , dataBankPath , uncertainties ) : <EOL> """<STR_LIT>""" <EOL> self . MCMC_bestp = bestp <EOL> self . MCMC_allparams = allparams <EOL> self . MCMC_acceptanceRate = acceptanceRate <EOL> self . dataBankPath = dataBankPath <EOL> self . MCMC_uncertainties = uncertainties <EOL> def uncertaintyString ( self ) : <EOL> """<STR_LIT>""" <EOL> savestring = '<STR_LIT>' <EOL> labels = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for i in range ( len ( labels ) ) : <EOL> savestring += '<STR_LIT>' % ( labels [ i ] , self . MCMC_bestp [ i ] , self . MCMC_uncertainties [ i ] [ <NUM_LIT:0> ] , self . MCMC_uncertainties [ i ] [ <NUM_LIT:1> ] ) <EOL> return savestring <EOL> def czechETDstring ( self , apertureRadiusIndex ) : <EOL> """<STR_LIT>""" <EOL> N_measurements = len ( self . lightCurves [ apertureRadiusIndex ] ) <EOL> outputString = '<STR_LIT>' <EOL> for i in xrange ( N_measurements ) : <EOL> outputString += '<STR_LIT:\t>' . join ( map ( str , [ self . times [ i ] , self . lightCurves [ apertureRadiusIndex ] [ i ] , self . lightCurveErrors [ apertureRadiusIndex ] [ i ] ] ) ) <EOL> outputString += '<STR_LIT:\n>' <EOL> return outputString <EOL> def plotLightCurve_multirad ( self , pointsPerBin = <NUM_LIT:10> ) : <EOL> for apertureRadiusIndex in range ( len ( self . apertureRadii ) ) : <EOL> meanTimeInt = int ( np . rint ( np . mean ( self . times ) ) ) <EOL> offsetTimes = self . times - meanTimeInt <EOL> binnedTime , binnedFlux , binnedStd = mathMethods . medianBin ( offsetTimes , self . lightCurves [ apertureRadiusIndex ] , pointsPerBin ) <EOL> fig = plt . figure ( num = None , figsize = ( <NUM_LIT:10> , <NUM_LIT:8> ) , facecolor = '<STR_LIT:w>' , edgecolor = '<STR_LIT:k>' ) <EOL> fig . canvas . set_window_title ( '<STR_LIT>' ) <EOL> axis = fig . add_subplot ( <NUM_LIT> ) <EOL> def format_coord ( x , y ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' % ( meanTimeInt + x , y ) <EOL> axis . format_coord = format_coord <EOL> axis . errorbar ( offsetTimes , self . lightCurves [ apertureRadiusIndex ] , yerr = self . lightCurveErrors [ apertureRadiusIndex ] , fmt = '<STR_LIT>' , ecolor = '<STR_LIT>' ) <EOL> axis . errorbar ( binnedTime , binnedFlux , yerr = binnedStd , fmt = '<STR_LIT>' , linewidth = <NUM_LIT:2> ) <EOL> axis . axvline ( ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , x = self . ingress - meanTimeInt , color = '<STR_LIT:k>' , ls = '<STR_LIT::>' ) <EOL> axis . axvline ( ymin = <NUM_LIT:0> , ymax = <NUM_LIT:1> , x = self . egress - meanTimeInt , color = '<STR_LIT:k>' , ls = '<STR_LIT::>' ) <EOL> axis . set_title ( '<STR_LIT>' % self . apertureRadii [ apertureRadiusIndex ] ) <EOL> axis . set_xlabel ( ( '<STR_LIT>' % meanTimeInt ) ) <EOL> axis . set_ylabel ( '<STR_LIT>' ) <EOL> plt . ioff ( ) <EOL> plt . show ( ) </s>
