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

Abstract routines out of gcpy/plot.py into smaller modules within the gcpy/plot folder #263

Merged
merged 10 commits into from
Oct 25, 2023

Conversation

yantosca
Copy link
Contributor

In this PR we have moved GCPy's plotting capability out of the monolithic module gcpy/plot.py into smaller modules in the gcpy/plot folder. These are:

  1. gcpy/plot/core.py: Contains common functions and definitions used by other plotting routines.

  2. gcpy/plot/single_panel.py: Module containing the single_panel routine, which creates a single-panel plot.

  3. gcpy/plot/six_plot.py: Module containing the six_plot routine (which calls single_panel 6 times to create a comparison plot), plus several helper functions that were abstracted and refactored for clarity.

  4. gcpy/plot/compare_single_level.py: Module containing the compare_single_level routine (creates a 6-panel comparison plot at a single model level).

  5. gcpy/plot/compare_zonal_mean.py: Module containing the compare_zonal_mean routine (creates a 6-panel comparison with zonal means).

  6. gcpy/plot/gcpy_plot_style: Style sheet with several plot attribute settings (moved from the gcpy/ folder).

  7. gcpy/plot/colormaps/: Folder with colormap definitions (moved from gcpy/colormaps).

  8. gcpy/plot/__init__.py: Import script

Import statements and other plot settings have now been updated accordingly in the following scripts:

  • gcpy/benchmark_funcs.py
  • gcpy/examples/diagnostics/compare_diags.py
  • gcpy/examples/plotting/plot_single_level.py
  • gcpy/examples/plotting/plot_comparisons.py
  • gcpy/examples/timeseries/mda8_o3_timeseries.py

The plotting code in GCPy is now much cleaner and easier to understand. Also, plotting-only functionality is now able to be abstracted from the benchmarking code.

I have confirmed that the benchmark plotting codes are able to run with these modifications.

This is the initial commit of the GCPy plot modules refactoring.  We
have split up gcpy/plot.py into:

gcpy/plot/core.py
gcpy/plot/six_plot.py
gcpy/plot/single_panel.py
gcpy/plot/compare_single_level.py
gcpy/plot/compare_zonal_mean.py

Some issues remain but we just wanted to stash code here before
moving on.  These issues will be resolved in subsequent commits.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/plot/compare_single_level.py
- Break up strings across multiple lines to avoid "line-too-long"
  warning from Pylint
- Trimmed trailing whitespace

gcpy/plot/compare_zonal_mean.py
- Convert target_index from numpy.int64 to int, to avoid a Pylint
  "Sequence index" warning.  (List indices must be int but not
   numpy.int32 or numpy.int64)
- Break up strings across multiple lines to avoid "line-too-long"
  warning from Pylint
- Now import six_panel_subplot names from gcpy.plot.core (so no
  need to call core.six_panel_subplot_names).
- Removed if __name__ == "__main__" block

gcpy/plot/core.py
- Removed unused import statement (as per Pylint)
- Removed "self" from call to super().__init in MidpointLogNorm class
- Removed if __name__ == "__main__" block

gcpy/plot/single_panel.py
- Now import normalize_colors from gcpy.plot.core (and replace the
  core.normalize_colors call with normalize_colors)
- Removed if __name__ == "__main__" block

gcpy/plot/six_plot.py
- Remove unused import statements
- Remove debug print statements

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/plot/six_plot.py
- Split the computation of vmin, vmax for absdiff and ratio plots
  into separate functions called by compute_vmin_vmax_for_plot
- Make sure that all functions return a value (to avoid an
  "inconsistent-return-statements" warning by Pylint
- Updated comments
- Trimmed trailing whitespace

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/benchmark_funcs.py
- Now import constants individually from gcpy.constants
- Import compare_single_level from gcpy.plot.compare_single_level
- Import compare_zonal_mean from gcpy.plot.compare_zonal_mean
- Remove unneeded "warning_format" variable

gcpy/examples/diagnostics/compare_diags.py
- Remove unused import for xarray
- Import functions individually from gcpy.util
- Import constants individually from gcpy.constants
- Import compare_single_level from gcpy.plot.compare_single_level
- Import compare_zonal_mean from gcpy.plot.compare_zonal_mean
- Now use dataset_reader to return the proper reader
- Fix exception handling

gcpy/examples/plotting/plot_comparisons.py
- Import compare_single_level from gcpy.plot.compare_single_level
- Import compare_zonal_mean from gcpy.plot.compare_zonal_mean

gcpy/examples/plotting/plot_single_panel.py
- Import single_panel from gcpy.plot.single_panel

gcpy/examples/timeseries/mda8_o3_timeseries
- Update plot styles for Matplolib 3.7.2

gcpy/gcpy_plot_style
- Removed, this is now in the plot folder

gcpy/plot.py
- Removed, this has now been split up to other modules in the plot folder

gcpy/gcpy
gcpy/gcpy.examples
- Remove these extraneous files

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
@yantosca yantosca added category: Feature Request New feature or request topic: Colors and Display Issues pertaining to color scales or other display issues topic: Benchmark Plots and Tables Issues pertaining to generating plots/tables from benchmark output labels Sep 21, 2023
@yantosca yantosca added this to the 1.4.0 milestone Sep 21, 2023
@yantosca yantosca self-assigned this Sep 21, 2023
gcpy/benchmark/benchmark_slurm.sh
- Now activate the "gcpy_env" environment, which is the same name
  in the default environment.yml file (and in the documentation)

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
gcpy/six_plot.py
- In routine "colorbar_for_small_data_range", now use
  pos = [vmin, vmin+vrange*0.25, vmin+vrange*0.5, vmin+vrange*0.75, vmax]
  which should place the intermediate tickpoints symmetrically.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
This merge brings the feature/plot-subdir up-to-date with the dev
branch (which now has the fixes for regridding that were added
by PR #266).

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
docs/environment_files/environment.yml
- Add the "tk" library to the GCPy python environment YAML file

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
Copy link
Contributor

@lizziel lizziel left a comment

Choose a reason for hiding this comment

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

This looks good to merge. I just added one comment on a typo I found in a comment.

gcpy/examples/diagnostics/compare_diags.py Outdated Show resolved Hide resolved
gcpy/examples/diagnostics/compare_diags.py
- Fixed typo "thed" -> "the"

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
@yantosca yantosca requested a review from lizziel October 24, 2023 18:19
CHANGELOG.md
- Now state that the 'tk' package has been added to the
  docs/environment_files/environment.yml file.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
@yantosca
Copy link
Contributor Author

Also updated CHANGELOG.md to state that the tk package has been added to the environment.yml file. This is so that we can use X11 backend tkagg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: Feature Request New feature or request topic: Benchmark Plots and Tables Issues pertaining to generating plots/tables from benchmark output topic: Colors and Display Issues pertaining to color scales or other display issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Split plot.py into smaller modules and move these into gcpy/plot
3 participants