Python astropy.units.erg() Examples
The following are 30
code examples of astropy.units.erg().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
astropy.units
, or try the search function
.
Example #1
Source File: test_equivalencies.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_equivalent_units2(): units = set(u.Hz.find_equivalent_units(u.spectral())) match = set( [u.AU, u.Angstrom, u.Hz, u.J, u.Ry, u.cm, u.eV, u.erg, u.lyr, u.m, u.micron, u.pc, u.solRad, u.Bq, u.Ci, u.k, u.earthRad, u.jupiterRad]) assert units == match from astropy.units import imperial with u.add_enabled_units(imperial): units = set(u.Hz.find_equivalent_units(u.spectral())) match = set( [u.AU, u.Angstrom, imperial.BTU, u.Hz, u.J, u.Ry, imperial.cal, u.cm, u.eV, u.erg, imperial.ft, imperial.fur, imperial.inch, imperial.kcal, u.lyr, u.m, imperial.mi, imperial.mil, u.micron, u.pc, u.solRad, imperial.yd, u.Bq, u.Ci, imperial.nmi, u.k, u.earthRad, u.jupiterRad]) assert units == match units = set(u.Hz.find_equivalent_units(u.spectral())) match = set( [u.AU, u.Angstrom, u.Hz, u.J, u.Ry, u.cm, u.eV, u.erg, u.lyr, u.m, u.micron, u.pc, u.solRad, u.Bq, u.Ci, u.k, u.earthRad, u.jupiterRad]) assert units == match
Example #2
Source File: test_misc.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_JsonCustomEncoder(): from astropy import units as u assert json.dumps(np.arange(3), cls=misc.JsonCustomEncoder) == '[0, 1, 2]' assert json.dumps(1+2j, cls=misc.JsonCustomEncoder) == '[1.0, 2.0]' assert json.dumps(set([1, 2, 1]), cls=misc.JsonCustomEncoder) == '[1, 2]' assert json.dumps(b'hello world \xc3\x85', cls=misc.JsonCustomEncoder) == '"hello world \\u00c5"' assert json.dumps({1: 2}, cls=misc.JsonCustomEncoder) == '{"1": 2}' # default assert json.dumps({1: u.m}, cls=misc.JsonCustomEncoder) == '{"1": "m"}' # Quantities tmp = json.dumps({'a': 5*u.cm}, cls=misc.JsonCustomEncoder) newd = json.loads(tmp) tmpd = {"a": {"unit": "cm", "value": 5.0}} assert newd == tmpd tmp2 = json.dumps({'a': np.arange(2)*u.cm}, cls=misc.JsonCustomEncoder) newd = json.loads(tmp2) tmpd = {"a": {"unit": "cm", "value": [0., 1.]}} assert newd == tmpd tmp3 = json.dumps({'a': np.arange(2)*u.erg/u.s}, cls=misc.JsonCustomEncoder) newd = json.loads(tmp3) tmpd = {"a": {"unit": "erg / s", "value": [0., 1.]}} assert newd == tmpd
Example #3
Source File: test_equivalencies.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_spectraldensity2(): # flux density flambda = u.erg / u.angstrom / u.cm ** 2 / u.s fnu = u.erg / u.Hz / u.cm ** 2 / u.s a = flambda.to(fnu, 1, u.spectral_density(u.Quantity(3500, u.AA))) assert_allclose(a, 4.086160166177361e-12) # luminosity density llambda = u.erg / u.angstrom / u.s lnu = u.erg / u.Hz / u.s a = llambda.to(lnu, 1, u.spectral_density(u.Quantity(3500, u.AA))) assert_allclose(a, 4.086160166177361e-12) a = lnu.to(llambda, 1, u.spectral_density(u.Quantity(3500, u.AA))) assert_allclose(a, 2.44728537142857e11)
Example #4
Source File: test_quantities.py From marvin with BSD 3-Clause "New" or "Revised" License | 6 votes |
def spectrum(): """Produces a simple 1D array for datacube testing.""" flux = numpy.arange(1, 1001, dtype=numpy.float32) ivar = (1. / (flux / 100))**2 mask = numpy.zeros(flux.shape, dtype=numpy.int) wave = numpy.arange(1, 1001) mask[50:100] = 2**10 mask[500:600] = 2**4 scale = 1e-3 datacube = Spectrum(flux, wave, ivar=ivar, mask=mask, scale=scale, unit=u.erg / u.s / (u.cm ** 2) / u.Angstrom / spaxel_unit, pixmask_flag='MANGA_DRP3PIXMASK') yield datacube
Example #5
Source File: test_quantities.py From marvin with BSD 3-Clause "New" or "Revised" License | 6 votes |
def datacube(): """Produces a simple 3D array for datacube testing.""" flux = numpy.tile([numpy.arange(1, 1001, dtype=numpy.float32)], (100, 1)).T.reshape(1000, 10, 10) ivar = (1. / (flux / 100))**2 mask = numpy.zeros(flux.shape, dtype=numpy.int) wave = numpy.arange(1, 1001) redcorr = numpy.ones(1000) * 1.5 mask[50:100, 5, 5] = 2**10 mask[500:600, 3, 3] = 2**4 scale = 1e-3 datacube = DataCube(flux, wave, ivar=ivar, mask=mask, redcorr=redcorr, scale=scale, unit=u.erg / u.s / (u.cm ** 2) / u.Angstrom / spaxel_unit, pixmask_flag='MANGA_DRP3PIXMASK') yield datacube
Example #6
Source File: model.py From grizli with MIT License | 6 votes |
def trace_table(self): """ Table of trace parameters. Trace is unit-indexed. """ dtype = np.float32 tab = utils.GTable() tab.meta['CONFFILE'] = os.path.basename(self.beam.conf.conf_file) tab['wavelength'] = np.cast[dtype](self.beam.lam*u.Angstrom) tab['trace'] = np.cast[dtype](self.beam.ytrace + self.beam.sh_beam[0]/2 - self.beam.ycenter) sens_units = u.erg/u.second/u.cm**2/u.Angstrom/(u.electron/u.second) tab['sensitivity'] = np.cast[dtype](self.beam.sensitivity*sens_units) return tab
Example #7
Source File: test_equivalencies.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_spectraldensity6(): """ Test surface brightness conversions. """ slam = u.erg / (u.cm ** 2 * u.s * u.AA * u.sr) snu = u.erg / (u.cm ** 2 * u.s * u.Hz * u.sr) wave = u.Quantity([4956.8, 4959.55, 4962.3], u.AA) sb_flam = [3.9135e-14, 4.0209e-14, 3.9169e-14] sb_fnu = [3.20735792e-25, 3.29903646e-25, 3.21727226e-25] # S(nu) <--> S(lambda) assert_allclose(snu.to( slam, sb_fnu, u.spectral_density(wave)), sb_flam, rtol=1e-6) assert_allclose(slam.to( snu, sb_flam, u.spectral_density(wave)), sb_fnu, rtol=1e-6)
Example #8
Source File: test_equivalencies.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_spectraldensity3(): # Define F_nu in Jy f_nu = u.Jy # Define F_lambda in ergs / cm^2 / s / micron f_lambda = u.erg / u.cm ** 2 / u.s / u.micron # 1 GHz one_ghz = u.Quantity(1, u.GHz) # Convert to ergs / cm^2 / s / Hz assert_allclose(f_nu.to(u.erg / u.cm ** 2 / u.s / u.Hz, 1.), 1.e-23, 10) # Convert to ergs / cm^2 / s at 10 Ghz assert_allclose(f_nu.to(u.erg / u.cm ** 2 / u.s, 1., equivalencies=u.spectral_density(one_ghz * 10)), 1.e-13, 10) # Convert to F_lambda at 1 Ghz assert_allclose(f_nu.to(f_lambda, 1., equivalencies=u.spectral_density(one_ghz)), 3.335640951981521e-20, 10) # Convert to Jy at 1 Ghz assert_allclose(f_lambda.to(u.Jy, 1., equivalencies=u.spectral_density(one_ghz)), 1. / 3.335640951981521e-20, 10) # Convert to ergs / cm^2 / s at 10 microns assert_allclose(f_lambda.to(u.erg / u.cm ** 2 / u.s, 1., equivalencies=u.spectral_density(u.Quantity(10, u.micron))), 10., 10)
Example #9
Source File: test_photometric.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_maggies_zpts(): assert_quantity_allclose((1*nmgy).to(ABflux, zero_point_flux(1*ABflux)), 3631e-9*Jy, rtol=1e-3) ST_base_unit = erg * cm**-2 / s / AA stmgy = (10*mgy).to(STflux, zero_point_flux(1*ST_base_unit)) assert_quantity_allclose(stmgy, 10*ST_base_unit) mgyst = (2*ST_base_unit).to(mgy, zero_point_flux(0.5*ST_base_unit)) assert_quantity_allclose(mgyst, 4*mgy) nmgyst = (5.e-10*ST_base_unit).to(mgy, zero_point_flux(0.5*ST_base_unit)) assert_quantity_allclose(nmgyst, 1*nmgy)
Example #10
Source File: test_format.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_latex(): fluxunit = u.erg / (u.cm ** 2 * u.s) assert fluxunit.to_string('latex') == r'$\mathrm{\frac{erg}{s\,cm^{2}}}$'
Example #11
Source File: test_physical.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_flam(): flam = u.erg / (u.cm**2 * u.s * u.AA) assert flam.physical_type == 'spectral flux density wav'
Example #12
Source File: test_logarithmic.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_complicated_addition_subtraction(self): """For fun, a more complicated example of addition and subtraction.""" dm0 = u.Unit('DM', 1./(4.*np.pi*(10.*u.pc)**2)) DMmag = u.mag(dm0) m_st = 10. * u.STmag dm = 5. * DMmag M_st = m_st - dm assert M_st.unit.is_equivalent(u.erg/u.s/u.AA) assert np.abs(M_st.physical / (m_st.physical*4.*np.pi*(100.*u.pc)**2) - 1.) < 1.e-15
Example #13
Source File: test_logarithmic.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_complicated_addition_subtraction(self): """for fun, a more complicated example of addition and subtraction""" dm0 = u.Unit('DM', 1./(4.*np.pi*(10.*u.pc)**2)) lu_dm = u.mag(dm0) lu_absST = u.STmag - lu_dm assert lu_absST.is_equivalent(u.erg/u.s/u.AA)
Example #14
Source File: test_logarithmic.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_predefined_magnitudes(): assert_quantity_allclose((-21.1*u.STmag).physical, 1.*u.erg/u.cm**2/u.s/u.AA) assert_quantity_allclose((-48.6*u.ABmag).physical, 1.*u.erg/u.cm**2/u.s/u.Hz) assert_quantity_allclose((0*u.M_bol).physical, c.L_bol0) assert_quantity_allclose((0*u.m_bol).physical, c.L_bol0/(4.*np.pi*(10.*c.pc)**2))
Example #15
Source File: test_format.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_fits_scale_factor_errors(): with pytest.raises(ValueError): x = u.Unit('1000 erg/(s cm**2 Angstrom)', format='fits') with pytest.raises(ValueError): x = u.Unit('12 erg/(s cm**2 Angstrom)', format='fits') x = u.Unit(1.2 * u.erg) with pytest.raises(ValueError): x.to_string(format='fits') x = u.Unit(100.0 * u.erg) assert x.to_string(format='fits') == '10**2 erg'
Example #16
Source File: test_format.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_fits_scale_factor(scale, number, string): x = u.Unit(scale + ' erg/(s cm**2 Angstrom)', format='fits') assert x == number * (u.erg / u.s / u.cm ** 2 / u.Angstrom) assert x.to_string(format='fits') == string + ' Angstrom-1 cm-2 erg s-1' x = u.Unit(scale + '*erg/(s cm**2 Angstrom)', format='fits') assert x == number * (u.erg / u.s / u.cm ** 2 / u.Angstrom) assert x.to_string(format='fits') == string + ' Angstrom-1 cm-2 erg s-1'
Example #17
Source File: test_format.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_flatten_to_known(): myunit = u.def_unit("FOOBAR_One", u.erg / u.Hz) assert myunit.to_string('fits') == 'erg Hz-1' myunit2 = myunit * u.bit ** 3 assert myunit2.to_string('fits') == 'bit3 erg Hz-1'
Example #18
Source File: test_format.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_format_styles(format_spec, string): fluxunit = u.erg / (u.cm ** 2 * u.s) assert format(fluxunit, format_spec) == string
Example #19
Source File: test_format.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_latex_inline_scale(): fluxunit = u.Unit(1.e-24 * u.erg / (u.cm ** 2 * u.s * u.Hz)) latex_inline = (r'$\mathrm{1 \times 10^{-24}\,erg' r'\,Hz^{-1}\,s^{-1}\,cm^{-2}}$') assert fluxunit.to_string('latex_inline') == latex_inline
Example #20
Source File: test_format.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_new_style_latex(): fluxunit = u.erg / (u.cm ** 2 * u.s) assert f"{fluxunit:latex}" == r'$\mathrm{\frac{erg}{s\,cm^{2}}}$'
Example #21
Source File: utils.py From tom_base with GNU General Public License v3.0 | 5 votes |
def get_flux_constant(self): return units.erg / units.angstrom
Example #22
Source File: test_units.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_fits_hst_unit(): """See #1911.""" with catch_warnings() as w: x = u.Unit("erg /s /cm**2 /angstrom") assert x == u.erg * u.s ** -1 * u.cm ** -2 * u.angstrom ** -1 assert len(w) == 1 assert 'multiple slashes' in str(w[0].message)
Example #23
Source File: test_units.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_units_manipulation(): # Just do some manipulation and check it's happy (u.kpc * u.yr) ** Fraction(1, 3) / u.Myr (u.AA * u.erg) ** 9
Example #24
Source File: physical_models.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def bolometric_flux(self): """Bolometric flux.""" # bolometric flux in the native units of the planck function native_bolflux = ( self.scale.value * const.sigma_sb * self.temperature ** 4 / np.pi ) # return in more "astro" units return native_bolflux.to(u.erg / (u.cm ** 2 * u.s))
Example #25
Source File: test_physical_models.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_blackbody_return_units(): # return of evaluate has no units when temperature has no units b = BlackBody(1000.0 * u.K, scale=1.0) assert not isinstance(b.evaluate(1.0 * u.micron, 1000.0, 1.0), u.Quantity) # return has "standard" units when scale has no units b = BlackBody(1000.0 * u.K, scale=1.0) assert isinstance(b(1.0 * u.micron), u.Quantity) assert b(1.0 * u.micron).unit == u.erg / (u.cm ** 2 * u.s * u.Hz * u.sr) # return has scale units when scale has units b = BlackBody(1000.0 * u.K, scale=1.0 * u.MJy / u.sr) assert isinstance(b(1.0 * u.micron), u.Quantity) assert b(1.0 * u.micron).unit == u.MJy / u.sr
Example #26
Source File: test_blackbody.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_fit(self): fitter = LevMarLSQFitter() b = BlackBody1D(3000 * u.K) wav = np.array([0.5, 5, 10]) * u.micron fnu = np.array([1, 10, 5]) * u.Jy b_fit = fitter(b, wav, fnu) assert_quantity_allclose(b_fit.temperature, 2840.7438339457754 * u.K) assert_quantity_allclose(b_fit.bolometric_flux, 6.821837075583734e-08 * u.erg / u.cm**2 / u.s)
Example #27
Source File: blackbody.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def blackbody_lambda(in_x, temperature): """Like :func:`blackbody_nu` but for :math:`B_{\\lambda}(T)`. Parameters ---------- in_x : number, array_like, or `~astropy.units.Quantity` Frequency, wavelength, or wave number. If not a Quantity, it is assumed to be in Angstrom. temperature : number, array_like, or `~astropy.units.Quantity` Blackbody temperature. If not a Quantity, it is assumed to be in Kelvin. Returns ------- flux : `~astropy.units.Quantity` Blackbody monochromatic flux in :math:`erg \\; cm^{-2} s^{-1} \\mathring{A}^{-1} sr^{-1}`. """ if getattr(in_x, 'unit', None) is None: in_x = u.Quantity(in_x, u.AA) bb_nu = blackbody_nu(in_x, temperature) * u.sr # Remove sr for conversion flux = bb_nu.to(FLAM, u.spectral_density(in_x)) return flux / u.sr # Add per steradian to output flux unit
Example #28
Source File: test_wcsprm.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_unit(): w = wcs.WCS() w.wcs.cunit[0] = u.erg assert w.wcs.cunit[0] == u.erg assert repr(w.wcs.cunit) == "['erg', '']"
Example #29
Source File: MODEL_AGNfitter.py From AGNfitter with MIT License | 5 votes |
def stellar_info(chain, data): """ computes stellar masses and SFRs """ gal_do, irlum_dict, nh_dict, BBebv_dict, SFRdict = data.dictkey_arrays #call dictionary info #relevanta parameters form the MCMC chain tau_mcmc = chain[:,0] age_mcmc = chain[:,1] GA = chain[:,6] - 18. #1e18 is the common normalization factor used in parspace.ymodel in order to have comparable NORMfactors z = data.z distance = z2Dlum(z) #constants solarlum = const.L_sun.to(u.erg/u.second) #3.839e33 solarmass = const.M_sun Mstar_list=[] SFR_list=[] for i in range (len (tau_mcmc)): N = 10**GA[i]* 4* pi* distance**2 / (solarlum.value)/ (1+z) gal_do.nearest_par2dict(tau_mcmc[i], 10**age_mcmc[i], 0.) tau_dct, age_dct, ebvg_dct=gal_do.t, gal_do.a,gal_do.e SFR_mcmc =SFRdict[tau_dct, age_dct] # Calculate Mstar. BC03 templates are normalized to M* = 1 M_sun. # Thanks to Kenneth Duncan, and his python version of BC03, smpy Mstar = np.log10(N * 1) #Calculate SFR. output is in [Msun/yr]. SFR = N * SFR_mcmc SFR_list.append(SFR.value) Mstar_list.append(Mstar) return np.array(Mstar_list) , np.array(SFR_list)
Example #30
Source File: fitted_point_sources.py From threeML with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, flux_unit, energy_unit, flux_model, test_model): """ Handles differential flux conversion and model building for point sources :param test_model: model to test the flux on :param flux_unit: an astropy unit string for differential flux :param energy_unit: an astropy unit string for energy :param flux_model: the base flux model to use """ self._flux_lookup = { "photon_flux": 1.0 / (u.keV * u.cm ** 2 * u.s), "energy_flux": old_div(u.erg, (u.keV * u.cm ** 2 * u.s)), "nufnu_flux": old_div(u.erg ** 2, (u.keV * u.cm ** 2 * u.s)), } self._model_converter = { "photon_flux": test_model, "energy_flux": lambda x: x * test_model(x), "nufnu_flux": lambda x: x * x * test_model(x), } self._model_builder = { "photon_flux": flux_model, "energy_flux": lambda x, **param_specification: x * flux_model(x, **param_specification), "nufnu_flux": lambda x, **param_specification: x * x * flux_model(x, **param_specification), } super(DifferentialFluxConversion, self).__init__( flux_unit, energy_unit, flux_model )