Compare commits
8 Commits
a3259f3379
...
6a45d1123e
Author | SHA1 | Date | |
---|---|---|---|
6a45d1123e | |||
23e3b95bb6 | |||
a326e80e00 | |||
56f660ff25 | |||
a5fd9c2304 | |||
0dbe874ac4 | |||
36454d5044 | |||
156019fdac |
@ -2,6 +2,13 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||
|
||||
### [0.8.8](https://gitea.deepak.science:2222/physics/pdme/compare/0.8.7...0.8.8) (2023-04-09)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* adds fast calc that allows for variable temp ([36454d5](https://gitea.deepak.science:2222/physics/pdme/commit/36454d5044d93b6b178e016b84dd59a5ebaf15e2))
|
||||
|
||||
### [0.8.7](https://gitea.deepak.science:2222/physics/pdme/compare/0.8.6...0.8.7) (2022-09-17)
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
[](https://jenkins.deepak.science/job/gitea-physics/job/pdme/job/master/)
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
This repo has library code for evaluating dipole models.
|
||||
|
||||
|
@ -69,6 +69,47 @@ def fast_vs_for_dipoleses(
|
||||
return numpy.einsum("...j->...", ases * bses)
|
||||
|
||||
|
||||
def fast_vs_for_asymmetric_dipoleses(
|
||||
dot_inputs: numpy.ndarray, dipoleses: numpy.ndarray, temp: numpy.ndarray
|
||||
) -> numpy.ndarray:
|
||||
"""
|
||||
No error correction here baby.
|
||||
Expects dot_inputs to be numpy array of [rx, ry, rz, f] entries, so a n by 4 where n is number of measurement points.
|
||||
|
||||
Dipoleses are expected to be array of arrays of arrays:
|
||||
list of sets of dipoles which are part of a single arrangement to be added together.
|
||||
Within each dipole, the expected format is [px, py, pz, sx, sy, sz, e1, e2, w]
|
||||
The passed in w is expected to be half the actual. This is bad, but here for historical reasons to be changed later.
|
||||
"""
|
||||
raw_ps = dipoleses[:, :, 0:3]
|
||||
ss = dipoleses[:, :, 3:6]
|
||||
e1s = dipoleses[:, :, 6]
|
||||
e2s = dipoleses[:, :, 7]
|
||||
raw_ws = dipoleses[:, :, 8]
|
||||
|
||||
rs = dot_inputs[:, 0:3]
|
||||
fs = dot_inputs[:, 3]
|
||||
|
||||
diffses = rs[:, None] - ss[:, None, :]
|
||||
|
||||
w1s = numpy.exp(-e1s / temp) * raw_ws
|
||||
w2s = numpy.exp(-e2s / temp) * raw_ws
|
||||
|
||||
mag_prefactor = 4 * ((w1s * w2s) / ((w1s + w2s) ** 2))
|
||||
ws = w1s + w2s
|
||||
|
||||
# some annoying broadcast thing here?
|
||||
ps = (raw_ps.T * mag_prefactor.T).T
|
||||
|
||||
norms = numpy.linalg.norm(diffses, axis=3) ** 3
|
||||
|
||||
ases = (numpy.einsum("abcd,acd->abc", diffses, ps) / norms) ** 2
|
||||
|
||||
bses = (1 / numpy.pi) * (ws[:, None, :] / (fs[:, None] ** 2 + ws[:, None, :] ** 2))
|
||||
|
||||
return numpy.einsum("...j->...", ases * bses)
|
||||
|
||||
|
||||
def between(a: numpy.ndarray, low: numpy.ndarray, high: numpy.ndarray) -> numpy.ndarray:
|
||||
"""
|
||||
Intended specifically for the case where a is a list of arrays, and each array must be between the single array low and high, but without error checking.
|
||||
|
19
poetry.lock
generated
19
poetry.lock
generated
@ -52,7 +52,7 @@ python-versions = "*"
|
||||
|
||||
[[package]]
|
||||
name = "black"
|
||||
version = "23.1.0"
|
||||
version = "23.3.0"
|
||||
description = "The uncompromising code formatter."
|
||||
category = "dev"
|
||||
optional = false
|
||||
@ -94,7 +94,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
|
||||
|
||||
[[package]]
|
||||
name = "coverage"
|
||||
version = "7.1.0"
|
||||
version = "7.2.3"
|
||||
description = "Code coverage measurement for Python"
|
||||
category = "dev"
|
||||
optional = false
|
||||
@ -417,14 +417,19 @@ testing = ["fields", "hunter", "process-tests", "six", "pytest-xdist", "virtuale
|
||||
|
||||
[[package]]
|
||||
name = "scipy"
|
||||
version = "1.8.0"
|
||||
description = "SciPy: Scientific Library for Python"
|
||||
version = "1.10.0"
|
||||
description = "Fundamental algorithms for scientific computing in Python"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.8,<3.11"
|
||||
python-versions = "<3.12,>=3.8"
|
||||
|
||||
[package.dependencies]
|
||||
numpy = ">=1.17.3,<1.25.0"
|
||||
numpy = ">=1.19.5,<1.27.0"
|
||||
|
||||
[package.extras]
|
||||
test = ["pytest", "pytest-cov", "pytest-timeout", "pytest-xdist", "asv", "mpmath", "gmpy2", "threadpoolctl", "scikit-umfpack", "pooch"]
|
||||
doc = ["sphinx (!=4.1.0)", "pydata-sphinx-theme (==0.9.0)", "sphinx-design (>=0.2.0)", "matplotlib (>2)", "numpydoc"]
|
||||
dev = ["mypy", "typing-extensions", "pycodestyle", "flake8", "rich-click", "click", "doit (>=0.36.0)", "pydevtool"]
|
||||
|
||||
[[package]]
|
||||
name = "six"
|
||||
@ -496,7 +501,7 @@ python-versions = "*"
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.8,<3.10"
|
||||
content-hash = "19a6af95086758eb503d273fa5366bf73cc0060ef5a395a41c51fcdf7372b5dd"
|
||||
content-hash = "be6bfa73e6db07338369f817a2d0c86f1072b313d23d470feb5ca49cfd5aa8ad"
|
||||
|
||||
[metadata.files]
|
||||
appnope = []
|
||||
|
@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "pdme"
|
||||
version = "0.8.7"
|
||||
version = "0.8.8"
|
||||
description = "Python dipole model evaluator"
|
||||
authors = ["Deepak <dmallubhotla+github@gmail.com>"]
|
||||
license = "GPL-3.0-only"
|
||||
@ -9,7 +9,7 @@ readme = "README.md"
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.8,<3.10"
|
||||
numpy = "^1.22.3"
|
||||
scipy = "~1.8"
|
||||
scipy = "~1.10"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pytest = ">=6"
|
||||
|
@ -107,3 +107,28 @@ def test_between():
|
||||
expected = numpy.array([False, False, True])
|
||||
|
||||
numpy.testing.assert_array_equal(actual, expected, err_msg="Between calc wrong")
|
||||
|
||||
|
||||
def test_fast_v_calc_asymmetric_multidipoles_but_symmetric():
|
||||
# expected format is [px, py, pz, sx, sy, sz, e1, e2, w]
|
||||
d1 = [1, 2, 3, 4, 5, 6, 1, 1, 7 / 2]
|
||||
d2 = [2, 5, 3, 4, -5, -6, 2, 2, 2 / 2]
|
||||
|
||||
dipoles = numpy.array([[d1, d2]])
|
||||
|
||||
dot_inputs = numpy.array([[-1, -1, -1, 11], [2, 3, 1, 5.5]])
|
||||
# expected_ij is for dot i, dipole j
|
||||
expected_11 = 0.00001421963287022476
|
||||
expected_12 = 0.00001107180225755457
|
||||
expected_21 = 0.000345021108583681380388722
|
||||
expected_22 = 0.0000377061050587914705139781
|
||||
|
||||
expected = numpy.array([[expected_11 + expected_12, expected_21 + expected_22]])
|
||||
|
||||
numpy.testing.assert_allclose(
|
||||
pdme.util.fast_v_calc.fast_vs_for_asymmetric_dipoleses(
|
||||
dot_inputs, dipoles, 1e10
|
||||
),
|
||||
expected,
|
||||
err_msg="Voltages at dot aren't as expected for multidipole calc.",
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user