Skip to content

Example 03 execution issues #3

@mkolopanis

Description

@mkolopanis
Environment Details
-> % uv pip list       
Using Python 3.13.5 environment at: ~/src/MPoL/.venv
Package                              Version
------------------------------------ ---------------------
absl-py                              2.3.1
accessible-pygments                  0.0.5
alabaster                            1.0.0
anyio                                4.9.0
appdirs                              1.4.4
argon2-cffi                          25.1.0
argon2-cffi-bindings                 21.2.0
argparse-dataclass                   2.0.0
arrow                                1.3.0
arviz                                0.22.0
asciitree                            0.3.3
asdf                                 4.2.0
asdf-standard                        1.3.0
asdf-transform-schemas               0.6.0
astropy                              7.1.0
astropy-iers-data                    0.2025.7.14.0.40.29
asttokens                            3.0.0
async-lru                            2.0.5
attrs                                25.3.0
babel                                2.17.0
beautifulsoup4                       4.13.4
bleach                               6.2.0
bokeh                                3.7.3
certifi                              2025.7.14
cffi                                 1.17.1
cftime                               1.6.4.post1
charset-normalizer                   3.4.2
click                                8.2.1
cloudpickle                          3.1.1
comm                                 0.2.2
conda-inject                         1.3.2
configargparse                       1.7.1
connection-pool                      0.0.3
contourpy                            1.3.2
coverage                             7.9.2
cycler                               0.12.1
dask                                 2025.5.1
debugpy                              1.8.14
decorator                            5.2.1
defusedxml                           0.7.1
deprecated                           1.2.18
distributed                          2025.5.1
dm-tree                              0.1.9
docutils                             0.21.2
dpath                                2.2.0
executing                            2.2.0
fast-histogram                       0.14
fasteners                            0.19
fastjsonschema                       2.21.1
filelock                             3.18.0
fonttools                            4.58.5
fqdn                                 1.5.1
frank                                1.2.3
fsspec                               2025.5.1
gitdb                                4.0.12
gitpython                            3.1.45
greenlet                             3.2.3
grpcio                               1.73.1
h11                                  0.16.0
h5netcdf                             1.6.3
h5py                                 3.14.0
httpcore                             1.0.9
httpx                                0.28.1
humanfriendly                        10.0
idna                                 3.10
imagesize                            1.4.1
immutables                           0.21
importlib-metadata                   8.7.0
iniconfig                            2.1.0
ipykernel                            6.29.5
ipython                              9.4.0
ipython-pygments-lexers              1.1.1
ipywidgets                           8.1.7
isoduration                          20.11.0
jedi                                 0.19.2
jinja2                               3.1.6
jmespath                             1.0.1
json5                                0.12.0
jsonpointer                          3.0.0
jsonschema                           4.24.0
jsonschema-specifications            2025.4.1
jupyter                              1.1.1
jupyter-cache                        1.0.1
jupyter-client                       8.6.3
jupyter-console                      6.6.3
jupyter-core                         5.8.1
jupyter-events                       0.12.0
jupyter-lsp                          2.2.5
jupyter-server                       2.16.0
jupyter-server-terminals             0.5.3
jupyterlab                           4.4.4
jupyterlab-pygments                  0.3.0
jupyterlab-server                    2.27.3
jupyterlab-widgets                   3.0.15
jupytext                             1.17.2
kiwisolver                           1.4.8
llvmlite                             0.44.0
locket                               1.0.0
markdown                             3.8.2
markdown-it-py                       3.0.0
markupsafe                           3.0.2
matplotlib                           3.10.3
matplotlib-inline                    0.1.7
mdit-py-plugins                      0.4.2
mdurl                                0.1.2
mistune                              3.1.3
mpmath                               1.3.0
mpol                                 0.3.0a1.dev4+gf1facdb
msgpack                              1.1.1
mypy                                 1.16.1
mypy-extensions                      1.1.0
myst-nb                              1.3.0
myst-parser                          4.0.1
narwhals                             1.47.0
nbclient                             0.10.2
nbconvert                            7.16.6
nbformat                             5.10.4
nbsphinx                             0.9.7
nest-asyncio                         1.6.0
netcdf4                              1.7.2
networkx                             3.5
notebook                             7.4.4
notebook-shim                        0.2.4
numba                                0.61.2
numcodecs                            0.15.1
numpy                                2.2.6
nvidia-cublas-cu12                   12.6.4.1
nvidia-cuda-cupti-cu12               12.6.80
nvidia-cuda-nvrtc-cu12               12.6.77
nvidia-cuda-runtime-cu12             12.6.77
nvidia-cudnn-cu12                    9.5.1.17
nvidia-cufft-cu12                    11.3.0.4
nvidia-cufile-cu12                   1.11.1.6
nvidia-curand-cu12                   10.3.7.77
nvidia-cusolver-cu12                 11.7.1.2
nvidia-cusparse-cu12                 12.5.4.2
nvidia-cusparselt-cu12               0.6.3
nvidia-nccl-cu12                     2.26.2
nvidia-nvjitlink-cu12                12.6.85
nvidia-nvtx-cu12                     12.6.77
opt-einsum                           3.4.0
overrides                            7.7.0
packaging                            25.0
pandas                               2.3.1
pandocfilters                        1.5.1
parso                                0.8.4
partd                                1.4.2
pathspec                             0.12.1
pexpect                              4.9.0
pillow                               11.3.0
platformdirs                         4.3.8
pluggy                               1.6.0
prometheus-client                    0.22.1
prompt-toolkit                       3.0.51
protobuf                             6.31.1
psutil                               7.0.0
ptyprocess                           0.7.0
pulp                                 3.2.2
pure-eval                            0.2.3
pycparser                            2.22
pydata-sphinx-theme                  0.15.4
pyerfa                               2.0.1.5
pygments                             2.19.2
pyparsing                            3.2.3
pyro-api                             0.1.2
pyro-ppl                             1.9.1
pytest                               8.4.1
pytest-cov                           6.2.1
python-dateutil                      2.9.0.post0
python-json-logger                   3.3.0
pytz                                 2025.2
pyyaml                               6.0.2
pyzmq                                27.0.0
referencing                          0.36.2
requests                             2.32.4
reretry                              0.11.8
rfc3339-validator                    0.1.4
rfc3986-validator                    0.1.1
rpds-py                              0.26.0
ruff                                 0.12.3
scipy                                1.16.0
semantic-version                     2.10.0
send2trash                           1.8.3
setuptools                           80.9.0
six                                  1.17.0
smart-open                           7.3.0.post1
smmap                                5.0.2
snakemake                            9.9.0
snakemake-interface-common           1.21.0
snakemake-interface-executor-plugins 9.3.9
snakemake-interface-logger-plugins   1.2.4
snakemake-interface-report-plugins   1.2.0
snakemake-interface-storage-plugins  4.2.2
sniffio                              1.3.1
snowballstemmer                      3.0.1
sortedcontainers                     2.4.0
soupsieve                            2.7
sphinx                               8.1.3
sphinx-book-theme                    1.1.4
sphinx-copybutton                    0.5.2
sphinxcontrib-applehelp              2.0.0
sphinxcontrib-devhelp                2.0.0
sphinxcontrib-htmlhelp               2.1.0
sphinxcontrib-jsmath                 1.0.1
sphinxcontrib-mermaid                1.0.0
sphinxcontrib-qthelp                 2.0.0
sphinxcontrib-serializinghtml        2.0.0
sqlalchemy                           2.0.41
stack-data                           0.6.3
sympy                                1.14.0
tabulate                             0.9.0
tblib                                3.1.0
tensorboard                          2.19.0
tensorboard-data-server              0.7.2
terminado                            0.18.1
throttler                            1.2.2
tinycss2                             1.4.0
toolz                                1.0.0
torch                                2.7.1
torchaudio                           2.7.1
torchkbnufft                         1.5.2
torchvision                          0.22.1
tornado                              6.5.1
tqdm                                 4.67.1
traitlets                            5.14.3
triton                               3.3.1
types-python-dateutil                2.9.0.20250708
typing-extensions                    4.14.1
tzdata                               2025.2
ujson                                5.10.0
uri-template                         1.3.0
urllib3                              2.5.0
visread                              0.0.5
wcwidth                              0.2.13
webcolors                            24.11.1
webencodings                         0.5.1
websocket-client                     1.8.0
werkzeug                             3.1.3
widgetsnbextension                   4.0.14
wrapt                                1.17.2
xarray                               2025.7.1
xarray-einstats                      0.9.1
xyzservices                          2025.4.0
yte                                  1.9.0
zarr                                 2.18.7
zict                                 3.0.0
zipp                                 3.23.0

I am working through the examples for my review but attempting to run example 3 errors quickly with an reference to a missing notebook_setup script trying to be run (see full error).

Missing notebook_setup
-> % jupytext --to ipynb --execute pyro.md
[jupytext] Reading pyro.md in format md
[jupytext] Executing notebook with kernel python3
Traceback (most recent call last):
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/jupyter_core/utils/__init__.py", line 154, in wrapped
    asyncio.get_running_loop()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
RuntimeError: no running event loop

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/matthew/src/MPoL/.venv/bin/jupytext", line 10, in <module>
    sys.exit(jupytext())
             ~~~~~~~~^^
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/jupytext/cli.py", line 497, in jupytext
    exit_code += jupytext_single_file(nb_file, args, log)
                 ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/jupytext/cli.py", line 741, in jupytext_single_file
    exec_proc.preprocess(notebook, resources=resources)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/nbconvert/preprocessors/execute.py", line 103, in preprocess
    self.preprocess_cell(cell, resources, index)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/nbconvert/preprocessors/execute.py", line 124, in preprocess_cell
    cell = self.execute_cell(cell, index, store_history=True)
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/jupyter_core/utils/__init__.py", line 158, in wrapped
    return loop.run_until_complete(inner)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/usr/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/nbclient/client.py", line 1062, in async_execute_cell
    await self._check_raise_for_error(cell, cell_index, exec_reply)
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/nbclient/client.py", line 918, in _check_raise_for_error
    raise CellExecutionError.from_cell_and_msg(cell, exec_reply_content)
nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell:
------------------
%matplotlib inline
%run notebook_setup
------------------


---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
File ~/src/MPoL/.venv/lib/python3.13/site-packages/IPython/core/magics/execution.py:728, in ExecutionMagics.run(self, parameter_s, runner, file_finder)
    727     fpath = arg_lst[0]
--> 728     filename = file_finder(fpath)
    729 except IndexError as e:

File ~/src/MPoL/.venv/lib/python3.13/site-packages/IPython/utils/path.py:90, in get_py_filename(name)
     89         return py_name
---> 90 raise IOError("File `%r` not found." % name)

OSError: File `'notebook_setup'` not found.

The above exception was the direct cause of the following exception:

Exception                                 Traceback (most recent call last)
Cell In[1], line 2
      1 get_ipython().run_line_magic('matplotlib', 'inline')
----> 2 get_ipython().run_line_magic('run', 'notebook_setup')

File ~/src/MPoL/.venv/lib/python3.13/site-packages/IPython/core/interactiveshell.py:2504, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
   2502     kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2503 with self.builtin_trap:
-> 2504     result = fn(*args, **kwargs)
   2506 # The code below prevents the output from being displayed
   2507 # when using magics with decorator @output_can_be_silenced
   2508 # when the last Python token in the expression is a ';'.
   2509 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/src/MPoL/.venv/lib/python3.13/site-packages/IPython/core/magics/execution.py:739, in ExecutionMagics.run(self, parameter_s, runner, file_finder)
    737     if os.name == 'nt' and re.match(r"^'.*'$",fpath):
    738         warn('For Windows, use double quotes to wrap a filename: %run "mypath\\myfile.py"')
