Exemple #1
0
def plot_model(dirname):

    model_name = dirname[dirname.index("_")+1:]

    dirs = glob.glob("catalog*")
    dirs.sort()

    print "Directories to consider:"
    for dir_ in dirs:
        print "- ", dir_

    rads = []
    counts = []

    for dir_ in dirs:
        rads.append(np.loadtxt(os.path.join(dir_, "radial.dat")))
        # print rads[-1]
        counts.append(np.loadtxt(os.path.join(dir_, "count.dat")))
        # print counts[-1]


    # Isolates 1st and 2nd columns of all files
    temp_nw = []
    temp_like = []
    temp_rgal = []
    temp_nb = []
    temp_nbl = []
    temp_ntot = []


    for rad, count in zip(rads, counts):
        temp_nw.append(rad[:, 0:1])
        # print temp_nw
        # sys.exit()
        temp_like.append(rad[:, 1:2])
        temp_rgal.append(rad[:, 2:3])
        
        temp_nb.append(count[0])
        temp_nbl.append(count[1])
        temp_ntot.append(count[5])
       
        
        
    # Now stacks into matrices
    nw = np.hstack(temp_nw)
    like = np.hstack(temp_like)
    rgal = np.hstack(temp_rgal)

    #nb = np.hstack(temp_nb)
    #nbl = np.hstack(temp_nbl)
    #ntot = np.hstack(temp_ntot)

    print nw
    print like
    print rgal


    nlikebin = np.mean(like, 1)
    serr = np.std(nw, 1)
    errmed = np.mean(nw, 1)
    err = errmed/nlikebin
    serrmed = serr/nlikebin

    radii = np.mean(rgal, 1)

    nb_med=np.mean(temp_nb)
    ntot_med=np.mean(temp_ntot)
    nbl_med=np.mean(temp_nbl)
    descr="%.0f, %.0f, %.0f" % (nb_med,nbl_med,ntot_med)


    #stds_nw = np.std(nw, 1)
    #print "means nw", means_nw
    #print "stds nw", stds_nw

    #read nw1 1 read nlike1 2 read rgal1 3 read ntot1 4
    #read nb1 1 read nbl 2 read nd 3 read ndl 4 read nbclip1 7 read nbclipno1 8 


    plot_thing(radii, err, serrmed, title, descr)
    plt.save_png("radial-%s.png" % model_name)
    plt.show()
    fit_sat = p1['xsat']
    fd = fitres['fitdata']
    
    print ('maximum count rate: %.1f cps, saturation power: %.1f microwatt'%(fit_A,fit_sat))
   
    dat.add_value('fit')
    plt.add_data(dat, coorddim=0, valdim=2)
    dat.add_data_point(x_axis,y_NV-y_BG,fd)

    plt.set_plottitle('power saturation '+name+', P_sat = '+str(int(fit_sat))+'uW, R_sat = '+str(int(A))+' counts/s')

else:
    dat.add_data_point(x_axis,y_NV-y_BG)
    print 'could not fit calibration curve!'
plt.set_legend(False)
plt.save_png(dat.get_filepath()+'png')
dat.close_file()

#result = open(path+'powerdependence_'+name+'.dat', 'w')
#result.write('# r_max (cps): %s\n'%fit_A)
#result.write('# p_sat (mW):  %s\n'%fit_sat)
#result.write('\n')
#result.write('# P (mW)\tr (cps)\tbg (cps)\tr_NV (cps)\n')
#for a in x:
#    result.write('%.4f\t%.1f\t%.1f\t%.1f\n'%(x_axis[a]/1000.0,y_NV[a],y_BG[a],(y_NV[a]-y_BG[a])))
#result.close()
    
#fig = plt.figure()

#dat = fig.add_subplot(111)
#x = x_axis/1000.0