def test_return_emission_curve_from_quantity_arrays(self, n, expected): wavelength = np.linspace(0.5, 2.5, n) * u.um emission = [1] * n * u.Unit("ph s-1 m-2 um-1") surf = opt_surf.SpectralSurface(wavelength=wavelength, emission=emission) integal = surf.emission.integrate().to(u.Unit("ph s-1 m-2")) assert np.isclose(integal.value, expected.value) # ph s-1 m-2
def test_return_emission_curve_from_basic_arrays_with_all_keywords(self): surf = opt_surf.SpectralSurface(wavelength=[0.5, 2.5], emission=[1., 1.], wavelength_unit="um", emission_unit="ph s-1 m-2 um-1") integal = surf.emission.integrate().to(u.Unit("ph s-1 m-2")) assert np.isclose(integal.value, 2) # ph s-1 m-2
def test_returns_synphot_object_per_steradian_scaled_to_per_arcsec2(self): sr2arcsec = u.sr.to(u.arcsec**2) srf = opt_surf.SpectralSurface(wavelength=[0.3, 3.0] * u.um, emission=[sr2arcsec] * 2 * PHOTLAM / u.sr) assert isinstance(srf.emission, SourceSpectrum) assert np.all(srf.emission([0.3, 3.0] * u.um) == [1, 1] * PHOTLAM)
def test_returns_none_for_none_input(self, colname1, colname2, col1, col2, expected): srf = opt_surf.SpectralSurface() srf.meta[colname1] = col1 srf.meta[colname2] = col2 col3 = srf._compliment_array(colname1, colname2) assert col3 is None
def test_add_empty_surface_to_full_table(self, input_tables, position): rt = opt_rad.RadiometryTable(tables=(input_tables[0])) surf = opt_surf.SpectralSurface() rt.add_surface(surf, "new_surf", position) colname = utils.real_colname("name", rt.table.colnames) assert rt.table[colname][position] == "new_surf" assert "new_surf" in rt.surfaces assert isinstance(rt.surfaces["new_surf"], opt_surf.SpectralSurface)
def test_return_none_if_table_is_empty(self): n = 10 surf = opt_surf.SpectralSurface(wavelength=np.linspace(1, 2, n) * u.um, transmission=np.ones(n)) dic = {"surf" + str(i + 1): surf for i in range(3)} tbl = Table() combi = rad_utils.combine_throughputs(tbl, dic, [0, 1, 2]) assert combi is None
def test_ter_property_of_object_from_file(self, col_name, ter_table): filename = os.path.join(MOCK_DIR, "TER_dichroic.dat") surf = opt_surf.SpectralSurface(filename=filename) tbl_ter_prop = ter_table[col_name] surf_ter_prop = getattr(surf, col_name).model.lookup_table assert isinstance(surf, opt_surf.SpectralSurface) assert np.all(surf_ter_prop == tbl_ter_prop)
def test_ter_property_of_object_from_arrays(self, col_name, ter_table): surf = opt_surf.SpectralSurface(wavelength=ter_table["wavelength"], wavelength_unit="um") surf.meta[col_name] = ter_table[col_name] tbl_ter_prop = ter_table[col_name] surf_ter_prop = getattr(surf, col_name).model.lookup_table assert isinstance(surf, opt_surf.SpectralSurface) assert np.all(surf_ter_prop == tbl_ter_prop)
def test_super_simple_combine_3_surfaces(self): n = 10 surf = opt_surf.SpectralSurface(wavelength=np.linspace(1, 2, n)*u.um, transmission=np.ones(n)) dic = {"surf"+str(i+1): surf for i in range(3)} tbl = ioascii.read(""" name action surf1 reflection surf2 transmission surf3 transmission """) combi = rad_utils.combine_throughputs(tbl, dic, [0, 1, 2]) assert isinstance(combi, SpectralElement)
def test_returns_right_answers_for_valid_table(self, col2_arr, expected): srf = opt_surf.SpectralSurface() srf.table.add_column(Column(name="col1", data=[0.8] * len(expected))) if col2_arr: srf.table.add_column(Column(name="col2", data=col2_arr)) col3 = srf._compliment_array("col1", "col2") if sys.version_info.major >= 3: assert col3.data == pytest.approx(expected) assert len(col3.data) == len(expected) else: warnings.warn("Data equality isn't tested for 2.7")
def test_the_right_answers_for_valid_input(self, colname1, colname2, col1, col2, expected): srf = opt_surf.SpectralSurface() srf.meta[colname1] = col1 srf.meta[colname2] = col2 col3 = srf._compliment_array(colname1, colname2) if sys.version_info.major >= 3: assert np.all(np.isclose(col3.data, expected.data)) assert col3.unit == expected.unit else: warnings.warn("Data equality isn't tested for 2.7") assert col3.unit == expected.unit
def test_returned_bb_curve_is_scaled_to_per_arcsec2(self): n = 11 sr2arcsec = u.sr.to(u.arcsec**2) wave = np.logspace(-1, 3, n) * u.um srf = opt_surf.SpectralSurface(wavelength=wave, transmission=np.zeros(n), temperature=0 * u.deg_C) emission_raw = SourceSpectrum(BlackBody1D, temperature=273) assert isinstance(srf.emission, SourceSpectrum) assert np.all( np.isclose( emission_raw(wave) / srf.emission(wave), np.array([sr2arcsec] * n)))
def test_returned_bb_curve_is_scaled_to_per_arcsec2(self): n = 11 sr2arcsec = u.sr.to(u.arcsec ** 2) wave = np.logspace(-1, 3, n) * u.um temp = (0 * u.deg_C).to(u.Kelvin, equivalencies=u.temperature()) srf = opt_surf.SpectralSurface(wavelength=wave, transmission=np.zeros(n), temperature=temp) emission_raw = SourceSpectrum(BlackBody1D, temperature=temp) assert isinstance(srf.emission, SourceSpectrum) assert np.allclose(emission_raw(wave) / sr2arcsec, srf.emission(wave))
def test_super_simple_case(self): n = 11 surf = opt_surf.SpectralSurface(wavelength=np.linspace(1, 2, n) * u.um, transmission=0.5*np.ones(n), area=2*u.m**2, angle=0*u.deg) dic = {"surf" + str(i + 1): surf for i in range(3)} tbl = ioascii.read(""" name action surf1 reflection surf2 transmission surf3 transmission """) etendue = 1 * u.m**2 * u.arcsec**2 combi = rad_utils.combine_emissions(tbl, dic, [0, 1, 2], etendue) assert isinstance(combi, SourceSpectrum)
def test_(self, input_tables, position): tbl = ioascii.read(input_tables[0]) surf = opt_surf.SpectralSurface(tbl[0]["filename"]) tbl = rad_utils.add_surface_to_table(tbl, surf, "new_row", position) assert tbl[position]["filename"] == surf.meta["filename"] assert tbl[position]["name"] == "new_row"
def test_returns_synphot_object_per_arcsec2_scaled_to_per_arcsec2(self): srf = opt_surf.SpectralSurface(wavelength=[0.3, 3.0] * u.um, emission=[1, 1] * PHOTLAM * u.arcsec**-2) assert isinstance(srf.emission, SourceSpectrum) assert np.all(srf.emission([0.3, 3.0] * u.um) == [1, 1] * PHOTLAM)
def test_returns_area_when_area_in_meta_dict(self): srf = opt_surf.SpectralSurface(area=1 * u.m**2) assert srf.area == 1 * u.m**2
def test_returns_quantity_if_wavelength_overridden_by_list(self): srf = opt_surf.SpectralSurface(wavelength=[0.3, 3.0]) assert np.all(srf.wavelength == [0.3, 3.0] * u.um)
def test_returns_quantity_if_wavelength_unit_overridden_by_string(self): srf = opt_surf.SpectralSurface(wavelength=[0.3, 3.0], wavelength_unit="Angstrom") assert srf.meta["wavelength_unit"] == u.Angstrom assert np.all(srf.wavelength == [0.3, 3.0] * u.Angstrom)
def test_returns_empty_table_if_path_is_bogus(self): srf = opt_surf.SpectralSurface(filename="bogus.txt") assert isinstance(srf, opt_surf.SpectralSurface) assert len(srf.table) == 0
def test_returns_quantity_array_from_file_with_no_unit(self, input_tables): srf = opt_surf.SpectralSurface(filename=input_tables[1]) assert isinstance(srf.wavelength, u.Quantity) assert srf.wavelength.unit == u.um
def test_can_exist_with_no_input(self): srf = opt_surf.SpectralSurface() assert isinstance(srf, opt_surf.SpectralSurface)
def test_reads_in_table_which_exists(self, input_tables): srf = opt_surf.SpectralSurface(filename=input_tables[0]) assert isinstance(srf.table, Table)
def test_returns_area_for_only_outer_in_meta_dict(self): srf = opt_surf.SpectralSurface(outer=1 * u.m) assert srf.area == (1 / 4.) * np.pi * u.m**2
def test_returns_area_for_outer_and_inner_in_meta_dict(self): srf = opt_surf.SpectralSurface(outer=1 * u.m, inner=0.5 * u.m) assert srf.area == (1 / 4. - 1 / 16.) * np.pi * u.m**2
def test_returns_none_when_no_wavelength_info_given(self): srf = opt_surf.SpectralSurface(transmission=[1, 1]) assert srf.transmission is None
def test_returns_none_when_no_info_in_meta(self): srf = opt_surf.SpectralSurface() assert srf.area is None
def test_source_spectrum_returned_for_temp(self, input_tables, temp): srf = opt_surf.SpectralSurface(filename=input_tables[0]) out = surf_utils.make_emission_from_emissivity(273, srf.emissivity) assert isinstance(out, SourceSpectrum) assert out.model.temperature_0 == 273
def test_add_empty_surface_to_empty_table(self): rt = opt_rad.RadiometryTable() surf = opt_surf.SpectralSurface() with pytest.raises(ValueError): rt.add_surface(surf, "new_surf", 0)
def test_return_emission_curve_from_file(self): filename = os.path.join(MOCK_DIR, "emission_file.dat") surf = opt_surf.SpectralSurface(filename=filename) integal = surf.emission.integrate().to(u.Unit("ph s-1 m-2")) assert np.isclose(integal.value, 2) # ph s-1 m-2