Exemplo n.º 1
0
def calcCompleteness(orbitfile, obsfile, outDir):
    """
    Calculate a basic set of metrics on the NEOs, including completeness.
    Saves the plots to disk.
    """
    # Read data back from disk.
    mos = MoSlicer(orbitfile, Hrange=np.arange(13, 26, 0.5))
    mos.readObs(obsfile)

    # Nobs
    metric = MoMetrics.NObsMetric()
    slicer = mos
    pandasConstraint = None
    plotDict = {'nxbins':100, 'nybins':100}
    nobs = mmb.MoMetricBundle(metric, slicer, pandasConstraint,
                          runName=runName, metadata=metadata, plotDict=plotDict)

    # Calculate completeness. First we must calculate "DiscoveryChances".
    # Set up an example metric bundle.
    metric = MoMetrics.DiscoveryChancesMetric()
    slicer = mos
    pandasConstraint = None
    discovery = mmb.MoMetricBundle(metric, slicer, pandasConstraint,
                                    runName=runName, metadata=metadata, plotDict=plotDict)


    bdict = {'nobs':nobs, 'discovery':discovery}
    bg = mmb.MoMetricBundleGroup(bdict, outDir=outDir)
    bg.runAll()
    bg.plotAll()

    ph = plots.PlotHandler(outDir=outDir)
    # Then calculate 'completeness' as function of H, as a secondary metric.
    completeness = discovery.reduceMetric(discovery.metric.reduceFuncs['Completeness'])

    # And we can make an 'integrated over H distribution' version.
    completenessInt = completeness.reduceMetric(completeness.metric.reduceFuncs['CumulativeH'])

    Hmark = 21.0
    for c in [completeness, completenessInt]:
        summaryMetric = ValueAtHMetric(Hmark=Hmark)
        c.setSummaryMetrics(summaryMetric)
        c.computeSummaryStats()
        label = "Completeness at H=%.1f: %.2f" %(Hmark, c.summaryValues['Value At H=%.1f' %Hmark])
        c.setPlotDict({'label':label})
        c.plot(plotFunc = moPlots.MetricVsH())
        plt.axvline(Hmark, color='r', linestyle=':')
        plt.axhline(c.summaryValues['Value At H=%.1f' %(Hmark)], color='r', linestyle='-')
        plt.legend(loc=(0.9, 0.2))
        plt.savefig(os.path.join(outDir, c.fileRoot + '_vsH' + '.png'), format='png')
Exemplo n.º 2
0
def calcCompleteness(orbitfile, obsfile, outDir, runName, metadata=None):
    """
    Calculate a basic set of metrics on the NEOs, including completeness.
    Saves the plots to disk.
    """
    # Read data back from disk.
    mos = MoSlicer(orbitfile, Hrange=np.arange(15, 27, 0.25))
    mos.readObs(obsfile)

    # Nobs
    metric = moMetrics.NObsMetric()
    slicer = mos
    pandasConstraint = None
    plotDict = {'nxbins': 200, 'nybins': 200}
    nobs = mmb.MoMetricBundle(metric,
                              slicer,
                              pandasConstraint,
                              runName=runName,
                              metadata=metadata,
                              plotDict=plotDict)

    # Calculate completeness. First we must calculate "DiscoveryChances".
    # Set up an example metric bundle.
    discovery = {}
    nObsList = [2, 3, 4]
    nyears = [3, 5, 10, 12, 15]
    for yr in nyears:
        discovery[yr] = {}
        for nObs in nObsList:
            md = metadata + ' %d visits/night after %d years' % (nObs, yr)
            #metric = moMetrics.DiscoveryMetric(tMin=0, tMax=90./60/24., nObsPerNight=nObs, nNightsPerWindow=3, tWindow=30)
            metric = moMetrics.DiscoveryChancesMetric(tNight=90. / 60. / 24.,
                                                      nObsPerNight=nObs,
                                                      nNightsPerWindow=3,
                                                      tWindow=15)
            slicer = mos
            pandasConstraint = 'night <= %d' % (yr * 365)
            discovery[yr][nObs] = mmb.MoMetricBundle(
                metric,
                slicer,
                pandasConstraint,
                runName=runName,
                metadata=md,
                plotDict=plotDict,
                plotFuncs=[moPlots.MetricVsH()])

        #metric = moMetrics.DiscoveryMetric(tMin=0, tMax=90./60/24., nObsPerNight=2, nNightsPerWindow=4, tWindow=30)
        metric = moMetrics.DiscoveryChancesMetric(tNight=90. / 60. / 24.,
                                                  nObsPerNight=2,
                                                  nNightsPerWindow=4,
                                                  tWindow=30)
        discovery[yr]['4nights'] = mmb.MoMetricBundle(
            metric=metric,
            slicer=mos,
            constraint=pandasConstraint,
            runName=runName,
            metadata=metadata + '4 nights/track after %d years' % (yr),
            plotDict=plotDict,
            plotFuncs=[moPlots.MetricVsH()])

    bdict = {}
    for yr in nyears:
        for nObs in nObsList:
            bdict['discovery_%s_%d' % (nObs, yr)] = discovery[yr][nObs]
        bdict['4nights_%d' % (yr)] = discovery[yr]['4nights']
    bdict['nobs'] = nobs

    bg = mmb.MoMetricBundleGroup(bdict, outDir=outDir)
    bg.runAll()
    bg.plotAll()

    Hmark = 22

    completeness = {}
    completenessInt = {}
    hVals = mos.Hrange
    for yr in nyears:
        completeness[yr] = {}
        completenessInt[yr] = {}
        for nObs in nObsList:
            #discChances = discovery[nObs].childBundles['N_Chances']
            discChances = discovery[yr][nObs]
            discChances.setSummaryMetrics([
                moSummaryMetrics.CompletenessMetric(),
                moSummaryMetrics.CumulativeCompletenessMetric()
            ])
            discChances.computeSummaryStats()
            completeness[yr][nObs] = discChances.summaryValues['Completeness'][
                0]
            completenessInt[yr][nObs] = discChances.summaryValues[
                'CumulativeCompleteness'][0]
        for nObs in ['4nights']:
            #discChances = discovery[nObs].childBundles['N_Chances']
            discChances = discovery[yr][nObs]
            discChances.setSummaryMetrics([
                moSummaryMetrics.CompletenessMetric(),
                moSummaryMetrics.CumulativeCompletenessMetric()
            ])
            discChances.computeSummaryStats()
            completeness[yr][nObs] = discChances.summaryValues['Completeness'][
                0]
            completenessInt[yr][nObs] = discChances.summaryValues[
                'CumulativeCompleteness'][0]

    # Make a figure of completeness with the different discovery patterns, for one year.
    yr = 12
    Hidx = np.where(hVals == Hmark)[0]
    plt.figure()
    plt.title('Completeness %s' % (runName))
    for nObs in nObsList:
        cval = completeness[yr][nObs][Hidx]
        plt.plot(hVals,
                 completeness[yr][nObs],
                 label='%d obs/tracklet, %.0f%s H @ %.1f' %
                 (nObs, cval * 100, '%', Hmark))
    for nObs in ['4nights']:
        cval = completeness[yr][nObs][Hidx]
        plt.plot(hVals,
                 completeness[yr][nObs],
                 label='4 pairs/track, %.0f%s H @ %.1f' %
                 (cval * 100, '%', Hmark))
    plt.axvline(Hmark, color='r', linestyle=':')
    plt.xlabel('H')
    plt.ylabel('Completeness @ H')
    plt.legend(loc='upper right',
               fancybox=True,
               numpoints=1,
               fontsize='smaller')
    plt.savefig(os.path.join(outDir, 'completeness.pdf'), format='pdf')

    plt.figure()
    plt.title('Cumulative completeness %s' % (runName))
    for nObs in nObsList:
        cval = completenessInt[yr][nObs][Hidx]
        plt.plot(hVals,
                 completenessInt[yr][nObs],
                 label='%d obs/tracklet, %.0f%s H <= %.1f' %
                 (nObs, cval * 100, '%', Hmark))
    for nObs in ['4nights']:
        cval = completenessInt[yr][nObs][Hidx]
        plt.plot(hVals,
                 completenessInt[yr][nObs],
                 label='4 pairs/track, %.0f%s H <= %.1f' %
                 (cval * 100, '%', Hmark))
    plt.axvline(Hmark, color='r', linestyle=':')
    plt.xlabel('H')
    plt.ylabel('Completeness <= H')
    plt.legend(loc='upper right',
               fancybox=True,
               numpoints=1,
               fontsize='smaller')
    plt.savefig(os.path.join(outDir, 'completenessInt.pdf'), format='pdf')

    # And make a figure for one set of discovery criterion, over time.
    nObs = 2
    plt.figure()
    plt.title('Completeness over time %s' % (runName))
    for yr in nyears:
        cval = completeness[yr][nObs][Hidx]
        plt.plot(hVals,
                 completeness[yr][nObs],
                 label='Year %d: %.0f @ H=%.1f' % (yr, cval * 100, Hmark))
    plt.axvline(Hmark, color='r', linestyle=':')
    plt.xlabel('H')
    plt.ylabel('Completeness @ H')
    plt.legend(loc='upper right',
               fancybox=True,
               numpoints=1,
               fontsize='smaller')
    plt.savefig(os.path.join(outDir, 'completenessTime.pdf'), format='pdf')

    nObs = 2
    plt.figure()
    plt.title('Completeness over time %s' % (runName))
    for yr in nyears:
        cval = completenessInt[yr][nObs][Hidx]
        plt.plot(hVals,
                 completenessInt[yr][nObs],
                 label='Year %d: %.0f <= H=%.1f' % (yr, cval * 100, Hmark))
    plt.axvline(Hmark, color='r', linestyle=':')
    plt.xlabel('H')
    plt.ylabel('Completeness <= H')
    plt.legend(loc='upper right',
               fancybox=True,
               numpoints=1,
               fontsize='smaller')
    plt.savefig(os.path.join(outDir, 'completenessIntTime.pdf'), format='pdf')
