This repository has been archived on 2022-02-23. You can view files and clone it, but cannot push or open issues or pull requests.
Deepak 10b72bfaaa
All checks were successful
gitea-physics/pathfinder/pipeline/head This commit looks good
Adds some tests and dot methods and jacobian
2021-09-13 11:51:52 -05:00

35 lines
1.1 KiB
Python

import numpy
import numpy.testing
import pathfinder.model.oscillating as model
def test_dot_v_from_dipole():
dot_position1 = (-1, -1, -1)
dot_frequency1 = 11
expected_v1 = 0.00001421963287022476
dot = model.DotMeasurement(expected_v1, dot_position1, dot_frequency1)
# and dipole located at (4, 5, 6) with p=(1, 2, 3) and w = 7
pt = numpy.array((1, 2, 3, 4, 5, 6, 7))
numpy.testing.assert_allclose(dot.v_for_point(pt), dot.v, err_msg="v from dipole at a dot was incorrect!")
numpy.testing.assert_allclose(dot.cost(pt), 0, atol=1e-12, err_msg="cost should be zero")
def test_jac():
expected_jac = [
3.742008650059147e-6, 4.4904103800709765e-6, 5.238812110082806e-6,
-3.12967996186765e-6, -3.1568945702317167e-6, -3.184109178595783e-6,
8.603475350051953e-7
]
dot = model.DotMeasurement(50, (-1, -1, -1), 11)
# dipole located at (4, 5, 6) with p=(1, 2, 3) and w = 7
pt = numpy.array((1, 2, 3, 4, 5, 6, 7))
assert len(dot.jac_pt(pt)) == 7
numpy.testing.assert_allclose(dot.jac_pt(pt), expected_jac, err_msg="Jac pt doesn't match Mathematica result.")
# numpy.testing.assert_allclose(dot.jac(pts), jac_row_target, err_msg="whole row should match")