def plot_psrrates(pkllist, outname=''):
    """ Plot cumulative rate histograms. List of pkl files in order, as for make_psrrates.
    """

    if not outname:
        outname = 'tmp.png'

    labels = {0: 'Flux at 0\'', 1: 'Flux at 7\'', 2: 'Flux at 15\'', 3: 'Flux at 25\''}
    labelsr = {1: 'Flux Ratio 7\' to 0\'', 2: 'Flux Ratio 15\' to 0\'', 3: 'Flux Ratio 25\' to 0\''}
    colors = {0: 'b.', 1: 'r.', 2: 'g.', 3: 'y.'}

    rates = make_psrrates(pkllist)
    plt.clf()
    fig = plt.figure(1, figsize=(10,8), facecolor='white')
    ax = fig.add_subplot(211, axis_bgcolor='white')
    for kk in rates.keys():
        flux, rate = rates[kk]
        plt.plot(flux, rate, colors[kk], label=labels[kk])

    plt.setp( ax.get_xticklabels(), visible=False)
    plt.ylabel('Flux (Jy)', fontsize='20')
    plt.legend(numpoints=1)
    plt.loglog()

    ax2 = fig.add_subplot(212, sharex=ax, axis_bgcolor='white')
    flux0, rate0 = rates[0]
    for kk in rates.keys():
        flux, rate = rates[kk]
        if kk == 1:
            r10 = [rate[i]/rate0[np.where(flux0 == flux[i])[0][0]] for i in range(len(rate))]
            plt.plot(flux, r10, colors[kk], label=labelsr[kk])
        elif kk == 2:
            r20 = [rate[i]/rate0[np.where(flux0 == flux[i])[0][0]] for i in range(len(rate))]
            plt.plot(flux, r20, colors[kk], label=labelsr[kk])
        elif kk == 3:
            r30 = [rate[i]/rate0[np.where(flux0 == flux[i])[0][0]] for i in range(len(rate))]
            plt.plot(flux, r30, colors[kk], label=labelsr[kk])

    plt.xlabel('Rate (1/s)', fontsize='20')
    plt.ylabel('Flux ratio', fontsize='20')
    plt.legend(numpoints=1)
    plt.subplots_adjust(hspace=0)

    # find typical ratio. avoid pulsar period saturation and low-count regimes (high and low ends)
    if len(rates) == 4:
        logger.info('flux ratio, lowest common (1/0, 2/0, 3/0):', (r10[len(r30)-1], r20[len(r30)-1], r30[-1]))
        logger.info('flux ratio, high end (1/0, 2/0, 3/0):', (r10[-1], r20[-1], r30[-1]))
    elif len(rates) == 3:
        logger.info('flux ratio, lowest common (1/0, 2/0):', (r10[len(r20)-1], r20[-1]))
        logger.info('flux ratio, high end (1/0, 2/0):', (r10[-1], r20[-1]))

    plt.savefig(outname)
def plot_psrrates ( pkllist , outname = '' ) : if not outname : outname = 'tmp.png' labels = { 0 : 'Flux at 0\'' , 1 : 'Flux at 7\'' , 2 : 'Flux at 15\'' , 3 : 'Flux at 25\'' } labelsr = { 1 : 'Flux Ratio 7\' to 0\'' , 2 : 'Flux Ratio 15\' to 0\'' , 3 : 'Flux Ratio 25\' to 0\'' } colors = { 0 : 'b.' , 1 : 'r.' , 2 : 'g.' , 3 : 'y.' } rates = make_psrrates ( pkllist ) plt . clf ( ) fig = plt . figure ( 1 , figsize = ( 10 , 8 ) , facecolor = 'white' ) ax = fig . add_subplot ( 211 , axis_bgcolor = 'white' ) for kk in rates . keys ( ) : flux , rate = rates [ kk ] plt . plot ( flux , rate , colors [ kk ] , label = labels [ kk ] ) plt . setp ( ax . get_xticklabels ( ) , visible = False ) plt . ylabel ( 'Flux (Jy)' , fontsize = '20' ) plt . legend ( numpoints = 1 ) plt . loglog ( ) ax2 = fig . add_subplot ( 212 , sharex = ax , axis_bgcolor = 'white' ) flux0 , rate0 = rates [ 0 ] for kk in rates . keys ( ) : flux , rate = rates [ kk ] if kk == 1 : r10 = [ rate [ i ] / rate0 [ np . where ( flux0 == flux [ i ] ) [ 0 ] [ 0 ] ] for i in range ( len ( rate ) ) ] plt . plot ( flux , r10 , colors [ kk ] , label = labelsr [ kk ] ) elif kk == 2 : r20 = [ rate [ i ] / rate0 [ np . where ( flux0 == flux [ i ] ) [ 0 ] [ 0 ] ] for i in range ( len ( rate ) ) ] plt . plot ( flux , r20 , colors [ kk ] , label = labelsr [ kk ] ) elif kk == 3 : r30 = [ rate [ i ] / rate0 [ np . where ( flux0 == flux [ i ] ) [ 0 ] [ 0 ] ] for i in range ( len ( rate ) ) ] plt . plot ( flux , r30 , colors [ kk ] , label = labelsr [ kk ] ) plt . xlabel ( 'Rate (1/s)' , fontsize = '20' ) plt . ylabel ( 'Flux ratio' , fontsize = '20' ) plt . legend ( numpoints = 1 ) plt . subplots_adjust ( hspace = 0 ) if len ( rates ) == 4 : logger . info ( 'flux ratio, lowest common (1/0, 2/0, 3/0):' , ( r10 [ len ( r30 ) - 1 ] , r20 [ len ( r30 ) - 1 ] , r30 [ - 1 ] ) ) logger . info ( 'flux ratio, high end (1/0, 2/0, 3/0):' , ( r10 [ - 1 ] , r20 [ - 1 ] , r30 [ - 1 ] ) ) elif len ( rates ) == 3 : logger . info ( 'flux ratio, lowest common (1/0, 2/0):' , ( r10 [ len ( r20 ) - 1 ] , r20 [ - 1 ] ) ) logger . info ( 'flux ratio, high end (1/0, 2/0):' , ( r10 [ - 1 ] , r20 [ - 1 ] ) ) plt . savefig ( outname )
Plot cumulative rate histograms. List of pkl files in order, as for make_psrrates.