Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-12848: ap_verify unit tests fail on lsst-dev #17

Merged
merged 2 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 55 additions & 15 deletions tests/test_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,88 @@

import unittest

import numpy as np
import astropy.units as u

from lsst.ip.isr import IsrTask
import lsst.utils.tests
from lsst.verify import Measurement
import lsst.afw.image as afwImage
from lsst.ip.isr import FringeTask
import lsst.verify
from lsst.ap.verify.measurements.profiling import measureRuntime


def _createFringe(width, height, filterName):
"""Create a fringe frame

Parameters
----------
width, height: `int`
Size of image
filterName: `str`
name of the filterName to use

Returns
-------
fringe: `lsst.afw.image.ExposureF`
Fringe frame
"""
image = afwImage.ImageF(width, height)
array = image.getArray()
freq = np.pi / 10.0
x, y = np.indices(array.shape)
array[x, y] = np.sin(freq * x) + np.sin(freq * y)
exp = afwImage.makeExposure(afwImage.makeMaskedImage(image))
exp.setFilter(afwImage.Filter(filterName))
return exp


class MeasureRuntimeTestSuite(lsst.utils.tests.TestCase):

def setUp(self):
self.task = IsrTask()
try:
self.task.run(ccdExposure=None)
except AttributeError:
# I wanted the run to fail...
pass
"""Run a dummy instance of `FringeTask` so that test cases can measure it.
"""
# Create dummy filter and fringe so that `FringeTask` has short but
# significant run time.
# Code adapted from lsst.ip.isr.test_fringes
size = 128
dummyFilter = 'FILTER'
afwImage.utils.defineFilter(dummyFilter, lambdaEff=0)
exp = _createFringe(size, size, dummyFilter)

# Create and run `FringeTask` itself
config = FringeTask.ConfigClass()
config.filters = [dummyFilter]
config.num = 1000
config.small = 1
config.large = size // 4
config.pedestal = False
self.task = FringeTask(name="fringe", config=config)
self.task.run(exp, exp)

def tearDown(self):
del self.task

def testValid(self):
"""Verify that timing information can be recovered.
"""
meas = measureRuntime(self.task.getFullMetadata(), taskName='isr', metricName='ip_isr.IsrTime')
self.assertIsInstance(meas, Measurement)
meas = measureRuntime(self.task.getFullMetadata(), taskName='fringe', metricName='ip_isr.IsrTime')
self.assertIsInstance(meas, lsst.verify.Measurement)
self.assertEqual(meas.metric_name, lsst.verify.Name(metric='ip_isr.IsrTime'))
self.assertGreater(meas.quantity, 0.0 * u.second)
# The Task didn't actually do anything, so it should be short
self.assertLess(meas.quantity, 1.0 * u.second)
# Task normally takes 0.2 s, so this should be a safe margin of error
self.assertLess(meas.quantity, 10.0 * u.second)

def testNoMetric(self):
"""Verify that trying to measure a nonexistent metric fails.
"""
with self.assertRaises(TypeError):
measureRuntime(self.task.getFullMetadata(), taskName='isr', metricName='foo.bar.FooBarTime')
measureRuntime(self.task.getFullMetadata(), taskName='fringe', metricName='foo.bar.FooBarTime')

def testNotRun(self):
"""Verify that trying to measure a real but inapplicable metric returns None.
"""
notRun = IsrTask(IsrTask.ConfigClass())
meas = measureRuntime(notRun.getFullMetadata(), taskName='isr', metricName='ip_isr.IsrTime')
notRun = FringeTask(name="fringe", config=FringeTask.ConfigClass())
meas = measureRuntime(notRun.getFullMetadata(), taskName='fringe', metricName='ip_isr.IsrTime')
self.assertIsNone(meas)


Expand Down
22 changes: 11 additions & 11 deletions ups/ap_verify.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- python -*-
import lsst.sconsUtils
dependencies = {
}
config = lsst.sconsUtils.Configuration(
__file__,
hasDoxygenInclude=False,
hasSwigFiles=False,
# -*- python -*-

import lsst.sconsUtils

dependencies = {
}

config = lsst.sconsUtils.Configuration(
__file__,
hasDoxygenInclude=False,
hasSwigFiles=False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything that changed here. Is this just something weird the commit history?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the "Fix Windows line endings" commit.

)
26 changes: 14 additions & 12 deletions ups/ap_verify.table
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
setupRequired(python)
setupRequired(python_future)

setupRequired(utils)
setupRequired(daf_persistence)

setupRequired(verify)
setupRequired(ap_pipe)

setupOptional(ap_verify_hits2015)

envPrepend(PYTHONPATH, ${PRODUCT_DIR}/python)
setupRequired(python)
setupRequired(python_future)

setupRequired(utils)
setupRequired(afw)
setupRequired(daf_persistence)
setupRequired(ip_isr)

setupRequired(verify)
setupRequired(ap_pipe)

setupOptional(ap_verify_hits2015)

envPrepend(PYTHONPATH, ${PRODUCT_DIR}/python)
envPrepend(PATH, ${PRODUCT_DIR}/bin)