Skip to content

Commit 3345860

Browse files
authored
Fixes GLIBC Linux wheel issue and adds more progress callbacks (#187)
* Change MANYLINUX_X86_64_IMAGE to fix issue on centos 8 * Add progress callback for panel plot helper
1 parent 8ea392b commit 3345860

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

.github/workflows/build_wheel.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
env:
1616
CIBW_SKIP: 'pp*'
1717
CIBW_ARCHS: 'auto64'
18+
CIBW_MANYLINUX_X86_64_IMAGE: 'manylinux_2_28'
1819
CIBW_PROJECT_REQUIRES_PYTHON: '>=3.10'
1920
CIBW_TEST_REQUIRES: 'pytest'
2021
defaults:

ratapi/utils/plotting.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,10 @@ def plot_contour(
982982

983983

984984
def panel_plot_helper(
985-
plot_func: Callable, indices: list[int], fig: matplotlib.figure.Figure | None = None
985+
plot_func: Callable,
986+
indices: list[int],
987+
fig: matplotlib.figure.Figure | None = None,
988+
progress_callback: Callable[[int, int], None] | None = None,
986989
) -> matplotlib.figure.Figure:
987990
"""Generate a panel-based plot from a single plot function.
988991
@@ -994,6 +997,9 @@ def panel_plot_helper(
994997
The list of indices to pass into ``plot_func``.
995998
fig : matplotlib.figure.Figure, optional
996999
The figure object to use for plot.
1000+
progress_callback: Union[Callable[[int, int], None], None]
1001+
Callback function for providing progress during plot creation
1002+
First argument is current completed sub plot and second is total number of sub plots
9971003
9981004
Returns
9991005
-------
@@ -1005,21 +1011,19 @@ def panel_plot_helper(
10051011
nrows, ncols = ceil(sqrt(nplots)), round(sqrt(nplots))
10061012

10071013
if fig is None:
1008-
fig = plt.subplots(nrows, ncols, figsize=(11, 10))[0]
1014+
fig = plt.subplots(nrows, ncols, figsize=(11, 10), subplot_kw={"visible": False})[0]
10091015
else:
10101016
fig.clf()
1011-
fig.subplots(nrows, ncols)
1017+
fig.subplots(nrows, ncols, subplot_kw={"visible": False})
10121018
axs = fig.get_axes()
1013-
1014-
for plot_num, index in enumerate(indices):
1015-
axs[plot_num].tick_params(which="both", labelsize="medium")
1016-
axs[plot_num].xaxis.offsetText.set_fontsize("small")
1017-
axs[plot_num].yaxis.offsetText.set_fontsize("small")
1018-
plot_func(axs[plot_num], index)
1019-
1020-
# blank unused plots
1021-
for i in range(nplots, len(axs)):
1022-
axs[i].set_visible(False)
1019+
for index, plot_num in enumerate(indices):
1020+
axs[index].tick_params(which="both", labelsize="medium")
1021+
axs[index].xaxis.offsetText.set_fontsize("small")
1022+
axs[index].yaxis.offsetText.set_fontsize("small")
1023+
axs[index].set_visible(True)
1024+
plot_func(axs[index], plot_num)
1025+
if progress_callback is not None:
1026+
progress_callback(index, nplots)
10231027

10241028
fig.tight_layout()
10251029
return fig
@@ -1036,6 +1040,7 @@ def plot_hists(
10361040
block: bool = False,
10371041
fig: matplotlib.figure.Figure | None = None,
10381042
return_fig: bool = False,
1043+
progress_callback: Callable[[int, int], None] | None = None,
10391044
**hist_settings,
10401045
):
10411046
"""Plot marginalised posteriors for several parameters from a Bayesian analysis.
@@ -1072,6 +1077,9 @@ def plot_hists(
10721077
The figure object to use for plot.
10731078
return_fig: bool, default False
10741079
If True, return the figure as an object instead of showing it.
1080+
progress_callback: Union[Callable[[int, int], None], None]
1081+
Callback function for providing progress during plot creation
1082+
First argument is current completed sub plot and second is total number of sub plots
10751083
hist_settings :
10761084
Settings passed to `np.histogram`. By default, the settings
10771085
passed are `bins = 25` and `density = True`.
@@ -1130,6 +1138,7 @@ def validate_dens_type(dens_type: str | None, param: str):
11301138
),
11311139
params,
11321140
fig,
1141+
progress_callback,
11331142
)
11341143
if return_fig:
11351144
return fig
@@ -1144,6 +1153,7 @@ def plot_chain(
11441153
block: bool = False,
11451154
fig: matplotlib.figure.Figure | None = None,
11461155
return_fig: bool = False,
1156+
progress_callback: Callable[[int, int], None] | None = None,
11471157
):
11481158
"""Plot the MCMC chain for each parameter of a Bayesian analysis.
11491159
@@ -1162,6 +1172,9 @@ def plot_chain(
11621172
The figure object to use for plot.
11631173
return_fig: bool, default False
11641174
If True, return the figure as an object instead of showing it.
1175+
progress_callback: Union[Callable[[int, int], None], None]
1176+
Callback function for providing progress during plot creation
1177+
First argument is current completed sub plot and second is total number of sub plots
11651178
11661179
Returns
11671180
-------
@@ -1187,7 +1200,7 @@ def plot_one_chain(axes: Axes, i: int):
11871200
axes.plot(range(0, nsimulations, skip), chain[:, i][0:nsimulations:skip])
11881201
axes.set_title(results.fitNames[i], fontsize="small")
11891202

1190-
fig = panel_plot_helper(plot_one_chain, params, fig=fig)
1203+
fig = panel_plot_helper(plot_one_chain, params, fig, progress_callback)
11911204
if return_fig:
11921205
return fig
11931206
plt.show(block=block)

0 commit comments

Comments
 (0)