Skip to content

Commit

Permalink
Fixes and doc improvement (#860)
Browse files Browse the repository at this point in the history
* Fixes and doc improvement

* Fixes in dynamics
  • Loading branch information
blackyblack authored Jul 18, 2024
1 parent d8d48e7 commit 7df9963
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: mypy .

- name: Run linter with pylint
run: pylint --fail-under=9.8 ./test/**/*.py ./symplyphysics
run: pylint ./test/**/*.py ./symplyphysics ./examples ./plots ./docs

- name: Run tests with pytest
run: pytest
Expand Down
4 changes: 2 additions & 2 deletions examples/optics/image_formed_by_two_lenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@
distance_to_image_2 = solve(thin_lens_2, thin_lens.distance_to_image)[0]
distance_to_image_2_value = distance_to_image_2.subs(values).evalf(3)

side = "right" if distance_to_image_2_value > 0 else "left"
print(f"The image is located {abs(distance_to_image_2_value)} cm to the {side} of lens 2.")
SIDE = "right" if distance_to_image_2_value > 0 else "left"
print(f"The image is located {abs(distance_to_image_2_value)} cm to the {SIDE} of lens 2.")
2 changes: 1 addition & 1 deletion examples/thermodynamics/speed_distribution_in_gas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from sympy import solve, symbols, S, integrate
from sympy import solve, symbols, integrate
from symplyphysics import Quantity, units, convert_to, quantities
from symplyphysics.laws.chemistry import molar_mass_via_mass_of_single_particle as molar_mass_law
from symplyphysics.laws.thermodynamics.maxwell_boltzmann_statistics import speed_distribution
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from sympy import solve, symbols, Eq
from sympy.plotting import plot
from sympy.plotting.plot import MatplotlibBackend
from symplyphysics import print_expression
from sympy.physics.units import speed_of_light
from symplyphysics import print_expression
from symplyphysics.laws.relativistic import coordinate_conversion_velocity_constant as transform_law

reduced_speed = symbols("reduced_speed")
Expand Down
4 changes: 2 additions & 2 deletions plots/laws/relativistic/relativistic_mass_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from sympy import solve, symbols, Eq
from sympy.plotting import plot
from sympy.plotting.plot import MatplotlibBackend
from symplyphysics import print_expression
from sympy.physics.units import speed_of_light
import symplyphysics.laws.relativistic.relativistic_mass as relativistic_mass
from symplyphysics import print_expression
from symplyphysics.laws.relativistic import relativistic_mass

# Description
## Plot the dependency of the relativistic to rest mass ratio on the fraction of the speed of light
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@

for value_ in values_:
expr_ = distribution_expr.subs(reduced_chemical_potential, value_)
label = r"$\mu = " + (str(value_) if value_ != -1 else "-") + r" k_\text{B} T$"
LABEL = r"$\mu = " + (str(value_) if value_ != -1 else "-") + r" k_\text{B} T$"
sub_plot = plot(
expr_,
(reduced_energy, 0, 5),
label=label,
label=LABEL,
show=False,
)
base_plot.extend(sub_plot)
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ testpaths = [
"test",
]

[tool.pylint.master]
fail-under = "9.8"

[tool.pylint.basic]
good-names-rgxs = ["^[_a-z][_a-z0-9]?$,^[_A-Z][_a-z0-9]?$"]

Expand All @@ -48,6 +51,7 @@ disable = [
"line-too-long",
"similarities",
"too-many-locals",
"fixme"
]

[tool.mypy]
Expand Down
2 changes: 1 addition & 1 deletion symplyphysics/core/vectors/vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def rebase(self, coordinate_system: CoordinateSystem) -> Vector:
def simplify(self, **kwargs: Any) -> Vector:
components = [simplify(component, **kwargs) for component in self.components]
return Vector(components, self.coordinate_system)

def subs(self, *args: Any) -> Vector:
components = [sympify(component).subs(*args) for component in self.components]
return Vector(components, self.coordinate_system)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
M = m - 5 * lg(d / d0)
Latex:
:math:`M = m - 5 * \log_{10}(d / d0)`
:math:`M = m - 5 \log_{10} \left( \frac{d}{d0} \right)`
"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
The angle of the gravitational maneuver depends on the aiming range, the mass of the planet and the velocity of the rocket relative to the planet.
.. image:: https://upload.wikimedia.org/wikipedia/commons/a/ad/Gravity_assist\_-\_ru.svg
:width: 240px
"""

from sympy import Eq, solve, atan
Expand Down Expand Up @@ -55,7 +56,7 @@
phi = 2 * arctg(G * M / (b * v^2))
Latex:
:math:`\phi = 2 * \arctan(G * M / (b * v^2))`
:math:`\phi = 2 \arctan \left( \frac{G M}{b v^2} \right)`
"""


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
M2 / M1 = ((1 - (V / c)) / (1 + (V / c)))^(c / (2 * Ve))
Latex:
:math:`M_2 / M_1 = ((1 - (V / c)) / (1 + (V / c)))^{c / (2 * V_e)}`
:math:`\frac{M_2}{M_1} = \left( \frac{1 - \frac{V}{c}}{1 + \frac{V}{c}} \right) ^ {\frac{c}{2 V_e}}`
"""


Expand Down
6 changes: 6 additions & 0 deletions symplyphysics/laws/dynamics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
Dynamics
========
Dynamics is the study of the cause of motion, or more precisely the cause of *changes* in motion.
"""
6 changes: 6 additions & 0 deletions symplyphysics/laws/dynamics/deformation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
Dynamics (Deformation)
=================================================
In physics and continuum mechanics, deformation is the change in the shape or size of an object.
"""
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Rotational stiffness is torque_applied over angle
Rotational stiffness is torque applied over angle
=================================================
*Rotational stiffness* is the extent to which an object resists rotational deformation.
Expand Down Expand Up @@ -32,7 +32,7 @@
tau
Latex:
:math:`tau`
:math:`\tau`
"""

rotation_angle = Symbol("rotation_angle", angle_type)
Expand Down
4 changes: 2 additions & 2 deletions symplyphysics/laws/quantities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
Physical quantities can often be categorized as being either *extensive* or *intensive*, according to
how the property changes when the size or extent of the system changes.
Intensive quantity
**Intensive quantity**
A quantity whose magnitude is independent of the size of the system.
Extensive quantity
**Extensive quantity**
A quantity whose magnitude scales linearly with the size of the system,
i.e. it is additive with respect to its subsystems.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
When light is propagating in a gravitational field, its frequency changes proportionally to the
change in the potential of the gravitational field.
Let us consider an infinitesimally small section :math:`d \vec r` of the light's path, such that
Let us consider an infinitesimally small section :math:`\Delta \vec r` of the light's path, such that
the frequency of light is constant within that section. In that case we can obtain a dependency
between the change in light's frequency and the change in the gravitational potential.
"""
Expand All @@ -21,53 +21,53 @@

frequency_change = Symbol("frequency_change", units.frequency)
r"""
The infinitesimal change in frequency after passing an infinitesimal section :math:`d \vec r`.
The infinitesimal change in frequency after passing an infinitesimal section :math:`\Delta \vec r`.
Symbol:
frequency_change
df
Latex:
:math:`d \nu`
:math:`\Delta \nu`
"""

frequency = Symbol("frequency", units.frequency)
r"""
The frequency of light within an infinitesimal section :math:`d \vec r`.
The frequency of light within an infinitesimal section :math:`\Delta \vec r`.
Symbol:
frequency
f
Latex:
:math:`\nu`
"""

gravitational_potential_change = Symbol("gravitational_potential_change", units.velocity**2)
r"""
The infinitesimal change in gravitational potential after passing an infinitesimal section :math:`d \vec r`.
The infinitesimal change in gravitational potential after passing an infinitesimal section :math:`\Delta \vec r`.
The *gravitational potential* :math:`\varphi` is defined as a scalar quantity such that the equation
:math:`\vec g = - \nabla \varphi` is hold where :math:`\vec g` is the vector of acceleration due to gravity
and :math:`\nabla` is the nabla operator.
Note that :math:`d \varphi = - \left( \vec g, d \vec r \right)` where :math:`\left( \vec a_1, \vec a_2 \right)` is
Note that :math:`\Delta \varphi = - \left( \vec g, \Delta \vec r \right)` where :math:`\left( \vec a_1, \vec a_2 \right)` is
the dot product between :math:`\vec a_1` and :math:`\vec a_2`.
Symbol:
gravitational_potential_change
dPhi
Latex:
:math:`d \varphi`
:math:`\Delta \varphi`
"""

law = Eq(
frequency_change / frequency,
-1 * gravitational_potential_change / units.speed_of_light**2,
)
r"""
frequency_change / frequency = -1 * gravitational_potential_change / speed_of_light^2
df / f = -1 * dPhi / c^2
Latex:
:math:`\frac{d \nu}{\nu} = - \frac{d \varphi}{c^2}`
:math:`\frac{\Delta \nu}{\nu} = - \frac{\Delta \varphi}{c^2}`
"""


Expand Down
4 changes: 2 additions & 2 deletions symplyphysics/quantities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
It is also temperature for Standard Temperature and Pressure (STP)
Symbol:
t0
t_std
Latex:
:math:`t_\text{std}`
Expand All @@ -27,7 +27,7 @@
Approximately 25 Celsius degrees. Commonly used temperature for tabulation purposes.
Symbol:
t_std
t_lab
Latex:
:math:`t_\text{lab}`
Expand Down
4 changes: 2 additions & 2 deletions symplyphysics/symbols/basic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Basic
======
Symbols (Basic)
===============
Contains fundamental properties of matter.
"""
Expand Down
4 changes: 2 additions & 2 deletions symplyphysics/symbols/dynamics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Dynamics
========
Symbols (Dynamics)
==================
Contains properties for 'dynamics' branch of physics.
Expand Down
4 changes: 2 additions & 2 deletions symplyphysics/symbols/kinematic/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Kinematics
==========
Symbols (Kinematics)
====================
Contains properties for 'kinematics' branch of physics
Expand Down
4 changes: 2 additions & 2 deletions symplyphysics/symbols/thermodynamics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Thermodynamics
==============
Symbols (Thermodynamics)
========================
Contains properties for 'thermodynamics' branch of physics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
assert_equal_vectors,
errors,
units,
Quantity,
QuantityVector,
)
from symplyphysics.laws.kinematic.vector import centrifugal_acceleration_via_centripetal_acceleration as law
Expand Down Expand Up @@ -33,7 +32,7 @@ def test_centripetal_law(test_args: Args) -> None:
assert_equal_vectors(result, test_args.acp)


def test_bad_acceleration(test_args: Args) -> None:
def test_bad_acceleration() -> None:
ab_vector = QuantityVector([units.coulomb])
with raises(errors.UnitsError):
law.calculate_centrifugal_acceleration(ab_vector)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
assert_equal,
errors,
units,
prefixes,
Quantity,
)
from symplyphysics.laws.waves import (
Expand Down

0 comments on commit 7df9963

Please sign in to comment.