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

Set figsize to consistent 8 by 8 inches, and reduce resolution to 100 dpi #786

Merged
merged 2 commits into from
Aug 21, 2024

Conversation

jfrost-mo
Copy link
Member

@jfrost-mo jfrost-mo commented Aug 12, 2024

This reduces some plot resolutions to make them a bit smaller (800px by 800px). 100 dpi is the matplotlib default. This makes the plots load faster on the website.

Contribution checklist

Aim to have all relevant checks ticked off before merging. See the developer's guide for more detail.

  • Documentation has been updated to reflect change.
  • New code has tests, and affected old tests have been updated.
  • All tests and CI checks pass.
  • Ensured the pull request title is descriptive.
  • Conda lock files have been updated if dependencies have changed.
  • Attributed any Generative AI, such as GitHub Copilot, used in this PR.
  • Marked the PR as ready to review.

Copy link
Contributor

github-actions bot commented Aug 12, 2024

Coverage

@jfrost-mo jfrost-mo changed the title Set figsize to consistent 8 by 8 inches, and dpi to 100 Set figsize to consistent 8 by 8 inches, and reduce dpi to 100 Aug 12, 2024
@jfrost-mo jfrost-mo changed the title Set figsize to consistent 8 by 8 inches, and reduce dpi to 100 Set figsize to consistent 8 by 8 inches, and reduce resolution to 100dpi Aug 12, 2024
@jfrost-mo jfrost-mo changed the title Set figsize to consistent 8 by 8 inches, and reduce resolution to 100dpi Set figsize to consistent 8 by 8 inches, and reduce resolution to 100 dpi Aug 12, 2024
@jfrost-mo jfrost-mo marked this pull request as ready for review August 12, 2024 15:11
@jfrost-mo jfrost-mo self-assigned this Aug 12, 2024
@jfrost-mo jfrost-mo added the enhancement New feature or request label Aug 15, 2024
Copy link
Contributor

@ukmo-huw-lewis ukmo-huw-lewis left a comment

Choose a reason for hiding this comment

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

Code changes as intended, but please consider following:

  1. Evidence of different outputs between dpi=150 and default (dpi=100) on ticket would be useful. Helpful to also ensure no loss of image quality if e.g. copy/paste to ppt.

  2. Would be preferable if still explicitly set dpi=(e.g.)100 in the figure settings, either so easier for local editing if user wished to change this or (preferred option) if dpi could be a user-modifiable setting in CSET. This in particular could cover use-cases where default=100dpi if not set, but dpi increases to e.g. 300dpi if user wished to generate "publication-ready" outputs.

  3. Have any other approaches been considered/tested for reducing output image filesizes beyond iris/matlplotlib save defaults? Played with this a bit in ukep_plot (e.g. see https://code.metoffice.gov.uk/trac/utils/browser/ukeputils/trunk/ukep_plot/ukep_mod/plot_ukep.py#L1626), but looks like alternative methods commented out - can't recall history on this. May be useful to do some further trial and error on dpi vs filesize etc.

@jfrost-mo
Copy link
Member Author

1

Here are some plots to compare resolutions. You'll probably want to open them in a new tab, else they are going to be resized anyway.

150 dpi:
test_150

100 dpi:
test_100

2

I'll keep the dpi argument in then.

3

I've done some image optimisation experiments in #500. 100 dpi drops the filesize to 60% of the original size. I can get roughly the same savings with lossless compression, however that will make the image harder to work with (e.g, it can't be dropped straight into a PowerPoint.).

The best I can do with lossless PNG is about 75% of the original file size. Reducing the resolution brings this to 50%.

@jfrost-mo jfrost-mo force-pushed the reduce_plot_resolution branch 2 times, most recently from 4998756 to dfed8e0 Compare August 15, 2024 16:13
Copy link
Contributor

@ukmo-huw-lewis ukmo-huw-lewis left a comment

Choose a reason for hiding this comment

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

Updated since first review, but being a bit pedantic on this one - sorry!

src/CSET/operators/plot.py Outdated Show resolved Hide resolved
This reduces some plot resolutions to make them a bit smaller. 100
dpi is the matplotlib default.
Set plotting resolution from workflow config via rose edit. The plot
resolution is then read via a function. This keeps importing the module
from having side effects.

Setting and getting plot resolution is tested.
@jfrost-mo
Copy link
Member Author

I've now made the plot resolution configurable via rose edit, or a command line option if directly using the cset CLI. It defaults to 100 dpi if not set.

Copy link
Contributor

@ukmo-huw-lewis ukmo-huw-lewis left a comment

Choose a reason for hiding this comment

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

Thanks for further updates on this one.
All looks good to me.

cset-workflow/meta/rose-meta.conf Show resolved Hide resolved
src/CSET/operators/plot.py Show resolved Hide resolved
@ukmo-huw-lewis ukmo-huw-lewis merged commit 61cb85b into main Aug 21, 2024
13 checks passed
@ukmo-huw-lewis ukmo-huw-lewis deleted the reduce_plot_resolution branch August 21, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants