diff --git a/docs/source/api.rst b/docs/source/api.rst new file mode 100644 index 0000000..b7d62e6 --- /dev/null +++ b/docs/source/api.rst @@ -0,0 +1,37 @@ +API documentation +================= + +This is a reference covering public API for PremLike. + +Modules +------- + +`const` +^^^^^^^ + +.. automodule:: premlike.const + :members: + +`earth_model` +^^^^^^^^^^^^^ + +.. automodule:: premlike.earth_model + :members: + +`piece_poly` +^^^^^^^^^^^^ + +.. automodule:: premlike.piece_poly + :members: + +`physics` +^^^^^^^^^ + +.. automodule:: premlike.physics + :members: + +`PREM` +^^^^^^ + +.. automodule:: premlike.PREM + :members: \ No newline at end of file diff --git a/docs/source/conf.py b/docs/source/conf.py index 83e4451..2c1de4d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -21,8 +21,7 @@ copyright = f'2026, {authors}' author = authors -#release = premlike.__version__ -release = "0.1.0-alpha1" +release = premlike.__version__ # -- General configuration diff --git a/docs/source/index.rst b/docs/source/index.rst index a9ceb30..7e0996c 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -1,4 +1,19 @@ PremLike documentation ====================== -TBC \ No newline at end of file +Work with models of the Earth that are parameterized +like PREM. + +.. note:: + + This project is under active development. The api + is likely to change without warning. + +Contents +-------- + +.. toctree:: + + usage + api + theory \ No newline at end of file diff --git a/docs/source/theory.rst b/docs/source/theory.rst new file mode 100644 index 0000000..f737984 --- /dev/null +++ b/docs/source/theory.rst @@ -0,0 +1,10 @@ +Theory in PremLike +================== + +I need to write about the piecewise polynomials. To +do this I'll need LaTeX maths: + +.. math:: + y = ax^2 + b + +or math:`y = ax^2`. \ No newline at end of file diff --git a/docs/source/usage.rst b/docs/source/usage.rst new file mode 100644 index 0000000..d57e9a4 --- /dev/null +++ b/docs/source/usage.rst @@ -0,0 +1,4 @@ +Usage +===== + +Some words need to go here \ No newline at end of file diff --git a/src/premlike/__init__.py b/src/premlike/__init__.py index c759d59..4752c17 100644 --- a/src/premlike/__init__.py +++ b/src/premlike/__init__.py @@ -4,4 +4,5 @@ from .const import R_EARTH from .PREM import PREM -__all__ = ["OneDModel", "R_EARTH", "PREM", "tabulate_model"] \ No newline at end of file +__all__ = ["OneDModel", "R_EARTH", "PREM", "tabulate_model"] +__version__ = "0.1.0-alpha2" \ No newline at end of file diff --git a/src/premlike/earth_model.py b/src/premlike/earth_model.py index 2213fbb..440b4e4 100644 --- a/src/premlike/earth_model.py +++ b/src/premlike/earth_model.py @@ -9,7 +9,7 @@ import numpy as np from .const import R_EARTH -from .peice_poly import PeicewisePolynomial as PP +from .piece_poly import PiecewisePolynomial as PP from .physics import ( calculate_bulk_modulus, calculate_density, diff --git a/src/premlike/physics.py b/src/premlike/physics.py index accb818..01879c3 100644 --- a/src/premlike/physics.py +++ b/src/premlike/physics.py @@ -1,7 +1,7 @@ import numpy as np from .const import G, R_EARTH -from .peice_poly import PeicewisePolynomial as PP +from .piece_poly import PiecewisePolynomial as PP def calculate_vs( diff --git a/src/premlike/peice_poly.py b/src/premlike/piece_poly.py similarity index 97% rename from src/premlike/peice_poly.py rename to src/premlike/piece_poly.py index 5fe106c..7a65f22 100644 --- a/src/premlike/peice_poly.py +++ b/src/premlike/piece_poly.py @@ -1,16 +1,16 @@ #!/usr/bin/env python # coding=utf8 """ -Peicewise polynomials like PREM +Piecewise polynomials like PREM """ import numpy as np -class PeicewisePolynomial(object): +class PiecewisePolynomial(object): """ - Peicewise Polynomials a different way + Piecewise Polynomials a different way The SciPy PPoly class defines a function from polynomials with coefficents c and breakpoints x @@ -137,7 +137,7 @@ def derivative(self): deriv_neg_coeffs[seg, i + 1] = ( -1 * self.negative_coeffs[seg, i] * i ) - deriv = PeicewisePolynomial(deriv_coeffs, deriv_breakpoints, deriv_neg_coeffs) + deriv = PiecewisePolynomial(deriv_coeffs, deriv_breakpoints, deriv_neg_coeffs) return deriv def antiderivative(self): @@ -166,7 +166,7 @@ def antiderivative(self): antideriv_neg_coeffs[seg, i - 1] = ( -1 * self.negative_coeffs[seg, i] / (i - 1) ) - antideriv = PeicewisePolynomial( + antideriv = PiecewisePolynomial( antideriv_coeffs, antideriv_breakpoints, antideriv_neg_coeffs ) return antideriv @@ -213,7 +213,7 @@ def integrating_poly(self): # add all the other segments if bpi > 0: ip_coeffs[bpi, 0] = ip_coeffs[bpi, 0] + antiderivative.integrate(0, bp) - return PeicewisePolynomial(ip_coeffs, antiderivative.breakpoints) + return PiecewisePolynomial(ip_coeffs, antiderivative.breakpoints) def mult(self, other): # FIXME - for this approach brakepoints need to be same place too @@ -301,7 +301,7 @@ def mult(self, other): # TODO: handle non-overlapping breakpoints (first chop the # segments). Also implement do poly * const etc. - mult_poly = PeicewisePolynomial( + mult_poly = PiecewisePolynomial( mult_coefs, mult_breakpoints, mult_negative_coefs ) return mult_poly diff --git a/tests/test_peice_poly.py b/tests/test_piece_poly.py similarity index 91% rename from tests/test_peice_poly.py rename to tests/test_piece_poly.py index 1ab18ad..667fec8 100644 --- a/tests/test_peice_poly.py +++ b/tests/test_piece_poly.py @@ -1,18 +1,18 @@ """ -Test cases for PeicewisePolynomial class +Test cases for PiecewisePolynomial class """ import numpy as np import numpy.testing as npt -import premlike.peice_poly as pp +import premlike.piece_poly as pp def test_constant(): """ Check that a constant function gives allways gives its value """ - poly = pp.PeicewisePolynomial(np.array([[2.0], [2.0]]), + poly = pp.PiecewisePolynomial(np.array([[2.0], [2.0]]), np.array([0.0, 0.5, 1.0])) assert poly(0.0) == 2.0 assert poly(0.25) == 2.0 @@ -36,7 +36,7 @@ def test_quadratic(): """ Check that a quadratic function gives the correct value """ - poly = pp.PeicewisePolynomial(np.array([[0.0, 0.0, 1.0], [0.0, 0.0, 1.0]]), + poly = pp.PiecewisePolynomial(np.array([[0.0, 0.0, 1.0], [0.0, 0.0, 1.0]]), np.array([0.0, 0.5, 1.0])) assert poly(0.0) == 0.0 assert poly(0.25) == 0.25**2 @@ -60,7 +60,7 @@ def test_one_over_x(): Check that a 1/x function gives the correct value using a quadratic for x less than 0.5 """ - poly = pp.PeicewisePolynomial(np.array([[0.0, 0.0, 1.0], [0.0, 0.0, 0.0]]), + poly = pp.PiecewisePolynomial(np.array([[0.0, 0.0, 1.0], [0.0, 0.0, 0.0]]), np.array([0.0, 0.5, 1.0]), c_neg=np.array([[0.0, 0.0], [0.0, 1.0]])) assert poly(0.0) == 0.0 @@ -81,9 +81,9 @@ def test_one_over_x(): def test_step(): """ - Check that two peicewise constants give the right values + Check that two piecewise constants give the right values """ - poly = pp.PeicewisePolynomial(np.array([[2.0], [20.0]]), + poly = pp.PiecewisePolynomial(np.array([[2.0], [20.0]]), np.array([0.0, 0.5, 1.0])) assert poly(0.0) == 2.0 assert poly(0.25) == 2.0 @@ -117,7 +117,7 @@ def test_deriv(): And we can multiply everything by 10 and split the polynomial. """ - poly = pp.PeicewisePolynomial(np.array([[4.0, 3.0, 2.0], + poly = pp.PiecewisePolynomial(np.array([[4.0, 3.0, 2.0], [40.0, 30.0, 20.0]]), np.array([0.0, 2.0, 4.0])) expected_deriv_coefs = np.array([[3.0, 4.0], [30.0, 40.0]]) @@ -147,7 +147,7 @@ def test_recip_deriv(): And we can multiply everything by 10 and split the polynomial. """ - poly = pp.PeicewisePolynomial(np.array([[3.0, 4.0], + poly = pp.PiecewisePolynomial(np.array([[3.0, 4.0], [30.0, 40.0]]), np.array([0.0, 2.0, 4.0]), c_neg=np.array([[0.0, 2.0, 3.0], @@ -172,7 +172,7 @@ def test_antideriv(): And we can multiply everything by 10 and split the polynomial. """ - poly = pp.PeicewisePolynomial(np.array([[4.0, 3.0, 2.0], + poly = pp.PiecewisePolynomial(np.array([[4.0, 3.0, 2.0], [40.0, 30.0, 20.0]]), np.array([0.0, 2.0, 4.0])) expected_antideriv_coefs = np.array([[0.0, 4.0, 3.0/2.0, 2.0/3.0], @@ -191,7 +191,7 @@ def test_recip_antideriv(): And we can multiply everything by 10 and split the polynomial. """ - poly = pp.PeicewisePolynomial(np.array([[4.0], + poly = pp.PiecewisePolynomial(np.array([[4.0], [40.0]]), np.array([0.0, 2.0, 4.0]), c_neg=np.array([[0.0, 0.0, -2.0, -6.0], @@ -216,7 +216,7 @@ def test_log_deriv_int(): And we can multiply everything by 10 and split the polynomial. """ - poly = pp.PeicewisePolynomial(np.array([[3.0, 4.0], + poly = pp.PiecewisePolynomial(np.array([[3.0, 4.0], [30.0, 40.0]]), np.array([0.0, 2.0, 4.0]), c_neg=np.array([[5.0, 2.0, 3.0], @@ -251,7 +251,7 @@ def test_integrate(): And we can multiply everything by 10 and split the polynomial with addition over breakpoints. """ - poly = pp.PeicewisePolynomial(np.array([[4.0, 3.0, 2.0], + poly = pp.PiecewisePolynomial(np.array([[4.0, 3.0, 2.0], [40.0, 30.0, 20.0]]), np.array([0.0, 2.0, 4.0])) antideriv = poly.antiderivative() @@ -284,13 +284,13 @@ def test_mult(): and we split this polynomial in two to excercise the breakpoint checking. """ - poly1 = pp.PeicewisePolynomial(np.array([[4.0, 3.0, 2.0], + poly1 = pp.PiecewisePolynomial(np.array([[4.0, 3.0, 2.0], [4.0, 3.0, 2.0]]), np.array([0.0, 2.0, 4.0])) - poly2 = pp.PeicewisePolynomial(np.array([[1.0, 2.0, 4.0], + poly2 = pp.PiecewisePolynomial(np.array([[1.0, 2.0, 4.0], [1.0, 2.0, 4.0]]), np.array([0.0, 2.0, 4.0])) - expect_poly_mult = pp.PeicewisePolynomial( + expect_poly_mult = pp.PiecewisePolynomial( np.array([[4.0, 11.0, 24.0, 16.0, 8.0], [4.0, 11.0, 24.0, 16.0, 8.0]]), np.array([0.0, 2.0, 4.0])) @@ -308,17 +308,17 @@ def test_mult2(): breakpoint checking. Also check that order does not matter and we can square both polynomials """ - poly1 = pp.PeicewisePolynomial(np.array([[4.0, 3.0, 2.0], + poly1 = pp.PiecewisePolynomial(np.array([[4.0, 3.0, 2.0], [4.0, 3.0, 2.0]]), np.array([0.0, 2.0, 4.0]), np.array([[0.0, 3.0, 4.0], [0.0, 3.0, 4.0]])) - poly2 = pp.PeicewisePolynomial(np.array([[1.0, 2.0, 4.0], + poly2 = pp.PiecewisePolynomial(np.array([[1.0, 2.0, 4.0], [1.0, 2.0, 4.0]]), np.array([0.0, 2.0, 4.0]), np.array([[0.0, 0.0, 2.0], [0.0, 0.0, 2.0]])) - expect_poly_mult = pp.PeicewisePolynomial( + expect_poly_mult = pp.PiecewisePolynomial( np.array([[30.0, 23.0, 24.0, 16.0, 8.0], [30.0, 23.0, 24.0, 16.0, 8.0]]), np.array([0.0, 2.0, 4.0]), @@ -334,7 +334,7 @@ def test_mult2(): npt.assert_allclose(calc_poly_mult.negative_coeffs, expect_poly_mult.negative_coeffs) # Square poly 1 - expect_poly_mult = pp.PeicewisePolynomial( + expect_poly_mult = pp.PiecewisePolynomial( np.array([[50.0, 36.0, 25.0, 12.0, 4.0], [50.0, 36.0, 25.0, 12.0, 4.0]]), np.array([0.0, 2.0, 4.0]), @@ -354,15 +354,15 @@ def test_mult3(): and we split the polynomials in two to excercise the breakpoint checking. Also check that order does not matter """ - poly1 = pp.PeicewisePolynomial(np.array([[4.0, 3.0, 2.0], + poly1 = pp.PiecewisePolynomial(np.array([[4.0, 3.0, 2.0], [4.0, 3.0, 2.0]]), np.array([0.0, 2.0, 4.0]), np.array([[0.0, 3.0, 4.0], [0.0, 3.0, 4.0]])) - poly2 = pp.PeicewisePolynomial(np.array([[1.0, 2.0, 4.0], + poly2 = pp.PiecewisePolynomial(np.array([[1.0, 2.0, 4.0], [1.0, 2.0, 4.0]]), np.array([0.0, 2.0, 4.0])) - expect_poly_mult = pp.PeicewisePolynomial( + expect_poly_mult = pp.PiecewisePolynomial( np.array([[26.0, 23.0, 24.0, 16.0, 8.0], [26.0, 23.0, 24.0, 16.0, 8.0]]), np.array([0.0, 2.0, 4.0]),