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


Python units.cm方法代码示例

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


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

示例1: trace_table

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
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 
开发者ID:gbrammer,项目名称:grizli,代码行数:18,代码来源:model.py

示例2: test_find_neighbor_pixels

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
def test_find_neighbor_pixels():
    """ test basic neighbor functionality """
    n_pixels = 5
    x, y = u.Quantity(
        np.meshgrid(np.linspace(-5, 5, n_pixels), np.linspace(-5, 5, n_pixels)), u.cm
    )

    geom = CameraGeometry(
        "test",
        pix_id=np.arange(n_pixels),
        pix_area=u.Quantity(4, u.cm ** 2),
        pix_x=x.ravel(),
        pix_y=y.ravel(),
        pix_type="rectangular",
    )

    neigh = geom.neighbors
    assert set(neigh[11]) == {16, 6, 10, 12} 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:20,代码来源:test_geometry.py

示例3: test_calc_pixel_neighbors_square_diagonal

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
def test_calc_pixel_neighbors_square_diagonal():
    """
    check that neighbors for square-pixel cameras are what we expect,
    namely that the diagonals are included if requested.
    """
    x, y = np.meshgrid(np.arange(20), np.arange(20))

    cam = CameraGeometry(
        camera_name="test",
        pix_id=np.arange(400),
        pix_type="rectangular",
        pix_x=u.Quantity(x.ravel(), u.cm),
        pix_y=u.Quantity(y.ravel(), u.cm),
        pix_area=u.Quantity(np.ones(400), u.cm ** 2),
    )

    cam._neighbors = cam.calc_pixel_neighbors(diagonal=True)
    assert set(cam.neighbors[21]) == {0, 1, 2, 20, 22, 40, 41, 42} 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:20,代码来源:test_geometry.py

示例4: test_guess_area

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
def test_guess_area():
    x = u.Quantity([0, 1, 2], u.cm)
    y = u.Quantity([0, 0, 0], u.cm)
    n_pixels = len(x)

    geom = CameraGeometry(
        "test",
        pix_id=np.arange(n_pixels),
        pix_area=None,
        pix_x=x,
        pix_y=y,
        pix_type="rect",
    )

    assert np.all(geom.pix_area == 1 * u.cm ** 2)

    geom = CameraGeometry(
        "test",
        pix_id=np.arange(n_pixels),
        pix_area=None,
        pix_x=x,
        pix_y=y,
        pix_type="hexagonal",
    )
    assert u.allclose(geom.pix_area, 2 * np.sqrt(3) * (0.5 * u.cm) ** 2) 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:27,代码来源:test_geometry.py

示例5: test_single_pixel

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
def test_single_pixel():
    x = y = np.arange(3)
    x, y = np.meshgrid(x, y)

    geom = CameraGeometry(
        camera_name="testcam",
        pix_id=np.arange(9),
        pix_x=x.ravel() * u.cm,
        pix_y=y.ravel() * u.cm,
        pix_type="rectangular",
        pix_area=1 * u.cm ** 2,
    )

    image = np.zeros((3, 3))
    image[1, 1] = 10
    image = image.ravel()

    hillas = hillas_parameters(geom, image)

    assert hillas.length.value == 0
    assert hillas.width.value == 0
    assert np.isnan(hillas.psi) 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:24,代码来源:test_hillas.py

示例6: test_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
def test_units():
    class WithUnits(Container):
        inverse_length = Field(5 / u.m, "foo")
        time = Field(1 * u.s, "bar", unit=u.s)
        grammage = Field(2 * u.g / u.cm ** 2, "baz", unit=u.g / u.cm ** 2)

    c = WithUnits()

    with tempfile.NamedTemporaryFile() as f:
        with HDF5TableWriter(f.name, "data") as writer:
            writer.write("units", c)

        with tables.open_file(f.name, "r") as f:

            assert f.root.data.units.attrs["inverse_length_UNIT"] == "m-1"
            assert f.root.data.units.attrs["time_UNIT"] == "s"
            assert f.root.data.units.attrs["grammage_UNIT"] == "cm-2 g" 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:19,代码来源:test_hdf5.py

示例7: datacube

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
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 
开发者ID:sdss,项目名称:marvin,代码行数:23,代码来源:test_quantities.py

示例8: spectrum

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
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 
开发者ID:sdss,项目名称:marvin,代码行数:20,代码来源:test_quantities.py

示例9: test_set_units

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

    p = Parameter('test_parameter',1.0, unit=u.keV)

    p.value = 3.0 * u.MeV

    assert p.value == 3000.0

    with pytest.raises(u.UnitConversionError):

        p.value = 3.0 * u.cm

    with pytest.raises(CannotConvertValueToNewUnits):

        p.unit = u.cm

    with pytest.raises(CannotConvertValueToNewUnits):

        p.unit = u.dimensionless_unscaled

    p.unit = u.MeV

    assert p.unit == u.MeV

    p.display() 
开发者ID:threeML,项目名称:astromodels,代码行数:27,代码来源:test_parameter.py

