Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create figure in current directory #273

Merged

Conversation

marcpaterno
Copy link
Collaborator

This fixes the issue by creating the figure in the current directory, which was simpler than creating a subdirectory.

@marcpaterno marcpaterno linked an issue May 16, 2023 that may be closed by this pull request
@@ -295,7 +295,8 @@ def run_likelihood() -> None:
[a.legend(fontsize="small") for a in ax]

fig.suptitle("PT Cls, including IA, galaxy bias, magnification")
fig.savefig("plots/pt_cls.png", facecolor="white", dpi=300)
with open("pt_cls.png", "w+b") as png_file:
fig.savefig(png_file, facecolor="white", dpi=300)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the context manager instead of using the file name directly in savefig?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Habit. I prefer to make it obvious the resource is “cleaned up” (in this case, the file closed) rather than having a reader need to know whether the routine being called does the right thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's just here that fine but generally I'd argue having a context manager for savefig is overkill and likely to confuse users (what happens if you forget the "b"?). Might as well throw in a os.makedirs("plots", exists_ok=True) to deal with the subdir in that case.

@@ -295,7 +295,8 @@ def run_likelihood() -> None:
[a.legend(fontsize="small") for a in ax]

fig.suptitle("PT Cls, including IA, galaxy bias, magnification")
fig.savefig("plots/pt_cls.png", facecolor="white", dpi=300)
with open("pt_cls.png", "w+b") as png_file:
fig.savefig(png_file, facecolor="white", dpi=300)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's just here that fine but generally I'd argue having a context manager for savefig is overkill and likely to confuse users (what happens if you forget the "b"?). Might as well throw in a os.makedirs("plots", exists_ok=True) to deal with the subdir in that case.

@vitenti vitenti merged commit 84c4798 into master May 18, 2023
@vitenti vitenti deleted the 272-example-des_y1_3x2pt_ptpy-crashes-when-run-as-a-script branch May 18, 2023 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Example des_y1_3x2pt_PT.py crashes when run as a script
3 participants