Coverage for tests/test_curve.py : 22%

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
# This file is part of meas_algorithms. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (https://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>.
self.name = name self.box = bbox
return self.name
return self.box
"""Tests for the Curve class"""
self.wavelength = np.linspace(3000, 5000, 150)*u.angstrom self.efficiency = signal.gaussian(len(self.wavelength), std=100)*u.percent self.metadata = dict([('MODE', 'AMP'), ('TYPE', 'QE'), ('CALIBDATE', '1970-01-01T00:00:00'), ('INSTRUME', 'ts8'), ('OBSTYPE', 'qe_curve'), ('DETECTOR', 99), ('DATE', '2019-09-27T22:15:13.518320'), ('CALIB_CREATION_DATE', '2019-09-27'), ('CALIB_CREATION_TIME', '22:15:13')])
del self.wavelength del self.efficiency del self.metadata
curve = curve_class(*args)
# Serialization round trip table = curve.toTable() curve2 = curve_class.fromTable(table) self.assertEqual(curve, curve2)
# via FITS with lsst.utils.tests.getTempFilePath(".fits") as tmpFile: curve.writeFits(tmpFile) curve2 = algorithms.Curve.readFits(tmpFile)
self.assertEqual(curve2, curve)
# via text file with lsst.utils.tests.getTempFilePath(".ecsv") as tmpFile: curve.writeText(tmpFile) curve2 = algorithms.Curve.readText(tmpFile)
self.assertEqual(curve2, curve)
# Check bad values with self.assertRaises(ValueError): # test that raised when non quantities are passed nargs = [] for arg in args: if hasattr(arg, 'unit'): nargs.append(arg.value) else: nargs.append(arg) _ = curve_class(*nargs)
# Check bad values with self.assertRaises(ValueError): # test that raised when non-length quantities are passed nargs = [] for arg in args: if hasattr(arg, 'unit'): nargs.append(arg.value*u.amp) else: nargs.append(arg) _ = curve_class(*nargs)
curve = curve_class(*args) w = 3500*u.angstrom xs = np.linspace(0, 1023, 33) ys = np.linspace(0, 1023, 33) val_map = {'A': 0.9329662, 'B': 0.7463730} # Does interpolation work for x, y in zip(xs, ys): point = Point2D(x, y) if detector: amp = cgUtils.findAmp(detector, Point2I(point)) value = val_map[amp.getName()] else: value = 0.9329662 interp_val = curve.evaluate(detector, point, w) self.assertAlmostEqual(interp_val.value, value, places=5) self.assertEqual(interp_val.unit, u.percent) # Does interpolation work with arrays w_arr = np.linspace(320, 430, 70)*u.nm out_arr = curve.evaluate(detector, point, w_arr) self.assertEqual(len(w_arr), len(out_arr)) # Does interpolation with different units work as expected point = Point2D(500., 500.) val1 = curve.evaluate(detector, point, w) new_w = w.to(u.mm) val2 = curve.evaluate(detector, point, new_w) self.assertEqual(val1.value, val2.value) # Does out of band interpolation do something reasonable # Default is to clamp to 0 outside the bounds. w = 0.*u.angstrom interp_val = curve.evaluate(detector, point, w) self.assertEqual(interp_val, 0.*u.percent) # interpolation with non-quantity should raise with self.assertRaises(ValueError): interp_val = curve.evaluate(detector, point, w.value) # Does interpolation fail with non-length unit with self.assertRaises(ValueError): w = 0.*u.Kelvin interp_val = curve.evaluate(detector, point, w)
args = (self.wavelength, self.efficiency, self.metadata) self.curve_tester(algorithms.DetectorCurve, args) self.interp_tester(algorithms.DetectorCurve, args, None)
# Future versions of astropy will pass unit through concatenation amp_wavelength = np.concatenate([self.wavelength.value, self.wavelength.value])*u.angstrom # Two amps amp_efficiency = np.concatenate([self.efficiency.value, self.efficiency.value*0.8])*u.percent # Two amps amp_name = np.concatenate([['A' for el in self.wavelength], ['B' for el in self.wavelength]]) amplist = [MockAmp('A', Box2I(Point2I(0, 0), Extent2I(512, 1025))), MockAmp('B', Box2I(Point2I(512, 10), Extent2I(512, 1024)))] args = (amp_name, amp_wavelength, amp_efficiency, self.metadata) self.curve_tester(algorithms.AmpCurve, args) self.interp_tester(algorithms.AmpCurve, args, amplist)
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |