Skip to content

Commit

Permalink
add unit test code
Browse files Browse the repository at this point in the history
  • Loading branch information
jchiang87 committed Aug 11, 2018
1 parent 15cf486 commit df4a4cb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/desc/imsim/flats.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def make_flat(gs_det, counts_per_iter, niter, rng, buf=2, logger=None,
galsim.ImageF
"""
if logger is None:
logger = desc.imsim.get_logger('INFO', name='make_flat')
logger = desc.imsim.get_logger('DEBUG', name='make_flat')
if wcs is None:
wcs = gs_det.wcs
ncol = gs_det.xMaxPix - gs_det.xMinPix + 1
Expand Down
50 changes: 50 additions & 0 deletions tests/test_flats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Unit test code for flat production code.
"""
from collections import namedtuple
import unittest
import numpy as np
import galsim
import desc.imsim

TreeRingInfo = namedtuple('TreeRingInfo', ['center', 'func'])

class GsDetector:
"""
Minimal implementation of an interface-compatible version
of GalSimDetector for testing the flat production code.
"""
def __init__(self):
self.xMaxPix = 256
self.yMaxPix = 256
self.xMinPix = 1
self.yMinPix = 1
self.wcs = galsim.wcs.PixelScale(0.2)
self.tree_rings \
= TreeRingInfo(galsim.PositionD(0, 0),
galsim.SiliconSensor.simple_treerings(0.26, 47))


class FlatTestCase(unittest.TestCase):
"""TestCase class for flat production code."""
def setUp(self):
pass

def tearDown(self):
pass

def test_make_flat(self):
"""Test of make_flat function."""
gs_det = GsDetector()
counts_per_iter = 1000
niter = 10
rng = galsim.UniformDeviate()
logger = desc.imsim.get_logger('WARN')
flat = desc.imsim.make_flat(gs_det, counts_per_iter, niter, rng,
logger=logger)
self.assertLess(np.abs(niter*counts_per_iter - flat.array.mean()),
flat.array.std())


if __name__ == '__main__':
unittest.main()

0 comments on commit df4a4cb

Please sign in to comment.