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


Python units.Hz方法代码示例

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


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

示例1: test_stream_template

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def test_stream_template(self, tmpdir):
        template = str(tmpdir.join('{x2_0_64:03d}_{file_nr:02d}.bare'))
        header0 = BareHeader.fromvalues()
        with self.open(template, 'ws', header0=header0,
                       sample_rate=10*u.Hz) as fw:
            assert isinstance(fw, BareStreamWriter)
            assert isinstance(fw.fh_raw, sf.SequentialFileWriter)
            assert isinstance(fw.fh_raw.files, sf.FileNameSequencer)
            assert fw.fh_raw.files[0].endswith('001_00.bare')

        with self.open(template, 'w', x2_0_64=4,
                       sample_rate=10*u.Hz, parrot='life') as fw:
            assert fw.fh_raw.files[0].endswith('004_00.bare')

        with pytest.raises(TypeError):
            self.open(template, 'ws', coocoo=10,
                      sample_rate=10*u.Hz) 
开发者ID:mhvk,项目名称:baseband,代码行数:19,代码来源:test_opener.py

示例2: get_frame_rate

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def get_frame_rate(self):
        """Determine the number of frames per second.

        This method first tries to determine the frame rate by looking for
        the highest frame number in the first second of data.  If that fails,
        it attempts to extract the sample rate from the header.

        Returns
        -------
        frame_rate : `~astropy.units.Quantity`
            Frames per second.
        """
        try:
            return super().get_frame_rate()
        except Exception as exc:
            with self.temporary_offset(0):
                try:
                    header = self.read_header()
                    return (header.sample_rate
                            / header.samples_per_frame).to(u.Hz).round()
                except Exception:
                    pass
            raise exc 
开发者ID:mhvk,项目名称:baseband,代码行数:25,代码来源:base.py

示例3: test_timestamp_io

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def test_timestamp_io(self, tmpdir, sample):
        """Tests GSBTimeStampIO in base.py."""
        with open(sample, 'rt') as fh:
            header0 = gsb.GSBHeader.fromfile(fh, verify=True)

        with gsb.open(sample, 'rt') as fh:
            header1 = fh.read_timestamp()
            assert header1 == header0
            current_pos = fh.tell()
            frame_rate = fh.get_frame_rate()
            assert abs(frame_rate - u.Hz / 0.251658240) < 1. * u.nHz
            assert fh.tell() == current_pos

        testfile = str(tmpdir.join('test.timestamp'))
        with gsb.open(testfile, 'wt') as fw:
            fw.write_timestamp(header=header1)
        with gsb.open(testfile, 'rt') as fh:
            header2 = fh.read_timestamp()
            assert header2 == header1

        # Check that extra arguments raise TypeError.
        with pytest.raises(TypeError):
            gsb.open(testfile, 'rt', raw='bla') 
开发者ID:mhvk,项目名称:baseband,代码行数:25,代码来源:test_gsb.py

示例4: test_partial_last_frame

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def test_partial_last_frame(self, tmpdir):
        """Test reading a file with an incomplete last frame."""
        # Read in sample file as a byte stream.
        with guppi.open(SAMPLE_FILE, 'rb') as fh:
            puppi_raw = fh.read()

        # Try reading a file with an incomplete payload.
        with guppi.open(str(tmpdir.join('puppi_partframe.raw')), 'wb') as fw:
            fw.write(puppi_raw[:len(puppi_raw) - 6091])
        nsample = 3*1024 - 2*64  # 3 frames minus 2 overlaps
        with guppi.open(str(tmpdir.join('puppi_partframe.raw')), 'rs') as fn:
            assert fn.shape == (nsample, 2, 4)
            assert np.abs(fn.stop_time
                          - fn.start_time - nsample / (250 * u.Hz)) < 1. * u.ns

        # Try reading a file with an incomplete header.
        with guppi.open(str(tmpdir.join('puppi_partframe.raw')), 'wb') as fw:
            fw.write(puppi_raw[:len(puppi_raw) - 17605])
        with guppi.open(str(tmpdir.join('puppi_partframe.raw')), 'rs') as fn:
            assert fn.shape == (nsample, 2, 4)
            assert np.abs(fn.stop_time
                          - fn.start_time - nsample / (250 * u.Hz)) < 1. * u.ns 
