def test_snr_constant_wav_ref_outside_wav(wav_ref): """Wav-ref outside bounds of wav should raise ValueError""" wav = np.linspace(1, 3, 60) flux = np.random.randn(len(wav)) with pytest.raises(ValueError): snrnorm.snr_constant_wav(wav, flux, wav_ref)
def test_band_snr_norm(testing_spectrum, sampling): """Compared to wav snr norm.""" wav, flux = testing_spectrum wav, flux = convolve_and_resample( wav, flux, vsini=1, R=100000, band="J", sampling=sampling ) assert snrnorm.snr_constant_band( wav, flux, band="J", snr=100, sampling=sampling ) == snrnorm.snr_constant_wav(wav, flux, wav_ref=1.25, snr=100, sampling=sampling) assert snrnorm.snr_constant_band( wav, flux, band="J", snr=100, sampling=sampling ) != snrnorm.snr_constant_wav(wav, flux, wav_ref=1.24, snr=100, sampling=sampling)
def test_snr_normalization_constant(desired_snr, band, testing_spectrum): """Test snr_constant_band and snr_constant_wav produce same result.""" wav, flux = testing_spectrum band_mid = utils.band_middle(band) assert snrnorm.snr_constant_band( wav, flux, band=band, snr=desired_snr ) == snrnorm.snr_constant_wav(wav, flux, band_mid, snr=desired_snr)
def test_band_snr_norm_test_data(): """Compared to wav snr norm.""" # snr_constant_band star, band, vel, res = "M0", "J", 1.0, "100k" test_data = os.path.join(eniric.paths["resampled"], resampled_template.format(star, band, vel, res)) wav, flux = io.pdread_2col(test_data) assert snrnorm.snr_constant_band( wav, flux, band="J", snr=100) == snrnorm.snr_constant_wav(wav, flux, wav_ref=1.25, snr=100) assert snrnorm.snr_constant_band(wav, flux, band="J", snr=100) != snrnorm.snr_constant_wav( wav, flux, wav_ref=1.24, snr=100)
def test_snr_constant_band_returns_mid_value_const(band): size = 100 np.random.seed(40) flux = 500 * np.random.rand( size ) # To give a random spectrum (but consistent between tests) lim = utils.band_limits(band) wav = np.linspace(lim[0], lim[1], size) band_const = snrnorm.snr_constant_band(wav, flux, band=band) wav_const = snrnorm.snr_constant_wav(wav, flux, wav_ref=utils.band_middle(band)) assert isinstance(band_const, float) assert isinstance(wav_const, float) assert band_const == wav_const # Since band calls wave at midpoint
def test_snr_normalization_logic(band): """Testing direct value. snr = sqrt(sum(3 pixels)) const = (snr/ref_snr)**2 if pixel value = 3 then the normalization constant will be 1. """ size = 100 band = "K" lim = utils.band_limits(band) wav = np.linspace(lim[0], lim[1], size) flux = 3 * np.ones(size) band_const = snrnorm.snr_constant_band(wav, flux, snr=3, band=band) wav_const = snrnorm.snr_constant_wav( wav, flux, snr=3, wav_ref=(lim[0] + lim[1]) / 2 ) assert band_const == 1 assert wav_const == 1