本文整理汇总了Python中astropy.units.second方法的典型用法代码示例。如果您正苦于以下问题:Python units.second方法的具体用法?Python units.second怎么用?Python units.second使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.units
的用法示例。
在下文中一共展示了units.second方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_KeplerLightCurveFile
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_KeplerLightCurveFile(path, mission):
lc = KeplerLightCurveFile(path, flux_column="sap_flux", quality_bitmask=None)
assert lc.obsmode == 'long cadence'
assert len(lc.pos_corr1) == len(lc.pos_corr2)
assert lc.mission.lower() == mission.lower()
if lc.mission.lower() == 'kepler':
assert lc.meta.get('campaign') is None
assert lc.quarter == 8
elif lc.mission.lower() == 'k2':
assert lc.campaign == 8
assert lc.meta.get('quarter') is None
assert lc.time.format == 'bkjd'
assert lc.time.scale == 'tdb'
assert lc.flux.unit == u.electron / u.second
# Does the data match what one would obtain using pyfits.open?
hdu = pyfits.open(path)
assert lc.label == hdu[0].header['OBJECT']
nanmask = ~np.isnan(hdu[1].data['TIME'])
assert_array_equal(lc.time.value, hdu[1].data['TIME'][nanmask])
assert_array_equal(lc.flux.value, hdu[1].data['SAP_FLUX'][nanmask])
示例2: test_TessLightCurveFile
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_TessLightCurveFile(quality_bitmask):
lc = TessLightCurveFile.read(TESS_SIM, quality_bitmask=quality_bitmask, flux_column="sap_flux")
hdu = pyfits.open(TESS_SIM)
assert lc.mission == 'TESS'
assert lc.label == hdu[0].header['OBJECT']
assert lc.time.format == 'btjd'
assert lc.time.scale == 'tdb'
assert lc.flux.unit == u.electron / u.second
assert lc.sector == hdu[0].header['SECTOR']
assert lc.camera == hdu[0].header['CAMERA']
assert lc.ccd == hdu[0].header['CCD']
assert lc.ra == hdu[0].header['RA_OBJ']
assert lc.dec == hdu[0].header['DEC_OBJ']
assert_array_equal(lc.time[0:10].value, hdu[1].data['TIME'][0:10])
assert_array_equal(lc.flux[0:10].value, hdu[1].data['SAP_FLUX'][0:10])
# Regression test for https://github.com/KeplerGO/lightkurve/pull/236
assert np.isnan(lc.time.value).sum() == 0
示例3: test_flux_unit
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_flux_unit():
"""Checks the use of lc.flux_unit and lc.flux_quantity."""
with warnings.catch_warnings(): # We deprecated `flux_unit` in v2.0
warnings.simplefilter("ignore", LightkurveDeprecationWarning)
unit_obj = u.Unit("electron/second")
# Can we set flux units using a Unit object?
time, flux = range(3), np.ones(3)
lc = LightCurve(time=time, flux=flux, flux_unit=unit_obj)
assert lc.flux.unit == unit_obj
# Can we set flux units using a string?
lc = LightCurve(time=time, flux=flux, flux_unit="electron/second")
assert lc.flux.unit == unit_obj
# Can we pass a quantity to flux?
lc = LightCurve(time=time, flux=flux*unit_obj)
assert lc.flux.unit == unit_obj
# Can we retrieve correct flux quantities?
with warnings.catch_warnings(): # flux_quantity is deprecated
warnings.simplefilter("ignore", LightkurveDeprecationWarning)
assert lc.flux_quantity.unit ==unit_obj
assert_array_equal(lc.flux_quantity.value, flux)
# Is invalid user input validated?
with pytest.raises(ValueError) as err:
lc = LightCurve(time=time, flux=flux, flux_unit="blablabla")
assert "not a valid unit" in err.value.args[0]
示例4: test_interpolate_lightcurve
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_interpolate_lightcurve():
"""Test that a lightcurve is correctly interpolated to have the
correct number of entries
"""
samples_per_frame_time = 5
frame_time = 1.
# Create simple lightcurve
light_curve = {}
light_curve['times'] = np.arange(0, 10) * u.second
light_curve['fluxes'] = np.repeat(1., len(light_curve['times'])) * FLAMBDA_CGS_UNITS
# Interpolate
interp = tso.interpolate_lightcurve(light_curve, samples_per_frame_time, frame_time)
assert len(interp['times'].value) == (10 - 1) * frame_time * (samples_per_frame_time - 1)
assert np.all(interp['times'].value[0:5] == [0, 0.25, 0.5, 0.75, 1.0])
示例5: semi_major_axis
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def semi_major_axis(P, Mtotal):
"""Semi-major axis
Kepler's third law
Args:
P (float): Orbital period [days]
Mtotal (float): Mass [Msun]
Returns:
float or array: semi-major axis in AU
"""
# convert inputs to array so they work with units
P = np.array(P)
Mtotal = np.array(Mtotal)
Mtotal = Mtotal*c.M_sun.value
P = (P * u.d).to(u.second).value
G = c.G.value
a = ((P**2)*G*Mtotal/(4*(np.pi)**2))**(1/3.)
a = a/c.au.value
return a
示例6: test_now
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_now():
"""
Tests creating a Time object with the `now` class method.
"""
now = datetime.datetime.utcnow()
t = Time.now()
assert t.format == 'datetime'
assert t.scale == 'utc'
dt = t.datetime - now # a datetime.timedelta object
# this gives a .1 second margin between the `utcnow` call and the `Time`
# initializer, which is really way more generous than necessary - typical
# times are more like microseconds. But it seems safer in case some
# platforms have slow clock calls or something.
assert dt.total_seconds() < 0.1
示例7: test_ymdhms_output
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_ymdhms_output():
t = Time({'year': 2015, 'month': 2, 'day': 3,
'hour': 12, 'minute': 13, 'second': 14.567},
scale='utc')
# NOTE: actually comes back as np.void for some reason
# NOTE: not necessarily a python int; might be an int32
assert t.ymdhms.year == 2015
# There are two stages of validation now - one on input into a format, so that
# the format conversion code has tidy matched arrays to work with, and the
# other when object construction does not go through a format object. Or at
# least, the format object is constructed with "from_jd=True". In this case the
# normal input validation does not happen but the new input validation does,
# and can ensure that strange broadcasting anomalies can't happen.
# This form of construction uses from_jd=True.
示例8: test_valid_quantity_operations1
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_valid_quantity_operations1(self):
"""Check adding/substracting/comparing a time-valued quantity works
with a TimeDelta. Addition/subtraction should give TimeDelta"""
t0 = TimeDelta(106400., format='sec')
q1 = 10.*u.second
t1 = t0 + q1
assert isinstance(t1, TimeDelta)
assert t1.value == t0.value+q1.to_value(u.second)
q2 = 1.*u.day
t2 = t0 - q2
assert isinstance(t2, TimeDelta)
assert allclose_sec(t2.value, t0.value-q2.to_value(u.second))
# now comparisons
assert t0 > q1
assert t0 < 1.*u.yr
# and broadcasting
q3 = np.arange(12.).reshape(4, 3) * u.hour
t3 = t0 + q3
assert isinstance(t3, TimeDelta)
assert t3.shape == q3.shape
assert allclose_sec(t3.value, t0.value + q3.to_value(u.second))
示例9: test_errors_on_unit_mismatch
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_errors_on_unit_mismatch(method, data):
t, y, dy = data
t = t * u.second
y = y * u.mag
frequency = np.linspace(0.5, 1.5, 10)
# this should fail because frequency and 1/t units do not match
with pytest.raises(ValueError) as err:
LombScargle(t, y, fit_mean=False).power(frequency, method=method)
assert str(err.value).startswith('Units of frequency not equivalent')
# this should fail because dy and y units do not match
with pytest.raises(ValueError) as err:
LombScargle(t, y, dy, fit_mean=False).power(frequency / t.unit)
assert str(err.value).startswith('Units of dy not equivalent')
# we don't test all normalizations here because they are tested above
# only test method='auto' because unit handling does not depend on method
示例10: test_1
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_1(self):
# create objects through operations with Unit objects:
quantity = 11.42 * u.meter # returns a Quantity object
assert isinstance(quantity, u.Quantity)
quantity = u.meter * 11.42 # returns a Quantity object
assert isinstance(quantity, u.Quantity)
quantity = 11.42 / u.meter
assert isinstance(quantity, u.Quantity)
quantity = u.meter / 11.42
assert isinstance(quantity, u.Quantity)
quantity = 11.42 * u.meter / u.second
assert isinstance(quantity, u.Quantity)
with pytest.raises(TypeError):
quantity = 182.234 + u.meter
with pytest.raises(TypeError):
quantity = 182.234 - u.meter
with pytest.raises(TypeError):
quantity = 182.234 % u.meter
示例11: test_complicated_operation
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_complicated_operation(self):
""" Perform a more complicated test """
from astropy.units import imperial
# Multiple units
distance = u.Quantity(15., u.meter)
time = u.Quantity(11., u.second)
velocity = (distance / time).to(imperial.mile / u.hour)
assert_array_almost_equal(
velocity.value, 3.05037, decimal=5)
G = u.Quantity(6.673E-11, u.m ** 3 / u.kg / u.s ** 2)
new_q = ((1. / (4. * np.pi * G)).to(u.pc ** -3 / u.s ** -2 * u.kg))
# Area
side1 = u.Quantity(11., u.centimeter)
side2 = u.Quantity(7., u.centimeter)
area = side1 * side2
assert_array_almost_equal(area.value, 77., decimal=15)
assert area.unit == u.cm * u.cm
示例12: test_quantity_comparison
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_quantity_comparison(self):
assert u.Quantity(1100, unit=u.meter) > u.Quantity(1, unit=u.kilometer)
assert u.Quantity(900, unit=u.meter) < u.Quantity(1, unit=u.kilometer)
with pytest.raises(u.UnitsError):
assert u.Quantity(1100, unit=u.meter) > u.Quantity(1, unit=u.second)
with pytest.raises(u.UnitsError):
assert u.Quantity(1100, unit=u.meter) < u.Quantity(1, unit=u.second)
assert u.Quantity(1100, unit=u.meter) >= u.Quantity(1, unit=u.kilometer)
assert u.Quantity(1000, unit=u.meter) >= u.Quantity(1, unit=u.kilometer)
assert u.Quantity(900, unit=u.meter) <= u.Quantity(1, unit=u.kilometer)
assert u.Quantity(1000, unit=u.meter) <= u.Quantity(1, unit=u.kilometer)
with pytest.raises(u.UnitsError):
assert u.Quantity(
1100, unit=u.meter) >= u.Quantity(1, unit=u.second)
with pytest.raises(u.UnitsError):
assert u.Quantity(1100, unit=u.meter) <= u.Quantity(1, unit=u.second)
assert u.Quantity(1200, unit=u.meter) != u.Quantity(1, unit=u.kilometer)
示例13: test_inverse_quantity
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_inverse_quantity():
"""
Regression test from issue #679
"""
q = u.Quantity(4., u.meter / u.second)
qot = q / 2
toq = 2 / q
npqot = q / np.array(2)
assert npqot.value == 2.0
assert npqot.unit == (u.meter / u.second)
assert qot.value == 2.0
assert qot.unit == (u.meter / u.second)
assert toq.value == 0.5
assert toq.unit == (u.second / u.meter)
示例14: test_periodogram_normalization
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_periodogram_normalization():
"""Tests the normalization options"""
lc = LightCurve(time=np.arange(1000), flux=np.random.normal(1, 0.1, 1000),
flux_err=np.zeros(1000)+0.1, flux_unit='electron/second')
# Test amplitude normalization and correct units
pg = lc.to_periodogram(normalization='amplitude')
assert pg.power.unit == u.electron / u.second
pg = lc.normalize(unit='ppm').to_periodogram(normalization='amplitude')
assert pg.power.unit == u.cds.ppm
# Test PSD normalization and correct units
pg = lc.to_periodogram(freq_unit=u.microhertz, normalization='psd')
assert pg.power.unit == (u.electron/u.second)**2 / u.microhertz
pg = lc.normalize(unit='ppm').to_periodogram(freq_unit=u.microhertz, normalization='psd')
assert pg.power.unit == u.cds.ppm**2 / u.microhertz
示例15: test_periodogram_units
# 需要导入模块: from astropy import units [as 别名]
# 或者: from astropy.units import second [as 别名]
def test_periodogram_units():
"""Tests whether periodogram has correct units"""
# Fake, noisy data
lc = LightCurve(time=np.arange(1000), flux=np.random.normal(1, 0.1, 1000),
flux_err=np.zeros(1000)+0.1, flux_unit='electron/second')
p = lc.to_periodogram(normalization='amplitude')
# Has units
assert hasattr(p.frequency, 'unit')
# Has the correct units
assert p.frequency.unit == 1./u.day
assert p.power.unit == u.electron / u.second
assert p.period.unit == u.day
assert p.frequency_at_max_power.unit == 1./u.day
assert p.max_power.unit == u.electron / u.second