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

PEP8 and black #34

Merged
merged 3 commits into from
Apr 5, 2022
Merged

PEP8 and black #34

merged 3 commits into from
Apr 5, 2022

Conversation

bryanwweber
Copy link
Member

@bryanwweber bryanwweber commented Feb 20, 2022

  • Variable names conform to PEP 8 style
  • Run the Black code formatter on the notebooks
  • Show the currently running Cantera version in all the Notebooks
  • Switch all plots to %matplotlib inline because:
    1. JupyterLab does not support %matplotlib notebook and I found the recommended replacement %matplotlib widgets to be unreliable in terms of showing up after I closed the notebook
    2. This should give a consistent look to the output on the website

@bryanwweber
Copy link
Member Author

Screen Shot 2022-02-20 at 3 46 26 PM

This is simply ridiculous! It must be from removing all the %matplotlib notebook JS garbage from the output.

@ischoegl
Copy link
Member

Indeed impressive 😄. You could save even more with non-executed notebooks … which would also make changes tractable; otherwise I’m not sure that it’s reasonable to go through this line-by-line 😆

@ischoegl
Copy link
Member

But out of curiosity: would SVG images be more economical to save than png?

@bryanwweber
Copy link
Member Author

You could save even more with non-executed notebooks … which would also make changes tractable; otherwise I’m not sure that it’s reasonable to go through this line-by-line 😆

Yah, reviewing these PRs is super hard. I don't think this really needs a review, unless we want to bikeshed about Black's formatting style. I'm posting it here mainly to have a place to discuss anything that might come up, and so there's some record of this happening aside from the commit messages, even if I hit the big green button myself 😄

I executed everything so I know it all works, and so that it would show up in the static view on GitHub itself. The website build runs the Notebooks (I think), so that's fine.

But out of curiosity: would SVG images be more economical to save than png?

I'm not sure, possibly. But I don't know how to generate those automatically with a magic like %matplotlib inline 😄

@ischoegl
Copy link
Member

ischoegl commented Feb 21, 2022

I believe there’s this magic … not sure though as I just ‘borrowed’ this from some recent notebook from our group

%config InlineBackend.figure_formats = ['svg']

@bryanwweber
Copy link
Member Author

FYI, you can comment/review the Notebooks in this PR over here: https://app.reviewnb.com/Cantera/cantera-jupyter/pull/34/

Copy link
Member

@ischoegl ischoegl left a comment

Choose a reason for hiding this comment

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

I mainly had a cursory look and as this is mostly formatting this looks good to me. (Fwiw, if we want to update content of individual notebooks, this is probably not the place.)

So I overall have no issues with adopting as is (although it would be great if the issues I pointed out in Cantera/cantera-website#171 could be addressed. Notably, the LaTeX formatting glitch in equations_of_state.ipynb doesn't show up here, which is odd).

@ischoegl
Copy link
Member

@bryanwweber ... I cannot reproduce the LaTeX artifacts, so from my perspective it's ok to :shipit:

@bryanwweber
Copy link
Member Author

@bryanwweber ... I cannot reproduce the LaTeX artifacts, so from my perspective it's ok to :shipit:

👍 I'm planning to add those few fixes plus the fix for SolutionArray extra elements

@speth
Copy link
Member

speth commented Apr 1, 2022

@bryanwweber - Unless whatever other changes you want to make are as pervasive as these, can we handle them in a separate PR? Otherwise, waiting on this makes any other PRs against this repo impossible without running into merge conflicts. Also, any additional changes made in this repository will be difficult to review for the same reason.

@bryanwweber
Copy link
Member Author

@speth sure, the other changes can go in a new PR. This is ready for review then, or merging if it's good.

Copy link
Member

@speth speth left a comment

Choose a reason for hiding this comment

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

Having to switch to %matplotlib inline is a little disappointing -- I think the figures end up looking a lot worse than they do with the notebook or widget backends, but I'm also seeing the issue with restoring plots in a saved notebook. Two things that would improve things are

  • setting plt.rcParams['figure.dpi'] to a higher value than the default of 72 -- maybe 96 or even 120 since the figures are pretty tiny by default.
  • Using @ischoegl's suggestion of %config InlineBackend.figure_formats = ['svg']. On high-DPI displays, this seems to result in much crisper figures than the PNG images that end up looking fuzzy after they get blown up.

For once I'm OK with running black on the repository -- I think these notebooks have been harder to keep consistent formatting in, and I'd say the result here is clearly an improvement.

@bryanwweber
Copy link
Member Author

Thanks for the review @speth! I'm out of town for the weekend, so if you want to push one of those options to this branch, please feel free. Otherwise, I'll pick it up on Monday.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@bryanwweber
Copy link
Member Author

@speth I updated based on your suggestions! Figures look much better now.

@ischoegl
Copy link
Member

ischoegl commented Apr 5, 2022

Too bad that figures don't render on ReviewNB (I checked only one of the files though) ... per discussion elsewhere, I hope that display works as intended once things are uploaded to GH / embedded in the website.

@speth
Copy link
Member

speth commented Apr 5, 2022

I just tested this with a local checkout of both the cantera-jupyter and cantera-website repositories, and all of the figures look great.

@speth speth merged commit f609a9f into Cantera:main Apr 5, 2022
@bryanwweber bryanwweber deleted the pep8-and-black branch April 5, 2022 16:01
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.

3 participants