Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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/capitalization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* 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.

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
24 changes: 15 additions & 9 deletions src/diffpy/morph/morph_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def get_terminal_morph_output(mr_copy, uncertainties):
# Handle special inputs (numerical)
if "squeeze" in mr_copy:
sq_dict = mr_copy.pop("squeeze")
rw_pos = list(mr_copy.keys()).index("Rw")
rw_pos = list(mr_copy.keys()).index("rw")
morph_results_list = list(mr_copy.items())
for idx, _ in enumerate(sq_dict):
morph_results_list.insert(
Expand All @@ -148,22 +148,28 @@ def get_terminal_morph_output(mr_copy, uncertainties):
func_dicts[func][0] = mr_copy.pop(f"{func}_function")
if func in mr_copy:
func_dicts[func][1] = mr_copy.pop(func)
rw_pos = list(mr_copy.keys()).index("Rw")
rw_pos = list(mr_copy.keys()).index("rw")
morph_results_list = list(mr_copy.items())
for idx, key in enumerate(func_dicts[func][1]):
morph_results_list.insert(
rw_pos + idx, (f"{func} {key}", func_dicts[func][1][key])
)
mr_copy = dict(morph_results_list)

# Get uncertainties
# Keywords that should be capitalized in the saved files
special_keywords = ["rw", "pearson"]

# Print outputs including uncertainties when applicable
if uncertainties is None:
morphs_out += "\n".join(
f"# {key} = {mr_copy[key]:.6f}" for key in mr_copy.keys()
f"# {key.capitalize() if key in special_keywords else key} = "
f"{mr_copy[key]:.6f}"
for key in mr_copy.keys()
)
else:
morphs_out += "\n".join(
f"# {key} = {mr_copy[key]:.6f}"
f"# {key.capitalize() if key in special_keywords else key} = "
f"{mr_copy[key]:.6f}"
+ (
f" +/- {uncertainties[key]:.6f}"
if key in uncertainties
Expand Down Expand Up @@ -431,11 +437,11 @@ def multiple_morph_output(

# Table labels
if not mm:
labels = "\n# Labels: [Target]"
labels = "\n# Labels: [target]"
else:
labels = "\n# Labels: [Morph]"
labels = "\n# Labels: [morph]"
if field is not None:
labels += f" [{field}]"
labels += f" [{field.lower()}]"
for param in tabulated_results.keys():
if len(tabulated_results[param]) > 0:
labels += f" [{param}]"
Expand Down Expand Up @@ -501,7 +507,7 @@ def tabulate_results(multiple_morph_results):
corresponding value is a list of data for that column.
"""
# We only care about the following parameters in our data tables
relevant_parameters = ["Scale", "Smear", "Stretch", "Pearson", "Rw"]
relevant_parameters = ["scale", "smear", "stretch", "pearson", "rw"]

# Keys in this table represent column names and the value will be a list
# of column data
Expand Down
10 changes: 5 additions & 5 deletions src/diffpy/morph/morphapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,8 @@ def single_morph(
# Output morph parameters
morph_results = dict(config.items())
# Ensure Rw, Pearson last two outputs
morph_results.update({"Rw": rw})
morph_results.update({"Pearson": pcc})
morph_results.update({"rw": rw})
morph_results.update({"pearson": pcc})

# Print summary to terminal and save morph to file if requested
xy_save = [chain.x_morph_out, chain.y_morph_out]
Expand Down Expand Up @@ -921,7 +921,7 @@ def single_morph(
if python_wrap:
morph_info = morph_results
if opts.estimate_uncertainty is not None and unc is not None:
morph_info.update({"Uncertainties": unc})
morph_info.update({"uncertainties": unc})
morph_table = numpy.array(xy_save).T
return morph_info, morph_table
else:
Expand Down Expand Up @@ -1089,7 +1089,7 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True, python_wrap=False):
plot_results = io.tabulate_results(morph_results)
# Default parameter is Rw
param_name = r"$R_w$"
param_list = plot_results["Rw"]
param_list = plot_results["rw"]
# Find parameter if specified
if opts.plotparam is not None:
param_name = opts.plotparam
Expand Down Expand Up @@ -1284,7 +1284,7 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True, python_wrap=False):
plot_results = io.tabulate_results(morph_results)
# Default parameter is Rw
param_name = r"$R_w$"
param_list = plot_results["Rw"]
param_list = plot_results["rw"]
# Find parameter if specified
if opts.plotparam is not None:
param_name = opts.plotparam
Expand Down
4 changes: 2 additions & 2 deletions tests/test_morphapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def gaussian(x, mu, sigma):
)[0]
# Variances add, and 3^2+4^2=5^2
assert pytest.approx(abs(smear_results["smear"])) == 4.0
assert pytest.approx(smear_results["Rw"]) == 0.0
assert pytest.approx(smear_results["rw"]) == 0.0

# PDF-specific smear (should activate baseline slope)
opts, _ = self.parser.parse_args(
Expand All @@ -361,4 +361,4 @@ def gaussian(x, mu, sigma):
self.parser, opts, pargs, stdout_flag=False
)[0]
assert pytest.approx(abs(pdf_smear_results["smear"])) == 4.0
assert pytest.approx(pdf_smear_results["Rw"]) == 0.0
assert pytest.approx(pdf_smear_results["rw"]) == 0.0
6 changes: 3 additions & 3 deletions tests/test_morphio.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ def fx(x, y, ax0, ax1):
uncertainty=True,
)

assert "Uncertainties" in morph_info.keys()
assert "uncertainties" in morph_info.keys()
params = ["funcy ay0", "funcy ay1", "funcx ax0", "funcx ax1"]
for unc in morph_info["Uncertainties"].keys():
for unc in morph_info["uncertainties"].keys():
assert unc in params
assert morph_info["Uncertainties"][unc] is not None
assert morph_info["uncertainties"][unc] is not None
4 changes: 2 additions & 2 deletions tests/test_morphpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class Chain:
rw = get_rw(chain)
del chain
assert np.allclose(
[rw], [self.morphapp_results[target_file.name]["Rw"]]
[rw], [self.morphapp_results[target_file.name]["rw"]]
)
# Check values in dictionaries are approximately equal
for file in morph_results.keys():
Expand Down Expand Up @@ -257,7 +257,7 @@ class Chain:
rw = get_rw(chain)
del chain
assert np.allclose(
[rw], [self.morphapp_results[target_file.name]["Rw"]]
[rw], [self.morphapp_results[target_file.name]["rw"]]
)
# Check values in dictionaries are approximately equal
for file in morph_results.keys():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# hshift = None
# vshift = None

# Labels: [Target] [Temperature] [Pearson] [Rw]
# Labels: [target] [temperature] [pearson] [rw]
f_180K.gr 180.0 0.999810 0.020141
e_186K.gr 186.0 0.999424 0.034859
d_192K.gr 192.0 0.998077 0.062392
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
# Rw = 0.127100
# Pearson = 0.992111

# Labels: [Target] [Temperature] [Pearson] [Rw]
# Labels: [target] [temperature] [pearson] [rw]
f_180K.gr 180.0 0.999810 0.020141
e_186K.gr 186.0 0.999424 0.034859
d_192K.gr 192.0 0.998077 0.062392
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# Rw = 0.117614
# Pearson = 0.993059

# Labels: [Target] [Temperature] [Scale] [Pearson] [Rw]
# Labels: [target] [temperature] [scale] [pearson] [rw]
f_180K.gr 180.0 0.994948 0.999842 0.017766
e_186K.gr 186.0 0.992167 0.999549 0.030029
d_192K.gr 192.0 0.993095 0.998318 0.057982
Expand Down
Loading