コード例 #1
0
def standardAngleMetrics(colname, replace_colname=None):
    """A set of standard simple metrics for some quantity which is a wrap-around angle.

    Parameters
    ----------
    colname : str
        The column name to apply the metrics to.
    replace_colname: str or None, opt
        Value to replace colname with in the metricName.
        i.e. if replace_colname='' then metric name is Mean, instead of Mean Airmass, or
        if replace_colname='seeingGeom', then metric name is Mean seeingGeom instead of Mean seeingFwhmGeom.
        Default is None, which does not alter the metric name.

    Returns
    -------
    List of configured metrics.
    """
    standardAngleMetrics = [
        metrics.MeanAngleMetric(colname),
        metrics.RmsAngleMetric(colname),
        metrics.FullRangeAngleMetric(colname),
        metrics.MinMetric(colname),
        metrics.MaxMetric(colname)
    ]
    if replace_colname is not None:
        for m in standardAngleMetrics:
            if len(replace_colname) > 0:
                m.name = m.name.replace('%s' % colname, '%s' % replace_colname)
            else:
                m.name = m.name.rstrip(' %s' % colname)
    return standardAngleMetrics
コード例 #2
0
ファイル: skycoverage.py プロジェクト: pgris/sims_maf
def meanRADec(colmap=None, runName='opsim', extraSql=None, extraMetadata=None):
    """Plot the range of RA/Dec as a function of night.

    Parameters
    ----------
    colmap : dict, opt
        A dictionary with a mapping of column names. Default will use OpsimV4 column names.
    runName : str, opt
        The name of the simulated survey. Default is "opsim".
    extraSql : str, opt
        Additional constraint to add to any sql constraints (e.g. 'night<365')
        Default None, for no additional constraints.
    extraMetadata : str, opt
        Additional metadata to add before any below (i.e. "WFD").  Default is None.
    """
    if colmap is None:
        colmap = ColMapDict('opsimV4')
    bundleList = []
    plotBundles = []

    group = 'RA Dec coverage'

    subgroup = 'All visits'
    if extraMetadata is not None:
        subgroup = extraMetadata

    displayDict = {'group': group, 'subgroup': subgroup, 'order': 0}

    ra_metrics = [metrics.MeanAngleMetric(colmap['ra']), metrics.FullRangeAngleMetric(colmap['ra'])]
    dec_metrics = [metrics.MeanMetric(colmap['dec']), metrics.MinMetric(colmap['dec']),
                   metrics.MaxMetric(colmap['dec'])]
    for m in ra_metrics:
        slicer = slicers.OneDSlicer(sliceColName=colmap['night'], binsize=1)
        if not colmap['raDecDeg']:
            plotDict = {'yMin': np.radians(-5), 'yMax': np.radians(365)}
        else:
            plotDict = {'yMin': -5, 'yMax': 365}
        bundle = mb.MetricBundle(m, slicer, extraSql, metadata=extraMetadata,
                                 displayDict=displayDict, plotDict=plotDict)
        bundleList.append(bundle)

    for m in dec_metrics:
        slicer = slicers.OneDSlicer(sliceColName=colmap['night'], binsize=1)
        bundle = mb.MetricBundle(m, slicer, extraSql, metadata=extraMetadata,
                                 displayDict=displayDict)
        bundleList.append(bundle)

    # Set the runName for all bundles and return the bundleDict.
    for b in bundleList:
        b.setRunName(runName)
    return mb.makeBundlesDictFromList(bundleList), plotBundles
コード例 #3
0
 def testMeanAngleMetric(self):
     """Test mean angle metric."""
     dv1 = np.arange(0, 32, 2.5)
     dv2 = (dv1 - 20.0) % 360.
     dv1 = np.array(list(zip(dv1)), dtype=[('testdata', 'float')])
     dv2 = np.array(list(zip(dv2)), dtype=[('testdata', 'float')])
     testmetric = metrics.MeanAngleMetric('testdata')
     result1 = testmetric.run(dv1)
     result2 = testmetric.run(dv2)
     self.assertAlmostEqual(result1, (result2+20)%360.)
     dv = np.random.rand(10000)*360.0
     dv = dv
     dv = np.array(list(zip(dv)), dtype=[('testdata', 'float')])
     result = testmetric.run(dv)
     result = result
     self.assertAlmostEqual(result, 180)