--> 739     raise Exception(msg) from e
    740 except TypeError:
    741     if fpath in sys.meta_path:

Exception: File `'notebook_setup'` not found.

I see that notebook_setup.py exists in the large-tutorials directory. Pointing the pyro.md file there via %run ../large-tutorials/notebook_setup though also produces an issue when making the dirty image.

Dirty Image Zero-Sized Array
-> % jupytext --to ipynb --execute pyro.md
[jupytext] Reading pyro.md in format md
[jupytext] Executing notebook with kernel python3
Traceback (most recent call last):
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/jupyter_core/utils/__init__.py", line 154, in wrapped
    asyncio.get_running_loop()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
RuntimeError: no running event loop

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/matthew/src/MPoL/.venv/bin/jupytext", line 10, in <module>
    sys.exit(jupytext())
             ~~~~~~~~^^
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/jupytext/cli.py", line 497, in jupytext
    exit_code += jupytext_single_file(nb_file, args, log)
                 ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/jupytext/cli.py", line 741, in jupytext_single_file
    exec_proc.preprocess(notebook, resources=resources)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/nbconvert/preprocessors/execute.py", line 103, in preprocess
    self.preprocess_cell(cell, resources, index)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/nbconvert/preprocessors/execute.py", line 124, in preprocess_cell
    cell = self.execute_cell(cell, index, store_history=True)
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/jupyter_core/utils/__init__.py", line 158, in wrapped
    return loop.run_until_complete(inner)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/usr/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/nbclient/client.py", line 1062, in async_execute_cell
    await self._check_raise_for_error(cell, cell_index, exec_reply)
  File "/home/matthew/src/MPoL/.venv/lib/python3.13/site-packages/nbclient/client.py", line 918, in _check_raise_for_error
    raise CellExecutionError.from_cell_and_msg(cell, exec_reply_content)
nbclient.exceptions.CellExecutionError: An error occurred while executing the following cell:
------------------
img, beam = make_dirty_image(np.real(data), np.imag(data))

# set plot dimensions
xx = 8 # in
cax_width = 0.2 # in
cax_sep = 0.1 # in
mmargin = 1.2
lmargin = 0.7
rmargin = 0.7
tmargin = 0.3
bmargin = 0.5

npanels = 2
# the size of image axes + cax_sep + cax_width
block_width = (xx - lmargin - rmargin - mmargin * (npanels - 1) )/npanels
ax_width = block_width - cax_width - cax_sep
ax_height = ax_width
yy = bmargin + ax_height + tmargin

fig = plt.figure(figsize=(xx, yy))
ax = []
cax = []
for i in range(npanels):
    ax.append(fig.add_axes([(lmargin + i * (block_width + mmargin))/xx, bmargin/yy, ax_width/xx, ax_height/yy]))
    cax.append(fig.add_axes([(lmargin + i * (block_width + mmargin) + ax_width + cax_sep)/xx, bmargin/yy, cax_width/xx, ax_height/yy]))

# single-channel image cube
chan = 0

im_beam = ax[0].imshow(beam[chan], **kw)
cbar = plt.colorbar(im_beam, cax=cax[0])
ax[0].set_title("beam")
# zoom in a bit
r = 0.3
ax[0].set_xlim(r, -r)
ax[0].set_ylim(-r, r)

im = ax[1].imshow(img[chan], **kw)
ax[1].set_title("dirty image")
cbar = plt.colorbar(im, cax=cax[1])
cbar.set_label(r"Jy/$\mathrm{arcsec}^2$")

for a in ax:
    a.set_xlabel(r"$\Delta \alpha \cos \delta$ [${}^{\prime\prime}$]")
    a.set_ylabel(r"$\Delta \delta$ [${}^{\prime\prime}$]")