Exemplo n.º 3
0
def calcCompleteness(orbitfile, obsfile, outDir, runName, metadata=None):
    """
    Calculate a basic set of metrics on the NEOs, including completeness.
    Saves the plots to disk.
    """
    # Read data back from disk.
    mos = MoSlicer(orbitfile, Hrange=np.arange(15, 27, 0.25))
    mos.readObs(obsfile)

    # Nobs
    metric = moMetrics.NObsMetric()
    slicer = mos
    pandasConstraint = None
    plotDict = {'nxbins':200, 'nybins':200}
    nobs = mmb.MoMetricBundle(metric, slicer, pandasConstraint,
                          runName=runName, metadata=metadata, plotDict=plotDict)

    # Calculate completeness. First we must calculate "DiscoveryChances".
    # Set up an example metric bundle.
    discovery = {}
    nObsList = [2, 3, 4]
    nyears = [3, 5, 10, 12, 15]
    for yr in nyears:
        discovery[yr] = {}
        for nObs in nObsList:
            md = metadata + ' %d visits/night after %d years' %(nObs, yr)
            #metric = moMetrics.DiscoveryMetric(tMin=0, tMax=90./60/24., nObsPerNight=nObs, nNightsPerWindow=3, tWindow=30)
            metric = moMetrics.DiscoveryChancesMetric(tNight=90./60./24., nObsPerNight=nObs, nNightsPerWindow=3, tWindow=15)
            slicer = mos
            pandasConstraint = 'night <= %d' %(yr*365)
            discovery[yr][nObs] = mmb.MoMetricBundle(metric, slicer, pandasConstraint,
                                                    runName=runName, metadata=md,
                                                    plotDict=plotDict, plotFuncs=[moPlots.MetricVsH()])

        #metric = moMetrics.DiscoveryMetric(tMin=0, tMax=90./60/24., nObsPerNight=2, nNightsPerWindow=4, tWindow=30)
        metric = moMetrics.DiscoveryChancesMetric(tNight=90./60./24., nObsPerNight=2, nNightsPerWindow=4, tWindow=30)
        discovery[yr]['4nights'] = mmb.MoMetricBundle(metric=metric,
                                                slicer=mos, constraint=pandasConstraint, runName=runName,
                                                metadata = metadata+'4 nights/track after %d years' %(yr),
                                                plotDict=plotDict, plotFuncs=[moPlots.MetricVsH()])

    bdict = {}
    for yr in nyears:
        for nObs in nObsList:
            bdict['discovery_%s_%d' %(nObs, yr)] = discovery[yr][nObs]
        bdict['4nights_%d' %(yr)] = discovery[yr]['4nights']
    bdict['nobs'] = nobs

    bg = mmb.MoMetricBundleGroup(bdict, outDir=outDir)
    bg.runAll()
    bg.plotAll()

    Hmark = 22

    completeness = {}
    completenessInt = {}
    hVals = mos.Hrange
    for yr in nyears:
        completeness[yr] = {}
        completenessInt[yr] = {}
        for nObs in nObsList:
        #discChances = discovery[nObs].childBundles['N_Chances']
            discChances = discovery[yr][nObs]
            discChances.setSummaryMetrics([moSummaryMetrics.CompletenessMetric(), moSummaryMetrics.CumulativeCompletenessMetric()])
            discChances.computeSummaryStats()
            completeness[yr][nObs] = discChances.summaryValues['Completeness'][0]
            completenessInt[yr][nObs] = discChances.summaryValues['CumulativeCompleteness'][0]
        for nObs in ['4nights']:
        #discChances = discovery[nObs].childBundles['N_Chances']
            discChances = discovery[yr][nObs]
            discChances.setSummaryMetrics([moSummaryMetrics.CompletenessMetric(), moSummaryMetrics.CumulativeCompletenessMetric()])
            discChances.computeSummaryStats()
            completeness[yr][nObs] = discChances.summaryValues['Completeness'][0]
            completenessInt[yr][nObs] = discChances.summaryValues['CumulativeCompleteness'][0]

    # Make a figure of completeness with the different discovery patterns, for one year.
    yr = 12
    Hidx = np.where(hVals == Hmark)[0]
    plt.figure()
    plt.title('Completeness %s' %(runName))
    for nObs in nObsList:
        cval = completeness[yr][nObs][Hidx]
        plt.plot(hVals, completeness[yr][nObs], label='%d obs/tracklet, %.0f%s H @ %.1f' %(nObs, cval*100, '%', Hmark))
    for nObs in ['4nights']:
        cval = completeness[yr][nObs][Hidx]
        plt.plot(hVals, completeness[yr][nObs], label='4 pairs/track, %.0f%s H @ %.1f' %(cval*100, '%', Hmark))
    plt.axvline(Hmark, color='r', linestyle=':')
    plt.xlabel('H')
    plt.ylabel('Completeness @ H')
    plt.legend(loc='upper right', fancybox=True, numpoints=1, fontsize='smaller')
    plt.savefig(os.path.join(outDir, 'completeness.pdf'), format='pdf')

    plt.figure()
    plt.title('Cumulative completeness %s' %(runName))
    for nObs in nObsList:
        cval = completenessInt[yr][nObs][Hidx]
        plt.plot(hVals, completenessInt[yr][nObs], label='%d obs/tracklet, %.0f%s H <= %.1f' %(nObs, cval*100, '%', Hmark))
    for nObs in ['4nights']:
        cval = completenessInt[yr][nObs][Hidx]
        plt.plot(hVals, completenessInt[yr][nObs], label='4 pairs/track, %.0f%s H <= %.1f' %(cval*100, '%', Hmark))
    plt.axvline(Hmark, color='r', linestyle=':')
    plt.xlabel('H')
    plt.ylabel('Completeness <= H')
    plt.legend(loc='upper right', fancybox=True, numpoints=1, fontsize='smaller')
    plt.savefig(os.path.join(outDir, 'completenessInt.pdf'), format='pdf')

    # And make a figure for one set of discovery criterion, over time.
    nObs = 2
    plt.figure()
    plt.title('Completeness over time %s' %(runName))
    for yr in nyears:
        cval = completeness[yr][nObs][Hidx]
        plt.plot(hVals, completeness[yr][nObs], label='Year %d: %.0f @ H=%.1f' %(yr, cval*100, Hmark))
    plt.axvline(Hmark, color='r', linestyle=':')
    plt.xlabel('H')
    plt.ylabel('Completeness @ H')
    plt.legend(loc='upper right', fancybox=True, numpoints=1, fontsize='smaller')
    plt.savefig(os.path.join(outDir, 'completenessTime.pdf'), format='pdf')

    nObs = 2
    plt.figure()
    plt.title('Completeness over time %s' %(runName))
    for yr in nyears:
        cval = completenessInt[yr][nObs][Hidx]
        plt.plot(hVals, completenessInt[yr][nObs], label='Year %d: %.0f <= H=%.1f' %(yr, cval*100, Hmark))
    plt.axvline(Hmark, color='r', linestyle=':')
    plt.xlabel('H')
    plt.ylabel('Completeness <= H')
    plt.legend(loc='upper right', fancybox=True, numpoints=1, fontsize='smaller')
    plt.savefig(os.path.join(outDir, 'completenessIntTime.pdf'), format='pdf')