Skip to content

Commit eb594de

Browse files
committed
DOCS: added example notebook to docs page, more docstring updates
1 parent 5b97c62 commit eb594de

File tree

13 files changed

+1167
-78
lines changed

13 files changed

+1167
-78
lines changed

docs/notebook_prep.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import argparse
2+
import json
3+
import base64
4+
from pathlib import Path
5+
6+
def convert_notebook_attachments(notebook_path: str, output_path: str):
7+
"""Convert notebook attachments to embedded base64 images."""
8+
with open(notebook_path, 'r', encoding='utf-8') as f:
9+
nb = json.load(f)
10+
11+
for cell in nb.get('cells', []):
12+
if cell.get('cell_type') == 'markdown' and 'attachments' in cell:
13+
attachments = cell['attachments']
14+
source = cell['source']
15+
16+
# Convert source to list if it's a string
17+
if isinstance(source, str):
18+
source = [source]
19+
20+
new_source = []
21+
for line in source:
22+
# Replace attachment references with data URIs
23+
for att_name, att_data in attachments.items():
24+
if f'attachment:{att_name}' in line:
25+
# Get the first available image format
26+
mime_type = list(att_data.keys())[0]
27+
data = att_data[mime_type]
28+
data_uri = f'data:{mime_type};base64,{data}'
29+
line = line.replace(f'attachment:{att_name}', data_uri)
30+
new_source.append(line)
31+
32+
cell['source'] = new_source
33+
# Remove attachments after conversion
34+
del cell['attachments']
35+
36+
# Save the modified notebook
37+
with open(output_path, 'w', encoding='utf-8') as f:
38+
json.dump(nb, f, indent=1)
39+
40+
print(f"Converted notebook saved to: {output_path}")
41+
42+
# ----------------------------------------------------------------------
43+
def main() -> None:
44+
parser = argparse.ArgumentParser()
45+
parser.add_argument(
46+
"notebook_path",
47+
)
48+
parser.add_argument(
49+
"output_path",
50+
)
51+
args = parser.parse_args()
52+
53+
convert_notebook_attachments(args.notebook_path, args.output_path)
54+
55+
if __name__ == "__main__":
56+
main()

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
sphinx
22
sphinx-rtd-theme
3-
nbsphinx
3+
myst-nb

docs/source/api/io.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ To load the data, you can either: 1) use the appropriate loading function or 2)
2424

2525
* Loading functions:
2626
* Ptychography data processed by PEAR/Pty-Chi: :func:`pyxalign.io.loaders.pear.load_data_from_pear_format`
27-
* XRF Data: :func:`pyxalign.io.loaders.pear.load_data_from_xrf_format`
27+
* XRF Data: :func:`pyxalign.io.loaders.xrf.load_data_from_xrf_format`
2828
* Loading GUI:
2929
* Any type of data: :func:`pyxalign.gui.launch_data_loader`
3030

@@ -69,19 +69,19 @@ XRF
6969

7070
.. autofunction:: pyxalign.io.loaders.xrf.load_data_from_xrf_format
7171

72-
.. autoclass:: pyxalign.io.loaders.xrf.XRFLoadOptions
73-
:members:
74-
:inherited-members:
75-
:undoc-members:
76-
:show-inheritance:
77-
:member-order: bysource
72+
.. .. autoclass:: pyxalign.io.loaders.xrf.XRFLoadOptions
73+
.. :members:
74+
.. :inherited-members:
75+
.. :undoc-members:
76+
.. :show-inheritance:
77+
.. :member-order: bysource
7878
7979
.. automodule:: pyxalign.io.loaders.xrf
8080
:members:
8181
:inherited-members:
8282
:undoc-members:
8383
:show-inheritance:
84-
:exclude-members: XRFLoadOptions, load_data_from_xrf_format
84+
:exclude-members: load_data_from_xrf_format
8585

8686
Data Structures
8787
^^^^^^^^^^^^^^^^^^^

docs/source/conf.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,34 @@
1717

1818
extensions = [
1919
"sphinx.ext.autodoc",
20-
# 'sphinx.ext.autosummary',
2120
"sphinx.ext.napoleon",
2221
"sphinx.ext.viewcode",
23-
"nbsphinx",
22+
"myst_nb",
2423
]
2524

26-
# # Enable autosummary to glsenerate stub pages automatically
27-
# autosummary_generate = True
25+
# MyST-NB configuration
26+
nb_execution_mode = "off" # Don't re-execute notebooks
27+
nb_render_image_options = {"align": "center"}
28+
29+
# Enable processing of notebook attachments (pasted images)
30+
nb_output_stderr = "show"
31+
nb_merge_streams = True
32+
33+
# Configure MIME type priorities for different output formats
34+
nb_mime_priority_overrides = [
35+
('html', 'image/png', 10),
36+
('html', 'image/jpeg', 10),
37+
('html', 'image/svg+xml', 10),
38+
('html', 'text/html', 20),
39+
]
40+
41+
# Ensure MyST parser is configured
42+
myst_enable_extensions = [
43+
"colon_fence",
44+
"deflist",
45+
"dollarmath",
46+
"html_image",
47+
]
2848

2949
# Configure autodoc to respect __all__
3050
autodoc_default_options = {
@@ -39,9 +59,9 @@
3959
templates_path = ["_templates"]
4060
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
4161

42-
4362
# -- Options for HTML output -------------------------------------------------
4463
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
4564

4665
html_theme = "sphinx_rtd_theme"
4766
html_static_path = ["_static"]
67+

docs/source/examples/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Examples
2+
===========
3+
4+
Additional examples will be added periodically.
5+
6+
.. toctree::
7+
:maxdepth: 1
8+
9+
simulated_shepp_logan_phantom_alignment_converted

docs/source/examples/simulated_shepp_logan_phantom_alignment_converted.ipynb

Lines changed: 672 additions & 0 deletions
Large diffs are not rendered by default.

docs/source/index.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@
33
.. You can adapt this file completely to your liking, but it should at least
44
.. contain the root `toctree` directive.
55
6-
pyxalign documentation
6+
pyxalign Documentation
77
======================
88

99
.. Add your content using ``reStructuredText`` syntax. See the
1010
.. `reStructuredText <https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html>`_
1111
.. documentation for details.
1212
13-
hello!
13+
Welcome to the docs page for **pyxalign**!
14+
15+
pyxalign is a python package for loading, aligning, and reconstructing 3D volumes for tomography or laminography datasets. pyxalign currently supports ptychography and x-ray flourescence (XRF) datasets.
16+
17+
To get started with pyxalign, try running an :doc:`example </examples/index>` and consult the :doc:`file loading documentation </api/io>` to learn how to load data from your beamline.
18+
19+
If you have any questions about pyxalign or if you would like me to add a data loader for your experiment, please email me at hruth@anl.gov.
1420

1521
.. toctree::
1622
:maxdepth: 2
1723
:caption: Contents:
1824

1925
api/index
2026
examples/index
27+
install_guide
2128

docs/source/install_guide.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.. include:: ../../README.md
2+
:parser: myst_parser.sphinx_

src/pyxalign/data_structures/volume.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ def save_as_h5(self, file_path: str):
335335
print("There is no volume data to save!")
336336
with h5py.File(file_path, "w") as F:
337337
F.create_dataset(name="volume", data=self.data)
338+
print(f"File saved to: {file_path}")
338339

339340

340341
def get_tomogram_rotation_angles(

src/pyxalign/io/loaders/xrf/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def load_data_from_xrf_format(
1414
format.
1515
1616
Args:
17-
options (pear.options.XRFLoadOptions): Configuration options
17+
options (xrf.options.XRFLoadOptions): Configuration options
1818
for loading data.
1919
2020
Returns:

0 commit comments

Comments
 (0)