------------------


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[7], line 1
----> 1 img, beam = make_dirty_image(np.real(data), np.imag(data))
      3 # set plot dimensions
      4 xx = 8 # in

Cell In[6], line 35, in make_dirty_image(data_real, data_imag, robust)
     14 """
     15 Make a plot of the dirty beam and dirty image (in units of Jy/arcsec^2).
     16 
   (...)     23     beam, image numpy arrays
     24 """
     26 imager = gridding.DirtyImager(
     27     coords=coords,
     28     uu=uu,
   (...)     32     data_im=data_imag,
     33 )
---> 35 return imager.get_dirty_image(weighting="briggs", robust=robust, unit="Jy/arcsec^2")

File ~/src/MPoL/.venv/lib/python3.13/site-packages/mpol/gridding.py:1172, in DirtyImager.get_dirty_image(self, weighting, robust, taper_function, unit, check_visibility_scatter, max_scatter, **beam_kwargs)
   1167 # for units of Jy/arcsec^2, we could just leave out the C constant *if* we were
   1168 # doing uniform weighting. The relationships get more complex for robust or
   1169 # natural weighting, however, so it's safer to calculate the number of
   1170 # arcseconds^2 per beam
   1171 if unit == "Jy/arcsec^2":
-> 1172     beam_area_per_chan = self.get_dirty_beam_area(**beam_kwargs)  # [arcsec^2]
   1174     # convert image
   1175     # (Jy/1 arcsec^2) = (Jy/ 1 beam) * (1 beam/ n arcsec^2)
   1176     # beam_area_per_chan is the n of arcsec^2 per 1 beam
   1178     img /= beam_area_per_chan[:, np.newaxis, np.newaxis]

File ~/src/MPoL/.venv/lib/python3.13/site-packages/mpol/gridding.py:1067, in DirtyImager.get_dirty_beam_area(self, ntheta, single_channel_estimate)
   1042 def get_dirty_beam_area(
   1043     self, ntheta: int = 24, single_channel_estimate: bool = True
   1044 ) -> npt.NDArray[np.floating[Any]]:
   1045     r"""
   1046     Compute the effective area of the dirty beam for each channel. Assumes that the
   1047     beam has already been generated by running
   (...)   1065         :math:`[\mathrm{arcsec}^{2}]`
   1066     """
-> 1067     nulled = self._null_dirty_beam(
   1068         ntheta=ntheta, single_channel_estimate=single_channel_estimate
   1069     )
   1070     area: npt.NDArray[np.floating[Any]] = self.coords.cell_size**2 * np.sum(
   1071         nulled, axis=(1, 2)
   1072     )  # arcsec^2
   1073     return area

File ~/src/MPoL/.venv/lib/python3.13/site-packages/mpol/gridding.py:1027, in DirtyImager._null_dirty_beam(self, ntheta, single_channel_estimate)
   1024 ind_neg_and_az = ind_neg & ind_azimuth
   1026 # find the smallest r within this slice
-> 1027 min_r = np.min(rr[ind_neg_and_az])
   1029 # null all pixels within this slice with radii r or greater
   1030 ind_r = rr >= min_r

File ~/src/MPoL/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:3302, in min(a, axis, out, keepdims, initial, where)
   3190 @array_function_dispatch(_min_dispatcher)
   3191 def min(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
   3192         where=np._NoValue):
   3193     """
   3194     Return the minimum of an array or minimum along an axis.
   3195 
   (...)   3300     6
   3301     """
-> 3302     return _wrapreduction(a, np.minimum, 'min', axis, None, out,
   3303                           keepdims=keepdims, initial=initial, where=where)

File ~/src/MPoL/.venv/lib/python3.13/site-packages/numpy/_core/fromnumeric.py:86, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
     83         else:
     84             return reduction(axis=axis, out=out, **passkwargs)
---> 86 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

ValueError: zero-size array to reduction operation minimum which has no identity

Additionally, all the mermaid inclusions appear to be broken in the mardown file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions