Coverage for python/lsst/sims/maf/metrics/baseMetric.py : 78%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# Base class for metrics - defines methods which must be implemented. # If a metric calculates a vector or list at each gridpoint, then there # should be additional 'reduce_*' functions defined, to convert the vector # into scalar (and thus plottable) values at each gridpoint. # The philosophy behind keeping the vector instead of the scalar at each gridpoint # is that these vectors may be expensive to compute; by keeping/writing the full # vector we permit multiple 'reduce' functions to be executed on the same data.
""" Meta class for metrics, to build a registry of metric classes. """ else: if len(modname.split('.')) > 1: modname = '.'.join(modname.split('.')[:-1]) + '.' else: modname = modname + '.' raise Exception('Redefining metric %s! (there are >1 metrics with the same name)' % (metricname))
return cls.registry[metricname]
for metricname in sorted(cls.registry): if not doc: print(metricname) if doc: print('---- ', metricname, ' ----') print(inspect.getdoc(cls.registry[metricname]))
print(metricname) print(inspect.getdoc(cls.registry[metricname])) k = inspect.signature(cls.registry[metricname]) print(' Metric __init__ keyword args and defaults: ') print(k)
""" ColRegistry tracks the columns needed for all metric objects (kept internally in a set).
ColRegistry.colSet : a set of all unique columns required for metrics. ColRegistry.dbCols : the subset of these which come from the database. ColRegistry.stackerCols : the dictionary of [columns: stacker class]. """
"""Add the columns in ColArray into the ColRegistry.
Add the columns in colArray into the ColRegistry set (self.colSet) and identifies their source, using ColInfo (lsst.sims.maf.stackers.getColInfo).
Parameters ---------- colArray : list list of columns used in a metric. """ else:
""" Base class for the metrics. Sets up some basic functionality for the MAF framework: after __init__ every metric will record the columns (and stackers) it requires into the column registry, and the metricName, metricDtype, and units for the metric will be set.
Parameters ---------- col : str or list Names of the data columns that the metric will use. The columns required for each metric is tracked in the ColRegistry, and used to retrieve data from the opsim database. Can be a single string or a list. metricName : str Name to use for the metric (optional - if not set, will be derived). maps : list of lsst.sims.maf.maps objects The maps that the metric will need (passed from the slicer). units : str The units for the value returned by the metric (optional - if not set, will be derived from the ColInfo). metricDtype : str The type of value returned by the metric - 'int', 'float', 'object'. If not set, will be derived by introspection. badval : float The value indicating "bad" values calculated by the metric. """
metricDtype=None, badval=-666): # Turn cols into numpy array so we know we can iterate over the columns. # To support simple metrics operating on a single column, set self.colname # Add the columns to the colRegistry. # Set the maps that are needed: # Value to return if the metric can't be computed # Save a unique name for the metric. # If none provided, construct our own from the class name and the data columns. ', '.join(map(str, self.colNameArr))) # Set up dictionary of reduce functions (may be empty). # Identify type of metric return value. else: # Set physical units, for plotting purposes. # Add the ability to set a comment # (that could be propagated automatically to a benchmark's display caption).
# Default to only return one metric value per slice
"""Calculate metric values.
Parameters ---------- dataSlice : numpy.NDarray Values passed to metric by the slicer, which the metric will use to calculate metric values at each slicePoint. slicePoint : Dict Dictionary of slicePoint metadata passed to each metric. E.g. the ra/dec of the healpix pixel or opsim fieldId.
Returns ------- int, float or object The metric value at each slicePoint. """ raise NotImplementedError('Please implement your metric calculation.') |