当前位置: 首页>>代码示例>>Python>>正文


Python units.nm方法代码示例

本文整理汇总了Python中astropy.units.nm方法的典型用法代码示例。如果您正苦于以下问题:Python units.nm方法的具体用法?Python units.nm怎么用?Python units.nm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astropy.units的用法示例。


在下文中一共展示了units.nm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: calc_brightness_ratio_from_Teff

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def calc_brightness_ratio_from_Teff(Teff_1, Teff_2, plot=False):

    bandpass = np.genfromtxt('tess-response-function-v1.0.csv', delimiter=',', names=['wavelength','transmission'])
    wavelength_grid = np.arange(500,2000,1)
    
    if plot:
        fig, ax = plt.subplots()
        ax.plot(list(bandpass['wavelength'])+[2000], list(bandpass['transmission'])+[0], lw=2)
        ax.set(ylabel='TESS Transmission')
        ax2 = ax.twinx()
        ax2.plot(wavelength_grid, blackbody_lambda(wavelength_grid*u.nm, Teff_1*u.K), 'r-', lw=2, color='darkorange')
        ax2.plot(wavelength_grid, blackbody_lambda(wavelength_grid*u.nm, Teff_2*u.K), 'r-', lw=2, color='brown')
        ax2.set(ylabel='Blackbody Flux\n'+r'($erg \, cm^{-2} \, s^{-1} \, A^{-1} \, sr^{-1}$)')
    
    int1 = np.trapz(bandpass['transmission']*u.nm*blackbody_lambda(bandpass['wavelength']*u.nm, Teff_1*u.K), x=bandpass['wavelength']*u.nm, dx=np.diff(bandpass['wavelength']*u.nm))
    int2 = np.trapz(bandpass['transmission']*u.nm*blackbody_lambda(bandpass['wavelength']*u.nm, Teff_2*u.K), x=bandpass['wavelength']*u.nm, dx=np.diff(bandpass['wavelength']*u.nm))
    sbratio = int2/int1
    
    return sbratio 
开发者ID:MNGuenther,项目名称:allesfitter,代码行数:21,代码来源:spot_temp.py

示例2: test_evaluate_with_quantities_and_equivalencies

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def test_evaluate_with_quantities_and_equivalencies():
    """
    We now make sure that equivalencies are correctly taken into account
    """

    g = Gaussian1D(1 * u.Jy, 10 * u.nm, 2 * u.nm)

    # We aren't setting the equivalencies, so this won't work
    with pytest.raises(UnitsError) as exc:
        g(30 * u.PHz)
    assert exc.value.args[0] == ("Gaussian1D: Units of input 'x', PHz (frequency), could "
                                 "not be converted to required input units of "
                                 "nm (length)")

    # But it should now work if we pass equivalencies when evaluating
    assert_quantity_allclose(g(30 * u.PHz, equivalencies={'x': u.spectral()}),
                             g(9.993081933333332 * u.nm)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_quantities_evaluation.py

示例3: test_compose_equivalencies

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def test_compose_equivalencies():
    x = u.Unit("arcsec").compose(units=(u.pc,), equivalencies=u.parallax())
    assert x[0] == u.pc

    x = u.Unit("2 arcsec").compose(units=(u.pc,), equivalencies=u.parallax())
    assert x[0] == u.Unit(0.5 * u.pc)

    x = u.degree.compose(equivalencies=u.dimensionless_angles())
    assert u.Unit(u.degree.to(u.radian)) in x

    x = (u.nm).compose(units=(u.m, u.s), equivalencies=u.doppler_optical(0.55*u.micron))
    for y in x:
        if y.bases == [u.m, u.s]:
            assert y.powers == [1, -1]
            assert_allclose(
                y.scale,
                u.nm.to(u.m / u.s, equivalencies=u.doppler_optical(0.55 * u.micron)))
            break
    else:
        assert False, "Didn't find speed in compose results" 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_equivalencies.py

示例4: get_equivalencies

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def get_equivalencies():
    """
    Return a list of example equivalencies for testing serialization.
    """
    return [eq.plate_scale(.3 * u.deg/u.mm), eq.pixel_scale(.5 * u.deg/u.pix),
            eq.spectral_density(350 * u.nm, factor=2),
            eq.spectral_density(350 * u.nm), eq.spectral(),
            eq.brightness_temperature(500 * u.GHz),
            eq.brightness_temperature(500 * u.GHz, beam_area=23 * u.sr),
            eq.with_H0(), eq.temperature_energy(), eq.temperature(),
            eq.thermodynamic_temperature(300 * u.Hz),
            eq.thermodynamic_temperature(140 * u.GHz, Planck15.Tcmb0),
            eq.beam_angular_area(3 * u.sr), eq.mass_energy(),
            eq.molar_mass_amu(), eq.doppler_relativistic(2 * u.m),
            eq.doppler_optical(2 * u.nm), eq.doppler_radio(2 * u.Hz),
            eq.parallax(), eq.logarithmic(), eq.dimensionless_angles(),
            eq.spectral() + eq.temperature(),
            (eq.spectral_density(35 * u.nm) +
             eq.brightness_temperature(5 * u.Hz, beam_area=2 * u.sr)),
            (eq.spectral() + eq.spectral_density(35 * u.nm) +
             eq.brightness_temperature(5 * u.Hz, beam_area=2 * u.sr))
            ] 
开发者ID:holzschu,项目名称:Carnets,代码行数:24,代码来源:test_equivalency.py

示例5: compare_interpolants

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def compare_interpolants(self, f1, f2, param, msg=''):
        r"""Compare two interpolants f1 and f2 by probing them randomly."""
        # Find out the number of input arguments expected
        f1_info = inspect.getargspec(f1)
        f2_info = inspect.getargspec(f2)
        # this is the number of formal arguments MINUS the number of defaults
        # (EXOSIMS uses defaults to provide functional closure, though it's unneeded)
        nargin1 = len(f1_info.args) - (0 if not f1_info.defaults else len(f1_info.defaults))
        nargin2 = len(f2_info.args) - (0 if not f2_info.defaults else len(f2_info.defaults))
        if nargin1 != nargin2:
            raise self.failureException(msg + '-- functions have different arity (arg lengths)')
        # make a few random probes of the interpolant on the interval (0,1)
        for count in range(10):
            # obtain a vector of length nargin1
            arg_in = np.random.random(nargin1)
            # the result can be a float (for contrast),
            # a numpy array (for PSF), or a Quantity (for QE)
            if  param in ('core_thruput', 'core_contrast'):
                out_1 = f1(arg_in[0]*u.nm,arg_in[1]*u.arcsec)
            else:
                out_1 = f1(*arg_in)
            out_2 = f2(*arg_in)
            diff = out_1 - out_2
            # if it's a quantity, unbox the difference
            if isinstance(diff, u.quantity.Quantity):
                diff = diff.value
            if np.any(np.abs(diff) > 1e-5):
                errmsg = msg + '-- function mismatch: %r != %r' % (out_1, out_2)
                raise self.failureException(errmsg) 
开发者ID:dsavransky,项目名称:EXOSIMS,代码行数:31,代码来源:test_OpticalSystem.py

示例6: test_diffprop_matches_airydisk

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def test_diffprop_matches_airydisk(efl, epd, wvl):
    fno = efl / epd

    p = Pupil(dia=epd, xy_unit=u.mm, z_unit=u.nm, wavelength=mkwvl(wvl, u.um))
    psf = PSF.from_pupil(p, efl, Q=3)  # use Q=3 not Q=4 for improved accuracy
    s = psf.slices()
    u_, sx = s.x
    u_, sy = s.y
    analytic = airydisk(u_, fno, wvl)
    assert np.allclose(sx, analytic, atol=PRECISION)
    assert np.allclose(sy, analytic, atol=PRECISION) 
开发者ID:brandondube,项目名称:prysm,代码行数:13,代码来源:test_physics.py

示例7: test_diffprop_matches_analyticmtf

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def test_diffprop_matches_analyticmtf(efl, epd, wvl):
    fno = efl / epd
    p = Pupil(dia=epd, xy_unit=u.mm, z_unit=u.nm, wavelength=mkwvl(wvl, u.um))
    psf = PSF.from_pupil(p, efl)
    mtf = MTF.from_psf(psf)
    s = mtf.slices()
    u_, x = s.x
    u__, y = s.y

    analytic_1 = diffraction_limited_mtf(fno, wvl, frequencies=u_)
    analytic_2 = diffraction_limited_mtf(fno, wvl, frequencies=u__)
    assert np.allclose(analytic_1, x, atol=PRECISION)
    assert np.allclose(analytic_2, y, atol=PRECISION) 
开发者ID:brandondube,项目名称:prysm,代码行数:15,代码来源:test_physics.py

示例8: mkwvl

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def mkwvl(quantity, base=u.um):
    """Generate a new Wavelength unit.

    Parameters
    ----------
    quantity : `float` or `astropy.units.unit`
        number of (base) for the wavelength, e.g. quantity=632.8 with base=u.nm for HeNe.
        if an astropy unit, simply returned by this function
    base : `astropy.units.Unit`
        base unit, e.g. um or nm

    Returns
    -------
    `astropy.units.Unit`
        new Unit for appropriate wavelength

    """
    if quantity is None:
        return quantity
    elif not isinstance(quantity, u.Unit):
        return u.def_unit(['wave', 'wavelength'], quantity * base,
                          format={'latex': r'\lambda', 'unicode': 'λ'})
    else:
        return quantity


# IR 
开发者ID:brandondube,项目名称:prysm,代码行数:29,代码来源:wavelengths.py

示例9: _parse_mc_header

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def _parse_mc_header(self):
        mc_run_head = self.file_.mc_run_headers[-1]

        return MCHeaderContainer(
            corsika_version=mc_run_head["shower_prog_vers"],
            simtel_version=mc_run_head["detector_prog_vers"],
            energy_range_min=mc_run_head["E_range"][0] * u.TeV,
            energy_range_max=mc_run_head["E_range"][1] * u.TeV,
            prod_site_B_total=mc_run_head["B_total"] * u.uT,
            prod_site_B_declination=Angle(mc_run_head["B_declination"], u.rad,),
            prod_site_B_inclination=Angle(mc_run_head["B_inclination"], u.rad,),
            prod_site_alt=mc_run_head["obsheight"] * u.m,
            spectral_index=mc_run_head["spectral_index"],
            shower_prog_start=mc_run_head["shower_prog_start"],
            shower_prog_id=mc_run_head["shower_prog_id"],
            detector_prog_start=mc_run_head["detector_prog_start"],
            detector_prog_id=mc_run_head["detector_prog_id"],
            num_showers=mc_run_head["n_showers"],
            shower_reuse=mc_run_head["n_use"],
            max_alt=mc_run_head["alt_range"][1] * u.rad,
            min_alt=mc_run_head["alt_range"][0] * u.rad,
            max_az=mc_run_head["az_range"][1] * u.rad,
            min_az=mc_run_head["az_range"][0] * u.rad,
            diffuse=mc_run_head["diffuse"],
            max_viewcone_radius=mc_run_head["viewcone"][1] * u.deg,
            min_viewcone_radius=mc_run_head["viewcone"][0] * u.deg,
            max_scatter_range=mc_run_head["core_range"][1] * u.m,
            min_scatter_range=mc_run_head["core_range"][0] * u.m,
            core_pos_mode=mc_run_head["core_pos_mode"],
            injection_height=mc_run_head["injection_height"] * u.m,
            atmosphere=mc_run_head["atmosphere"],
            corsika_iact_options=mc_run_head["corsika_iact_options"],
            corsika_low_E_model=mc_run_head["corsika_low_E_model"],
            corsika_high_E_model=mc_run_head["corsika_high_E_model"],
            corsika_bunchsize=mc_run_head["corsika_bunchsize"],
            corsika_wlen_min=mc_run_head["corsika_wlen_min"] * u.nm,
            corsika_wlen_max=mc_run_head["corsika_wlen_max"] * u.nm,
            corsika_low_E_detail=mc_run_head["corsika_low_E_detail"],
            corsika_high_E_detail=mc_run_head["corsika_high_E_detail"],
            run_array_direction=Angle(self.file_.header["direction"] * u.rad),
        ) 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:43,代码来源:simteleventsource.py

示例10: test_additional_meta_data_from_mc_header

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def test_additional_meta_data_from_mc_header():
    with SimTelEventSource(input_url=gamma_test_large_path) as reader:
        data = next(iter(reader))

    # for expectation values
    from astropy import units as u
    from astropy.coordinates import Angle

    assert data.mcheader.corsika_version == 6990
    assert data.mcheader.spectral_index == -2.0
    assert data.mcheader.shower_reuse == 20
    assert data.mcheader.core_pos_mode == 1
    assert data.mcheader.diffuse == 1
    assert data.mcheader.atmosphere == 26

    # value read by hand from input card
    name_expectation = {
        "energy_range_min": u.Quantity(3.0e-03, u.TeV),
        "energy_range_max": u.Quantity(3.3e02, u.TeV),
        "prod_site_B_total": u.Quantity(23.11772346496582, u.uT),
        "prod_site_B_declination": Angle(0.0 * u.rad),
        "prod_site_B_inclination": Angle(-0.39641156792640686 * u.rad),
        "prod_site_alt": 2150.0 * u.m,
        "max_scatter_range": 3000.0 * u.m,
        "min_az": 0.0 * u.rad,
        "min_alt": 1.2217305 * u.rad,
        "max_viewcone_radius": 10.0 * u.deg,
        "corsika_wlen_min": 240 * u.nm,
    }

    for name, expectation in name_expectation.items():
        value = getattr(data.mcheader, name)

        assert value.unit == expectation.unit
        assert np.isclose(
            value.to_value(expectation.unit), expectation.to_value(expectation.unit)
        ) 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:39,代码来源:test_simteleventsource.py

示例11: download_grond

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def download_grond(filter_dict):

    save_path = os.path.join(get_speclite_filter_path(), "ESO")

    if_directory_not_existing_then_make(save_path)

    grond_filter_url = "http://www.mpe.mpg.de/~jcg/GROND/GROND_filtercurves.txt"

    url_response = urllib.request.urlopen(grond_filter_url)

    grond_table = pd.read_table(url_response)

    wave = grond_table["A"].as_matrix()

    bands = ["g", "r", "i", "z", "H", "J", "K"]

    for band in bands:

        curve = np.array(grond_table["%sBand" % band])
        curve[curve < 0] = 0
        curve[0] = 0
        curve[-1] = 0

        grond_spec = spec_filter.FilterResponse(
            wavelength=wave * u.nm,
            response=curve,
            meta=dict(group_name="GROND", band_name=band),
        )

        grond_spec.save(directory_name=save_path)

    filter_dict["ESO"] = {"GROND": bands}

    return filter_dict 
开发者ID:threeML,项目名称:threeML,代码行数:36,代码来源:filter_library.py

示例12: test_tabular_interp_1d

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def test_tabular_interp_1d():
    """
    Test Tabular1D model.
    """
    points = np.arange(0, 5)
    values = [1., 10, 2, 45, -3]
    LookupTable = models.tabular_model(1)
    model = LookupTable(points=points, lookup_table=values)
    xnew = [0., .7, 1.4, 2.1, 3.9]
    ans1 = [1., 7.3, 6.8, 6.3, 1.8]
    assert_allclose(model(xnew), ans1)
    # Test evaluate without passing `points`.
    model = LookupTable(lookup_table=values)
    assert_allclose(model(xnew), ans1)
    # Test bounds error.
    xextrap = [0., .7, 1.4, 2.1, 3.9, 4.1]
    with pytest.raises(ValueError):
        model(xextrap)
    # test extrapolation and fill value
    model = LookupTable(lookup_table=values, bounds_error=False,
                        fill_value=None)
    assert_allclose(model(xextrap),
                    [1., 7.3, 6.8, 6.3, 1.8, -7.8])

    # Test unit support
    xnew = xnew * u.nm
    ans1 = ans1 * u.nJy
    model = LookupTable(points=points*u.nm, lookup_table=values*u.nJy)
    assert_quantity_allclose(model(xnew), ans1)
    assert_quantity_allclose(model(xnew.to(u.nm)), ans1)
    assert model.bounding_box == (0 * u.nm, 4 * u.nm)

    # Test fill value unit conversion and unitless input on table with unit
    model = LookupTable([1, 2, 3], [10, 20, 30] * u.nJy, bounds_error=False,
                        fill_value=1e-33*(u.W / (u.m * u.m * u.Hz)))
    assert_quantity_allclose(model(np.arange(5)),
                             [100, 10, 20, 30, 100] * u.nJy) 
开发者ID:holzschu,项目名称:Carnets,代码行数:39,代码来源:test_models.py

示例13: test_b_wien

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def test_b_wien():
    """b_wien should give the correct peak wavelength for
    given blackbody temperature. The Sun is used in this test.

    """
    from astropy.constants import b_wien
    from astropy import units as u
    t = 5778 * u.K
    w = (b_wien / t).to(u.nm)
    assert round(w.value) == 502 
开发者ID:holzschu,项目名称:Carnets,代码行数:12,代码来源:test_constant.py

示例14: test_b_wien

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def test_b_wien():
    """b_wien should give the correct peak wavelength for
    given blackbody temperature. The Sun is used in this test.

    """
    from astropy.constants.astropyconst13 import b_wien
    from astropy import units as u
    t = 5778 * u.K
    w = (b_wien / t).to(u.nm)
    assert round(w.value) == 502 
开发者ID:holzschu,项目名称:Carnets,代码行数:12,代码来源:test_prior_version.py

示例15: test_doppler_wavelength_circle

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import nm [as 别名]
def test_doppler_wavelength_circle(function):
    rest = 105.01 * u.nm
    shifted = 105.03 * u.nm
    velo = shifted.to(u.km / u.s, equivalencies=function(rest))
    wav = velo.to(u.nm, equivalencies=function(rest))
    np.testing.assert_almost_equal(wav.value, shifted.value, decimal=7) 
开发者ID:holzschu,项目名称:Carnets,代码行数:8,代码来源:test_equivalencies.py


注:本文中的astropy.units.nm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。