Skip to content

Commit 0bc478a

Browse files
authored
Merge branch 'main' into strictly-increasing-squeeze
2 parents d6b320d + dce54cf commit 0bc478a

File tree

13 files changed

+339
-10
lines changed

13 files changed

+339
-10
lines changed

docs/source/tutorials.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ selected directory and plot resulting :math:`R_w` values from each morph.
6767

6868
4. Between 192K and 198K, the Rw has a sharp increase, indicating that
6969
we may have a phase change. To confirm, let us now apply morphs
70-
onto `` SrFe2As2_150K.gr`` with all other files in
70+
onto ``SrFe2As2_150K.gr`` with all other files in
7171
``morphsequence`` as targets ::
7272

7373
diffpy.morph --scale=1 --stretch=0 SrFe2As2_150K.gr . --multiple-targets --sort-by=temperature
@@ -191,10 +191,10 @@ Currently, the supported nanoparticle shapes include: spheres and spheroids.
191191

192192
* Within the ``additionalData`` directory, ``cd`` into the
193193
``morphShape`` subdirectory. Inside, you will find a sample Ni bulk
194-
material PDF ``Ni_bulk.gr``. This PDF is from `"Atomic Pair
195-
Distribution Function Analysis:
196-
A primer" <https://global.oup.com/academic/product/
197-
atomic-pair-distribution-function-analysis-9780198885801>`_.
194+
material PDF ``Ni_bulk.gr``. This PDF is from
195+
`"Atomic Pair Distribution Function Analysis: A primer"
196+
<https://global.oup.com/academic/product/
197+
atomic-pair-distribution-function-analysis-9780198885801>`_.
198198
There are also multiple ``.cgr`` files with calculated Ni nanoparticle PDFs.
199199

200200
* Let us apply various shape effect morphs on the bulk material to

news/enough-regression-points.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* Raise ``ValueError`` if the number of shared grid points between morphed and target functions is less than the number of parameters.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

news/extrapolate-warning.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news added: Add warning for extrapolation in morphsqueeze.py.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

news/no-subprocess.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* Removed subprocess calls in test functions.

news/reduce-warns.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* Only give user extrapolation warning after refinement.
20+
21+
**Security:**
22+
23+
* <news item>

news/rst-markup.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news added: Fix rst markup in the documentation.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

requirements/conda.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
numpy
22
scipy
3-
diffpy.utils
3+
diffpy.utils>=3.6.1
44
matplotlib-base
55
bg-mpl-stylesheets

src/diffpy/morph/morph_io.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import inspect
2020
import sys
21+
import warnings
2122
from pathlib import Path
2223

2324
import numpy
@@ -26,6 +27,13 @@
2627
from diffpy.morph import __save_morph_as__
2728

2829

30+
def custom_formatwarning(msg, *args, **kwargs):
31+
return f"{msg}\n"
32+
33+
34+
warnings.formatwarning = custom_formatwarning
35+
36+
2937
def single_morph_output(
3038
morph_inputs,
3139
morph_results,
@@ -398,3 +406,34 @@ def tabulate_results(multiple_morph_results):
398406
}
399407
)
400408
return tabulated_results
409+
410+
411+
def handle_warnings(squeeze_morph):
412+
if squeeze_morph is not None:
413+
eil = squeeze_morph.extrap_index_low
414+
eih = squeeze_morph.extrap_index_high
415+
416+
if eil is not None or eih is not None:
417+
if eih is None:
418+
wmsg = (
419+
"Warning: points with grid value below "
420+
f"{squeeze_morph.squeeze_cutoff_low} "
421+
f"will be extrapolated."
422+
)
423+
elif eil is None:
424+
wmsg = (
425+
"Warning: points with grid value above "
426+
f"{squeeze_morph.squeeze_cutoff_high} "
427+
f"will be extrapolated."
428+
)
429+
else:
430+
wmsg = (
431+
"Warning: points with grid value below "
432+
f"{squeeze_morph.squeeze_cutoff_low} and above "
433+
f"{squeeze_morph.squeeze_cutoff_high} "
434+
f"will be extrapolated."
435+
)
436+
warnings.warn(
437+
wmsg,
438+
UserWarning,
439+
)

src/diffpy/morph/morphapp.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ def single_morph(
546546
# Squeeze
547547
squeeze_poly_deg = -1
548548
squeeze_dict_in = {}
549+
squeeze_morph = None
549550
if opts.squeeze is not None:
550551
# Handles both list and csv input
551552
if (
@@ -570,7 +571,8 @@ def single_morph(
570571
except ValueError:
571572
parser.error(f"{coeff} could not be converted to float.")
572573
squeeze_poly_deg = len(squeeze_dict_in.keys())
573-
chain.append(morphs.MorphSqueeze())
574+
squeeze_morph = morphs.MorphSqueeze()
575+
chain.append(squeeze_morph)
574576
config["squeeze"] = squeeze_dict_in
575577
# config["extrap_index_low"] = None
576578
# config["extrap_index_high"] = None
@@ -696,6 +698,9 @@ def single_morph(
696698
else:
697699
chain(x_morph, y_morph, x_target, y_target)
698700

701+
# THROW ANY WARNINGS HERE
702+
io.handle_warnings(squeeze_morph)
703+
699704
# Get Rw for the morph range
700705
rw = tools.getRw(chain)
701706
pcc = tools.get_pearson(chain)

src/diffpy/morph/morphs/morphsqueeze.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ class MorphSqueeze(Morph):
6666
# extrap_index_high: first index after interpolation region
6767
extrap_index_low = None
6868
extrap_index_high = None
69+
squeeze_cutoff_low = None
70+
squeeze_cutoff_high = None
71+
72+
def __init__(self, config=None):
73+
super().__init__(config)
6974

7075
def morph(self, x_morph, y_morph, x_target, y_target):
7176
"""Apply a polynomial to squeeze the morph function.
@@ -85,11 +90,15 @@ def morph(self, x_morph, y_morph, x_target, y_target):
8590
"Please change the input x_morph or the squeeze "
8691
"coefficients."
8792
)
93+
94+
self.squeeze_cutoff_low = min(x_squeezed)
95+
self.squeeze_cutoff_high = max(x_squeezed)
8896
self.y_morph_out = CubicSpline(x_squeezed, self.y_morph_in)(
8997
self.x_morph_in
9098
)
91-
low_extrap = np.where(self.x_morph_in < x_squeezed[0])[0]
92-
high_extrap = np.where(self.x_morph_in > x_squeezed[-1])[0]
99+
low_extrap = np.where(self.x_morph_in < self.squeeze_cutoff_low)[0]
100+
high_extrap = np.where(self.x_morph_in > self.squeeze_cutoff_high)[0]
93101
self.extrap_index_low = low_extrap[-1] if low_extrap.size else None
94102
self.extrap_index_high = high_extrap[0] if high_extrap.size else None
103+
95104
return self.xyallout

0 commit comments

Comments
 (0)