def test_sky_correct_from_slit_with_multiple_sources(): width = 200 height = 100 np.random.seed(0) y0 = height // 2 y1 = 7 * height // 16 fwhm = 0.05 * height source = ( fake_point_source_spatial_profile(height, width, {'c0': y0, 'c1': 0.0}, fwhm=fwhm) + fake_point_source_spatial_profile(height, width, {'c0': y1, 'c1': 0.0}, fwhm=fwhm) ) sky = SkyLines(n_lines=width // 2, max_position=width - 1) ad = create_zero_filled_fake_astrodata(height, width) ad[0].data += source ad[0].data += sky(ad[0].data, axis=1) ad[0].APERTURE = get_aperture_table(height, width, center=height // 2) ad[0].APERTURE.add_row([1, 1, 0, 0, width - 1, y1, -3, 3]) # Running the test ---------------- _p = primitives_spect.Spect([]) # ToDo @csimpson: Is it modifying the input ad? ad_out = _p.skyCorrectFromSlit([ad])[0] np.testing.assert_allclose(ad_out[0].data, source, atol=0.00625)
def test_extract_1d_spectra_with_sky_lines(): # Input Parameters ---------------- width = 600 height = 300 source_intensity = 1 # Boilerplate code ---------------- np.random.seed(0) sky = fake_emission_line_spectrum(width, n_lines=20, max_intensity=1, fwhm=2.) sky = np.repeat(sky[np.newaxis, :], height, axis=0) ad = create_zero_filled_fake_astrodata(height, width) ad[0].data += sky ad[0].data[height // 2] += source_intensity ad[0].APERTURE = get_aperture_table(height, width) # Running the test ---------------- _p = primitives_spect.Spect([]) # todo: if input is a single astrodata, # should not the output have the same format? ad_out = _p.extract1DSpectra([ad])[0] np.testing.assert_equal(ad_out[0].shape[0], ad[0].shape[1]) np.testing.assert_allclose(ad_out[0].data, source_intensity, atol=1e-3)
def test_sky_correct_from_slit_with_aperture_table(): # Input Parameters ---------------- width = 200 height = 100 # Simulate Data ------------------- np.random.seed(0) source_model_parameters = {'c0': height // 2, 'c1': 0.0} source = fake_point_source_spatial_profile( height, width, source_model_parameters, fwhm=0.08 * height) sky = SkyLines(n_lines=width // 2, max_position=width - 1) ad = create_zero_filled_fake_astrodata(height, width) ad[0].data += source ad[0].data += sky(ad[0].data, axis=1) ad[0].APERTURE = get_aperture_table(height, width) # Running the test ---------------- _p = primitives_spect.Spect([]) # ToDo @csimpson: Is it modifying the input ad? ad_out = _p.skyCorrectFromSlit([ad])[0] np.testing.assert_allclose(ad_out[0].data, source, atol=0.00625)
def test_trace_apertures(): # Input parameters ---------------- width = 400 height = 200 trace_model_parameters = { 'c0': height // 2, 'c1': 5.0, 'c2': -0.5, 'c3': 0.5 } # Boilerplate code ---------------- ad = create_zero_filled_fake_astrodata(height, width) ad[0].data += fake_point_source_spatial_profile(height, width, trace_model_parameters) ad[0].APERTURE = get_aperture_table(height, width) # Running the test ---------------- _p = primitives_spect.Spect([]) ad_out = _p.traceApertures([ad], trace_order=len(trace_model_parameters) + 1)[0] keys = trace_model_parameters.keys() desired = np.array([trace_model_parameters[k] for k in keys]) actual = np.array([ad_out[0].APERTURE[0][k] for k in keys]) np.testing.assert_allclose(desired, actual, atol=0.18)
def test_get_spectrophotometry(path_to_outputs): def create_fake_table(): wavelengths = np.arange(350., 750., 10) flux = np.ones(wavelengths.size) bandpass = np.ones(wavelengths.size) * 5. _table = table.Table([wavelengths, flux, bandpass], names=['WAVELENGTH', 'FLUX', 'FWHM']) _table.name = os.path.join(path_to_outputs, 'specphot.dat') _table.write(_table.name, format='ascii') return _table.name _p = primitives_spect.Spect([]) fake_table = _p._get_spectrophotometry(create_fake_table()) np.testing.assert_allclose(fake_table['FLUX'], 1) assert 'WAVELENGTH' in fake_table.columns assert 'FLUX' in fake_table.columns assert 'WIDTH' in fake_table.columns assert hasattr(fake_table['WAVELENGTH'], 'quantity') assert hasattr(fake_table['FLUX'], 'quantity') assert hasattr(fake_table['WIDTH'], 'quantity')
def test_extract_1d_spectra(): # Input Parameters ---------------- width = 200 height = 100 # Boilerplate code ---------------- ad = create_zero_filled_fake_astrodata(height, width) ad[0].data[height // 2] = 1 ad[0].APERTURE = get_aperture_table(height, width) # Running the test ---------------- _p = primitives_spect.Spect([]) # todo: if input is a single astrodata, # should not the output have the same format? ad_out = _p.extract1DSpectra([ad])[0] np.testing.assert_equal(ad_out[0].shape[0], ad[0].shape[1]) np.testing.assert_allclose(ad_out[0].data, ad[0].data[height // 2], atol=1e-3)
def test_find_apertures(): _p = primitives_spect.Spect([]) _p.findSourceApertures()