diff --git a/news/capitalization.rst b/news/capitalization.rst new file mode 100644 index 0000000..1dc04a9 --- /dev/null +++ b/news/capitalization.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**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:** + +* + +**Removed:** + +* + +**Fixed:** + +* + +**Security:** + +* diff --git a/src/diffpy/morph/morph_io.py b/src/diffpy/morph/morph_io.py index b2d7e02..59bd4f4 100644 --- a/src/diffpy/morph/morph_io.py +++ b/src/diffpy/morph/morph_io.py @@ -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( @@ -148,7 +148,7 @@ 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( @@ -156,14 +156,20 @@ def get_terminal_morph_output(mr_copy, uncertainties): ) 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 @@ -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}]" @@ -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 diff --git a/src/diffpy/morph/morphapp.py b/src/diffpy/morph/morphapp.py index e23f148..27e4ee6 100755 --- a/src/diffpy/morph/morphapp.py +++ b/src/diffpy/morph/morphapp.py @@ -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] @@ -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: @@ -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 @@ -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 diff --git a/tests/test_morphapp.py b/tests/test_morphapp.py index 15e2d98..40641c4 100644 --- a/tests/test_morphapp.py +++ b/tests/test_morphapp.py @@ -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( @@ -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 diff --git a/tests/test_morphio.py b/tests/test_morphio.py index 67ca6da..1b08715 100644 --- a/tests/test_morphio.py +++ b/tests/test_morphio.py @@ -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 diff --git a/tests/test_morphpy.py b/tests/test_morphpy.py index 68b659a..cabb32d 100644 --- a/tests/test_morphpy.py +++ b/tests/test_morphpy.py @@ -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(): @@ -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(): diff --git a/tests/testdata/testsequence/testsaving/succinct/Morph_Reference_Table.txt b/tests/testdata/testsequence/testsaving/succinct/Morph_Reference_Table.txt index 9759b83..fc1e07b 100644 --- a/tests/testdata/testsequence/testsaving/succinct/Morph_Reference_Table.txt +++ b/tests/testdata/testsequence/testsaving/succinct/Morph_Reference_Table.txt @@ -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 diff --git a/tests/testdata/testsequence/testsaving/verbose/Morph_Reference_Table.txt b/tests/testdata/testsequence/testsaving/verbose/Morph_Reference_Table.txt index 83445d1..d31a73f 100644 --- a/tests/testdata/testsequence/testsaving/verbose/Morph_Reference_Table.txt +++ b/tests/testdata/testsequence/testsaving/verbose/Morph_Reference_Table.txt @@ -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 diff --git a/tests/testdata/testsequence/testsaving/verbose_unc/Morph_Reference_Table.txt b/tests/testdata/testsequence/testsaving/verbose_unc/Morph_Reference_Table.txt index af8f85e..45cd6d0 100644 --- a/tests/testdata/testsequence/testsaving/verbose_unc/Morph_Reference_Table.txt +++ b/tests/testdata/testsequence/testsaving/verbose_unc/Morph_Reference_Table.txt @@ -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