Skip to content

Commit 71010e2

Browse files
Sparks29032sbillingepre-commit-ci[bot]
authored
Support 3.14. Switch from loadData->load_data. (#303)
* Update deprecations, support 3.14 * [pre-commit.ci] auto fixes from pre-commit hooks --------- Co-authored-by: Simon Billinge <sbillinge@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d3eb142 commit 71010e2

10 files changed

Lines changed: 61 additions & 36 deletions

File tree

docs/source/funcxy.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ kapton background ``background.chi``.
4040
4141
from diffpy.pdfgetx.pdfgetter import PDFGetter
4242
from diffpy.morph.morphpy import morph_arrays
43-
from diffpy.utils.parsers.loaddata import loadData
43+
from diffpy.utils.parsers import load_data
4444
4545
pg = PDFGetter()
4646
@@ -60,8 +60,8 @@ kapton background ``background.chi``.
6060
return (r, gr)
6161
6262
63-
sample_iq = loadData("sample.chi")
64-
target_gr = loadData("target.cgr")
63+
sample_iq = load_data("sample.chi")
64+
target_gr = load_data("target.cgr")
6565
params_to_morph = {
6666
"bgscale": 1.0,
6767
"qmin": 0.0, "qmax": 25.0,
@@ -124,7 +124,7 @@ our wavelength was ``1.11`` angstroms.
124124
import pyFAI.integrator.azimuthal as pyfai
125125
import pyFAI.detectors as pfd
126126
from diffpy.morph.morphpy import morph_arrays
127-
from diffpy.utils.parsers.loaddata import loadData
127+
from diffpy.utils.parsers.load_data import load_data
128128
129129
pattern_2d = np.load("diffraction_image.npy")
130130
wavelength = 0.1110e-9 # in m
@@ -163,8 +163,8 @@ our wavelength was ``1.11`` angstroms.
163163
"cent_offset_y": 0 # in number of pixels
164164
}
165165
166-
sample_chi = loadData("sample.chi")
167-
target_chi = loadData("target.chi")
166+
sample_chi = load_data("sample.chi")
167+
target_chi = load_data("target.chi")
168168
169169
morph_info, morphed_chi = morph_arrays(
170170
sample_chi, target_chi,

news/3.14.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* Updated support from 3.11-3.13 to 3.12-3.14.
8+
* Requires diffpy.utils>=3.7.1.
9+
10+
**Deprecated:**
11+
12+
* <news item>
13+
14+
**Removed:**
15+
16+
* <news item>
17+
18+
**Fixed:**
19+
20+
* <news item>
21+
22+
**Security:**
23+
24+
* <news item>

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ maintainers = [
1414
description = "Python package for manipulating and comparing 1D signals."
1515
keywords = ['diffpy', 'pdf', 'data interpretation']
1616
readme = "README.rst"
17-
requires-python = ">=3.11, <3.14"
17+
requires-python = ">=3.12, <3.15"
1818
classifiers = [
1919
'Development Status :: 5 - Production/Stable',
2020
'Environment :: Console',
@@ -25,9 +25,9 @@ classifiers = [
2525
'Operating System :: Microsoft :: Windows',
2626
'Operating System :: POSIX',
2727
'Operating System :: Unix',
28-
'Programming Language :: Python :: 3.11',
2928
'Programming Language :: Python :: 3.12',
3029
'Programming Language :: Python :: 3.13',
30+
'Programming Language :: Python :: 3.14',
3131
'Topic :: Scientific/Engineering :: Physics',
3232
'Topic :: Scientific/Engineering :: Chemistry',
3333
]

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.6.1
3+
diffpy.utils>=3.7.1
44
matplotlib-base
55
bg-mpl-stylesheets

src/diffpy/morph/morph_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def morph(
245245
chain(x_morph, y_morph, x_target, y_target)
246246

247247
# summary
248-
rw = tools.getRw(chain)
248+
rw = tools.get_rw(chain)
249249
pcc = tools.get_pearson(chain)
250250
# restore rgrid
251251
chain[0] = morphs.Morph()

src/diffpy/morph/morphapp.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@ def single_morph(
527527
x_target = pargs[4]
528528
y_target = pargs[5]
529529
else:
530-
x_morph, y_morph = getPDFFromFile(pargs[0])
531-
x_target, y_target = getPDFFromFile(pargs[1])
530+
x_morph, y_morph = get_two_column_from_file(pargs[0])
531+
x_target, y_target = get_two_column_from_file(pargs[1])
532532

533533
if y_morph is None:
534534
parser.morph_error(f"No data table found in: {pargs[0]}.", ValueError)
@@ -754,7 +754,7 @@ def single_morph(
754754
io.handle_extrapolation_warnings(stretch_morph)
755755

756756
# Get Rw for the morph range
757-
rw = tools.getRw(chain)
757+
rw = tools.get_rw(chain)
758758
pcc = tools.get_pearson(chain)
759759
# Replace the MorphRGrid with Morph identity
760760
# This removes the r-range morph as mentioned above
@@ -1261,19 +1261,20 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False):
12611261
return morph_results
12621262

12631263

1264-
def getPDFFromFile(fn):
1265-
from diffpy.morph.tools import readPDF
1264+
def get_two_column_from_file(fn):
1265+
"""Open a two column data file and extract the data."""
1266+
from diffpy.morph.tools import read_two_column
12661267

12671268
try:
1268-
r, gr = readPDF(fn)
1269+
x, fx = read_two_column(fn)
12691270
except IOError as errmsg:
12701271
print("%s: %s" % (fn, errmsg), file=sys.stderr)
12711272
sys.exit(1)
12721273
except ValueError:
12731274
print("Cannot read %s" % fn, file=sys.stderr)
12741275
sys.exit(1)
12751276

1276-
return r, gr
1277+
return x, fx
12771278

12781279

12791280
def main():

src/diffpy/morph/tools.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616

1717
import numpy
1818

19-
from diffpy.utils.parsers.loaddata import loadData
19+
from diffpy.utils.parsers import load_data
2020
from diffpy.utils.parsers.serialization import deserialize_data
2121

2222

23-
def estimateScale(y_morph_in, y_target_in):
23+
def estimate_scale(y_morph_in, y_target_in):
2424
"""Set the scale that best matches the morph to the target."""
2525
dot = numpy.dot
2626
scale = dot(y_morph_in, y_target_in) / dot(y_morph_in, y_morph_in)
2727
return scale
2828

2929

30-
def estimateBaselineSlope(r, gr, rmin=None, rmax=None):
30+
def estimate_baseline_slope(r, gr, rmin=None, rmax=None):
3131
"""Estimate the slope of the linear baseline of a PDF.
3232
3333
This fits a slope into the equation slope*r through the bottom of the PDF.
@@ -84,7 +84,7 @@ def chiv(pars):
8484
return slope
8585

8686

87-
def getRw(chain):
87+
def get_rw(chain):
8888
"""Get Rw from the outputs of a morph or chain."""
8989
# Make sure we put these on the proper grid
9090
x_morph, y_morph, x_target, y_target = chain.xyallout
@@ -103,8 +103,8 @@ def get_pearson(chain):
103103
return pcc
104104

105105

106-
def readPDF(fname):
107-
"""Reads an .gr file, loads r and G(r) vectors.
106+
def read_two_column(fname):
107+
"""Reads a two-column data file, loads x and f(x) vectors.
108108
109109
Parameters
110110
----------
@@ -113,10 +113,10 @@ def readPDF(fname):
113113
114114
Returns
115115
-------
116-
r,gr
116+
x,fx
117117
Arrays read from data.
118118
"""
119-
rv = loadData(fname, unpack=True)
119+
rv = load_data(fname, unpack=True)
120120
if len(rv) >= 2:
121121
return rv[:2]
122122
return (None, None)
@@ -204,7 +204,7 @@ def field_sort(
204204
files_field_values = []
205205
if serfile is None:
206206
for path in filepaths:
207-
fhd = loadData(path, headers=True)
207+
fhd = load_data(path, headers=True)
208208
files_field_values.append(
209209
[path, case_insensitive_dictionary_search(field, fhd)]
210210
)

tests/test_morphio.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
single_morph,
1212
)
1313
from diffpy.morph.morphpy import morph_arrays
14-
from diffpy.utils.parsers.loaddata import loadData
14+
from diffpy.utils.parsers import load_data
1515

1616
# Support Python 2
1717
try:
@@ -68,9 +68,9 @@ def are_files_same(file1, file2):
6868
def are_diffs_right(file1, file2, diff_file):
6969
"""Assert that diff_file ordinate data is approximately file1
7070
ordinate data minus file2 ordinate data."""
71-
f1_data = loadData(file1)
72-
f2_data = loadData(file2)
73-
diff_data = loadData(diff_file)
71+
f1_data = load_data(file1)
72+
f2_data = load_data(file2)
73+
diff_data = load_data(diff_file)
7474

7575
xmin = max(min(f1_data[:, 0]), min(f1_data[:, 1]))
7676
xmax = min(max(f2_data[:, 0]), max(f2_data[:, 1]))

tests/test_morphpy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from diffpy.morph.morphapp import create_option_parser, single_morph
99
from diffpy.morph.morphpy import __get_morph_opts__, morph, morph_arrays
10-
from diffpy.morph.tools import getRw
10+
from diffpy.morph.tools import get_rw
1111

1212
thisfile = locals().get("__file__", "file.py")
1313
tests_dir = Path(thisfile).parent.resolve()
@@ -166,7 +166,7 @@ class Chain:
166166
xyallout = grm[:, 0], grm[:, 1], grt[:, 0], grt[:, 1]
167167

168168
chain = Chain()
169-
rw = getRw(chain)
169+
rw = get_rw(chain)
170170
del chain
171171
assert np.allclose(
172172
[rw], [self.morphapp_results[target_file.name]["Rw"]]
@@ -237,7 +237,7 @@ class Chain:
237237
xyallout = grm[:, 0], grm[:, 1], grt[:, 0], grt[:, 1]
238238

239239
chain = Chain()
240-
rw = getRw(chain)
240+
rw = get_rw(chain)
241241
del chain
242242
assert np.allclose(
243243
[rw], [self.morphapp_results[target_file.name]["Rw"]]

tests/test_tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def setup(self):
2626
self.rho0 = 0.0917132
2727
return
2828

29-
def test_estimateBaselineSlope(self, setup):
29+
def test_estimate_baseline_slope(self, setup):
3030
"""Check estimateBaselineSlope() using calculated data."""
31-
slope = tools.estimateBaselineSlope(self.x_morph, self.y_morph)
31+
slope = tools.estimate_baseline_slope(self.x_morph, self.y_morph)
3232
slopecalc = -4 * numpy.pi * self.rho0
3333
assert numpy.allclose(slopecalc, slope, 1e-2)
3434
return
@@ -38,7 +38,7 @@ def test_estimateScale(self, setup):
3838
import random
3939

4040
x = random.random()
41-
scale = tools.estimateScale(self.y_morph, x * self.y_morph)
41+
scale = tools.estimate_scale(self.y_morph, x * self.y_morph)
4242
assert x, scale
4343
return
4444

0 commit comments

Comments
 (0)