Skip to content

Commit d1339f6

Browse files
committed
Standardize lower-case for all dictionary keys
1 parent 2c7dbe5 commit d1339f6

9 files changed

Lines changed: 53 additions & 24 deletions

File tree

news/capitalization.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+
* All dictionary keys and column headers are lower-cased. This includes Rw->rw, Pearson->pearson, and the user-given --field-sort quantity is made lower-case.
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>

src/diffpy/morph/morph_io.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def get_terminal_morph_output(mr_copy, uncertainties):
129129
# Handle special inputs (numerical)
130130
if "squeeze" in mr_copy:
131131
sq_dict = mr_copy.pop("squeeze")
132-
rw_pos = list(mr_copy.keys()).index("Rw")
132+
rw_pos = list(mr_copy.keys()).index("rw")
133133
morph_results_list = list(mr_copy.items())
134134
for idx, _ in enumerate(sq_dict):
135135
morph_results_list.insert(
@@ -148,22 +148,28 @@ def get_terminal_morph_output(mr_copy, uncertainties):
148148
func_dicts[func][0] = mr_copy.pop(f"{func}_function")
149149
if func in mr_copy:
150150
func_dicts[func][1] = mr_copy.pop(func)
151-
rw_pos = list(mr_copy.keys()).index("Rw")
151+
rw_pos = list(mr_copy.keys()).index("rw")
152152
morph_results_list = list(mr_copy.items())
153153
for idx, key in enumerate(func_dicts[func][1]):
154154
morph_results_list.insert(
155155
rw_pos + idx, (f"{func} {key}", func_dicts[func][1][key])
156156
)
157157
mr_copy = dict(morph_results_list)
158158

159-
# Get uncertainties
159+
# Keywords that should be capitalized in the saved files
160+
special_keywords = ["rw", "pearson"]
161+
162+
# Print outputs including uncertainties when applicable
160163
if uncertainties is None:
161164
morphs_out += "\n".join(
162-
f"# {key} = {mr_copy[key]:.6f}" for key in mr_copy.keys()
165+
f"# {key.capitalize() if key in special_keywords else key} = "
166+
f"{mr_copy[key]:.6f}"
167+
for key in mr_copy.keys()
163168
)
164169
else:
165170
morphs_out += "\n".join(
166-
f"# {key} = {mr_copy[key]:.6f}"
171+
f"# {key.capitalize() if key in special_keywords else key} = "
172+
f"{mr_copy[key]:.6f}"
167173
+ (
168174
f" +/- {uncertainties[key]:.6f}"
169175
if key in uncertainties
@@ -431,11 +437,11 @@ def multiple_morph_output(
431437

432438
# Table labels
433439
if not mm:
434-
labels = "\n# Labels: [Target]"
440+
labels = "\n# Labels: [target]"
435441
else:
436-
labels = "\n# Labels: [Morph]"
442+
labels = "\n# Labels: [morph]"
437443
if field is not None:
438-
labels += f" [{field}]"
444+
labels += f" [{field.lower()}]"
439445
for param in tabulated_results.keys():
440446
if len(tabulated_results[param]) > 0:
441447
labels += f" [{param}]"
@@ -501,7 +507,7 @@ def tabulate_results(multiple_morph_results):
501507
corresponding value is a list of data for that column.
502508
"""
503509
# We only care about the following parameters in our data tables
504-
relevant_parameters = ["Scale", "Smear", "Stretch", "Pearson", "Rw"]
510+
relevant_parameters = ["scale", "smear", "stretch", "pearson", "rw"]
505511

506512
# Keys in this table represent column names and the value will be a list
507513
# of column data

src/diffpy/morph/morphapp.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@ def single_morph(
854854
# Output morph parameters
855855
morph_results = dict(config.items())
856856
# Ensure Rw, Pearson last two outputs
857-
morph_results.update({"Rw": rw})
858-
morph_results.update({"Pearson": pcc})
857+
morph_results.update({"rw": rw})
858+
morph_results.update({"pearson": pcc})
859859

860860
# Print summary to terminal and save morph to file if requested
861861
xy_save = [chain.x_morph_out, chain.y_morph_out]
@@ -921,7 +921,7 @@ def single_morph(
921921
if python_wrap:
922922
morph_info = morph_results
923923
if opts.estimate_uncertainty is not None and unc is not None:
924-
morph_info.update({"Uncertainties": unc})
924+
morph_info.update({"uncertainties": unc})
925925
morph_table = numpy.array(xy_save).T
926926
return morph_info, morph_table
927927
else:
@@ -1089,7 +1089,7 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False):
10891089
plot_results = io.tabulate_results(morph_results)
10901090
# Default parameter is Rw
10911091
param_name = r"$R_w$"
1092-
param_list = plot_results["Rw"]
1092+
param_list = plot_results["rw"]
10931093
# Find parameter if specified
10941094
if opts.plotparam is not None:
10951095
param_name = opts.plotparam
@@ -1284,7 +1284,7 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False):
12841284
plot_results = io.tabulate_results(morph_results)
12851285
# Default parameter is Rw
12861286
param_name = r"$R_w$"
1287-
param_list = plot_results["Rw"]
1287+
param_list = plot_results["rw"]
12881288
# Find parameter if specified
12891289
if opts.plotparam is not None:
12901290
param_name = opts.plotparam

tests/test_morphapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def gaussian(x, mu, sigma):
344344
)[0]
345345
# Variances add, and 3^2+4^2=5^2
346346
assert pytest.approx(abs(smear_results["smear"])) == 4.0
347-
assert pytest.approx(smear_results["Rw"]) == 0.0
347+
assert pytest.approx(smear_results["rw"]) == 0.0
348348

349349
# PDF-specific smear (should activate baseline slope)
350350
opts, _ = self.parser.parse_args(
@@ -361,4 +361,4 @@ def gaussian(x, mu, sigma):
361361
self.parser, opts, pargs, stdout_flag=False
362362
)[0]
363363
assert pytest.approx(abs(pdf_smear_results["smear"])) == 4.0
364-
assert pytest.approx(pdf_smear_results["Rw"]) == 0.0
364+
assert pytest.approx(pdf_smear_results["rw"]) == 0.0

tests/test_morphio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ def fx(x, y, ax0, ax1):
461461
uncertainty=True,
462462
)
463463

464-
assert "Uncertainties" in morph_info.keys()
464+
assert "uncertainties" in morph_info.keys()
465465
params = ["funcy ay0", "funcy ay1", "funcx ax0", "funcx ax1"]
466-
for unc in morph_info["Uncertainties"].keys():
466+
for unc in morph_info["uncertainties"].keys():
467467
assert unc in params
468-
assert morph_info["Uncertainties"][unc] is not None
468+
assert morph_info["uncertainties"][unc] is not None

tests/test_morphpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class Chain:
186186
rw = get_rw(chain)
187187
del chain
188188
assert np.allclose(
189-
[rw], [self.morphapp_results[target_file.name]["Rw"]]
189+
[rw], [self.morphapp_results[target_file.name]["rw"]]
190190
)
191191
# Check values in dictionaries are approximately equal
192192
for file in morph_results.keys():
@@ -257,7 +257,7 @@ class Chain:
257257
rw = get_rw(chain)
258258
del chain
259259
assert np.allclose(
260-
[rw], [self.morphapp_results[target_file.name]["Rw"]]
260+
[rw], [self.morphapp_results[target_file.name]["rw"]]
261261
)
262262
# Check values in dictionaries are approximately equal
263263
for file in morph_results.keys():

tests/testdata/testsequence/testsaving/succinct/Morph_Reference_Table.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# hshift = None
1010
# vshift = None
1111

12-
# Labels: [Target] [Temperature] [Pearson] [Rw]
12+
# Labels: [target] [temperature] [pearson] [rw]
1313
f_180K.gr 180.0 0.999810 0.020141
1414
e_186K.gr 186.0 0.999424 0.034859
1515
d_192K.gr 192.0 0.998077 0.062392

tests/testdata/testsequence/testsaving/verbose/Morph_Reference_Table.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
# Rw = 0.127100
5858
# Pearson = 0.992111
5959

60-
# Labels: [Target] [Temperature] [Pearson] [Rw]
60+
# Labels: [target] [temperature] [pearson] [rw]
6161
f_180K.gr 180.0 0.999810 0.020141
6262
e_186K.gr 186.0 0.999424 0.034859
6363
d_192K.gr 192.0 0.998077 0.062392

tests/testdata/testsequence/testsaving/verbose_unc/Morph_Reference_Table.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
# Rw = 0.117614
7878
# Pearson = 0.993059
7979

80-
# Labels: [Target] [Temperature] [Scale] [Pearson] [Rw]
80+
# Labels: [target] [temperature] [scale] [pearson] [rw]
8181
f_180K.gr 180.0 0.994948 0.999842 0.017766
8282
e_186K.gr 186.0 0.992167 0.999549 0.030029
8383
d_192K.gr 192.0 0.993095 0.998318 0.057982

0 commit comments

Comments
 (0)