up follow livre
This commit is contained in:
parent
b4b4398bb0
commit
3a7a3849ae
12242 changed files with 2564461 additions and 6914 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,78 @@
|
|||
from scipy.constants import find, value, c, speed_of_light, precision
|
||||
from numpy.testing import assert_equal, assert_, assert_almost_equal
|
||||
import scipy.constants._codata as _cd
|
||||
from scipy import constants
|
||||
|
||||
|
||||
def test_find():
|
||||
keys = find('weak mixing', disp=False)
|
||||
assert_equal(keys, ['weak mixing angle'])
|
||||
|
||||
keys = find('qwertyuiop', disp=False)
|
||||
assert_equal(keys, [])
|
||||
|
||||
keys = find('natural unit', disp=False)
|
||||
assert_equal(keys, sorted(['natural unit of velocity',
|
||||
'natural unit of action',
|
||||
'natural unit of action in eV s',
|
||||
'natural unit of mass',
|
||||
'natural unit of energy',
|
||||
'natural unit of energy in MeV',
|
||||
'natural unit of momentum',
|
||||
'natural unit of momentum in MeV/c',
|
||||
'natural unit of length',
|
||||
'natural unit of time']))
|
||||
|
||||
|
||||
def test_basic_table_parse():
|
||||
c_s = 'speed of light in vacuum'
|
||||
assert_equal(value(c_s), c)
|
||||
assert_equal(value(c_s), speed_of_light)
|
||||
|
||||
|
||||
def test_basic_lookup():
|
||||
assert_equal('{} {}'.format(int(_cd.value('speed of light in vacuum')),
|
||||
_cd.unit('speed of light in vacuum')),
|
||||
'299792458 m s^-1')
|
||||
|
||||
|
||||
def test_find_all():
|
||||
assert_(len(find(disp=False)) > 300)
|
||||
|
||||
|
||||
def test_find_single():
|
||||
assert_equal(find('Wien freq', disp=False)[0],
|
||||
'Wien frequency displacement law constant')
|
||||
|
||||
|
||||
def test_2002_vs_2006():
|
||||
assert_almost_equal(value('magn. flux quantum'),
|
||||
value('mag. flux quantum'))
|
||||
|
||||
|
||||
def test_exact_values():
|
||||
# Check that updating stored values with exact ones worked.
|
||||
exact = dict((k, v[0]) for k, v in _cd._physical_constants_2018.items())
|
||||
replace = _cd.exact2018(exact)
|
||||
for key, val in replace.items():
|
||||
assert_equal(val, value(key))
|
||||
assert precision(key) == 0
|
||||
|
||||
|
||||
def test_gh11341():
|
||||
# gh-11341 noted that these three constants should exist (for backward
|
||||
# compatibility) and should always have the same value:
|
||||
a = constants.epsilon_0
|
||||
b = constants.physical_constants['electric constant'][0]
|
||||
c = constants.physical_constants['vacuum electric permittivity'][0]
|
||||
assert a == b == c
|
||||
|
||||
|
||||
def test_gh14467():
|
||||
# gh-14467 noted that some physical constants in CODATA are rounded
|
||||
# to only ten significant figures even though they are supposed to be
|
||||
# exact. Check that (at least) the case mentioned in the issue is resolved.
|
||||
res = constants.physical_constants['Boltzmann constant in eV/K'][0]
|
||||
ref = (constants.physical_constants['Boltzmann constant'][0]
|
||||
/ constants.physical_constants['elementary charge'][0])
|
||||
assert res == ref
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
import pytest
|
||||
|
||||
import scipy.constants as sc
|
||||
from scipy._lib._array_api_no_0d import xp_assert_equal, xp_assert_close
|
||||
from scipy._lib._array_api import make_xp_test_case
|
||||
|
||||
lazy_xp_modules = [sc]
|
||||
|
||||
|
||||
@make_xp_test_case(sc.convert_temperature)
|
||||
class TestConvertTemperature:
|
||||
def test_convert_temperature(self, xp):
|
||||
xp_assert_equal(sc.convert_temperature(xp.asarray(32.), 'f', 'Celsius'),
|
||||
xp.asarray(0.0))
|
||||
xp_assert_equal(sc.convert_temperature(xp.asarray([0., 0.]),
|
||||
'celsius', 'Kelvin'),
|
||||
xp.asarray([273.15, 273.15]))
|
||||
xp_assert_equal(sc.convert_temperature(xp.asarray([0., 0.]), 'kelvin', 'c'),
|
||||
xp.asarray([-273.15, -273.15]))
|
||||
xp_assert_equal(sc.convert_temperature(xp.asarray([32., 32.]), 'f', 'k'),
|
||||
xp.asarray([273.15, 273.15]))
|
||||
xp_assert_equal(sc.convert_temperature(xp.asarray([273.15, 273.15]),
|
||||
'kelvin', 'F'),
|
||||
xp.asarray([32., 32.]))
|
||||
xp_assert_equal(sc.convert_temperature(xp.asarray([0., 0.]), 'C', 'fahrenheit'),
|
||||
xp.asarray([32., 32.]))
|
||||
xp_assert_close(sc.convert_temperature(xp.asarray([0., 0.], dtype=xp.float64),
|
||||
'c', 'r'),
|
||||
xp.asarray([491.67, 491.67], dtype=xp.float64),
|
||||
rtol=0., atol=1e-13)
|
||||
xp_assert_close(sc.convert_temperature(xp.asarray([491.67, 491.67],
|
||||
dtype=xp.float64),
|
||||
'Rankine', 'C'),
|
||||
xp.asarray([0., 0.], dtype=xp.float64), rtol=0., atol=1e-13)
|
||||
xp_assert_close(sc.convert_temperature(xp.asarray([491.67, 491.67],
|
||||
dtype=xp.float64),
|
||||
'r', 'F'),
|
||||
xp.asarray([32., 32.], dtype=xp.float64), rtol=0., atol=1e-13)
|
||||
xp_assert_close(sc.convert_temperature(xp.asarray([32., 32.], dtype=xp.float64),
|
||||
'fahrenheit', 'R'),
|
||||
xp.asarray([491.67, 491.67], dtype=xp.float64),
|
||||
rtol=0., atol=1e-13)
|
||||
xp_assert_close(sc.convert_temperature(xp.asarray([273.15, 273.15],
|
||||
dtype=xp.float64),
|
||||
'K', 'R'),
|
||||
xp.asarray([491.67, 491.67], dtype=xp.float64),
|
||||
rtol=0., atol=1e-13)
|
||||
xp_assert_close(sc.convert_temperature(xp.asarray([491.67, 0.],
|
||||
dtype=xp.float64),
|
||||
'rankine', 'kelvin'),
|
||||
xp.asarray([273.15, 0.], dtype=xp.float64), rtol=0., atol=1e-13)
|
||||
|
||||
def test_convert_temperature_array_like(self):
|
||||
xp_assert_close(sc.convert_temperature([491.67, 0.], 'rankine', 'kelvin'),
|
||||
[273.15, 0.], rtol=0., atol=1e-13)
|
||||
|
||||
|
||||
def test_convert_temperature_errors(self):
|
||||
with pytest.raises(NotImplementedError, match="old_scale="):
|
||||
sc.convert_temperature(1, old_scale="cheddar", new_scale="kelvin")
|
||||
with pytest.raises(NotImplementedError, match="new_scale="):
|
||||
sc.convert_temperature(1, old_scale="kelvin", new_scale="brie")
|
||||
|
||||
|
||||
@make_xp_test_case(sc.lambda2nu)
|
||||
class TestLambdaToNu:
|
||||
def test_lambda_to_nu(self, xp):
|
||||
xp_assert_equal(sc.lambda2nu(xp.asarray([sc.speed_of_light, 1])),
|
||||
xp.asarray([1, sc.speed_of_light]))
|
||||
|
||||
|
||||
def test_lambda_to_nu_array_like(self):
|
||||
xp_assert_close(sc.lambda2nu([sc.speed_of_light, 1]), [1, sc.speed_of_light])
|
||||
|
||||
|
||||
@make_xp_test_case(sc.nu2lambda)
|
||||
class TestNuToLambda:
|
||||
def test_nu_to_lambda(self, xp):
|
||||
xp_assert_equal(sc.nu2lambda(xp.asarray([sc.speed_of_light, 1])),
|
||||
xp.asarray([1, sc.speed_of_light]))
|
||||
|
||||
def test_nu_to_lambda_array_like(self):
|
||||
xp_assert_close(sc.nu2lambda([sc.speed_of_light, 1]), [1, sc.speed_of_light])
|
||||
Loading…
Add table
Add a link
Reference in a new issue