Skip to content

feat: increase fast cal to muD=7 #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 23 additions & 0 deletions news/fastcalto7.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Fast calculation support up to muD = 7

**Changed:**

* Clarified error message for fast calculation to explicitly states the invalid muD value

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
12 changes: 7 additions & 5 deletions src/diffpy/labpdfproc/data/coefficient_list.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-6.543824057313183,2.517676049711881e-10,-430.98705781061807,-1390.1242894055792,-2233.6043531698424,-2624.226082870084,-2590.22123249732
5.020666247920394,-4.676545705328227e-10,875.3743680589598,2744.521375373735,4366.230491983095,5113.620084734874,5051.51673764446
1.8615172482459748,3.25649449911046e-10,-663.8228448830648,-2027.2101338882571,-3194.0427904869357,-3728.3876362721985,-3684.6430045258744
-1.9688714316525813,0.9999999998992586,224.64320300800793,666.0546805817288,1038.3830530062712,1207.4338980088214,1193.1790131535502
0.9819818977427489,1.1680695590205036e-11,-28.533774174029173,-82.17596308875525,-126.6770208129477,-146.65755463691826,-144.8506009433783
-20619.128648244743,2.4364997877410417e-06,26505.585137008606,-337279.3213902739,-1056051.2792994028,-1815539.1160187968,-2372171.980894541,-2642993.4538858426
56203.20048346139,-6.774323967911372e-06,-51225.01460831775,1005023.6254387972,3051609.2101441943,5201294.212075991,6773264.754466731,7538833.212217793
-63802.106117440504,7.845612740225726e-06,33089.880661840034,-1242527.9972772636,-3668761.3028854067,-6202335.40819644,-8050708.344579743,-8951452.327576341
38603.18842240787,-4.844608638276231e-06,-4028.752491140328,816333.2796219026,2349291.871863084,3940828.5623758254,5099123.959731602,5663734.051678175
-13126.533425725584,1.6822282153058894e-06,-4395.4012467221355,-300757.7094990732,-845218.597424347,-1407243.8630987857,-1815244.4369415767,-2014105.8565458413
2378.155272695758,0.9999996885549859,1912.0755691304305,58944.34388638723,162014.93660541167,267802.2088119374,344395.5526651557,381710.2334140182
-178.70587585316136,2.4018054840276848e-08,-234.76082555771987,-4803.1698085743365,-12928.521798999534,-21220.235622246797,-27207.092578054173,-30121.285267280207
23 changes: 13 additions & 10 deletions src/diffpy/labpdfproc/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CVE_METHODS = ["brute_force", "polynomial_interpolation"]

# Pre-computed datasets for polynomial interpolation (fast calculation)
MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6]
MUD_LIST = [0.5, 1, 2, 3, 4, 5, 6, 7]
CWD = Path(__file__).parent.resolve()
MULS = np.loadtxt(CWD / "data" / "inverse_cve.xy")
COEFFICIENT_LIST = np.array(
Expand Down Expand Up @@ -206,25 +206,28 @@ def _cve_brute_force(input_pattern, mud):

def _cve_polynomial_interpolation(input_pattern, mud):
"""Compute cve using polynomial interpolation method,
raise an error if the mu*D value is out of the range (0.5 to 6).
raise an error if the mu*D value is out of the range (0.5 to 7).
"""
if mud > 6 or mud < 0.5:
if mud > 7 or mud < 0.5:
raise ValueError(
f"mu*D is out of the acceptable range (0.5 to 6) "
f"Input mu*D = {mud} is out of the acceptable range "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this message is a bit harsh.

Is there a reason we don't just print a warning message and default to computing using the brute-force method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited! Please check.

f"({min(MUD_LIST)} to {max(MUD_LIST)}) "
f"for polynomial interpolation. "
f"Please rerun with a value within this range "
f"or specifying another method from {*CVE_METHODS, }."
)
coeff_a, coeff_b, coeff_c, coeff_d, coeff_e = [
coef1, coef2, coef3, coef4, coef5, coef6, coef7 = [
interpolation_function(mud)
for interpolation_function in INTERPOLATION_FUNCTIONS
]
muls = np.array(
coeff_a * MULS**4
+ coeff_b * MULS**3
+ coeff_c * MULS**2
+ coeff_d * MULS
+ coeff_e
coef1 * MULS**6
+ coef2 * MULS**5
+ coef3 * MULS**4
+ coef4 * MULS**3
+ coef5 * MULS**2
+ coef6 * MULS
+ coef7
)
cve = 1 / muls
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the codes here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!


Expand Down
4 changes: 2 additions & 2 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def test_compute_cve(input_xtype, expected, mocker):
"inputs, msg",
[
(
{"mud": 7, "method": "polynomial_interpolation"},
f"mu*D is out of the acceptable range (0.5 to 6) "
{"mud": 10, "method": "polynomial_interpolation"},
f"mu*D = 10 is out of the acceptable range (0.5 to 7) "
f"for polynomial interpolation. "
f"Please rerun with a value within this range "
f"or specifying another method from {*CVE_METHODS, }.",
Expand Down
Loading