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

pass the received block to plotfunc on parallel computes #160

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ They have a signature of the type:

.. code-block::

def plotfunc(da, fig, timestamp, framedim, **kwargs):
...
def plotfunc(da, fig, timestamp, framedim, **kwargs): ...

.. autosummary::
:toctree: api/
Expand Down
8 changes: 4 additions & 4 deletions xmovie/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def __init__(
self.plotfunc, self.data, self.framedim, **self.kwargs
)

def render_single_frame(self, timestep):
def render_single_frame(self, timestep, block=None):
"""renders complete figure (frame) for given timestep.

Parameters
Expand All @@ -329,14 +329,14 @@ def render_single_frame(self, timestep):
# produce dummy output for ax and pp if the plotfunc does not provide them
if self.plotfunc_n_outargs == 2:
# this should be the case for all presets provided by xmovie
ax, pp = self.plotfunc(self.data, fig, timestep, self.framedim, **self.kwargs)
ax, pp = self.plotfunc(self.data, fig, timestep, self.framedim, block=block, **self.kwargs)
else:
warnings.warn(
"The provided `plotfunc` does not provide the expected number of output arguments.\
Expected a function `ax,pp =plotfunc(...)` but got %i output arguments. Inserting dummy values. This should not affect output. ",
UserWarning,
)
_ = self.plotfunc(self.data, fig, timestep, self.framedim, **self.kwargs)
_ = self.plotfunc(self.data, fig, timestep, self.framedim, block=block, **self.kwargs)
ax, pp = None, None
return fig, ax, pp

Expand Down Expand Up @@ -412,7 +412,7 @@ def _save_single_frame_parallel(xr_array, framedim):
abs(total_time - time_of_chunk[0]).argmin().item()
) # get index of chunk in framedim

fig, ax, pp = self.render_single_frame(timestep)
fig, ax, pp = self.render_single_frame(timestep, block=xr_array)
save_single_frame(fig, timestep, odir=odir, frame_pattern=self.frame_pattern, dpi=self.dpi)

return time_of_chunk
Expand Down