def testingTFimpact(): # These are the data we'll be using folder = '/Users/uqnsomme/Documents/Obelix/FakeAGN/TFs/' names = ['0Phi', '001Phi', '010Phi', '025Phi', '01TH', 'Gamma', 'Gauss', 'Sphere'] nn = len(names) maxLag = 1000.0 # Initialisation bins = np.arange(0.0, maxLag, 10) # Grid/x-axis for histograms binssmall = np.arange(0.0, maxLag) # Grid/x-axis for accurate median calculation est = np.zeros((nn, 1000)) # Array to hold all the time lag estimates from Javelin n = np.zeros((nn, 99)) # y-axis for hisograms nsmall = np.zeros((nn, 999)) # y-axis for accurate median calculation # We'll be making the same kind of plot for all of the TFs for i in range(nn): print 'About to start reading ' + names[i] # Import data lagMatrName = folder + 'TFs' + names[i] + '.dat' lagMatr = np.loadtxt(lagMatrName) # Load in results file true = lagMatr[:, 0] # Time lag, as created by me est[i,:] = lagMatr[:, 1] # Estimates found by Javelin # Depending on what physical scenario we're considering, choose appropriate axes and labels for figure if (i==0): maxN = 4e-2 ymal = 1e-2 ymil = 5e-3 else: maxN = 1e-2 ymal = 2e-3 ymil = 1e-3 # End if-statement # Calculate histograms to do some maths n[i,:], _ = np.histogram(est, bins=bins, normed=True) nsmall[i,:], _ = np.histogram(est, bins=binssmall, normed=True) # Fit skewed Gaussian distribution to the result to later calculate median skewFits, skewCovar = opt.curve_fit(Stacking.skewGaussian, bins[0:-1], n[i,:], p0=(1./np.std(n[i,:]), np.argmax(n[i,:]), 0, 0, 1)) ySkew = Stacking.skewGaussian(binssmall, skewFits[0], skewFits[1], skewFits[2], skewFits[3], skewFits[4]) # Determine maximum likelihood and its uncertainties llhood = Stats() llhood.best = -1000 llhood.minus = 0 llhood.plus = 0 llhood.likeLimits1D(ySkew, binssmall, 1) # Determine median and error estimates median, minus, plus = Stats.getMedianEstimates(binssmall, nsmall[i,:]) # Print distribution properties to screen print "=" * 60, "\n" print "\tMaximum likelihood: tau0 =", llhood.best print "\tDifference to lower limit:", llhood.minus print "\tDifference to upper limit:", llhood.plus print "\tMedian:", median print "\tMedian lower:", minus print "\tMedian upper:", plus print "\n", "=" * 60 # Create figure showing the distribution of estimates for a particular TF fig = plt.figure(figsize=(6,10)) plt.hist(est, bins=bins, normed=True, label='JAVELIN estimates') plt.plot(binssmall, ySkew, linewidth=2, label="Best skewed Gaussian fit") plt.plot([true[i], true[i]], [0, maxN], linewidth=2, label='True lag') # Specify figure properties plt.axis([0, maxLag, 0, maxN]) plt.xlabel('Time lag [days]', fontsize='large') plt.ylabel('Number of instances', fontsize='large') plt.legend() ax = plt.axes() ax.xaxis.set_major_locator(tck.MultipleLocator(200)) ax.xaxis.set_minor_locator(tck.MultipleLocator(100)) ax.yaxis.set_major_locator(tck.MultipleLocator(ymal)) ax.yaxis.set_minor_locator(tck.MultipleLocator(ymil)) ax.set_aspect(maxLag/maxN) plt.savefig(folder+names[i]+'.png', dpi=500, bbox_inches='tight') # End for-loop # Create plot showing the different estimate distributions for all of the TFs fig = plt.figure(figsize=(6,10)) plt.hist(est[4,:], bins=bins, normed=True, histtype='step', color='darkblue', label=r'$\mathrm{Face-on\ ring}$') plt.hist(est[7,:], bins=bins, normed=True, histtype='step', color='paleturquoise', label=r'$\mathrm{Sphere}$') plt.hist(est[1,:], bins=bins, normed=True, histtype='step', color='mediumorchid', label=r'$\phi=\pi/100$') plt.hist(est[2,:], bins=bins, normed=True, histtype='step', color='darkgreen', label=r'$\phi=\pi/10$') plt.hist(est[3,:], bins=bins, normed=True, histtype='step', color='black', label=r'$\phi=\pi/4$') plt.hist(est[5,:], bins=bins, normed=True, histtype='step', color='olivedrab', label=r'$\mathrm{Gamma}$') plt.hist(est[4,:], bins=bins, normed=True, histtype='step', color='pink', label=r'$\mathrm{Gauss}$') plt.plot([true[i], true[i]], [0, maxN], 'r', label=r'$\mathrm{True\ lag}$') # Specify figure properties plt.axis([0, maxLag, 0, 0.009]) plt.xlabel(r'$\mathrm{Time\ lag\ [days]}$', fontsize='large') plt.ylabel(r'$N_{norm}$', fontsize='large') plt.legend() ax = plt.axes() ax.xaxis.set_major_locator(tck.MultipleLocator(200)) ax.xaxis.set_minor_locator(tck.MultipleLocator(100)) ax.yaxis.set_major_locator(tck.MultipleLocator(0.001)) ax.yaxis.set_minor_locator(tck.MultipleLocator(0.0005)) ax.set_aspect(maxLag/maxN) plt.savefig('/Users/uqnsomme/Documents/ManyHists.png', dpi=500, bbox_inches='tight')
section = 'oneline' emLine = 'Hb' binends = np.array([-26.15, -25.75, -25.35, -24.95, -24.55, -24.15, -23.75, -23.35, -22.85, -22.35])#, -21.55]) pm = 1.3 limits = np.array([0., 0.74, -22.90-pm, -22.90])#MagBins[30], MagBins[31]]) number = findAGNnumber(limits, QSOtemplate) #number = 1 print ' ' print 'Limits:', limits print 'Number of AGN within limits:', number # Initialisation AGN = createOzDESAGN(QSOtemplate) stack = Stacking() stats = Stats() conv = Convergence() plotOzDESAGN(QSOtemplate, plotIndividuals=False, binends=binends, name='MgII') # Create AGN AGN.generateAGN(limits, True, number, resDir, fName) output = AGN.generateLightCurveParameters(section, resDir+fName) AGN.printLightCurveParametersToFile(output, resDir+params) lag = printLagValueInParameterBin(resDir+params, limits, emLine=emLine) # Do the Javelin magic runJavelinOnFakeData(resDir+params, limits, number, resDir, string, emLine=emLine) # Stack and analyse