def test_header_has_biaslevel(mock_cal, mock_frame): nx = 101 ny = 103 context = make_context_with_master_bias(nx=nx, ny=ny) subtractor = BiasSubtractor(context) image = subtractor.do_stage(FakeImage(nx=nx, ny=ny)) assert image.header.get('BIASLVL') == 0.0
def test_raises_exception_if_no_master_calibration(mock_cal, mock_images): mock_cal.return_value = None mock_images.return_value = FakeBiasImage() subtractor = BiasSubtractor(None) with pytest.raises(MasterCalibrationDoesNotExist): images = subtractor.do_stage([FakeImage() for x in range(6)])
def test_flags_image_if_no_master_calibration(mock_cal): mock_cal.return_value = None nx = 101 ny = 103 context = make_context_with_master_bias(nx=nx, ny=ny) subtractor = BiasSubtractor(context) image = subtractor.do_stage(FakeImage(nx=nx, ny=ny) ) assert image.is_bad is True
def test_header_biaslevel_is_2(mock_cal, mock_frame): nx = 101 ny = 103 mock_frame.return_value = FakeBiasImage(bias_level=2.0, nx=nx, ny=ny) context = make_context_with_master_bias(bias_level=2.0, readnoise=10.0, nx=nx, ny=ny) subtractor = BiasSubtractor(context) image = subtractor.do_stage(FakeImage(nx=nx, ny=ny)) assert image.header.get('BIASLVL') == 2.0
def test_bias_subtraction_is_reasonable(mock_frame, mock_cal): mock_cal.return_value = 'test.fits' input_bias = 1000.0 input_readnoise = 9.0 input_level = 2000.0 nx = 101 ny = 103 mock_frame.return_value = FakeBiasImage(bias_level=input_bias, data=np.random.normal(0.0, input_readnoise, size=(ny, nx)), nx=nx, ny=ny) # TODO: make_context_with_master_bias can now go away. Just use a FakeContext instead context = make_context_with_master_bias(bias_level=input_bias, readnoise=input_readnoise, nx=nx, ny=ny) subtractor = BiasSubtractor(context) image = FakeImage(image_multiplier=input_level) image = subtractor.do_stage(image) assert np.abs(image.header.get('BIASLVL') - input_bias) < 1.0 assert np.abs(np.mean(image.data) - (input_level - input_bias)) < 1.0
def test_bias_subtraction_is_reasonable(mock_cal, mock_image): mock_cal.return_value = 'test.fits' input_bias = 1000.0 input_readnoise = 9.0 input_level = 2000.0 nx = 101 ny = 103 fake_master_bias = FakeBiasImage(bias_level=input_bias) fake_master_bias.data = np.random.normal(0.0, input_readnoise, size=(ny, nx)) mock_image.return_value = fake_master_bias subtractor = BiasSubtractor(None) images = [FakeImage(image_multiplier=input_level) for x in range(6)] images = subtractor.do_stage(images) for image in images: assert np.abs(image.header['BIASLVL'][0] - input_bias) < 1.0 assert np.abs(np.mean(image.data) - input_level + input_bias) < 1.0
def test_null_input_image(): subtractor = BiasSubtractor(FakeContext()) image = subtractor.run(None) assert image is None
def test_header_biaslevel_is_2(mock_cal, mock_image): mock_image.return_value = FakeBiasImage(bias_level=2.0) subtractor = BiasSubtractor(None) images = subtractor.do_stage([FakeImage() for x in range(6)]) for image in images: assert image.header['BIASLVL'][0] == 2
def test_no_input_images(): subtractor = BiasSubtractor(None) images = subtractor.do_stage([]) assert len(images) == 0
def test_group_by_keywords(): subtractor = BiasSubtractor(None) assert subtractor.group_by_keywords == ['ccdsum']