Esempio n. 1
0
def _plotDifferenceIndividualVsJoined(individuals, joined, title='800nm', sigma=3,
                                      requirementFWHM=10.8, requirementE=0.156, requirementR2=0.002,
                                      truthx=None, truthy=None, FWHMlims=(7.5, 10.3)):
    """
    Simple plot
    """
    ind = []
    for file in g.glob(individuals):
        print file
        ind.append(fileIO.cPicleRead(file))

    join = fileIO.cPicleRead(joined)
    xtmp = np.arange(len(ind)) + 1

    #plot FWHM
    fig = plt.figure()
    ax1 = fig.add_subplot(211)
    ax2 = fig.add_subplot(212)
    fig.subplots_adjust(hspace=0, top=0.93, bottom=0.17, left=0.11, right=0.98)
    ax1.set_title(title)

    ax1.errorbar(xtmp, [_FWHMGauss(data['wx']) for data in ind], yerr=[sigma*_FWHMGauss(data['wxerr']) for data in ind],
                 fmt='o')
    ax1.errorbar(xtmp[-1]+1, _FWHMGauss(join['wx']), yerr=sigma*_FWHMGauss(join['wxerr']), fmt='s')
    ax2.errorbar(xtmp, [_FWHMGauss(data['wy']) for data in ind], yerr=[sigma*_FWHMGauss(data['wyerr']) for data in ind],
                 fmt='o')
    ax2.errorbar(xtmp[-1]+1, _FWHMGauss(join['wy']), yerr=sigma*_FWHMGauss(join['wyerr']), fmt='s')

    #simulations
    if truthx is not None:
        ax1.axhline(y=_FWHMGauss(truthx), label='Truth', c='g')
    if truthy is not None:
        ax2.axhline(y=_FWHMGauss(truthy), label='Truth', c='g')

    #requirements
    if requirementFWHM is not None:
        ax1.axhline(y=requirementFWHM, label='Requirement (800nm)', c='r')
        ax2.axhline(y=requirementFWHM, label='Requirement (800nm)', c='r')

    plt.sca(ax1)
    plt.xticks(visible=False)
    plt.sca(ax2)

    ltmp = np.hstack((xtmp, xtmp[-1]+1))
    plt.xticks(ltmp, ['Individual %i' % x for x in ltmp[:-1]] + ['Joint',], rotation=45)

    ax1.set_ylim(*FWHMlims)
    ax2.set_ylim(*FWHMlims)
    ax1.set_xlim(xtmp.min()*0.9, (xtmp.max() + 1)*1.05)
    ax2.set_xlim(xtmp.min()*0.9, (xtmp.max() + 1)*1.05)

    ax1.set_ylabel(r'FWHM$_{X} \quad [\mu$m$]$')
    ax2.set_ylabel(r'FWHM$_{Y} \quad [\mu$m$]$')
    ax1.legend(shadow=True, fancybox=True)
    plt.savefig('IndividualVsJoinedFWHM%s.pdf' % title)
    plt.close()

    #plot R2 and ellipticity
    fig = plt.figure()
    ax1 = fig.add_subplot(211)
    ax2 = fig.add_subplot(212)
    fig.subplots_adjust(hspace=0, top=0.93, bottom=0.17, left=0.11, right=0.98)
    ax1.set_title(title)

    ax1.errorbar(xtmp, [_R2FromGaussian(data['wx'], data['wy'])*1e3 for data in ind],
                 yerr=[sigma*1.e3*_R2FromGaussian(data['wxerr'], data['wyerr']) for data in ind], fmt='o')
    ax1.errorbar(xtmp[-1]+1, _R2FromGaussian(join['wx'], join['wy'])*1e3,
                 yerr=sigma*1.e3*_R2FromGaussian(join['wxerr'], join['wyerr']), fmt='s')

    ax2.errorbar(xtmp, [_ellipticityFromGaussian(data['wy'], data['wx']) for data in ind],
                 yerr=[_ellipticityFromGaussian(data['wyerr'], data['wxerr'])/30. for data in ind], fmt='o')
    ax2.errorbar(xtmp[-1]+1, _ellipticityFromGaussian(join['wy'], join['wx']),
                 yerr=_ellipticityFromGaussian(join['wyerr'], join['wxerr'])/30., fmt='s')

    if requirementE is not None:
        ax2.axhline(y=requirementE, label='Requirement (800nm)', c='r')
    if requirementR2 is not None:
        ax1.axhline(y=requirementR2*1e3, label='Requirement (800nm)', c='r')

    #simulations
    if truthx and truthy is not None:
        ax2.axhline(y=_ellipticityFromGaussian(truthx, truthy), label='Truth', c='g')
        ax1.axhline(y= _R2FromGaussian(truthx, truthy)*1e3, label='Truth', c='g')

    plt.sca(ax1)
    plt.xticks(visible=False)
    plt.sca(ax2)
    ltmp = np.hstack((xtmp, xtmp[-1]+1))
    plt.xticks(ltmp, ['Individual%i' % x for x in ltmp[:-1]] + ['Joint',], rotation=45)

    ax1.set_ylim(0.001*1e3, 0.004*1e3)
    ax2.set_ylim(0., 0.33)
    ax1.set_xlim(xtmp.min()*0.9, (xtmp.max() + 1)*1.05)
    ax2.set_xlim(xtmp.min()*0.9, (xtmp.max() + 1)*1.05)

    ax1.set_ylabel(r'$R^{2}$ [mas$^{2}$]')
    ax2.set_ylabel('ellipticity')
    ax1.legend(shadow=True, fancybox=True)
    plt.savefig('IndividualVsJoinedR2e%s.pdf' % title)
    plt.close()