示例10: evaluate

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
def evaluate(self, x, mass, channel, sigmav, J):

        if isinstance(x, astropy_units.Quantity):

            # We need to convert to GeV
            xx = x.to(astropy_units.MeV)

        else:

            # We can assume that the input is in keV

            keVtoGeV = 1E-6

            xx = np.multiply(x, keVtoGeV)  # xm expects gamma ray energies in MeV

        xm = np.log10(np.divide(xx, mass))

        phip = 1. / (8. * np.pi) * np.power(mass, -2) * (sigmav * J)  # units of this should be 1 / cm**2
        dn = self._dn_interp((mass, xm))  # note this is unitless (dx = d(xm))
        dn[xm > 0] = 0

        return np.multiply(phip, np.divide(dn, x)) 
开发者ID:threeML,项目名称:astromodels,代码行数:24,代码来源:dm_models.py

示例11: evaluate

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
def evaluate(self, x, NH, redshift):

            if isinstance(x, astropy_units.Quantity):

                _unit = astropy_units.cm ** 2
                _y_unit = astropy_units.dimensionless_unscaled
                _x = x.value

            else:

                _unit = 1.0
                _y_unit = 1.0

                _x = x

            xsect_interp = self._cached_interp(_x * (1 + redshift))

            spec = np.exp(-NH * xsect_interp * _unit) * _y_unit

            return spec


    # TbAbs class 
开发者ID:threeML,项目名称:astromodels,代码行数:25,代码来源:apec.py

示例12: test_param_unit

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
def test_param_unit():
    with pytest.raises(ValueError):
        NDData(np.ones((5, 5)), unit="NotAValidUnit")
    NDData([1, 2, 3], unit='meter')
    # Test conflicting units (quantity as data)
    q = np.array([1, 2, 3]) * u.m
    nd = NDData(q, unit='cm')
    assert nd.unit != q.unit
    assert nd.unit == u.cm
    # (masked quantity)
    mq = np.ma.array(np.array([2, 3])*u.m, mask=False)
    nd2 = NDData(mq, unit=u.s)
    assert nd2.unit == u.s
    # (another NDData as data)
    nd3 = NDData(nd, unit='km')
    assert nd3.unit == u.km 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_nddata.py

示例13: test_init_fake_with_fake

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
def test_init_fake_with_fake(UncertClass):
    uncert = np.arange(5).reshape(5, 1)
    fake_uncert1 = UncertClass(uncert)
    fake_uncert2 = UncertClass(fake_uncert1)
    assert_array_equal(fake_uncert2.array, uncert)
    assert fake_uncert2.array is not uncert
    # Without making copies
    fake_uncert1 = UncertClass(uncert, copy=False)
    fake_uncert2 = UncertClass(fake_uncert1, copy=False)
    assert_array_equal(fake_uncert2.array, fake_uncert1.array)
    assert fake_uncert2.array is fake_uncert1.array
    # With a unit
    uncert = np.arange(5).reshape(5, 1) * u.adu
    fake_uncert1 = UncertClass(uncert)
    fake_uncert2 = UncertClass(fake_uncert1)
    assert_array_equal(fake_uncert2.array, uncert.value)
    assert fake_uncert2.array is not uncert.value
    assert fake_uncert2.unit is u.adu
    # With a unit and an explicit unit-parameter
    fake_uncert2 = UncertClass(fake_uncert1, unit=u.cm)
    assert_array_equal(fake_uncert2.array, uncert.value)
    assert fake_uncert2.array is not uncert.value
    assert fake_uncert2.unit is u.cm 
开发者ID:holzschu,项目名称:Carnets,代码行数:25,代码来源:test_nduncertainty.py

示例14: test_arithmetic_overload_differing_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import cm [as 别名]
def test_arithmetic_overload_differing_units():
    a = np.array([1, 2, 3]) * u.m
    b = np.array([1, 2, 3]) * u.cm
    ccddata = CCDData(a)

    # TODO: Could also be parametrized.
    res = ccddata.add(b)
    np.testing.assert_array_almost_equal(res.data, np.add(a, b).value)
    assert res.unit == np.add(a, b).unit

    res = ccddata.subtract(b)
    np.testing.assert_array_almost_equal(res.data, np.subtract(a, b).value)
    assert res.unit == np.subtract(a, b).unit

    res = ccddata.multiply(b)
    np.testing.assert_array_almost_equal(res.data, np.multiply(a, b).value)
    assert res.unit == np.multiply(a, b).unit

    res = ccddata.divide(b)
    np.testing.assert_array_almost_equal(res.data, np.divide(a, b).value)
    assert res.unit == np.divide(a, b).unit 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:test_ccddata.py

示例15: test_cartesian_cylindrical_roundtrip

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

    s1 = CartesianRepresentation(x=np.array([1., 2000.]) * u.kpc,
                                 y=np.array([3000., 4.]) * u.pc,
                                 z=np.array([5., 600.]) * u.cm)

    s2 = CylindricalRepresentation.from_representation(s1)

    s3 = CartesianRepresentation.from_representation(s2)

    s4 = CylindricalRepresentation.from_representation(s3)

    assert_allclose_quantity(s1.x, s3.x)
    assert_allclose_quantity(s1.y, s3.y)
    assert_allclose_quantity(s1.z, s3.z)

    assert_allclose_quantity(s2.rho, s4.rho)
    assert_allclose_quantity(s2.phi, s4.phi)
    assert_allclose_quantity(s2.z, s4.z) 
开发者ID:holzschu,项目名称:Carnets,代码行数:21,代码来源:test_representation.py


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