Fixed database typo and removed unnecessary class identifier.
This commit is contained in:
parent
00ad49a143
commit
45fb349a7d
5098 changed files with 952558 additions and 85 deletions
338
venv/Lib/site-packages/scipy/constants/__init__.py
Normal file
338
venv/Lib/site-packages/scipy/constants/__init__.py
Normal file
|
@ -0,0 +1,338 @@
|
|||
r"""
|
||||
==================================
|
||||
Constants (:mod:`scipy.constants`)
|
||||
==================================
|
||||
|
||||
.. currentmodule:: scipy.constants
|
||||
|
||||
Physical and mathematical constants and units.
|
||||
|
||||
|
||||
Mathematical constants
|
||||
======================
|
||||
|
||||
================ =================================================================
|
||||
``pi`` Pi
|
||||
``golden`` Golden ratio
|
||||
``golden_ratio`` Golden ratio
|
||||
================ =================================================================
|
||||
|
||||
|
||||
Physical constants
|
||||
==================
|
||||
|
||||
=========================== =================================================================
|
||||
``c`` speed of light in vacuum
|
||||
``speed_of_light`` speed of light in vacuum
|
||||
``mu_0`` the magnetic constant :math:`\mu_0`
|
||||
``epsilon_0`` the electric constant (vacuum permittivity), :math:`\epsilon_0`
|
||||
``h`` the Planck constant :math:`h`
|
||||
``Planck`` the Planck constant :math:`h`
|
||||
``hbar`` :math:`\hbar = h/(2\pi)`
|
||||
``G`` Newtonian constant of gravitation
|
||||
``gravitational_constant`` Newtonian constant of gravitation
|
||||
``g`` standard acceleration of gravity
|
||||
``e`` elementary charge
|
||||
``elementary_charge`` elementary charge
|
||||
``R`` molar gas constant
|
||||
``gas_constant`` molar gas constant
|
||||
``alpha`` fine-structure constant
|
||||
``fine_structure`` fine-structure constant
|
||||
``N_A`` Avogadro constant
|
||||
``Avogadro`` Avogadro constant
|
||||
``k`` Boltzmann constant
|
||||
``Boltzmann`` Boltzmann constant
|
||||
``sigma`` Stefan-Boltzmann constant :math:`\sigma`
|
||||
``Stefan_Boltzmann`` Stefan-Boltzmann constant :math:`\sigma`
|
||||
``Wien`` Wien displacement law constant
|
||||
``Rydberg`` Rydberg constant
|
||||
``m_e`` electron mass
|
||||
``electron_mass`` electron mass
|
||||
``m_p`` proton mass
|
||||
``proton_mass`` proton mass
|
||||
``m_n`` neutron mass
|
||||
``neutron_mass`` neutron mass
|
||||
=========================== =================================================================
|
||||
|
||||
|
||||
Constants database
|
||||
------------------
|
||||
|
||||
In addition to the above variables, :mod:`scipy.constants` also contains the
|
||||
2018 CODATA recommended values [CODATA2018]_ database containing more physical
|
||||
constants.
|
||||
|
||||
.. autosummary::
|
||||
:toctree: generated/
|
||||
|
||||
value -- Value in physical_constants indexed by key
|
||||
unit -- Unit in physical_constants indexed by key
|
||||
precision -- Relative precision in physical_constants indexed by key
|
||||
find -- Return list of physical_constant keys with a given string
|
||||
ConstantWarning -- Constant sought not in newest CODATA data set
|
||||
|
||||
.. data:: physical_constants
|
||||
|
||||
Dictionary of physical constants, of the format
|
||||
``physical_constants[name] = (value, unit, uncertainty)``.
|
||||
|
||||
Available constants:
|
||||
|
||||
====================================================================== ====
|
||||
%(constant_names)s
|
||||
====================================================================== ====
|
||||
|
||||
|
||||
Units
|
||||
=====
|
||||
|
||||
SI prefixes
|
||||
-----------
|
||||
|
||||
============ =================================================================
|
||||
``yotta`` :math:`10^{24}`
|
||||
``zetta`` :math:`10^{21}`
|
||||
``exa`` :math:`10^{18}`
|
||||
``peta`` :math:`10^{15}`
|
||||
``tera`` :math:`10^{12}`
|
||||
``giga`` :math:`10^{9}`
|
||||
``mega`` :math:`10^{6}`
|
||||
``kilo`` :math:`10^{3}`
|
||||
``hecto`` :math:`10^{2}`
|
||||
``deka`` :math:`10^{1}`
|
||||
``deci`` :math:`10^{-1}`
|
||||
``centi`` :math:`10^{-2}`
|
||||
``milli`` :math:`10^{-3}`
|
||||
``micro`` :math:`10^{-6}`
|
||||
``nano`` :math:`10^{-9}`
|
||||
``pico`` :math:`10^{-12}`
|
||||
``femto`` :math:`10^{-15}`
|
||||
``atto`` :math:`10^{-18}`
|
||||
``zepto`` :math:`10^{-21}`
|
||||
============ =================================================================
|
||||
|
||||
Binary prefixes
|
||||
---------------
|
||||
|
||||
============ =================================================================
|
||||
``kibi`` :math:`2^{10}`
|
||||
``mebi`` :math:`2^{20}`
|
||||
``gibi`` :math:`2^{30}`
|
||||
``tebi`` :math:`2^{40}`
|
||||
``pebi`` :math:`2^{50}`
|
||||
``exbi`` :math:`2^{60}`
|
||||
``zebi`` :math:`2^{70}`
|
||||
``yobi`` :math:`2^{80}`
|
||||
============ =================================================================
|
||||
|
||||
Mass
|
||||
----
|
||||
|
||||
================= ============================================================
|
||||
``gram`` :math:`10^{-3}` kg
|
||||
``metric_ton`` :math:`10^{3}` kg
|
||||
``grain`` one grain in kg
|
||||
``lb`` one pound (avoirdupous) in kg
|
||||
``pound`` one pound (avoirdupous) in kg
|
||||
``blob`` one inch version of a slug in kg (added in 1.0.0)
|
||||
``slinch`` one inch version of a slug in kg (added in 1.0.0)
|
||||
``slug`` one slug in kg (added in 1.0.0)
|
||||
``oz`` one ounce in kg
|
||||
``ounce`` one ounce in kg
|
||||
``stone`` one stone in kg
|
||||
``grain`` one grain in kg
|
||||
``long_ton`` one long ton in kg
|
||||
``short_ton`` one short ton in kg
|
||||
``troy_ounce`` one Troy ounce in kg
|
||||
``troy_pound`` one Troy pound in kg
|
||||
``carat`` one carat in kg
|
||||
``m_u`` atomic mass constant (in kg)
|
||||
``u`` atomic mass constant (in kg)
|
||||
``atomic_mass`` atomic mass constant (in kg)
|
||||
================= ============================================================
|
||||
|
||||
Angle
|
||||
-----
|
||||
|
||||
================= ============================================================
|
||||
``degree`` degree in radians
|
||||
``arcmin`` arc minute in radians
|
||||
``arcminute`` arc minute in radians
|
||||
``arcsec`` arc second in radians
|
||||
``arcsecond`` arc second in radians
|
||||
================= ============================================================
|
||||
|
||||
|
||||
Time
|
||||
----
|
||||
|
||||
================= ============================================================
|
||||
``minute`` one minute in seconds
|
||||
``hour`` one hour in seconds
|
||||
``day`` one day in seconds
|
||||
``week`` one week in seconds
|
||||
``year`` one year (365 days) in seconds
|
||||
``Julian_year`` one Julian year (365.25 days) in seconds
|
||||
================= ============================================================
|
||||
|
||||
|
||||
Length
|
||||
------
|
||||
|
||||
===================== ============================================================
|
||||
``inch`` one inch in meters
|
||||
``foot`` one foot in meters
|
||||
``yard`` one yard in meters
|
||||
``mile`` one mile in meters
|
||||
``mil`` one mil in meters
|
||||
``pt`` one point in meters
|
||||
``point`` one point in meters
|
||||
``survey_foot`` one survey foot in meters
|
||||
``survey_mile`` one survey mile in meters
|
||||
``nautical_mile`` one nautical mile in meters
|
||||
``fermi`` one Fermi in meters
|
||||
``angstrom`` one Angstrom in meters
|
||||
``micron`` one micron in meters
|
||||
``au`` one astronomical unit in meters
|
||||
``astronomical_unit`` one astronomical unit in meters
|
||||
``light_year`` one light year in meters
|
||||
``parsec`` one parsec in meters
|
||||
===================== ============================================================
|
||||
|
||||
Pressure
|
||||
--------
|
||||
|
||||
================= ============================================================
|
||||
``atm`` standard atmosphere in pascals
|
||||
``atmosphere`` standard atmosphere in pascals
|
||||
``bar`` one bar in pascals
|
||||
``torr`` one torr (mmHg) in pascals
|
||||
``mmHg`` one torr (mmHg) in pascals
|
||||
``psi`` one psi in pascals
|
||||
================= ============================================================
|
||||
|
||||
Area
|
||||
----
|
||||
|
||||
================= ============================================================
|
||||
``hectare`` one hectare in square meters
|
||||
``acre`` one acre in square meters
|
||||
================= ============================================================
|
||||
|
||||
|
||||
Volume
|
||||
------
|
||||
|
||||
=================== ========================================================
|
||||
``liter`` one liter in cubic meters
|
||||
``litre`` one liter in cubic meters
|
||||
``gallon`` one gallon (US) in cubic meters
|
||||
``gallon_US`` one gallon (US) in cubic meters
|
||||
``gallon_imp`` one gallon (UK) in cubic meters
|
||||
``fluid_ounce`` one fluid ounce (US) in cubic meters
|
||||
``fluid_ounce_US`` one fluid ounce (US) in cubic meters
|
||||
``fluid_ounce_imp`` one fluid ounce (UK) in cubic meters
|
||||
``bbl`` one barrel in cubic meters
|
||||
``barrel`` one barrel in cubic meters
|
||||
=================== ========================================================
|
||||
|
||||
Speed
|
||||
-----
|
||||
|
||||
================== ==========================================================
|
||||
``kmh`` kilometers per hour in meters per second
|
||||
``mph`` miles per hour in meters per second
|
||||
``mach`` one Mach (approx., at 15 C, 1 atm) in meters per second
|
||||
``speed_of_sound`` one Mach (approx., at 15 C, 1 atm) in meters per second
|
||||
``knot`` one knot in meters per second
|
||||
================== ==========================================================
|
||||
|
||||
|
||||
Temperature
|
||||
-----------
|
||||
|
||||
===================== =======================================================
|
||||
``zero_Celsius`` zero of Celsius scale in Kelvin
|
||||
``degree_Fahrenheit`` one Fahrenheit (only differences) in Kelvins
|
||||
===================== =======================================================
|
||||
|
||||
.. autosummary::
|
||||
:toctree: generated/
|
||||
|
||||
convert_temperature
|
||||
|
||||
Energy
|
||||
------
|
||||
|
||||
==================== =======================================================
|
||||
``eV`` one electron volt in Joules
|
||||
``electron_volt`` one electron volt in Joules
|
||||
``calorie`` one calorie (thermochemical) in Joules
|
||||
``calorie_th`` one calorie (thermochemical) in Joules
|
||||
``calorie_IT`` one calorie (International Steam Table calorie, 1956) in Joules
|
||||
``erg`` one erg in Joules
|
||||
``Btu`` one British thermal unit (International Steam Table) in Joules
|
||||
``Btu_IT`` one British thermal unit (International Steam Table) in Joules
|
||||
``Btu_th`` one British thermal unit (thermochemical) in Joules
|
||||
``ton_TNT`` one ton of TNT in Joules
|
||||
==================== =======================================================
|
||||
|
||||
Power
|
||||
-----
|
||||
|
||||
==================== =======================================================
|
||||
``hp`` one horsepower in watts
|
||||
``horsepower`` one horsepower in watts
|
||||
==================== =======================================================
|
||||
|
||||
Force
|
||||
-----
|
||||
|
||||
==================== =======================================================
|
||||
``dyn`` one dyne in newtons
|
||||
``dyne`` one dyne in newtons
|
||||
``lbf`` one pound force in newtons
|
||||
``pound_force`` one pound force in newtons
|
||||
``kgf`` one kilogram force in newtons
|
||||
``kilogram_force`` one kilogram force in newtons
|
||||
==================== =======================================================
|
||||
|
||||
Optics
|
||||
------
|
||||
|
||||
.. autosummary::
|
||||
:toctree: generated/
|
||||
|
||||
lambda2nu
|
||||
nu2lambda
|
||||
|
||||
References
|
||||
==========
|
||||
|
||||
.. [CODATA2018] CODATA Recommended Values of the Fundamental
|
||||
Physical Constants 2018.
|
||||
|
||||
https://physics.nist.gov/cuu/Constants/
|
||||
|
||||
"""
|
||||
# Modules contributed by BasSw (wegwerp@gmail.com)
|
||||
from .codata import *
|
||||
from .constants import *
|
||||
from .codata import _obsolete_constants
|
||||
|
||||
_constant_names = [(_k.lower(), _k, _v)
|
||||
for _k, _v in physical_constants.items()
|
||||
if _k not in _obsolete_constants]
|
||||
_constant_names = "\n".join(["``%s``%s %s %s" % (_x[1], " "*(66-len(_x[1])),
|
||||
_x[2][0], _x[2][1])
|
||||
for _x in sorted(_constant_names)])
|
||||
if __doc__:
|
||||
__doc__ = __doc__ % dict(constant_names=_constant_names)
|
||||
|
||||
del _constant_names
|
||||
|
||||
__all__ = [s for s in dir() if not s.startswith('_')]
|
||||
|
||||
from scipy._lib._testutils import PytestTester
|
||||
test = PytestTester(__name__)
|
||||
del PytestTester
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1754
venv/Lib/site-packages/scipy/constants/codata.py
Normal file
1754
venv/Lib/site-packages/scipy/constants/codata.py
Normal file
File diff suppressed because it is too large
Load diff
305
venv/Lib/site-packages/scipy/constants/constants.py
Normal file
305
venv/Lib/site-packages/scipy/constants/constants.py
Normal file
|
@ -0,0 +1,305 @@
|
|||
"""
|
||||
Collection of physical constants and conversion factors.
|
||||
|
||||
Most constants are in SI units, so you can do
|
||||
print '10 mile per minute is', 10*mile/minute, 'm/s or', 10*mile/(minute*knot), 'knots'
|
||||
|
||||
The list is not meant to be comprehensive, but just convenient for everyday use.
|
||||
"""
|
||||
"""
|
||||
BasSw 2006
|
||||
physical constants: imported from CODATA
|
||||
unit conversion: see e.g., NIST special publication 811
|
||||
Use at own risk: double-check values before calculating your Mars orbit-insertion burn.
|
||||
Some constants exist in a few variants, which are marked with suffixes.
|
||||
The ones without any suffix should be the most common ones.
|
||||
"""
|
||||
|
||||
import math as _math
|
||||
from .codata import value as _cd
|
||||
import numpy as _np
|
||||
|
||||
# mathematical constants
|
||||
pi = _math.pi
|
||||
golden = golden_ratio = (1 + _math.sqrt(5)) / 2
|
||||
|
||||
# SI prefixes
|
||||
yotta = 1e24
|
||||
zetta = 1e21
|
||||
exa = 1e18
|
||||
peta = 1e15
|
||||
tera = 1e12
|
||||
giga = 1e9
|
||||
mega = 1e6
|
||||
kilo = 1e3
|
||||
hecto = 1e2
|
||||
deka = 1e1
|
||||
deci = 1e-1
|
||||
centi = 1e-2
|
||||
milli = 1e-3
|
||||
micro = 1e-6
|
||||
nano = 1e-9
|
||||
pico = 1e-12
|
||||
femto = 1e-15
|
||||
atto = 1e-18
|
||||
zepto = 1e-21
|
||||
|
||||
# binary prefixes
|
||||
kibi = 2**10
|
||||
mebi = 2**20
|
||||
gibi = 2**30
|
||||
tebi = 2**40
|
||||
pebi = 2**50
|
||||
exbi = 2**60
|
||||
zebi = 2**70
|
||||
yobi = 2**80
|
||||
|
||||
# physical constants
|
||||
c = speed_of_light = _cd('speed of light in vacuum')
|
||||
mu_0 = _cd('vacuum mag. permeability')
|
||||
epsilon_0 = _cd('vacuum electric permittivity')
|
||||
h = Planck = _cd('Planck constant')
|
||||
hbar = h / (2 * pi)
|
||||
G = gravitational_constant = _cd('Newtonian constant of gravitation')
|
||||
g = _cd('standard acceleration of gravity')
|
||||
e = elementary_charge = _cd('elementary charge')
|
||||
R = gas_constant = _cd('molar gas constant')
|
||||
alpha = fine_structure = _cd('fine-structure constant')
|
||||
N_A = Avogadro = _cd('Avogadro constant')
|
||||
k = Boltzmann = _cd('Boltzmann constant')
|
||||
sigma = Stefan_Boltzmann = _cd('Stefan-Boltzmann constant')
|
||||
Wien = _cd('Wien wavelength displacement law constant')
|
||||
Rydberg = _cd('Rydberg constant')
|
||||
|
||||
# mass in kg
|
||||
gram = 1e-3
|
||||
metric_ton = 1e3
|
||||
grain = 64.79891e-6
|
||||
lb = pound = 7000 * grain # avoirdupois
|
||||
blob = slinch = pound * g / 0.0254 # lbf*s**2/in (added in 1.0.0)
|
||||
slug = blob / 12 # lbf*s**2/foot (added in 1.0.0)
|
||||
oz = ounce = pound / 16
|
||||
stone = 14 * pound
|
||||
long_ton = 2240 * pound
|
||||
short_ton = 2000 * pound
|
||||
|
||||
troy_ounce = 480 * grain # only for metals / gems
|
||||
troy_pound = 12 * troy_ounce
|
||||
carat = 200e-6
|
||||
|
||||
m_e = electron_mass = _cd('electron mass')
|
||||
m_p = proton_mass = _cd('proton mass')
|
||||
m_n = neutron_mass = _cd('neutron mass')
|
||||
m_u = u = atomic_mass = _cd('atomic mass constant')
|
||||
|
||||
# angle in rad
|
||||
degree = pi / 180
|
||||
arcmin = arcminute = degree / 60
|
||||
arcsec = arcsecond = arcmin / 60
|
||||
|
||||
# time in second
|
||||
minute = 60.0
|
||||
hour = 60 * minute
|
||||
day = 24 * hour
|
||||
week = 7 * day
|
||||
year = 365 * day
|
||||
Julian_year = 365.25 * day
|
||||
|
||||
# length in meter
|
||||
inch = 0.0254
|
||||
foot = 12 * inch
|
||||
yard = 3 * foot
|
||||
mile = 1760 * yard
|
||||
mil = inch / 1000
|
||||
pt = point = inch / 72 # typography
|
||||
survey_foot = 1200.0 / 3937
|
||||
survey_mile = 5280 * survey_foot
|
||||
nautical_mile = 1852.0
|
||||
fermi = 1e-15
|
||||
angstrom = 1e-10
|
||||
micron = 1e-6
|
||||
au = astronomical_unit = 149597870700.0
|
||||
light_year = Julian_year * c
|
||||
parsec = au / arcsec
|
||||
|
||||
# pressure in pascal
|
||||
atm = atmosphere = _cd('standard atmosphere')
|
||||
bar = 1e5
|
||||
torr = mmHg = atm / 760
|
||||
psi = pound * g / (inch * inch)
|
||||
|
||||
# area in meter**2
|
||||
hectare = 1e4
|
||||
acre = 43560 * foot**2
|
||||
|
||||
# volume in meter**3
|
||||
litre = liter = 1e-3
|
||||
gallon = gallon_US = 231 * inch**3 # US
|
||||
# pint = gallon_US / 8
|
||||
fluid_ounce = fluid_ounce_US = gallon_US / 128
|
||||
bbl = barrel = 42 * gallon_US # for oil
|
||||
|
||||
gallon_imp = 4.54609e-3 # UK
|
||||
fluid_ounce_imp = gallon_imp / 160
|
||||
|
||||
# speed in meter per second
|
||||
kmh = 1e3 / hour
|
||||
mph = mile / hour
|
||||
mach = speed_of_sound = 340.5 # approx value at 15 degrees in 1 atm. Is this a common value?
|
||||
knot = nautical_mile / hour
|
||||
|
||||
# temperature in kelvin
|
||||
zero_Celsius = 273.15
|
||||
degree_Fahrenheit = 1/1.8 # only for differences
|
||||
|
||||
# energy in joule
|
||||
eV = electron_volt = elementary_charge # * 1 Volt
|
||||
calorie = calorie_th = 4.184
|
||||
calorie_IT = 4.1868
|
||||
erg = 1e-7
|
||||
Btu_th = pound * degree_Fahrenheit * calorie_th / gram
|
||||
Btu = Btu_IT = pound * degree_Fahrenheit * calorie_IT / gram
|
||||
ton_TNT = 1e9 * calorie_th
|
||||
# Wh = watt_hour
|
||||
|
||||
# power in watt
|
||||
hp = horsepower = 550 * foot * pound * g
|
||||
|
||||
# force in newton
|
||||
dyn = dyne = 1e-5
|
||||
lbf = pound_force = pound * g
|
||||
kgf = kilogram_force = g # * 1 kg
|
||||
|
||||
# functions for conversions that are not linear
|
||||
|
||||
|
||||
def convert_temperature(val, old_scale, new_scale):
|
||||
"""
|
||||
Convert from a temperature scale to another one among Celsius, Kelvin,
|
||||
Fahrenheit, and Rankine scales.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
val : array_like
|
||||
Value(s) of the temperature(s) to be converted expressed in the
|
||||
original scale.
|
||||
|
||||
old_scale: str
|
||||
Specifies as a string the original scale from which the temperature
|
||||
value(s) will be converted. Supported scales are Celsius ('Celsius',
|
||||
'celsius', 'C' or 'c'), Kelvin ('Kelvin', 'kelvin', 'K', 'k'),
|
||||
Fahrenheit ('Fahrenheit', 'fahrenheit', 'F' or 'f'), and Rankine
|
||||
('Rankine', 'rankine', 'R', 'r').
|
||||
|
||||
new_scale: str
|
||||
Specifies as a string the new scale to which the temperature
|
||||
value(s) will be converted. Supported scales are Celsius ('Celsius',
|
||||
'celsius', 'C' or 'c'), Kelvin ('Kelvin', 'kelvin', 'K', 'k'),
|
||||
Fahrenheit ('Fahrenheit', 'fahrenheit', 'F' or 'f'), and Rankine
|
||||
('Rankine', 'rankine', 'R', 'r').
|
||||
|
||||
Returns
|
||||
-------
|
||||
res : float or array of floats
|
||||
Value(s) of the converted temperature(s) expressed in the new scale.
|
||||
|
||||
Notes
|
||||
-----
|
||||
.. versionadded:: 0.18.0
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from scipy.constants import convert_temperature
|
||||
>>> convert_temperature(np.array([-40, 40]), 'Celsius', 'Kelvin')
|
||||
array([ 233.15, 313.15])
|
||||
|
||||
"""
|
||||
# Convert from `old_scale` to Kelvin
|
||||
if old_scale.lower() in ['celsius', 'c']:
|
||||
tempo = _np.asanyarray(val) + zero_Celsius
|
||||
elif old_scale.lower() in ['kelvin', 'k']:
|
||||
tempo = _np.asanyarray(val)
|
||||
elif old_scale.lower() in ['fahrenheit', 'f']:
|
||||
tempo = (_np.asanyarray(val) - 32) * 5 / 9 + zero_Celsius
|
||||
elif old_scale.lower() in ['rankine', 'r']:
|
||||
tempo = _np.asanyarray(val) * 5 / 9
|
||||
else:
|
||||
raise NotImplementedError("%s scale is unsupported: supported scales "
|
||||
"are Celsius, Kelvin, Fahrenheit, and "
|
||||
"Rankine" % old_scale)
|
||||
# and from Kelvin to `new_scale`.
|
||||
if new_scale.lower() in ['celsius', 'c']:
|
||||
res = tempo - zero_Celsius
|
||||
elif new_scale.lower() in ['kelvin', 'k']:
|
||||
res = tempo
|
||||
elif new_scale.lower() in ['fahrenheit', 'f']:
|
||||
res = (tempo - zero_Celsius) * 9 / 5 + 32
|
||||
elif new_scale.lower() in ['rankine', 'r']:
|
||||
res = tempo * 9 / 5
|
||||
else:
|
||||
raise NotImplementedError("'%s' scale is unsupported: supported "
|
||||
"scales are 'Celsius', 'Kelvin', "
|
||||
"'Fahrenheit', and 'Rankine'" % new_scale)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
# optics
|
||||
|
||||
|
||||
def lambda2nu(lambda_):
|
||||
"""
|
||||
Convert wavelength to optical frequency
|
||||
|
||||
Parameters
|
||||
----------
|
||||
lambda_ : array_like
|
||||
Wavelength(s) to be converted.
|
||||
|
||||
Returns
|
||||
-------
|
||||
nu : float or array of floats
|
||||
Equivalent optical frequency.
|
||||
|
||||
Notes
|
||||
-----
|
||||
Computes ``nu = c / lambda`` where c = 299792458.0, i.e., the
|
||||
(vacuum) speed of light in meters/second.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from scipy.constants import lambda2nu, speed_of_light
|
||||
>>> lambda2nu(np.array((1, speed_of_light)))
|
||||
array([ 2.99792458e+08, 1.00000000e+00])
|
||||
|
||||
"""
|
||||
return _np.asanyarray(c) / lambda_
|
||||
|
||||
|
||||
def nu2lambda(nu):
|
||||
"""
|
||||
Convert optical frequency to wavelength.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
nu : array_like
|
||||
Optical frequency to be converted.
|
||||
|
||||
Returns
|
||||
-------
|
||||
lambda : float or array of floats
|
||||
Equivalent wavelength(s).
|
||||
|
||||
Notes
|
||||
-----
|
||||
Computes ``lambda = c / nu`` where c = 299792458.0, i.e., the
|
||||
(vacuum) speed of light in meters/second.
|
||||
|
||||
Examples
|
||||
--------
|
||||
>>> from scipy.constants import nu2lambda, speed_of_light
|
||||
>>> nu2lambda(np.array((1, speed_of_light)))
|
||||
array([ 2.99792458e+08, 1.00000000e+00])
|
||||
|
||||
"""
|
||||
return c / _np.asanyarray(nu)
|
11
venv/Lib/site-packages/scipy/constants/setup.py
Normal file
11
venv/Lib/site-packages/scipy/constants/setup.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
def configuration(parent_package='', top_path=None):
|
||||
from numpy.distutils.misc_util import Configuration
|
||||
config = Configuration('constants', parent_package, top_path)
|
||||
config.add_data_dir('tests')
|
||||
return config
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from numpy.distutils.core import setup
|
||||
setup(**configuration(top_path='').todict())
|
0
venv/Lib/site-packages/scipy/constants/tests/__init__.py
Normal file
0
venv/Lib/site-packages/scipy/constants/tests/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
57
venv/Lib/site-packages/scipy/constants/tests/test_codata.py
Normal file
57
venv/Lib/site-packages/scipy/constants/tests/test_codata.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
from scipy.constants import constants, codata, find, value, ConstantWarning
|
||||
from numpy.testing import (assert_equal, assert_, assert_almost_equal,
|
||||
suppress_warnings)
|
||||
|
||||
|
||||
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 = 'speed of light in vacuum'
|
||||
assert_equal(codata.value(c), constants.c)
|
||||
assert_equal(codata.value(c), constants.speed_of_light)
|
||||
|
||||
|
||||
def test_basic_lookup():
|
||||
assert_equal('%d %s' % (codata.c, codata.unit('speed of light in vacuum')),
|
||||
'299792458 m s^-1')
|
||||
|
||||
|
||||
def test_find_all():
|
||||
assert_(len(codata.find(disp=False)) > 300)
|
||||
|
||||
|
||||
def test_find_single():
|
||||
assert_equal(codata.find('Wien freq', disp=False)[0],
|
||||
'Wien frequency displacement law constant')
|
||||
|
||||
|
||||
def test_2002_vs_2006():
|
||||
assert_almost_equal(codata.value('magn. flux quantum'),
|
||||
codata.value('mag. flux quantum'))
|
||||
|
||||
|
||||
def test_exact_values():
|
||||
# Check that updating stored values with exact ones worked.
|
||||
with suppress_warnings() as sup:
|
||||
sup.filter(ConstantWarning)
|
||||
for key in codata.exact_values:
|
||||
assert_((codata.exact_values[key][0] - value(key)) / value(key) == 0)
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
from numpy.testing import assert_equal, assert_allclose
|
||||
import scipy.constants as sc
|
||||
|
||||
|
||||
def test_convert_temperature():
|
||||
assert_equal(sc.convert_temperature(32, 'f', 'Celsius'), 0)
|
||||
assert_equal(sc.convert_temperature([0, 0], 'celsius', 'Kelvin'),
|
||||
[273.15, 273.15])
|
||||
assert_equal(sc.convert_temperature([0, 0], 'kelvin', 'c'),
|
||||
[-273.15, -273.15])
|
||||
assert_equal(sc.convert_temperature([32, 32], 'f', 'k'), [273.15, 273.15])
|
||||
assert_equal(sc.convert_temperature([273.15, 273.15], 'kelvin', 'F'),
|
||||
[32, 32])
|
||||
assert_equal(sc.convert_temperature([0, 0], 'C', 'fahrenheit'), [32, 32])
|
||||
assert_allclose(sc.convert_temperature([0, 0], 'c', 'r'), [491.67, 491.67],
|
||||
rtol=0., atol=1e-13)
|
||||
assert_allclose(sc.convert_temperature([491.67, 491.67], 'Rankine', 'C'),
|
||||
[0., 0.], rtol=0., atol=1e-13)
|
||||
assert_allclose(sc.convert_temperature([491.67, 491.67], 'r', 'F'),
|
||||
[32., 32.], rtol=0., atol=1e-13)
|
||||
assert_allclose(sc.convert_temperature([32, 32], 'fahrenheit', 'R'),
|
||||
[491.67, 491.67], rtol=0., atol=1e-13)
|
||||
assert_allclose(sc.convert_temperature([273.15, 273.15], 'K', 'R'),
|
||||
[491.67, 491.67], rtol=0., atol=1e-13)
|
||||
assert_allclose(sc.convert_temperature([491.67, 0.], 'rankine', 'kelvin'),
|
||||
[273.15, 0.], rtol=0., atol=1e-13)
|
||||
|
||||
|
||||
def test_lambda_to_nu():
|
||||
assert_equal(sc.lambda2nu(sc.speed_of_light), 1)
|
||||
|
||||
|
||||
def test_nu_to_lambda():
|
||||
assert_equal(sc.nu2lambda(1), sc.speed_of_light)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue