def testNormAirmass(self): """ Test the normalized airmass stacker. """ data = np.zeros(600, dtype=zip( ['airmass', 'fieldDec'], [float, float])) data['airmass'] = np.random.rand(600) data['fieldDec'] = np.random.rand(600) * np.pi - np.pi / 2. stacker = stackers.NormAirmassStacker() data = stacker.run(data) for i in np.arange(data.size): self.assertLessEqual(data['normairmass'][i], data['airmass'][i]) self.assertLess(np.min(data['normairmass'] - data['airmass']), 0)
def testNormAirmass(self): """ Test the normalized airmass stacker. """ rng = np.random.RandomState(232) data = np.zeros(600, dtype=list(zip(['airmass', 'fieldDec'], [float, float]))) data['airmass'] = rng.random_sample(600) data['fieldDec'] = rng.random_sample(600) * np.pi - np.pi / 2. data['fieldDec'] = np.degrees(data['fieldDec']) stacker = stackers.NormAirmassStacker(degrees=True) data = stacker.run(data) for i in np.arange(data.size): self.assertLessEqual(data['normairmass'][i], data['airmass'][i]) self.assertLess(np.min(data['normairmass'] - data['airmass']), 0)
def metadataMaps(value, colmap=None, runName='opsim', valueName=None, groupName=None, extraSql=None, extraMetadata=None, nside=64): """Calculate 25/50/75 percentile values on maps across sky for a single metadata value. TODO: handle stackers which need configuration (degrees, in particular) more automatically. Currently have a hack for HA & normairmass. 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. 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( None, colmap, None) 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) # Hack to make HA work, but really I need to account for any stackers/colmaps. if value == 'HA': stackerList = [ stackers.HourAngleStacker(lstCol=colmap['lst'], raCol=raCol, degrees=degrees) ] elif value == 'normairmass': stackerList = [stackers.NormAirmassStacker(degrees=degrees)] else: stackerList = None # Make maps of 25/median/75 for all and per filter, per RA/Dec, with standard summary stats. mList = [] mList.append( metrics.PercentileMetric(value, percentile=25, metricName='25thPercentile %s' % (valueName))) mList.append( metrics.MedianMetric(value, metricName='Median %s' % (valueName))) mList.append( metrics.PercentileMetric(value, percentile=75, metricName='75thPercentile %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) plotBundles = [] return mb.makeBundlesDictFromList(bundleList), plotBundles
import matplotlib.pyplot as plt import lsst.sims.maf.metricBundles as metricBundles import lsst.sims.maf.metrics as metrics import lsst.sims.maf.slicers as slicers import lsst.sims.maf.stackers as stackers import lsst.sims.maf.db as db database = db.OpsimDatabase('sqlite:///enigma_1189_sqlite.db') metric = metrics.MeanMetric(col='HA') slicer = slicers.HealpixSlicer(nside=4) stackerList = [stackers.NormAirmassStacker()] mb = metricBundles.MetricBundle(metric, slicer, stackerList=stackerList, sqlconstraint='filter="r" and night < 100') metric = metrics.RmsMetric(col='airmass') mb2 = metricBundles.MetricBundle(metric, slicer, stackerList=stackerList, sqlconstraint='filter="r" and night < 100') print mb.dbCols mbD = {0: mb, 1: mb2} mbg = metricBundles.MetricBundleGroup(mbD, database, outDir='test') mbg.runAll() mbg.plotAll(closefigs=False) plt.show()
def metadataBasics(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' (e.g. airmass, normalized airmass, seeing..). Calculates extended standard metrics (with unislicer) on the quantity (all visits and per filter), makes histogram of the value (all visits and per filter), TODO: handle stackers which need configuration (degrees, in particular) more automatically. Currently have a hack for HA & normairmass. 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) # Hack to make HA work, but really I need to account for any stackers/colmaps. if value == 'HA': stackerList = [ stackers.HourAngleStacker(lstCol=colmap['lst'], raCol=raCol, degrees=degrees) ] elif value == 'normairmass': stackerList = [stackers.NormAirmassStacker(degrees=degrees)] else: stackerList = None if ditherStacker is not None: if stackerList is None: stackerList = [ditherStacker] else: stackerList.append(ditherStacker) # Summarize values over all and per filter (min/mean/median/max/percentiles/outliers/rms). slicer = slicers.UniSlicer() for f in filterlist: for m in extendedMetrics(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.MinMetric(value, metricName='Min %s' % (valueName))) mList.append( metrics.MedianMetric(value, metricName='Median %s' % (valueName))) mList.append(metrics.MaxMetric(value, metricName='Max %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)
def metadataBasics(value, colmap=None, runName='opsim', valueName=None, groupName=None, extraSql=None, extraMetadata=None, nside=64, filterlist=('u', 'g', 'r', 'i', 'z', 'y')): """Calculate basic metrics on visit metadata 'value' (e.g. airmass, normalized airmass, seeing..). Calculates extended standard metrics (with unislicer) on the quantity (all visits and per filter), makes histogram of the value (all visits and per filter), TODO: handle stackers which need configuration (degrees, in particular) more automatically. Currently have a hack for HA & normairmass. 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 is set to match value. groupName : str, opt The group name for this quantity in the displayDict. Default is the same as 'value', 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. filterlist : list of str, opt List of the filternames to use for "per filter" evaluation. Default ('u', 'g', 'r', 'i', 'z', 'y'). If None is passed, the per-filter evaluations will be skipped. 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() displayDict = {'group': groupName, 'subgroup': subgroup} sqlconstraints = [''] metadata = ['all bands'] if filterlist is not None: sqlconstraints += ['%s = "%s"' % (colmap['filter'], f) for f in filterlist] metadata += ['%s band' % f for f in filterlist] if (extraSql is not None) and (len(extraSql) > 0): tmp = [] for s in sqlconstraints: if len(s) == 0: tmp.append(extraSql) else: tmp.append('%s and (%s)' % (s, extraSql)) sqlconstraints = tmp if extraMetadata is None: metadata = ['%s %s' % (extraSql, m) for m in metadata] if extraMetadata is not None: metadata = ['%s %s' % (extraMetadata, m) for m in metadata] # Hack to make HA work, but really I need to account for any stackers/colmaps. if value == 'HA': stackerList = [stackers.HourAngleStacker(lstCol=colmap['lst'], raCol=colmap['ra'], degrees=colmap['raDecDeg'])] elif value == 'normairmass': stackerList = [stackers.NormAirmassStacker(degrees=colmap['raDecDeg'])] else: stackerList = None # Summarize values over all and per filter (min/mean/median/max/percentiles/outliers/rms). slicer = slicers.UniSlicer() displayDict['caption'] = None for sql, meta in zip(sqlconstraints, metadata): displayDict['order'] = -1 for m in extendedMetrics(value, replace_colname=valueName): displayDict['order'] += 1 bundle = mb.MetricBundle(m, slicer, sql, stackerList=stackerList, metadata=meta, displayDict=displayDict) bundleList.append(bundle) # Histogram values over all and per filter. for sql, meta in zip(sqlconstraints, metadata): displayDict['caption'] = 'Histogram of %s' % (value) if valueName != value: displayDict['caption'] += ' (%s)' % (valueName) displayDict['caption'] += ' for %s visits.' % (meta) displayDict['order'] += 1 m = metrics.CountMetric(value, metricName='%s Histogram' % (valueName)) slicer = slicers.OneDSlicer(sliceColName=value) bundle = mb.MetricBundle(m, slicer, sql, stackerList=stackerList, metadata=meta, 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.MinMetric(value, metricName='Min %s' % (valueName))) mList.append(metrics.MedianMetric(value, metricName='Median %s' % (valueName))) mList.append(metrics.MaxMetric(value, metricName='Max %s' % (valueName))) slicer = slicers.HealpixSlicer(nside=nside, latCol=colmap['dec'], lonCol=colmap['ra'], latLonDeg=colmap['raDecDeg']) subsetPlots = [plots.HealpixSkyMap(), plots.HealpixHistogram()] displayDict['caption'] = None displayDict['order'] = -1 for sql, meta in zip(sqlconstraints, metadata): for m in mList: displayDict['order'] += 1 bundle = mb.MetricBundle(m, slicer, sql, stackerList=stackerList, metadata=meta, 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)