def _plotDifferenceIndividualVsJoined(individuals, joined, title='800nm', sigma=3,
                                      requirementFWHM=10.8, requirementE=0.156, requirementR2=0.002,
                                      truthx=None, truthy=None, FWHMlims=(7.6, 10.3)):
    """
    Simple plot
    """
    ind = []
    for file in g.glob(individuals):
        print file
        ind.append(fileIO.cPicleRead(file))

    join = fileIO.cPicleRead(joined)
    xtmp = np.arange(len(ind)) + 1

    #plot FWHM
    fig = plt.figure()
    ax1 = fig.add_subplot(311)
    ax2 = fig.add_subplot(312)
    ax3 = fig.add_subplot(313)
    fig.subplots_adjust(hspace=0, top=0.93, bottom=0.17, left=0.12, right=0.98)
    ax1.set_title(title)

    wxind = np.asarray([_FWHMGauss(data['wx']) for data in ind])
    wyind = np.asarray([_FWHMGauss(data['wy']) for data in ind])
    wxerr = np.asarray([sigma*_FWHMGauss(data['wxerr']) for data in ind])
    wyerr = np.asarray([sigma*_FWHMGauss(data['wyerr']) for data in ind])

    ax1.errorbar(xtmp, wxind, yerr=wxerr, fmt='o')
    ax1.errorbar(xtmp[-1]+1, _FWHMGauss(join['wx']), yerr=sigma*_FWHMGauss(join['wxerr']), fmt='s', c='r')
    ax2.errorbar(xtmp, wyind, yerr=wyerr, fmt='o')
    ax2.errorbar(xtmp[-1]+1, _FWHMGauss(join['wy']), yerr=sigma*_FWHMGauss(join['wyerr']), fmt='s', c='r')

    geommean = np.sqrt(wxind*wyind)
    err = np.sqrt(wxerr*wyerr)
    ax3.errorbar(xtmp, geommean, yerr=err, fmt='o')
    ax3.errorbar(xtmp[-1]+1, np.sqrt(_FWHMGauss(join['wx'])*_FWHMGauss(join['wy'])),
                 yerr=sigma*np.sqrt(_FWHMGauss(join['wxerr'])*_FWHMGauss(join['wyerr'])), fmt='s', c='r')

    #simulations
    if truthx is not None:
        ax1.axhline(y=_FWHMGauss(truthx), label='Input', c='g')
    if truthy is not None:
        ax2.axhline(y=_FWHMGauss(truthy), label='Input', c='g')
        ax3.axhline(y=np.sqrt(_FWHMGauss(truthx)*_FWHMGauss(truthy)), label='Input', c='g')

    #requirements
    if requirementFWHM is not None:
        ax1.axhline(y=requirementFWHM, label='Requirement (800nm)', c='r', ls='--')
        ax2.axhline(y=requirementFWHM, label='Requirement (800nm)', c='r', ls='--')
        ax3.axhline(y=requirementFWHM, label='Requirement (800nm)', c='r', ls='-')

    plt.sca(ax1)
    plt.xticks(visible=False)
    plt.sca(ax2)
    plt.xticks(visible=False)
    plt.sca(ax3)

    ltmp = np.hstack((xtmp, xtmp[-1]+1))
    plt.xticks(ltmp, ['Individual %i' % x for x in ltmp[:-1]] + ['Joint',], rotation=45)

    #ax1.set_ylim(7.1, 10.2)
    ax1.set_ylim(*FWHMlims)
    ax2.set_ylim(*FWHMlims)
    #ax2.set_ylim(8.6, 10.7)
    ax3.set_ylim(*FWHMlims)
    ax1.set_xlim(xtmp.min()*0.9, (xtmp.max() + 1)*1.05)
    ax2.set_xlim(xtmp.min()*0.9, (xtmp.max() + 1)*1.05)
    ax3.set_xlim(xtmp.min()*0.9, (xtmp.max() + 1)*1.05)

    ax1.set_ylabel(r'FWHM$_{X} \, [\mu$m$]$')
    ax2.set_ylabel(r'FWHM$_{Y} \, [\mu$m$]$')
    #ax3.set_ylabel(r'FWHM$=\sqrt{FWHM_{X}FWHM_{Y}} \quad [\mu$m$]$')
    ax3.set_ylabel(r'FWHM$ \, [\mu$m$]$')
    ax1.legend(shadow=True, fancybox=True)
    plt.savefig('IndividualVsJoinedFWHM%s.pdf' % title)
    plt.close()

    #plot R2 and ellipticity
    fig = plt.figure()
    ax1 = fig.add_subplot(211)
    ax2 = fig.add_subplot(212)
    fig.subplots_adjust(hspace=0, top=0.93, bottom=0.17, left=0.12, right=0.98)
    ax1.set_title(title)

    R2x = [_R2FromGaussian(data['wx'], data['wy'])*1e3 for data in ind]
    errR2 = [sigma*1.e3*_R2err(data['wx'], data['wy'], data['wxerr'], data['wyerr']) for data in ind]
    ax1.errorbar(xtmp, R2x, yerr=errR2, fmt='o')
    ax1.errorbar(xtmp[-1]+1, _R2FromGaussian(join['wx'], join['wy'])*1e3,
                 yerr=sigma*1.e3*_R2err(join['wx'], join['wy'], join['wxerr'], join['wyerr']), fmt='s')

    ell = [_ellipticityFromGaussian(data['wx'], data['wy']) for data in ind]
    ellerr = [sigma*_ellipticityerr(data['wx'], data['wy'], data['wxerr'], data['wyerr']) for data in ind]
    ax2.errorbar(xtmp, ell, yerr=ellerr, fmt='o')
    ax2.errorbar(xtmp[-1]+1, _ellipticityFromGaussian(join['wx'], join['wy']),
                 yerr=sigma*_ellipticityerr(join['wx'], join['wy'], join['wxerr'], join['wyerr']), fmt='s')

    if requirementE is not None:
        ax2.axhline(y=requirementE, label='Requirement (800nm)', c='r')
    if requirementR2 is not None:
        ax1.axhline(y=requirementR2*1e3, label='Requirement (800nm)', c='r')

    #simulations
    if truthx and truthy is not None:
        ax2.axhline(y=_ellipticityFromGaussian(truthx, truthy), label='Input', c='g')
        ax1.axhline(y= _R2FromGaussian(truthx, truthy)*1e3, label='Input', c='g')

    plt.sca(ax1)
    plt.xticks(visible=False)
    plt.sca(ax2)
    ltmp = np.hstack((xtmp, xtmp[-1]+1))
    plt.xticks(ltmp, ['Individual%i' % x for x in ltmp[:-1]] + ['Joint',], rotation=45)

    ax1.set_ylim(0.0011*1e3, 0.003*1e3)
    ax2.set_ylim(0., 0.23)
    ax1.set_xlim(xtmp.min()*0.9, (xtmp.max() + 1)*1.05)
    ax2.set_xlim(xtmp.min()*0.9, (xtmp.max() + 1)*1.05)

    ax1.set_ylabel(r'$R^{2}$ [mas$^{2}$]')
    ax2.set_ylabel('ellipticity')
    ax1.legend(shadow=True, fancybox=True)
    plt.savefig('IndividualVsJoinedR2e%s.pdf' % title)
    plt.close()