コード例 #4
0
def metadataBasicsAngle(value,
                        colmap=None,
                        runName='opsim',
                        valueName=None,
                        groupName=None,
                        extraSql=None,
                        extraMetadata=None,
                        nside=64,
                        ditherStacker=None,
                        ditherkwargs=None):
    """Calculate basic metrics on visit metadata 'value', where value is a wrap-around angle.

    Calculates extended standard metrics (with unislicer) on the quantity (all visits and per filter),
    makes histogram of the value (all visits and per filter),


    Parameters
    ----------
    value : str
        The column name for the quantity to evaluate. (column name in the database or created by a stacker).
    colmap : dict or None, opt
        A dictionary with a mapping of column names. Default will use OpsimV4 column names.
    runName : str, opt
        The name of the simulated survey. Default is "opsim".
    valueName : str, opt
        The name of the value to be reported in the resultsDb and added to the metric.
        This is intended to help standardize metric comparison between sim versions.
        value = name as it is in the database (seeingFwhmGeom, etc).
        valueName = name to be recorded ('seeingGeom', etc.).  Default is None, which will match 'value'.
    groupName : str, opt
        The group name for this quantity in the displayDict. Default is the same as 'valueName', capitalized.
    extraSql : str, opt
        Additional constraint to add to any sql constraints (e.g. 'propId=1' or 'fieldID=522').
        Default None, for no additional constraints.
    extraMetadata : str, opt
        Additional metadata to add before any below (i.e. "WFD").  Default is None.
    nside : int, opt
        Nside value for healpix slicer. Default 64.
        If "None" is passed, the healpixslicer-based metrics will be skipped.
    ditherStacker: str or lsst.sims.maf.stackers.BaseDitherStacker
        Optional dither stacker to use to define ra/dec columns.
    ditherkwargs: dict, opt
        Optional dictionary of kwargs for the dither stacker.

    Returns
    -------
    metricBundleDict
    """
    if colmap is None:
        colmap = ColMapDict('opsimV4')
    bundleList = []

    if valueName is None:
        valueName = value

    if groupName is None:
        groupName = valueName.capitalize()
        subgroup = extraMetadata
    else:
        groupName = groupName.capitalize()
        subgroup = valueName.capitalize()

    if subgroup is None:
        subgroup = 'All visits'

    displayDict = {'group': groupName, 'subgroup': subgroup}

    raCol, decCol, degrees, ditherStacker, ditherMeta = radecCols(
        ditherStacker, colmap, ditherkwargs)
    extraMetadata = combineMetadata(extraMetadata, ditherMeta)
    # Set up basic all and per filter sql constraints.
    filterlist, colors, orders, sqls, metadata = filterList(
        all=True, extraSql=extraSql, extraMetadata=extraMetadata)

    stackerList = [ditherStacker]

    # Summarize values over all and per filter.
    slicer = slicers.UniSlicer()
    for f in filterlist:
        for m in standardAngleMetrics(value, replace_colname=valueName):
            displayDict['caption'] = '%s for %s.' % (m.name, metadata[f])
            displayDict['order'] = orders[f]
            bundle = mb.MetricBundle(m,
                                     slicer,
                                     sqls[f],
                                     stackerList=stackerList,
                                     metadata=metadata[f],
                                     displayDict=displayDict)
            bundleList.append(bundle)

    # Histogram values over all and per filter.
    for f in filterlist:
        displayDict['caption'] = 'Histogram of %s' % (value)
        if valueName != value:
            displayDict['caption'] += ' (%s)' % (valueName)
        displayDict['caption'] += ' for %s.' % (metadata[f])
        displayDict['order'] = orders[f]
        m = metrics.CountMetric(value, metricName='%s Histogram' % (valueName))
        slicer = slicers.OneDSlicer(sliceColName=value)
        bundle = mb.MetricBundle(m,
                                 slicer,
                                 sqls[f],
                                 stackerList=stackerList,
                                 metadata=metadata[f],
                                 displayDict=displayDict)
        bundleList.append(bundle)

    # Make maps of min/median/max for all and per filter, per RA/Dec, with standard summary stats.
    mList = []
    mList.append(
        metrics.MeanAngleMetric(value,
                                metricName='AngleMean %s' % (valueName)))
    mList.append(
        metrics.FullRangeAngleMetric(value,
                                     metricName='AngleRange %s' % (valueName)))
    mList.append(
        metrics.RmsAngleMetric(value, metricName='AngleRms %s' % (valueName)))
    slicer = slicers.HealpixSlicer(nside=nside,
                                   latCol=decCol,
                                   lonCol=raCol,
                                   latLonDeg=degrees)
    subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()]
    for f in filterlist:
        for m in mList:
            displayDict['caption'] = 'Map of %s' % m.name
            if valueName != value:
                displayDict['caption'] += ' (%s)' % value
            displayDict['caption'] += ' for %s.' % metadata[f]
            displayDict['order'] = orders[f]
            bundle = mb.MetricBundle(m,
                                     slicer,
                                     sqls[f],
                                     stackerList=stackerList,
                                     metadata=metadata[f],
                                     plotFuncs=subsetPlots,
                                     displayDict=displayDict,
                                     summaryMetrics=standardSummary())
            bundleList.append(bundle)

    # Set the runName for all bundles and return the bundleDict.
    for b in bundleList:
        b.setRunName(runName)
    return mb.makeBundlesDictFromList(bundleList)