Skip to content

Commit

Permalink
[ENH] Fix bug with figure directory creation and correct string in fi…
Browse files Browse the repository at this point in the history
…gures
  • Loading branch information
JGarciaCondado committed Apr 3, 2024
1 parent 6a6975b commit 6908fa5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
3 changes: 0 additions & 3 deletions src/ageml/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ def __init__(self, args):
# Set up directory for storage of results
self.setup()

# Initialise objects form library
self.set_visualizer(self.dir_path)

def setup(self):
"""Create main directory."""

Expand Down
4 changes: 2 additions & 2 deletions src/ageml/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def true_vs_pred_age(self, y_true, y_pred, tag: NameTag):
# Plot true vs predicted age
plt.scatter(y_true, y_pred)
plt.plot(age_range, age_range, color="k", linestyle="dashed")
plt.title(f"Chronological vs Predicted Age \n [Covariate: {tag.covar}, System:{tag.system}")
plt.title(f"Chronological vs Predicted Age \n [Covariate: {tag.covar}, System: {tag.system}]")
plt.xlabel("Chronological Age")
plt.ylabel("Predicted Age")

Expand Down Expand Up @@ -210,7 +210,7 @@ def age_bias_correction(self, y_true, y_pred, y_corrected, tag: NameTag):
filename = (f"age_bias_correction"
f"{'_' + tag.covar if tag.covar != '' else ''}"
f"{'_' + tag.system if tag.system != '' else ''}.png")
plt.suptitle(f"[Covariate: {tag.covar}, System:{tag.system}\n", y=1.00)
plt.suptitle(f"[Covariate: {tag.covar}, System: {tag.system}]\n", y=1.00)
plt.savefig(os.path.join(self.path_for_fig, filename))
plt.close()

Expand Down
6 changes: 6 additions & 0 deletions tests/test_ageml/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,15 @@ def test_load_data_different_indexes_warning(dummy_interface, features, clinical


def test_age_distribution_warning(dummy_interface):

# Create different distributions
dist1 = np.random.normal(loc=50, scale=1, size=100)
dist2 = np.random.normal(loc=0, scale=1, size=100)
dists = {'dist1': dist1, 'dist2': dist2}

# Set visualized in temporal directory
dummy_interface.set_visualizer(tempfile.mkdtemp())

with pytest.warns(UserWarning) as warn_record:
dummy_interface.age_distribution(dists)
assert isinstance(warn_record.list[0].message, UserWarning)
Expand Down

0 comments on commit 6908fa5

Please sign in to comment.