Esempio n. 3
0
def _plotDifferenceIndividualVsJoined(individuals,
                                      joined,
                                      title='800nm',
                                      sigma=3,
                                      requirementFWHM=10.8,
                                      requirementE=0.156,
                                      requirementR2=0.002,
                                      truthx=None,
                                      truthy=None,
                                      FWHMlims=(7.6, 10.3)):
    """
    Simple plot
    """
    ind = []
    for file in g.glob(individuals):
        print file
        ind.append(fileIO.cPicleRead(file))

    join = fileIO.cPicleRead(joined)
    xtmp = np.arange(len(ind)) + 1

    #plot FWHM
    fig = plt.figure()
    ax1 = fig.add_subplot(311)
    ax2 = fig.add_subplot(312)
    ax3 = fig.add_subplot(313)
    fig.subplots_adjust(hspace=0, top=0.93, bottom=0.17, left=0.12, right=0.98)
    ax1.set_title(title)

    wxind = np.asarray([_FWHMGauss(data['wx']) for data in ind])
    wyind = np.asarray([_FWHMGauss(data['wy']) for data in ind])
    wxerr = np.asarray([sigma * _FWHMGauss(data['wxerr']) for data in ind])
    wyerr = np.asarray([sigma * _FWHMGauss(data['wyerr']) for data in ind])

    ax1.errorbar(xtmp, wxind, yerr=wxerr, fmt='o')
    ax1.errorbar(xtmp[-1] + 1,
                 _FWHMGauss(join['wx']),
                 yerr=sigma * _FWHMGauss(join['wxerr']),
                 fmt='s',
                 c='r')
    ax2.errorbar(xtmp, wyind, yerr=wyerr, fmt='o')
    ax2.errorbar(xtmp[-1] + 1,
                 _FWHMGauss(join['wy']),
                 yerr=sigma * _FWHMGauss(join['wyerr']),
                 fmt='s',
                 c='r')

    geommean = np.sqrt(wxind * wyind)
    err = np.sqrt(wxerr * wyerr)
    ax3.errorbar(xtmp, geommean, yerr=err, fmt='o')
    ax3.errorbar(
        xtmp[-1] + 1,
        np.sqrt(_FWHMGauss(join['wx']) * _FWHMGauss(join['wy'])),
        yerr=sigma *
        np.sqrt(_FWHMGauss(join['wxerr']) * _FWHMGauss(join['wyerr'])),
        fmt='s',
        c='r')

    #simulations
    if truthx is not None:
        ax1.axhline(y=_FWHMGauss(truthx), label='Input', c='g')
    if truthy is not None:
        ax2.axhline(y=_FWHMGauss(truthy), label='Input', c='g')
        ax3.axhline(y=np.sqrt(_FWHMGauss(truthx) * _FWHMGauss(truthy)),
                    label='Input',
                    c='g')

    #requirements
    if requirementFWHM is not None:
        ax1.axhline(y=requirementFWHM,
                    label='Requirement (800nm)',
                    c='r',
                    ls='--')
        ax2.axhline(y=requirementFWHM,
                    label='Requirement (800nm)',
                    c='r',
                    ls='--')
        ax3.axhline(y=requirementFWHM,
                    label='Requirement (800nm)',
                    c='r',
                    ls='-')

    plt.sca(ax1)
    plt.xticks(visible=False)
    plt.sca(ax2)
    plt.xticks(visible=False)
    plt.sca(ax3)

    ltmp = np.hstack((xtmp, xtmp[-1] + 1))
    plt.xticks(ltmp, ['Individual %i' % x for x in ltmp[:-1]] + [
        'Joint',
    ],
               rotation=45)

    #ax1.set_ylim(7.1, 10.2)
    ax1.set_ylim(*FWHMlims)
    ax2.set_ylim(*FWHMlims)
    #ax2.set_ylim(8.6, 10.7)
    ax3.set_ylim(*FWHMlims)
    ax1.set_xlim(xtmp.min() * 0.9, (xtmp.max() + 1) * 1.05)
    ax2.set_xlim(xtmp.min() * 0.9, (xtmp.max() + 1) * 1.05)
    ax3.set_xlim(xtmp.min() * 0.9, (xtmp.max() + 1) * 1.05)

    ax1.set_ylabel(r'FWHM$_{X} \, [\mu$m$]$')
    ax2.set_ylabel(r'FWHM$_{Y} \, [\mu$m$]$')
    #ax3.set_ylabel(r'FWHM$=\sqrt{FWHM_{X}FWHM_{Y}} \quad [\mu$m$]$')
    ax3.set_ylabel(r'FWHM$ \, [\mu$m$]$')
    ax1.legend(shadow=True, fancybox=True)
    plt.savefig('IndividualVsJoinedFWHM%s.pdf' % title)
    plt.close()

    #plot R2 and ellipticity
    fig = plt.figure()
    ax1 = fig.add_subplot(211)
    ax2 = fig.add_subplot(212)
    fig.subplots_adjust(hspace=0, top=0.93, bottom=0.17, left=0.12, right=0.98)
    ax1.set_title(title)

    R2x = [_R2FromGaussian(data['wx'], data['wy']) * 1e3 for data in ind]
    errR2 = [
        sigma * 1.e3 *
        _R2err(data['wx'], data['wy'], data['wxerr'], data['wyerr'])
        for data in ind
    ]
    ax1.errorbar(xtmp, R2x, yerr=errR2, fmt='o')
    ax1.errorbar(xtmp[-1] + 1,
                 _R2FromGaussian(join['wx'], join['wy']) * 1e3,
                 yerr=sigma * 1.e3 *
                 _R2err(join['wx'], join['wy'], join['wxerr'], join['wyerr']),
                 fmt='s')

    ell = [_ellipticityFromGaussian(data['wx'], data['wy']) for data in ind]
    ellerr = [
        sigma *
        _ellipticityerr(data['wx'], data['wy'], data['wxerr'], data['wyerr'])
        for data in ind
    ]
    ax2.errorbar(xtmp, ell, yerr=ellerr, fmt='o')
    ax2.errorbar(
        xtmp[-1] + 1,
        _ellipticityFromGaussian(join['wx'], join['wy']),
        yerr=sigma *
        _ellipticityerr(join['wx'], join['wy'], join['wxerr'], join['wyerr']),
        fmt='s')

    if requirementE is not None:
        ax2.axhline(y=requirementE, label='Requirement (800nm)', c='r')
    if requirementR2 is not None:
        ax1.axhline(y=requirementR2 * 1e3, label='Requirement (800nm)', c='r')

    #simulations
    if truthx and truthy is not None:
        ax2.axhline(y=_ellipticityFromGaussian(truthx, truthy),
                    label='Input',
                    c='g')
        ax1.axhline(y=_R2FromGaussian(truthx, truthy) * 1e3,
                    label='Input',
                    c='g')

    plt.sca(ax1)
    plt.xticks(visible=False)
    plt.sca(ax2)
    ltmp = np.hstack((xtmp, xtmp[-1] + 1))
    plt.xticks(ltmp, ['Individual%i' % x for x in ltmp[:-1]] + [
        'Joint',
    ],
               rotation=45)

    ax1.set_ylim(0.0011 * 1e3, 0.003 * 1e3)
    ax2.set_ylim(0., 0.23)
    ax1.set_xlim(xtmp.min() * 0.9, (xtmp.max() + 1) * 1.05)
    ax2.set_xlim(xtmp.min() * 0.9, (xtmp.max() + 1) * 1.05)

    ax1.set_ylabel(r'$R^{2}$ [mas$^{2}$]')
    ax2.set_ylabel('ellipticity')
    ax1.legend(shadow=True, fancybox=True)
    plt.savefig('IndividualVsJoinedR2e%s.pdf' % title)
    plt.close()