def setupMetrics(args, tstart, tnow, verbose=False): """ Define and instantiate metrics. Pass 'args' to access 'cumulative' flag, in order to set better limits for max/min. Could potentially access other 'args' values. """ # Define and set up metrics. # Note that it is useful to set up the plotDict so that the min/max range for the plot # is the same for all movie frames. t = time.time() metricList = [] #Simple metrics: coadded depth and number of visits nvisitsMin = 0 nvisitsMax = 300 coaddMin = 25 coaddMax = 28 if not args.cumulative: # Take a guess ... probably will need to be adjusted for your stepsize. nvisitsMax = 15 coaddMin = 24.0 coaddMax = 26.5 metricList.append( metrics.Coaddm5Metric('fiveSigmaDepth', metricName='Coaddm5Metric', plotDict={ 'colorMin': coaddMin, 'colorMax': coaddMax })) metricList.append( metrics.CountMetric('expMJD', metricName='N_Visits', plotDict={ 'colorMin': nvisitsMin, 'colorMax': nvisitsMax, 'cbarFormat': '%d', 'title': 'Number of Visits ' })) # Uniformity wants survey length in years. surveyLength = (tnow - tstart) / 365.0 metricList.append( metrics.UniformityMetric('expMJD', surveyLength=surveyLength, plotDict={ 'colorMin': 0, 'colorMax': 1, 'cbarFormat': '%.2f', 'title': 'Survey Uniformity' })) dt, t = dtime(t) if verbose: print 'Set up metrics %f s' % (dt) return metricList
def testUniformityMetric(self): names = ['observationStartMJD'] types = [float] data = np.zeros(100, dtype=list(zip(names, types))) metric = metrics.UniformityMetric() result1 = metric.run(data) # If all the observations are on the 1st day, should be 1 self.assertEqual(result1, 1) data['observationStartMJD'] = data['observationStartMJD']+365.25*10 slicePoint = {'sid': 0} result2 = metric.run(data, slicePoint) # All on last day should also be 1 self.assertEqual(result2, 1) # Make a perfectly uniform dist data['observationStartMJD'] = np.arange(0., 365.25*10, 365.25*10/100) result3 = metric.run(data, slicePoint) # Result should be zero for uniform np.testing.assert_almost_equal(result3, 0.) # A single obseravtion should give a result of 1 data = np.zeros(1, dtype=list(zip(names, types))) result4 = metric.run(data, slicePoint) self.assertEqual(result4, 1)