From 81e3bf0aa7c1d080ffce6188642d62bd9219c56a Mon Sep 17 00:00:00 2001 From: "Matthew N. White" Date: Tue, 20 Feb 2024 11:30:24 -0500 Subject: [PATCH 1/5] Remove metadata argument for jpg in make_figs Not supported for this filetype, was throwing error. --- HARK/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HARK/utilities.py b/HARK/utilities.py index 520dfc7dc..503e29056 100644 --- a/HARK/utilities.py +++ b/HARK/utilities.py @@ -1006,7 +1006,7 @@ def make_figs(figure_name, saveFigs, drawFigs, target_dir="Figures"): print(f"Saving figure {figure_name} in {target_dir}") plt.savefig( os.path.join(target_dir, f"{figure_name}.jpg"), - metadata={"CreationDate": None}, + #metadata={"CreationDate": None}, # metadata not supported for jpg ) # For web/html plt.savefig( os.path.join(target_dir, f"{figure_name}.png"), From 6e8e2db7fa4392920d34eec3937c69f31b098447 Mon Sep 17 00:00:00 2001 From: "Matthew N. White" Date: Tue, 20 Feb 2024 12:01:00 -0500 Subject: [PATCH 2/5] Adjust comment formatting I hate lint or black or whatever it is. PRs should not fail due to a missing space after a #. --- HARK/utilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HARK/utilities.py b/HARK/utilities.py index 503e29056..96181fbb9 100644 --- a/HARK/utilities.py +++ b/HARK/utilities.py @@ -1006,7 +1006,7 @@ def make_figs(figure_name, saveFigs, drawFigs, target_dir="Figures"): print(f"Saving figure {figure_name} in {target_dir}") plt.savefig( os.path.join(target_dir, f"{figure_name}.jpg"), - #metadata={"CreationDate": None}, # metadata not supported for jpg + # metadata is not supported for jpg ) # For web/html plt.savefig( os.path.join(target_dir, f"{figure_name}.png"), From b3baff42a2391e65e7b6dacd7e09ef7eb6bf4878 Mon Sep 17 00:00:00 2001 From: "Matthew N. White" Date: Tue, 20 Feb 2024 14:43:14 -0500 Subject: [PATCH 3/5] Add test for make_figs() --- HARK/tests/test_HARKutilities.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/HARK/tests/test_HARKutilities.py b/HARK/tests/test_HARKutilities.py index 2c9e27fc8..95be07999 100644 --- a/HARK/tests/test_HARKutilities.py +++ b/HARK/tests/test_HARKutilities.py @@ -3,6 +3,7 @@ """ # Bring in modules we need import unittest +import matplotlib.pyplot as plt from types import SimpleNamespace import numpy as np @@ -14,7 +15,7 @@ CRRAutilityPPP, CRRAutilityPPPP, ) -from HARK.utilities import construct_assets_grid +from HARK.utilities import construct_assets_grid, make_figs class testsForHARKutilities(unittest.TestCase): @@ -66,7 +67,7 @@ def test_CRRAutilityPPPP(self): self.derivative_func_comparison(CRRAutilityPPPP, CRRAutilityPPP) def test_asset_grid(self): - # test linear asset grid + # Test linear asset grid params = { "aXtraMin": 0.0, @@ -83,3 +84,10 @@ def test_asset_grid(self): test = np.unique(np.diff(aXtraGrid).round(decimals=3)) self.assertEqual(test.size, 1) + + def test_make_figs(self): + # Test the make_figs() function with a trivial output + plt.figure() + plt.plot(np.linspace(1,5,40),np.linspace(4,8,40) ) + make_figs('test', True , False, target_dir='') + plt.clf() From c8e63fb742bd94a3270b6d6c3c477edc26f81d91 Mon Sep 17 00:00:00 2001 From: "Matthew N. White" Date: Tue, 20 Feb 2024 14:48:43 -0500 Subject: [PATCH 4/5] Adjust spacing I hate this --- HARK/tests/test_HARKutilities.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/HARK/tests/test_HARKutilities.py b/HARK/tests/test_HARKutilities.py index 95be07999..1e945d513 100644 --- a/HARK/tests/test_HARKutilities.py +++ b/HARK/tests/test_HARKutilities.py @@ -3,9 +3,9 @@ """ # Bring in modules we need import unittest -import matplotlib.pyplot as plt from types import SimpleNamespace +import matplotlib.pyplot as plt import numpy as np from HARK.rewards import ( @@ -84,10 +84,10 @@ def test_asset_grid(self): test = np.unique(np.diff(aXtraGrid).round(decimals=3)) self.assertEqual(test.size, 1) - + def test_make_figs(self): # Test the make_figs() function with a trivial output plt.figure() - plt.plot(np.linspace(1,5,40),np.linspace(4,8,40) ) - make_figs('test', True , False, target_dir='') + plt.plot(np.linspace(1, 5, 40), np.linspace(4, 8, 40)) + make_figs("test", True , False, target_dir="") plt.clf() From c962d1e64055412b9f1b1b61a6a0d6d1de41bf8d Mon Sep 17 00:00:00 2001 From: "Matthew N. White" Date: Tue, 20 Feb 2024 14:51:15 -0500 Subject: [PATCH 5/5] Missed a space --- HARK/tests/test_HARKutilities.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HARK/tests/test_HARKutilities.py b/HARK/tests/test_HARKutilities.py index 1e945d513..a21ed3712 100644 --- a/HARK/tests/test_HARKutilities.py +++ b/HARK/tests/test_HARKutilities.py @@ -89,5 +89,5 @@ def test_make_figs(self): # Test the make_figs() function with a trivial output plt.figure() plt.plot(np.linspace(1, 5, 40), np.linspace(4, 8, 40)) - make_figs("test", True , False, target_dir="") + make_figs("test", True, False, target_dir="") plt.clf()