def bias_bySNR_analytic():
    '''
    Produces the analytic bias as a function of SNR.

    ToDo:
    Add this to bias_bySNR routine
    '''
    import src.measure_Bias as mBias
    import src.model_Production as modPro

    global imageParams
    modPro.set_modelParameter(imageParams, fitParamsLabels, fitParamsValues)

    handle = intialise_Output(Output+filePrefix+'_AnaBias.dat', mode = 'a')
    handle.write('## Recovered statistics as a result of bias run, single fit at a time, done analytically. Output of form [Bias] repeated for all fit quantities \n')
    for k in fitParamsLabels:
        handle.write('#'+str(k)+' = '+str(fittedParameters[k])+'\n')

    S = -1 #Counter
    filenames = []

    e = 0 ##Loop over this for multiple runs
    while True:
        print '\n'+400*'-'
        
        S += 1
        SNR = SNRRange[0] + S*SNRRange[2]

        ##Exit Condition
        if(SNR > SNRRange[1]):
            break

        ##Set Model
        imageParams['SNR'] = SNR

        ##Produce image to update noise to correct value (THIS IS A HACK AND NEEDS CHANGED) - estimate_Noise works fairly well, but you need to specify the noise correctly
        #disc, imageParams = modPro.get_Pixelised_Model(imageParams, noiseType = 'G', outputImage = False)

        ## Check image to get SNR
        imageSB, imageParams = modPro.user_get_Pixelised_Model(imageParams, outputImage = True, sbProfileFunc = SBPro.gaussian_SBProfile_Weave)
        imageParams['noise'] = modPro.SNR_Mapping(imageSB, SNR = SNR)

        print 'Analytic Bias Check: For SNR', SNR, ' has noise var:', imageParams['noise']

        bias = np.array(mBias.analytic_GaussianLikelihood_Bias(fitParamsValues, fitParamsLabels, imageParams, diffType = 'ana'))
        #bias = np.array([mBias.analytic_GaussianLikelihood_Bias(fitParamsValues[e], fitParamsLabels[e], imageParams, diffType = 'ana')])

        print '\n Analytic Bias for SNR:', SNR, ' is :', bias
        print ' '

        ### different to bias_bySNR
        np.savetxt(handle, np.hstack((np.array(SNR).reshape(1,1),bias.reshape(1,bias.shape[0]))))#.reshape(1,bias.shape[1]+1))

    handle.close()
imageParams['SNR'] = 50.
imageParams['size'] = 1.2
imageParams[derLabel] = S0
imageParams['stamp_size'] = np.array([50,50])
imageParams['centroid'] = (imageParams['stamp_size']+1)/2.

###Get image
image, imageParams = modPro.get_Pixelised_Model(imageParams, noiseType = 'G')

modelParams = imageParams.copy()

print 'modelParams test:', modelParams['stamp_size'], modelParams['noise']
print 'Estimated variance:', ML.estimate_Noise(image, maskCentroid = modelParams['centroid'])
raw_input('Check')

##Produce analytic bias
print 'Getting analytic bias:'
anbias = mBias.analytic_GaussianLikelihood_Bias(S0, derLabel, modelParams, diffType = 'ana')
print '\n ****** Analytic Bias is:', anbias

##Produce analytic bias
print 'Getting analytic bias:'
numanbias = mBias.analytic_GaussianLikelihood_Bias(S0, derLabel, modelParams, diffType = 'num')
print '\n ****** Numerical Analytic Bias is:', numanbias


##Produce fully numerical bias
bias = mBias.return_numerical_ML_Bias(S0, derLabel, modelParams)
print '\n ****** Fully Numerical Bias is found to be:', bias