def test_increasing_error(self): """As the PWV error increases so should the transmission error""" transm_1 = pwv_atm.trans_for_pwv(pwv=2, pwv_err=1) transm_5 = pwv_atm.trans_for_pwv(pwv=2, pwv_err=5) error_is_greater = (e5 > e1 for e1, e5 in zip(transm_1, transm_5)) pass_test = np.all(error_is_greater) self.assertTrue(pass_test)
def test_argument_values(self): """Test errors raised from function call with out of range values PWV concentrations should be between 0 and 30.1 mm (inclusive). This is due to the range of the atmospheric models. """ self.assertRaises(ValueError, pwv_atm.trans_for_pwv, -1) # Check value that uses interpolation self.assertIsNotNone(pwv_atm.trans_for_pwv(15.0)) # Check value outside domain that uses extrapolation self.assertIsNotNone(pwv_atm.trans_for_pwv(30.5))
def sed(temp: float, wavelengths: np.array, pwv: float, bins: Union[int, list, np.ndarray] = None): """Return the flux of a black body under the influence of pwv absorption Flux is returned in units of ergs / (angstrom * cm2 * s). Args: temp: The temperature of the black body in Kelvin wavelengths: The SED's wavelengths in Angstroms pwv: The PWV concentration along line of sight in mm bins: Integer number of bins or sequence of bin edges used to smooth atmospheric transmission Returns: An array of flux values in units of ergs / (angstrom * cm2 * s * sr) """ # blackbody_lambda returns ergs / (angstrom * cm2 * s * sr) bb_sed = blackbody_lambda(wavelengths, temp).value if pwv > 0: transmission = trans_for_pwv(pwv, bins=bins) sampled_transmission = np.interp(wavelengths, transmission['wavelength'], transmission['transmission']) bb_sed *= sampled_transmission return bb_sed
def test_zero_pwv_error(self): """Returned error should be zero for a PWV error of zero""" transmission = pwv_atm.trans_for_pwv(pwv=1, pwv_err=0) expected_error = np.zeros(len(transmission)) all_zeros = np.array_equal(transmission['transmission_err'], expected_error) self.assertTrue(all_zeros)
def test_works_with_binning(self): """Error should be returned regardless if binning occurs""" transmission = pwv_atm.trans_for_pwv(pwv=2, pwv_err=1, bins=5000) col_names = ['wavelength', 'transmission', 'transmission_err'] self.assertCountEqual(transmission.colnames, col_names)
def test_not_passed_pwv_error(self): """Returned transmission should have no error if not given PWV error""" transmission = pwv_atm.trans_for_pwv(1) no_err = np.all(('err' not in col for col in transmission.colnames)) self.assertTrue(no_err)