开发者ID:mhvk,项目名称:baseband,代码行数:24,代码来源:test_guppi.py

示例5: get_frame_rate

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def get_frame_rate(self):
        """Determine the number of frames per second.

        The frame rate is calculated from the time elapsed between the
        first two frames, as inferred from their time stamps.

        Returns
        -------
        frame_rate : `~astropy.units.Quantity`
            Frames per second.
        """
        with self.temporary_offset(0):
            header0 = self.find_header()
            self.seek(header0.frame_nbytes, 1)
            header1 = self.read_header()

        # Mark 4 specification states frames-lengths range from 1.25 ms
        # to 160 ms.
        tdelta = (header1.fraction[0] - header0.fraction[0]) % 1.
        return u.Quantity(1 / tdelta, u.Hz).round() 
开发者ID:mhvk,项目名称:baseband,代码行数:22,代码来源:base.py

示例6: __init__

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def __init__(self, frequency, power, nyquist=None, label=None,
                 targetid=None, default_view='frequency', meta={}):
        # Input validation
        if not isinstance(frequency, u.quantity.Quantity):
            raise ValueError('frequency must be an `astropy.units.Quantity` object.')
        if not isinstance(power, u.quantity.Quantity):
            raise ValueError('power must be an `astropy.units.Quantity` object.')
        # Frequency must have frequency units
        try:
            frequency.to(u.Hz)
        except u.UnitConversionError:
            raise ValueError('Frequency must be in units of 1/time.')
        # Frequency and power must have sensible shapes
        if frequency.shape[0] <= 1:
            raise ValueError('frequency and power must have a length greater than 1.')
        if frequency.shape != power.shape:
            raise ValueError('frequency and power must have the same length.')

        self.frequency = frequency
        self.power = power
        self.nyquist = nyquist
        self.label = label
        self.targetid = targetid
        self.default_view = self._validate_view(default_view)
        self.meta = meta 
开发者ID:KeplerGO,项目名称:lightkurve,代码行数:27,代码来源:periodogram.py

示例7: test_compound_without_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def test_compound_without_units(model):
    x = np.linspace(-5, 5, 10) * u.Angstrom
    with NumpyRNGContext(12345):
        y = np.random.sample(10)

    fitter = fitting.LevMarLSQFitter()
    res_fit = fitter(model, x, y * u.Hz)
    for param_name in res_fit.param_names:
        print(getattr(res_fit, param_name))
    assert all([res_fit[i]._has_units for i in range(3)])
    z = res_fit(x)
    assert isinstance(z, u.Quantity)

    res_fit = fitter(model, np.arange(10) * u.Unit('Angstrom'), y)
    assert all([res_fit[i]._has_units for i in range(3)])
    z = res_fit(x)
    assert isinstance(z, np.ndarray) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_quantities_fitting.py

示例8: test_compound_fitting_with_units

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def test_compound_fitting_with_units():
    x = np.linspace(-5, 5, 15) * u.Angstrom
    y = np.linspace(-5, 5, 15) * u.Angstrom

    fitter = fitting.LevMarLSQFitter()
    m = models.Gaussian2D(10*u.Hz,
                          3*u.Angstrom, 4*u.Angstrom,
                          1*u.Angstrom, 2*u.Angstrom)
    p = models.Planar2D(3*u.Hz/u.Angstrom, 4*u.Hz/u.Angstrom, 1*u.Hz)
    model = m + p

    z = model(x, y)
    res = fitter(model, x, y, z)
    assert isinstance(res(x, y), np.ndarray)
    assert all([res[i]._has_units for i in range(2)])

    model = models.Gaussian2D() + models.Planar2D()
    res = fitter(model, x, y, z)
    assert isinstance(res(x, y), np.ndarray)
    assert all([res[i]._has_units for i in range(2)]) 
开发者ID:holzschu,项目名称:Carnets,代码行数:22,代码来源:test_quantities_fitting.py

示例9: test_quantity_conversion_with_equiv

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def test_quantity_conversion_with_equiv():
    q1 = u.Quantity(0.1, unit=u.meter)
    v2 = q1.to_value(u.Hz, equivalencies=u.spectral())
    assert_allclose(v2, 2997924580.0)
    q2 = q1.to(u.Hz, equivalencies=u.spectral())
    assert_allclose(q2.value, v2)

    q1 = u.Quantity(0.4, unit=u.arcsecond)
    v2 = q1.to_value(u.au, equivalencies=u.parallax())
    q2 = q1.to(u.au, equivalencies=u.parallax())
    v3 = q2.to_value(u.arcminute, equivalencies=u.parallax())
    q3 = q2.to(u.arcminute, equivalencies=u.parallax())

    assert_allclose(v2, 515662.015)
    assert_allclose(q2.value, v2)
    assert q2.unit == u.au
    assert_allclose(v3, 0.0066666667)
    assert_allclose(q3.value, v3)
    assert q3.unit == u.arcminute 
开发者ID:holzschu,项目名称:Carnets,代码行数:21,代码来源:test_quantity.py

示例10: test_quantity_conversion_equivalency_passed_on

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def test_quantity_conversion_equivalency_passed_on():
    class MySpectral(u.Quantity):
        _equivalencies = u.spectral()

        def __quantity_view__(self, obj, unit):
            return obj.view(MySpectral)

        def __quantity_instance__(self, *args, **kwargs):
            return MySpectral(*args, **kwargs)

    q1 = MySpectral([1000, 2000], unit=u.Hz)
    q2 = q1.to(u.nm)
    assert q2.unit == u.nm
    q3 = q2.to(u.Hz)
    assert q3.unit == u.Hz
    assert_allclose(q3.value, q1.value)
    q4 = MySpectral([1000, 2000], unit=u.nm)
    q5 = q4.to(u.Hz).to(u.nm)
    assert q5.unit == u.nm
    assert_allclose(q4.value, q5.value)

# Regression test for issue #2315, divide-by-zero error when examining 0*unit 
开发者ID:holzschu,项目名称:Carnets,代码行数:24,代码来源:test_quantity.py

示例11: test_is_equivalent

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def test_is_equivalent():
    assert u.m.is_equivalent(u.pc)
    assert u.cycle.is_equivalent(u.mas)
    assert not u.cycle.is_equivalent(u.dimensionless_unscaled)
    assert u.cycle.is_equivalent(u.dimensionless_unscaled,
                                 u.dimensionless_angles())
    assert not (u.Hz.is_equivalent(u.J))
    assert u.Hz.is_equivalent(u.J, u.spectral())
    assert u.J.is_equivalent(u.Hz, u.spectral())
    assert u.pc.is_equivalent(u.arcsecond, u.parallax())
    assert u.arcminute.is_equivalent(u.au, u.parallax())

    # Pass a tuple for multiple possibilities
    assert u.cm.is_equivalent((u.m, u.s, u.kg))
    assert u.ms.is_equivalent((u.m, u.s, u.kg))
    assert u.g.is_equivalent((u.m, u.s, u.kg))
    assert not u.L.is_equivalent((u.m, u.s, u.kg))
    assert not (u.km / u.s).is_equivalent((u.m, u.s, u.kg)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:20,代码来源:test_equivalencies.py

示例12: test_spectraldensity2

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
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) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_equivalencies.py

示例13: test_equivalent_units2

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

示例14: get_equivalencies

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [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

示例15: __init__

# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import Hz [as 别名]
def __init__(self, fh_raw, header0, *, squeeze=True, **kwargs):
        # Required arguments.
        self.fh_raw = fh_raw
        self._header0 = header0
        # Arguments with defaults.
        self._squeeze = bool(squeeze)
        # Arguments that can override or complement information from header.
        for attr, getter in [
                ('bps', operator.index),
                ('complex_data', bool),
                ('samples_per_frame', operator.index),
                ('sample_shape', tuple),
                ('sample_rate', None)]:
            value = kwargs.pop(attr, None)
            if value is None:
                value = getattr(header0, attr, None)
            if getter is not None and value is not None:
                value = getter(value)
            setattr(self, '_'+attr, value)

        if kwargs:
            raise TypeError('got unexpected keyword(s): {}'
                            .format(', '.join(kwargs.keys())))
        # Pre-calculate.
        self._frame_rate = (self.sample_rate / self.samples_per_frame).to(u.Hz)
        # Initialize.
        self.offset = 0
        # Ensure that we have a sample_shape.
        self.sample_shape 
开发者ID:mhvk,项目名称:baseband,代码行数:31,代码来源:base.py


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