def testMetricDtype(self): """Test that base metric data value type set appropriately""" cols = 'onecolumn' testmetric = metrics.BaseMetric(cols) self.assertEqual(testmetric.metricDtype, 'float') testmetric = metrics.BaseMetric(cols, metricDtype='object') self.assertEqual(testmetric.metricDtype, 'object')
def testMetricName(self): """Test that metric name is set appropriately automatically and explicitly""" # Test automatic setting of metric name testmetric = metrics.BaseMetric('testcol') self.assertEqual(testmetric.name, 'Base testcol') testmetric = metrics.BaseMetric(['testcol1', 'testcol2']) self.assertEqual(testmetric.name, 'Base testcol1, testcol2') # Test explicit setting of metric name testmetric = metrics.BaseMetric('testcol', metricName='Test') self.assertEqual(testmetric.name, 'Test')
def testUnits(self): """Test unit setting (including units set by utils.getColInfo)""" cols = 'onecolumn' # Test for column not in colInfo, units not set by hand. testmetric = metrics.BaseMetric(cols) self.assertEqual(testmetric.units, '') # Test for column not in colInfo, units set by hand. testmetric = metrics.BaseMetric(cols, units='Test') self.assertEqual(testmetric.units, 'Test') # Test for column in colInfo (looking up units in colInfo) cols = 'finSeeing' testmetric = metrics.BaseMetric(cols) self.assertEqual(testmetric.units, 'arcsec') # Test for column in colInfo but units overriden testmetric = metrics.BaseMetric(cols, units='Test') self.assertEqual(testmetric.units, 'Test') # Test for multiple columns not in colInfo cols = ['onecol', 'twocol'] testmetric = metrics.BaseMetric(cols) self.assertEqual(testmetric.units, '') # Test for multiple columns in colInfo cols = ['finSeeing', 'filtSkyBrightness'] testmetric = metrics.BaseMetric(cols) self.assertEqual(testmetric.units, 'arcsec mag/sq arcsec') # Test for multiple columns, only one in colInfo cols = ['finSeeing', 'twocol'] testmetric = metrics.BaseMetric(cols) self.assertEqual(testmetric.units, 'arcsec ') # Test for multiple columns both in colInfo but repeated cols = ['finSeeing', 'finSeeing'] testmetric = metrics.BaseMetric(cols) self.assertEqual(testmetric.units, 'arcsec arcsec')
def testColRegistry(self): """Test column registry adds to colRegistry as expected""" cols = 'onecolumn' colset = set() colset.add(cols) testmetric = metrics.BaseMetric(cols) # Class registry should have dictionary with values = set of columns for metric class self.assertEqual(testmetric.colRegistry.colSet, colset) cols = ['onecolumn', 'twocolumn'] colset.add('twocolumn') testmetric = metrics.BaseMetric(cols) self.assertEqual(testmetric.colRegistry.colSet, colset) # Test with additional (different) metric cols = 'twocolumn' testmetric2 = metrics.MeanMetric(cols) self.assertEqual(testmetric.colRegistry.colSet, colset)
def createEmptyMetricBundle(): """Create an empty metric bundle. Returns ------- MetricBundle An empty metric bundle, configured with just the :class:`BaseMetric` and :class:`BaseSlicer`. """ return MetricBundle(metrics.BaseMetric(), slicers.BaseSlicer(), '')
def read(self, filename): """Read metricValues and associated metadata from disk. Overwrites any data currently in metricbundle. Parameters ---------- filename : str The file from which to read the metric bundle data. """ if not os.path.isfile(filename): raise IOError('%s not found' % filename) self._resetMetricBundle() # Set up a base slicer to read data (we don't know type yet). baseslicer = slicers.BaseSlicer() # Use baseslicer to read file. metricValues, slicer, header = baseslicer.readData(filename) self.slicer = slicer self.metricValues = metricValues self.metricValues.fill_value = slicer.badval # It's difficult to reinstantiate the metric object, as we don't # know what it is necessarily -- the metricName can be changed. self.metric = metrics.BaseMetric() # But, for plot label building, we do need to try to recreate the # metric name and units. self.metric.name = header['metricName'] if 'plotDict' in header: if 'units' in header['plotDict']: self.metric.units = header['plotDict']['units'] else: self.metric.units = '' self.runName = header['simDataName'] try: self.constraint = header['constraint'] except KeyError: self.constraint = header['sqlconstraint'] self.metadata = header['metadata'] if self.metadata is None: self._buildMetadata() if 'plotDict' in header: self.setPlotDict(header['plotDict']) if 'displayDict' in header: self.setDisplayDict(header['displayDict']) path, head = os.path.split(filename) self.fileRoot = head.replace('.npz', '') self.setPlotFuncs(None)
def testReduceDict(self): """Test that reduce dictionary is created.""" testmetric = metrics.BaseMetric('testcol') self.assertEqual(list(testmetric.reduceFuncs.keys()), [])