Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
@@ -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:
3 changes: 1 addition & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
copyright = f'2026, {authors}'
author = authors

#release = premlike.__version__
release = "0.1.0-alpha1"
release = premlike.__version__

# -- General configuration

Expand Down
17 changes: 16 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
PremLike documentation
======================

TBC
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
10 changes: 10 additions & 0 deletions docs/source/theory.rst
Original file line number Diff line number Diff line change
@@ -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`.
4 changes: 4 additions & 0 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Usage
=====

Some words need to go here
3 changes: 2 additions & 1 deletion src/premlike/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
from .const import R_EARTH
from .PREM import PREM

__all__ = ["OneDModel", "R_EARTH", "PREM", "tabulate_model"]
__all__ = ["OneDModel", "R_EARTH", "PREM", "tabulate_model"]
__version__ = "0.1.0-alpha2"
2 changes: 1 addition & 1 deletion src/premlike/earth_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/premlike/physics.py
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
14 changes: 7 additions & 7 deletions src/premlike/peice_poly.py → src/premlike/piece_poly.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
46 changes: 23 additions & 23 deletions tests/test_peice_poly.py → tests/test_piece_poly.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]])
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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]))
Expand All @@ -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]),
Expand All @@ -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]),
Expand All @@ -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]),
Expand Down