Skip to content

Create external scripts to break up lib/plotting_functions into organized helper methods#420

Merged
justin-richling merged 13 commits intoNCAR:mainfrom
justin-richling:utils-cleanup
Oct 23, 2025
Merged

Create external scripts to break up lib/plotting_functions into organized helper methods#420
justin-richling merged 13 commits intoNCAR:mainfrom
justin-richling:utils-cleanup

Conversation

@justin-richling
Copy link
Copy Markdown
Collaborator

@justin-richling justin-richling commented Oct 15, 2025

This PR will organize helper methods that currently live in lib/plotting_functions.py with the intent of bringing any ADF-wide utilities (non plotting related) to an external script lib/adf_untils.py so methods such as validating dimensions like zm_validate_dims, or averaging schemes like seasonal_mean, or any other non-plotting helpers like mask_land_or_ocean, etc would now fall under this script.

A second external script lib/plotting_utils.py is created for helper methods related to plotting such as prep_contour_plot and get_central_longitude, etc. This script would be called in plotting_functions.py so that plotting_functions.py can be specific to only plotting schemes for diagnostic plotting scripts.

Breaking these methods up into external scripts will not only organize helper functions better, but it will eliminate roughly 1000 lines from plotting_functions.py, specifically ones that are not related to plotting.

Additionally, this PR will create a warnings function in lib/adf_utils.py

#Format warning messages:
def my_formatwarning(msg, *args, **kwargs):
    """Issue `msg` as warning."""
    return str(msg) + '\n'

that is defined in most scripts currently so it can be centralized and called in scripts via adf_utils:

import warnings  # use to warn user about missing files.
import adf_utils as utils
warnings.formatwarning = utils.my_formatwarning

I'm open to also making a plotting directory in lib to organize plotting scripts since we will probably want to extend color maps to NCL soon thanks to the work of @brianpm

@justin-richling justin-richling added code clean-up Made code simpler and/or easier to read. plotting Related to plot generation analysis Related to data analysis and statistics averaging Concerns the calculation of temporal and spatial averages labels Oct 15, 2025
@justin-richling justin-richling marked this pull request as ready for review October 15, 2025 16:54
Copy link
Copy Markdown
Collaborator

@nusbaume nusbaume 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 the great cleanup @justin-richling! I have some change requests, but hopefully they will all be easy to handle (it is mostly about commented-out lines of code).

Comment thread scripts/analysis/amwg_table.py
Comment thread lib/plotting_functions.py Outdated
Comment thread lib/plotting_functions.py Outdated
Comment thread lib/plotting_functions.py Outdated
Comment thread lib/plotting_functions.py Outdated
Comment thread lib/plotting_utils.py Outdated
Comment thread lib/plotting_utils.py Outdated
Comment thread lib/plotting_utils.py Outdated
Comment thread lib/plotting_utils.py Outdated
Comment thread lib/plotting_utils.py Outdated
@justin-richling
Copy link
Copy Markdown
Collaborator Author

Hi @nusbaume, it looks like almost all of these requested changes are resolved; I had some erroneous code that got committed in to this branch. My apologies for the extra work, but could you double check the plotting_functions.py and plotting_utils.py again when you get a chance? Thanks!

Copy link
Copy Markdown
Collaborator

@nusbaume nusbaume 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 removing the erroneous code @justin-richling! I believe that has resolved all of my concerns except for the one request related to amwg_table.py. Once that is resolved this PR will be good to go (at least for me)!

Copy link
Copy Markdown
Collaborator

@nusbaume nusbaume left a comment

Choose a reason for hiding this comment

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

Everything looks great to me now. Thanks again!

@justin-richling justin-richling merged commit 4534fb5 into NCAR:main Oct 23, 2025
7 checks passed
@justin-richling justin-richling deleted the utils-cleanup branch November 4, 2025 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analysis Related to data analysis and statistics averaging Concerns the calculation of temporal and spatial averages code clean-up Made code simpler and/or easier to read. plotting Related to plot generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants