From 01363ab5111427ac4400d2a95f3d0b7060ef3cd4 Mon Sep 17 00:00:00 2001 From: YellowSub17 Date: Mon, 18 May 2026 11:50:26 +0200 Subject: [PATCH 01/13] fix cuda and install for maxwell --- CMakeLists.txt | 7 +- .../simple-checkpoint.ipynb | 1703 +++++++++++++++++ examples/simple.ipynb | 47 +- tests/CMakeLists.txt | 2 +- 4 files changed, 1744 insertions(+), 15 deletions(-) create mode 100644 examples/.ipynb_checkpoints/simple-checkpoint.ipynb diff --git a/CMakeLists.txt b/CMakeLists.txt index 3747208..f302581 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,11 @@ if(POLICY CMP0025) cmake_policy(SET CMP0025 NEW) # CMake 3.0 endif() +# If the variable is empty, set a sensible default (e.g., native or a common architecture) +if(NOT CMAKE_CUDA_ARCHITECTURES) + set(CMAKE_CUDA_ARCHITECTURES native) +endif() + project(spimage) include(CTest) @@ -162,7 +167,7 @@ endif() list(APPEND TESTS_LIBRARIES ${TIFF_LIBRARIES} ${FFTW3_LIBRARIES} ${PNG_LIBRARIES} ${HDF5_LIBRARIES} ${GSL_LIBRARIES}) -list(APPEND SPIMAGE_LIBRARIES ${TIFF_LIBRARIES} ${FFTW3_LIBRARIES} ${PNG_LIBRARIES} ${HDF5_LIBRARIES}) +list(APPEND SPIMAGE_LIBRARIES ${TIFF_LIBRARIES} ${FFTW3_LIBRARIES} ${PNG_LIBRARIES} ${HDF5_LIBRARIES} m) if(LINK_TO_DMALLOC) list(APPEND SPIMAGE_LIBRARIES ${DMALLOC_LIBRARY}) diff --git a/examples/.ipynb_checkpoints/simple-checkpoint.ipynb b/examples/.ipynb_checkpoints/simple-checkpoint.ipynb new file mode 100644 index 0000000..b918379 --- /dev/null +++ b/examples/.ipynb_checkpoints/simple-checkpoint.ipynb @@ -0,0 +1,1703 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "import spimage\n", + "import h5py\n", + "import numpy as np\n", + "import scipy as sp\n", + "import matplotlib.pyplot as plt\n", + "import matplotlib.colors as colors\n", + "%matplotlib notebook" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "# Simulate a simple diffraction pattern\n", + "square = np.zeros((200,200))\n", + "square[90:-90,90:-90] = 1.\n", + "square_smooth = sp.ndimage.gaussian_filter(square,2)\n", + "diffraction = np.abs(np.fft.fftn(square_smooth))**2" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "window.mpl = {};\n", + "\n", + "mpl.get_websocket_type = function() {\n", + " if (typeof(WebSocket) !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof(MozWebSocket) !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert('Your browser does not have WebSocket support.' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.');\n", + " };\n", + "}\n", + "\n", + "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = (this.ws.binaryType != undefined);\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById(\"mpl-warnings\");\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent = (\n", + " \"This browser does not support binary websocket messages. \" +\n", + " \"Performance may be slow.\");\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = $('
');\n", + " this._root_extra_style(this.root)\n", + " this.root.attr('style', 'display: inline-block');\n", + "\n", + " $(parent_element).append(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", + " fig.send_message(\"send_image_mode\", {});\n", + " fig.send_message(\"refresh\", {});\n", + " }\n", + "\n", + " this.imageObj.onload = function() {\n", + " if (fig.image_mode == 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function() {\n", + " this.ws.close();\n", + " }\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "}\n", + "\n", + "mpl.figure.prototype._init_header = function() {\n", + " var titlebar = $(\n", + " '
');\n", + " var titletext = $(\n", + " '
');\n", + " titlebar.append(titletext)\n", + " this.root.append(titlebar);\n", + " this.header = titletext[0];\n", + "}\n", + "\n", + "\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._init_canvas = function() {\n", + " var fig = this;\n", + "\n", + " var canvas_div = $('
');\n", + "\n", + " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", + "\n", + " function canvas_keyboard_event(event) {\n", + " return fig.key_event(event, event['data']);\n", + " }\n", + "\n", + " canvas_div.keydown('key_press', canvas_keyboard_event);\n", + " canvas_div.keyup('key_release', canvas_keyboard_event);\n", + " this.canvas_div = canvas_div\n", + " this._canvas_extra_style(canvas_div)\n", + " this.root.append(canvas_div);\n", + "\n", + " var canvas = $('');\n", + " canvas.addClass('mpl-canvas');\n", + " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", + "\n", + " this.canvas = canvas[0];\n", + " this.context = canvas[0].getContext(\"2d\");\n", + "\n", + " var rubberband = $('');\n", + " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", + "\n", + " var pass_mouse_events = true;\n", + "\n", + " canvas_div.resizable({\n", + " start: function(event, ui) {\n", + " pass_mouse_events = false;\n", + " },\n", + " resize: function(event, ui) {\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " stop: function(event, ui) {\n", + " pass_mouse_events = true;\n", + " fig.request_resize(ui.size.width, ui.size.height);\n", + " },\n", + " });\n", + "\n", + " function mouse_event_fn(event) {\n", + " if (pass_mouse_events)\n", + " return fig.mouse_event(event, event['data']);\n", + " }\n", + "\n", + " rubberband.mousedown('button_press', mouse_event_fn);\n", + " rubberband.mouseup('button_release', mouse_event_fn);\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband.mousemove('motion_notify', mouse_event_fn);\n", + "\n", + " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", + " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", + "\n", + " canvas_div.on(\"wheel\", function (event) {\n", + " event = event.originalEvent;\n", + " event['data'] = 'scroll'\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " mouse_event_fn(event);\n", + " });\n", + "\n", + " canvas_div.append(canvas);\n", + " canvas_div.append(rubberband);\n", + "\n", + " this.rubberband = rubberband;\n", + " this.rubberband_canvas = rubberband[0];\n", + " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", + " this.rubberband_context.strokeStyle = \"#000000\";\n", + "\n", + " this._resize_canvas = function(width, height) {\n", + " // Keep the size of the canvas, canvas container, and rubber band\n", + " // canvas in synch.\n", + " canvas_div.css('width', width)\n", + " canvas_div.css('height', height)\n", + "\n", + " canvas.attr('width', width);\n", + " canvas.attr('height', height);\n", + "\n", + " rubberband.attr('width', width);\n", + " rubberband.attr('height', height);\n", + " }\n", + "\n", + " // Set the figure to an initial 600x600px, this will subsequently be updated\n", + " // upon first draw.\n", + " this._resize_canvas(600, 600);\n", + "\n", + " // Disable right mouse context menu.\n", + " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", + " return false;\n", + " });\n", + "\n", + " function set_focus () {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "}\n", + "\n", + "mpl.figure.prototype._init_toolbar = function() {\n", + " var fig = this;\n", + "\n", + " var nav_element = $('
')\n", + " nav_element.attr('style', 'width: 100%');\n", + " this.root.append(nav_element);\n", + "\n", + " // Define a callback function for later on.\n", + " function toolbar_event(event) {\n", + " return fig.toolbar_button_onclick(event['data']);\n", + " }\n", + " function toolbar_mouse_event(event) {\n", + " return fig.toolbar_button_onmouseover(event['data']);\n", + " }\n", + "\n", + " for(var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " // put a spacer in here.\n", + " continue;\n", + " }\n", + " var button = $('');\n", + " button.click(method_name, toolbar_event);\n", + " button.mouseover(tooltip, toolbar_mouse_event);\n", + " nav_element.append(button);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = $('');\n", + " nav_element.append(status_bar);\n", + " this.message = status_bar[0];\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = $('
');\n", + " var button = $('');\n", + " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", + " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", + " buttongrp.append(button);\n", + " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", + " titlebar.prepend(buttongrp);\n", + "}\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(el){\n", + " var fig = this\n", + " el.on(\"remove\", function(){\n", + "\tfig.close_ws(fig, {});\n", + " });\n", + "}\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(el){\n", + " // this is important to make the div 'focusable\n", + " el.attr('tabindex', 0)\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " }\n", + " else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._key_event_extra = function(event, name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager)\n", + " manager = IPython.keyboard_manager;\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which == 13) {\n", + " this.canvas_div.blur();\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", + " }\n", + "}\n", + "\n", + "mpl.figure.prototype.handle_save = function(fig, msg) {\n", + " fig.ondownload(fig, null);\n", + "}\n", + "\n", + "\n", + "mpl.find_output_cell = function(html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] == html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "}\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel != null) {\n", + " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", + "}\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "# Plot phasing results\n", + "fig = plt.figure(figsize=(11,4))\n", + "ax1 = fig.add_subplot(121)\n", + "ax1.set_title('Original image')\n", + "ax1.imshow(square_smooth, cmap='viridis', vmin=0, vmax=1)\n", + "ax2 = fig.add_subplot(122)\n", + "ax2.set_title('Reconstructed image')\n", + "ax2.imshow(np.abs(recons)[-1], cmap='viridis', vmin=0, vmax=1)\n", + "plt.show()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 2", + "language": "python", + "name": "python2" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.10" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/examples/simple.ipynb b/examples/simple.ipynb index b918379..908ca94 100644 --- a/examples/simple.ipynb +++ b/examples/simple.ipynb @@ -4,7 +4,10 @@ "cell_type": "code", "execution_count": 9, "metadata": { - "collapsed": true + "collapsed": true, + "jupyter": { + "outputs_hidden": true + } }, "outputs": [], "source": [ @@ -21,7 +24,10 @@ "cell_type": "code", "execution_count": 16, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -36,7 +42,10 @@ "cell_type": "code", "execution_count": 28, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -833,7 +842,10 @@ "cell_type": "code", "execution_count": 46, "metadata": { - "collapsed": true + "collapsed": true, + "jupyter": { + "outputs_hidden": true + } }, "outputs": [], "source": [ @@ -849,7 +861,10 @@ "cell_type": "code", "execution_count": 47, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -870,7 +885,10 @@ "cell_type": "code", "execution_count": 49, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [], "source": [ @@ -886,7 +904,10 @@ "cell_type": "code", "execution_count": 54, "metadata": { - "collapsed": false + "collapsed": false, + "jupyter": { + "outputs_hidden": false + } }, "outputs": [ { @@ -1681,23 +1702,23 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 2", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "python2" + "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 2 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.10" + "pygments_lexer": "ipython3", + "version": "3.11.7" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9e01479..70de2bb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,7 +16,7 @@ if(CUDA_FOUND) #set_target_properties(tests PROPERTIES CUDA_ARCHITECTURES "35") endif() -target_link_libraries(tests PRIVATE ${TESTS_LIBRARIES}) +target_link_libraries(tests PRIVATE ${TESTS_LIBRARIES} m) enable_testing() From 72336fa968bf4fdd788cc27431d22f2ffed0672a Mon Sep 17 00:00:00 2001 From: YellowSub17 Date: Mon, 18 May 2026 11:55:35 +0200 Subject: [PATCH 02/13] adding cmake_settings_ref --- cmake_settings_reference.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 cmake_settings_reference.txt diff --git a/cmake_settings_reference.txt b/cmake_settings_reference.txt new file mode 100644 index 0000000..815f762 --- /dev/null +++ b/cmake_settings_reference.txt @@ -0,0 +1,20 @@ +-- CUDA found. Using CUDA. +-- Configuring done (1.5s) +-- Generating done (0.1s) +-- Build files have been written to: /gpfs/exfel/u/usr/SPB/202501/p006933/Shared/dfly-p6933/libspimage/build +-- Cache values +BUILD_STATIC_LIB:BOOL= +BUILD_TESTING:BOOL=ON +CMAKE_BUILD_TYPE:STRING= +CMAKE_CUDA_ARCHITECTURES:STRING= +CMAKE_INSTALL_PREFIX:PATH=/home/patricka/p6933/usr/Shared/dfly-p6933/dfly +CUDAToolkit_BIN_DIR:PATH=/software/cuda/cuda-12.6/bin +CUDAToolkit_CUPTI_INCLUDE_DIR:PATH=/software/cuda/cuda-12.6/include +DMALLOC_USE:BOOL=OFF +DOUBLE_PRECISION:BOOL=OFF +HDF5_C_LIBRARY_hdf5:FILEPATH=/usr/lib64/openmpi/lib/libhdf5.so +INCLUDE_DEPENDENCIES:BOOL= +PYTHON_EXECUTABLE:PATH=/home/patricka/p6933/usr/Shared/dfly-p6933/dfly/bin/python3.9 +PYTHON_WRAPPERS:BOOL=ON +SP_MEM_DEBUG:BOOL=OFF +USE_CUDA:BOOL=ON From 44f63ed4c6a88849cc0d1c8e1064f700a755c8aa Mon Sep 17 00:00:00 2001 From: YellowSub17 Date: Mon, 18 May 2026 11:58:18 +0200 Subject: [PATCH 03/13] x' --- cmake_settings_reference.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake_settings_reference.txt b/cmake_settings_reference.txt index 815f762..3603784 100644 --- a/cmake_settings_reference.txt +++ b/cmake_settings_reference.txt @@ -1,3 +1,4 @@ +-- options for ccmake :) -- CUDA found. Using CUDA. -- Configuring done (1.5s) -- Generating done (0.1s) From f80482a038df9be93cc5004cf53a65e21172a2b5 Mon Sep 17 00:00:00 2001 From: YellowSub17 Date: Mon, 13 Jul 2026 14:30:35 +0200 Subject: [PATCH 04/13] s --- examples/simple.ipynb | 901 ++---------------- .../_spimage_reconstructor-checkpoint.py | 783 +++++++++++++++ src/.ipynb_checkpoints/spimage-checkpoint.py | 30 + 3 files changed, 890 insertions(+), 824 deletions(-) create mode 100644 src/.ipynb_checkpoints/_spimage_reconstructor-checkpoint.py create mode 100644 src/.ipynb_checkpoints/spimage-checkpoint.py diff --git a/examples/simple.ipynb b/examples/simple.ipynb index 908ca94..edaae42 100644 --- a/examples/simple.ipynb +++ b/examples/simple.ipynb @@ -2,827 +2,71 @@ "cells": [ { "cell_type": "code", - "execution_count": 9, - "metadata": { - "collapsed": true, - "jupyter": { - "outputs_hidden": true - } - }, - "outputs": [], - "source": [ - "import spimage\n", - "import h5py\n", - "import numpy as np\n", - "import scipy as sp\n", - "import matplotlib.pyplot as plt\n", - "import matplotlib.colors as colors\n", - "%matplotlib notebook" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [], - "source": [ - "# Simulate a simple diffraction pattern\n", - "square = np.zeros((200,200))\n", - "square[90:-90,90:-90] = 1.\n", - "square_smooth = sp.ndimage.gaussian_filter(square,2)\n", - "diffraction = np.abs(np.fft.fftn(square_smooth))**2" - ] - }, - { - "cell_type": "code", - "execution_count": 28, - "metadata": { - "collapsed": false, - "jupyter": { - "outputs_hidden": false - } - }, - "outputs": [ - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "window.mpl = {};\n", - "\n", - "mpl.get_websocket_type = function() {\n", - " if (typeof(WebSocket) !== 'undefined') {\n", - " return WebSocket;\n", - " } else if (typeof(MozWebSocket) !== 'undefined') {\n", - " return MozWebSocket;\n", - " } else {\n", - " alert('Your browser does not have WebSocket support.' +\n", - " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", - " 'Firefox 4 and 5 are also supported but you ' +\n", - " 'have to enable WebSockets in about:config.');\n", - " };\n", - "}\n", - "\n", - "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", - " this.id = figure_id;\n", - "\n", - " this.ws = websocket;\n", - "\n", - " this.supports_binary = (this.ws.binaryType != undefined);\n", - "\n", - " if (!this.supports_binary) {\n", - " var warnings = document.getElementById(\"mpl-warnings\");\n", - " if (warnings) {\n", - " warnings.style.display = 'block';\n", - " warnings.textContent = (\n", - " \"This browser does not support binary websocket messages. \" +\n", - " \"Performance may be slow.\");\n", - " }\n", - " }\n", - "\n", - " this.imageObj = new Image();\n", - "\n", - " this.context = undefined;\n", - " this.message = undefined;\n", - " this.canvas = undefined;\n", - " this.rubberband_canvas = undefined;\n", - " this.rubberband_context = undefined;\n", - " this.format_dropdown = undefined;\n", - "\n", - " this.image_mode = 'full';\n", - "\n", - " this.root = $('
');\n", - " this._root_extra_style(this.root)\n", - " this.root.attr('style', 'display: inline-block');\n", - "\n", - " $(parent_element).append(this.root);\n", - "\n", - " this._init_header(this);\n", - " this._init_canvas(this);\n", - " this._init_toolbar(this);\n", - "\n", - " var fig = this;\n", - "\n", - " this.waiting = false;\n", - "\n", - " this.ws.onopen = function () {\n", - " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", - " fig.send_message(\"send_image_mode\", {});\n", - " fig.send_message(\"refresh\", {});\n", - " }\n", - "\n", - " this.imageObj.onload = function() {\n", - " if (fig.image_mode == 'full') {\n", - " // Full images could contain transparency (where diff images\n", - " // almost always do), so we need to clear the canvas so that\n", - " // there is no ghosting.\n", - " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", - " }\n", - " fig.context.drawImage(fig.imageObj, 0, 0);\n", - " };\n", - "\n", - " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", - " }\n", - "\n", - " this.ws.onmessage = this._make_on_message_function(this);\n", - "\n", - " this.ondownload = ondownload;\n", - "}\n", - "\n", - "mpl.figure.prototype._init_header = function() {\n", - " var titlebar = $(\n", - " '
');\n", - " var titletext = $(\n", - " '
');\n", - " titlebar.append(titletext)\n", - " this.root.append(titlebar);\n", - " this.header = titletext[0];\n", - "}\n", - "\n", - "\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", - "\n", - "}\n", - "\n", - "\n", - "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", - "\n", - "}\n", - "\n", - "mpl.figure.prototype._init_canvas = function() {\n", - " var fig = this;\n", - "\n", - " var canvas_div = $('
');\n", - "\n", - " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", - "\n", - " function canvas_keyboard_event(event) {\n", - " return fig.key_event(event, event['data']);\n", - " }\n", - "\n", - " canvas_div.keydown('key_press', canvas_keyboard_event);\n", - " canvas_div.keyup('key_release', canvas_keyboard_event);\n", - " this.canvas_div = canvas_div\n", - " this._canvas_extra_style(canvas_div)\n", - " this.root.append(canvas_div);\n", - "\n", - " var canvas = $('');\n", - " canvas.addClass('mpl-canvas');\n", - " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", - "\n", - " this.canvas = canvas[0];\n", - " this.context = canvas[0].getContext(\"2d\");\n", - "\n", - " var rubberband = $('');\n", - " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", - "\n", - " var pass_mouse_events = true;\n", - "\n", - " canvas_div.resizable({\n", - " start: function(event, ui) {\n", - " pass_mouse_events = false;\n", - " },\n", - " resize: function(event, ui) {\n", - " fig.request_resize(ui.size.width, ui.size.height);\n", - " },\n", - " stop: function(event, ui) {\n", - " pass_mouse_events = true;\n", - " fig.request_resize(ui.size.width, ui.size.height);\n", - " },\n", - " });\n", - "\n", - " function mouse_event_fn(event) {\n", - " if (pass_mouse_events)\n", - " return fig.mouse_event(event, event['data']);\n", - " }\n", - "\n", - " rubberband.mousedown('button_press', mouse_event_fn);\n", - " rubberband.mouseup('button_release', mouse_event_fn);\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " rubberband.mousemove('motion_notify', mouse_event_fn);\n", - "\n", - " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", - " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", - "\n", - " canvas_div.on(\"wheel\", function (event) {\n", - " event = event.originalEvent;\n", - " event['data'] = 'scroll'\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " mouse_event_fn(event);\n", - " });\n", - "\n", - " canvas_div.append(canvas);\n", - " canvas_div.append(rubberband);\n", - "\n", - " this.rubberband = rubberband;\n", - " this.rubberband_canvas = rubberband[0];\n", - " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", - " this.rubberband_context.strokeStyle = \"#000000\";\n", - "\n", - " this._resize_canvas = function(width, height) {\n", - " // Keep the size of the canvas, canvas container, and rubber band\n", - " // canvas in synch.\n", - " canvas_div.css('width', width)\n", - " canvas_div.css('height', height)\n", - "\n", - " canvas.attr('width', width);\n", - " canvas.attr('height', height);\n", - "\n", - " rubberband.attr('width', width);\n", - " rubberband.attr('height', height);\n", - " }\n", - "\n", - " // Set the figure to an initial 600x600px, this will subsequently be updated\n", - " // upon first draw.\n", - " this._resize_canvas(600, 600);\n", - "\n", - " // Disable right mouse context menu.\n", - " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", - " return false;\n", - " });\n", - "\n", - " function set_focus () {\n", - " canvas.focus();\n", - " canvas_div.focus();\n", - " }\n", - "\n", - " window.setTimeout(set_focus, 100);\n", - "}\n", - "\n", - "mpl.figure.prototype._init_toolbar = function() {\n", - " var fig = this;\n", - "\n", - " var nav_element = $('
')\n", - " nav_element.attr('style', 'width: 100%');\n", - " this.root.append(nav_element);\n", - "\n", - " // Define a callback function for later on.\n", - " function toolbar_event(event) {\n", - " return fig.toolbar_button_onclick(event['data']);\n", - " }\n", - " function toolbar_mouse_event(event) {\n", - " return fig.toolbar_button_onmouseover(event['data']);\n", - " }\n", - "\n", - " for(var toolbar_ind in mpl.toolbar_items) {\n", - " var name = mpl.toolbar_items[toolbar_ind][0];\n", - " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", - " var image = mpl.toolbar_items[toolbar_ind][2];\n", - " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", - "\n", - " if (!name) {\n", - " // put a spacer in here.\n", - " continue;\n", - " }\n", - " var button = $('');\n", - " button.click(method_name, toolbar_event);\n", - " button.mouseover(tooltip, toolbar_mouse_event);\n", - " nav_element.append(button);\n", - " }\n", - "\n", - " // Add the status bar.\n", - " var status_bar = $('');\n", - " nav_element.append(status_bar);\n", - " this.message = status_bar[0];\n", - "\n", - " // Add the close button to the window.\n", - " var buttongrp = $('
');\n", - " var button = $('');\n", - " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", - " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", - " buttongrp.append(button);\n", - " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", - " titlebar.prepend(buttongrp);\n", - "}\n", - "\n", - "mpl.figure.prototype._root_extra_style = function(el){\n", - " var fig = this\n", - " el.on(\"remove\", function(){\n", - "\tfig.close_ws(fig, {});\n", - " });\n", - "}\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function(el){\n", - " // this is important to make the div 'focusable\n", - " el.attr('tabindex', 0)\n", - " // reach out to IPython and tell the keyboard manager to turn it's self\n", - " // off when our div gets focus\n", - "\n", - " // location in version 3\n", - " if (IPython.notebook.keyboard_manager) {\n", - " IPython.notebook.keyboard_manager.register_events(el);\n", - " }\n", - " else {\n", - " // location in version 2\n", - " IPython.keyboard_manager.register_events(el);\n", - " }\n", - "\n", - "}\n", - "\n", - "mpl.figure.prototype._key_event_extra = function(event, name) {\n", - " var manager = IPython.notebook.keyboard_manager;\n", - " if (!manager)\n", - " manager = IPython.keyboard_manager;\n", - "\n", - " // Check for shift+enter\n", - " if (event.shiftKey && event.which == 13) {\n", - " this.canvas_div.blur();\n", - " event.shiftKey = false;\n", - " // Send a \"J\" for go to next cell\n", - " event.which = 74;\n", - " event.keyCode = 74;\n", - " manager.command_mode();\n", - " manager.handle_keydown(event);\n", - " }\n", - "}\n", - "\n", - "mpl.figure.prototype.handle_save = function(fig, msg) {\n", - " fig.ondownload(fig, null);\n", - "}\n", - "\n", - "\n", - "mpl.find_output_cell = function(html_output) {\n", - " // Return the cell and output element which can be found *uniquely* in the notebook.\n", - " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", - " // IPython event is triggered only after the cells have been serialised, which for\n", - " // our purposes (turning an active figure into a static one), is too late.\n", - " var cells = IPython.notebook.get_cells();\n", - " var ncells = cells.length;\n", - " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", - " data = data.data;\n", - " }\n", - " if (data['text/html'] == html_output) {\n", - " return [cell, data, j];\n", - " }\n", - " }\n", - " }\n", - " }\n", - "}\n", - "\n", - "// Register the function which deals with the matplotlib target/channel.\n", - "// The kernel may be null if the page has been refreshed.\n", - "if (IPython.notebook.kernel != null) {\n", - " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", - "}\n" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } - ], - "source": [ - "# Plot original image and simulated diffraction pattern\n", - "fig = plt.figure(figsize=(11,4))\n", - "ax1 = fig.add_subplot(121)\n", - "ax1.set_title('Original image')\n", - "ax1.imshow(square_smooth, cmap='viridis')\n", - "ax2 = fig.add_subplot(122)\n", - "ax2.set_title('Simulated diffraction pattern')\n", - "im2 = ax2.imshow(np.fft.fftshift(diffraction), norm=colors.LogNorm(vmin=1e-4), cmap='plasma')\n", - "fig.colorbar(im2)\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "# Phasing parameters\n", - "niter_hio = 5000\n", - "niter_er = 1000\n", - "niter_total = niter_hio + niter_er\n", - "beta = 0.9\n", - "support_size = 30." - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Run HIO algorithm with ER at the end\n", - "R = spimage.Reconstructor()\n", - "R.set_intensities(diffraction)\n", - "R.set_number_of_iterations(niter_total)\n", - "R.set_number_of_outputs_images(5)\n", - "R.set_number_of_outputs_scores(200)\n", - "R.set_initial_support(radius=support_size/2.)\n", - "R.set_support_algorithm(\"static\", number_of_iterations=niter_total)\n", - "R.append_phasing_algorithm(\"hio\",beta_init=beta, beta_final=beta, number_of_iterations=niter_hio)\n", - "R.append_phasing_algorithm(\"er\", number_of_iterations=niter_er)\n", - "output = R.reconstruct()" - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": { - "collapsed": false - }, - "outputs": [], - "source": [ - "# Collect results\n", - "recons = output['real_space']\n", - "fourier = output['fourier_space']\n", - "support = output['support']\n", - "rerror = output[\"real_error\"]\n", - "ferror = output[\"fourier_error\"]" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "data": { - "application/javascript": [ - "/* Put everything inside the global mpl namespace */\n", - "window.mpl = {};\n", - "\n", - "mpl.get_websocket_type = function() {\n", - " if (typeof(WebSocket) !== 'undefined') {\n", - " return WebSocket;\n", - " } else if (typeof(MozWebSocket) !== 'undefined') {\n", - " return MozWebSocket;\n", - " } else {\n", - " alert('Your browser does not have WebSocket support.' +\n", - " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", - " 'Firefox 4 and 5 are also supported but you ' +\n", - " 'have to enable WebSockets in about:config.');\n", - " };\n", - "}\n", - "\n", - "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", - " this.id = figure_id;\n", - "\n", - " this.ws = websocket;\n", - "\n", - " this.supports_binary = (this.ws.binaryType != undefined);\n", - "\n", - " if (!this.supports_binary) {\n", - " var warnings = document.getElementById(\"mpl-warnings\");\n", - " if (warnings) {\n", - " warnings.style.display = 'block';\n", - " warnings.textContent = (\n", - " \"This browser does not support binary websocket messages. \" +\n", - " \"Performance may be slow.\");\n", - " }\n", - " }\n", - "\n", - " this.imageObj = new Image();\n", - "\n", - " this.context = undefined;\n", - " this.message = undefined;\n", - " this.canvas = undefined;\n", - " this.rubberband_canvas = undefined;\n", - " this.rubberband_context = undefined;\n", - " this.format_dropdown = undefined;\n", - "\n", - " this.image_mode = 'full';\n", - "\n", - " this.root = $('
');\n", - " this._root_extra_style(this.root)\n", - " this.root.attr('style', 'display: inline-block');\n", - "\n", - " $(parent_element).append(this.root);\n", - "\n", - " this._init_header(this);\n", - " this._init_canvas(this);\n", - " this._init_toolbar(this);\n", - "\n", - " var fig = this;\n", - "\n", - " this.waiting = false;\n", - "\n", - " this.ws.onopen = function () {\n", - " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", - " fig.send_message(\"send_image_mode\", {});\n", - " fig.send_message(\"refresh\", {});\n", - " }\n", - "\n", - " this.imageObj.onload = function() {\n", - " if (fig.image_mode == 'full') {\n", - " // Full images could contain transparency (where diff images\n", - " // almost always do), so we need to clear the canvas so that\n", - " // there is no ghosting.\n", - " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", - " }\n", - " fig.context.drawImage(fig.imageObj, 0, 0);\n", - " };\n", - "\n", - " this.imageObj.onunload = function() {\n", - " this.ws.close();\n", - " }\n", - "\n", - " this.ws.onmessage = this._make_on_message_function(this);\n", - "\n", - " this.ondownload = ondownload;\n", - "}\n", - "\n", - "mpl.figure.prototype._init_header = function() {\n", - " var titlebar = $(\n", - " '
');\n", - " var titletext = $(\n", - " '
');\n", - " titlebar.append(titletext)\n", - " this.root.append(titlebar);\n", - " this.header = titletext[0];\n", - "}\n", - "\n", - "\n", - "\n", - "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", - "\n", - "}\n", - "\n", - "\n", - "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", - "\n", - "}\n", - "\n", - "mpl.figure.prototype._init_canvas = function() {\n", - " var fig = this;\n", - "\n", - " var canvas_div = $('
');\n", - "\n", - " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", - "\n", - " function canvas_keyboard_event(event) {\n", - " return fig.key_event(event, event['data']);\n", - " }\n", - "\n", - " canvas_div.keydown('key_press', canvas_keyboard_event);\n", - " canvas_div.keyup('key_release', canvas_keyboard_event);\n", - " this.canvas_div = canvas_div\n", - " this._canvas_extra_style(canvas_div)\n", - " this.root.append(canvas_div);\n", - "\n", - " var canvas = $('');\n", - " canvas.addClass('mpl-canvas');\n", - " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", - "\n", - " this.canvas = canvas[0];\n", - " this.context = canvas[0].getContext(\"2d\");\n", - "\n", - " var rubberband = $('');\n", - " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", - "\n", - " var pass_mouse_events = true;\n", - "\n", - " canvas_div.resizable({\n", - " start: function(event, ui) {\n", - " pass_mouse_events = false;\n", - " },\n", - " resize: function(event, ui) {\n", - " fig.request_resize(ui.size.width, ui.size.height);\n", - " },\n", - " stop: function(event, ui) {\n", - " pass_mouse_events = true;\n", - " fig.request_resize(ui.size.width, ui.size.height);\n", - " },\n", - " });\n", - "\n", - " function mouse_event_fn(event) {\n", - " if (pass_mouse_events)\n", - " return fig.mouse_event(event, event['data']);\n", - " }\n", - "\n", - " rubberband.mousedown('button_press', mouse_event_fn);\n", - " rubberband.mouseup('button_release', mouse_event_fn);\n", - " // Throttle sequential mouse events to 1 every 20ms.\n", - " rubberband.mousemove('motion_notify', mouse_event_fn);\n", - "\n", - " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", - " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", - "\n", - " canvas_div.on(\"wheel\", function (event) {\n", - " event = event.originalEvent;\n", - " event['data'] = 'scroll'\n", - " if (event.deltaY < 0) {\n", - " event.step = 1;\n", - " } else {\n", - " event.step = -1;\n", - " }\n", - " mouse_event_fn(event);\n", - " });\n", - "\n", - " canvas_div.append(canvas);\n", - " canvas_div.append(rubberband);\n", - "\n", - " this.rubberband = rubberband;\n", - " this.rubberband_canvas = rubberband[0];\n", - " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", - " this.rubberband_context.strokeStyle = \"#000000\";\n", - "\n", - " this._resize_canvas = function(width, height) {\n", - " // Keep the size of the canvas, canvas container, and rubber band\n", - " // canvas in synch.\n", - " canvas_div.css('width', width)\n", - " canvas_div.css('height', height)\n", - "\n", - " canvas.attr('width', width);\n", - " canvas.attr('height', height);\n", - "\n", - " rubberband.attr('width', width);\n", - " rubberband.attr('height', height);\n", - " }\n", - "\n", - " // Set the figure to an initial 600x600px, this will subsequently be updated\n", - " // upon first draw.\n", - " this._resize_canvas(600, 600);\n", - "\n", - " // Disable right mouse context menu.\n", - " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", - " return false;\n", - " });\n", - "\n", - " function set_focus () {\n", - " canvas.focus();\n", - " canvas_div.focus();\n", - " }\n", - "\n", - " window.setTimeout(set_focus, 100);\n", - "}\n", - "\n", - "mpl.figure.prototype._init_toolbar = function() {\n", - " var fig = this;\n", - "\n", - " var nav_element = $('
')\n", - " nav_element.attr('style', 'width: 100%');\n", - " this.root.append(nav_element);\n", - "\n", - " // Define a callback function for later on.\n", - " function toolbar_event(event) {\n", - " return fig.toolbar_button_onclick(event['data']);\n", - " }\n", - " function toolbar_mouse_event(event) {\n", - " return fig.toolbar_button_onmouseover(event['data']);\n", - " }\n", - "\n", - " for(var toolbar_ind in mpl.toolbar_items) {\n", - " var name = mpl.toolbar_items[toolbar_ind][0];\n", - " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", - " var image = mpl.toolbar_items[toolbar_ind][2];\n", - " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", - "\n", - " if (!name) {\n", - " // put a spacer in here.\n", - " continue;\n", - " }\n", - " var button = $('');\n", + " button.click(method_name, toolbar_event);\n", + " button.mouseover(tooltip, toolbar_mouse_event);\n", + " nav_element.append(button);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = $('');\n", + " nav_element.append(status_bar);\n", + " this.message = status_bar[0];\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = $('
');\n", + " var button = $('');\n", + " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", + " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", + " buttongrp.append(button);\n", + " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", + " titlebar.prepend(buttongrp);\n", + "}\n", + "\n", + "mpl.figure.prototype._root_extra_style = function(el){\n", + " var fig = this\n", + " el.on(\"remove\", function(){\n", + "\tfig.close_ws(fig, {});\n", + " });\n", + "}\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function(el){\n", + " // this is important to make the div 'focusable\n", + " el.attr('tabindex', 0)\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " }\n", + " else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "\n", + "}\n", + "\n", + "mpl.figure.prototype._key_event_extra = function(event, name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager)\n", + " manager = IPython.keyboard_manager;\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which == 13) {\n", + " this.canvas_div.blur();\n", + " event.shiftKey = false;\n", + " // Send a \"J\" for go to next cell\n", + " event.which = 74;\n", + " event.keyCode = 74;\n", + " manager.command_mode();\n", + " manager.handle_keydown(event);\n", + " }\n", + "}\n", + "\n", + "mpl.figure.prototype.handle_save = function(fig, msg) {\n", + " fig.ondownload(fig, null);\n", + "}\n", + "\n", + "\n", + "mpl.find_output_cell = function(html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] == html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "}\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel != null) {\n", + " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", + "}\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -125,15 +881,6 @@ "output = R.reconstruct()" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "output.keys()" - ] - }, { "cell_type": "code", "execution_count": 49, @@ -150,7 +897,7 @@ "fourier = output['fourier_space']\n", "support = output['support']\n", "rerror = output[\"real_error\"]\n", - "ferror = output[\"fourier_error\"]\n" + "ferror = output[\"fourier_error\"]" ] }, { @@ -955,9 +1702,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python (dfly)", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "dfly" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -969,7 +1716,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.25" + "version": "3.11.7" } }, "nbformat": 4, From 8e9230129060e7704f3f2e5c2039f9aa907f559b Mon Sep 17 00:00:00 2001 From: YellowSub17 Date: Mon, 13 Jul 2026 16:23:40 +0200 Subject: [PATCH 08/13] x --- .../cmake_settings_maxwell.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) rename cmake_settings_reference.txt => cmake/cmake_settings_maxwell.txt (71%) diff --git a/cmake_settings_reference.txt b/cmake/cmake_settings_maxwell.txt similarity index 71% rename from cmake_settings_reference.txt rename to cmake/cmake_settings_maxwell.txt index 3603784..53dc1b0 100644 --- a/cmake_settings_reference.txt +++ b/cmake/cmake_settings_maxwell.txt @@ -1,4 +1,10 @@ --- options for ccmake :) +-- options for ccmake that i used for building on maxwell +-- I also had to add the m library in libspimage/CMakeLists.txt and libspimage/test/CMakeLists.txt +-- On maxwell, i used python 3.9 with venv, and loaded the modules mpi/openmpi-x86_64, maxwell, and cuda +-- -PA +-- +-- +-- -- CUDA found. Using CUDA. -- Configuring done (1.5s) -- Generating done (0.1s) @@ -8,6 +14,7 @@ BUILD_STATIC_LIB:BOOL= BUILD_TESTING:BOOL=ON CMAKE_BUILD_TYPE:STRING= CMAKE_CUDA_ARCHITECTURES:STRING= +-- venv directory VVV CMAKE_INSTALL_PREFIX:PATH=/home/patricka/p6933/usr/Shared/dfly-p6933/dfly CUDAToolkit_BIN_DIR:PATH=/software/cuda/cuda-12.6/bin CUDAToolkit_CUPTI_INCLUDE_DIR:PATH=/software/cuda/cuda-12.6/include @@ -15,6 +22,7 @@ DMALLOC_USE:BOOL=OFF DOUBLE_PRECISION:BOOL=OFF HDF5_C_LIBRARY_hdf5:FILEPATH=/usr/lib64/openmpi/lib/libhdf5.so INCLUDE_DEPENDENCIES:BOOL= +-- venv directory VVV PYTHON_EXECUTABLE:PATH=/home/patricka/p6933/usr/Shared/dfly-p6933/dfly/bin/python3.9 PYTHON_WRAPPERS:BOOL=ON SP_MEM_DEBUG:BOOL=OFF From 08ad40ea4abb6ee00b6703742cbdb15c0b9b0120 Mon Sep 17 00:00:00 2001 From: YellowSub17 Date: Mon, 13 Jul 2026 16:25:28 +0200 Subject: [PATCH 09/13] s --- tests/CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index eabccfc..fd746eb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,10 +16,12 @@ if(CUDA_FOUND) #set_target_properties(tests PROPERTIES CUDA_ARCHITECTURES "35") endif() -target_link_libraries(tests PRIVATE ${TESTS_LIBRARIES} MATH_LIBRARY) -find_library(MATH_LIBRARY m) -target_link_libraries(tests PRIVATE ${TESTS_LIBRARIES} MATH_LIBRARY) +target_link_libraries(tests PRIVATE ${TESTS_LIBRARIES}) + +## PA: Fix for maxwell +#find_library(MATH_LIBRARY m) +#target_link_libraries(tests PRIVATE ${TESTS_LIBRARIES} MATH_LIBRARY) enable_testing() From d3e9cda9d0cf6da406832b50738965dd28826524 Mon Sep 17 00:00:00 2001 From: YellowSub17 Date: Mon, 13 Jul 2026 16:26:50 +0200 Subject: [PATCH 10/13] cleaner --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f1ef10..3c3ba38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,10 @@ if(POLICY CMP0025) endif() # If the variable is empty, set a sensible default (e.g., native or a common architecture) -if(NOT CMAKE_CUDA_ARCHITECTURES) - set(CMAKE_CUDA_ARCHITECTURES native) -endif() +## PA: Fix for maxwell +#if(NOT CMAKE_CUDA_ARCHITECTURES) + #set(CMAKE_CUDA_ARCHITECTURES native) +#endif() project(spimage) From b87b55de5fcc42f66d32636c24c4edbde6cae0dd Mon Sep 17 00:00:00 2001 From: YellowSub17 Date: Wed, 26 Aug 2026 11:08:12 +0200 Subject: [PATCH 11/13] setting output_n to -1 will auto set output_n to the number of iterations --- src/_spimage_reconstructor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/_spimage_reconstructor.py b/src/_spimage_reconstructor.py index f9401d0..f85d8ce 100644 --- a/src/_spimage_reconstructor.py +++ b/src/_spimage_reconstructor.py @@ -338,8 +338,16 @@ def _prepare_reconstruction(self): if self._i_phasing_algorithms != self._number_of_iterations: self._log("Connot prepare reconstruction. Phasing algorithms initialised are not in line with the set number of iterations.","ERROR") self._ready = False + + if self._number_of_outputs_images <0: + self._number_of_outputs_images = self._number_of_iterations + if self._number_of_outputs_scores <0: + self._number_of_outputs_scores = self._number_of_iterations + if not self._ready: return + + self._init_amplitudes() self._init_initial_support() self._init_iterations() From c20d512809d6c0127784588d7e226438c12fa518 Mon Sep 17 00:00:00 2001 From: YellowSub17 Date: Wed, 26 Aug 2026 11:31:31 +0200 Subject: [PATCH 12/13] added log statements for gpu/cpu engine --- src/_spimage_reconstructor.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/_spimage_reconstructor.py b/src/_spimage_reconstructor.py index f85d8ce..496a86d 100644 --- a/src/_spimage_reconstructor.py +++ b/src/_spimage_reconstructor.py @@ -548,8 +548,10 @@ def _init_phaser(self): self._sp_phaser = spimage.sp_phaser_alloc() if self._use_gpu: pe = spimage.SpEngineCUDA + self._log(f"Set phasing engine to GPU.") else: pe = spimage.SpEngineCPU + self._log(f"Set phasing engine to CPU.") self._log("Initialising phaser with the phasing algorithm %s and the support algorithm %s." % (self._phasing_algorithms[0]["type"],self._support_algorithms[0]["type"])) spimage.sp_phaser_init(self._sp_phaser, self._phasing_algorithms[0]["spimage_phasing"], self._support_algorithms[0]["spimage_support_array"], pe) spimage.sp_phaser_set_amplitudes(self._sp_phaser, self._sp_amplitudes) From df94d97c7d4c370abc26de40bd7a5a32b28f48ea Mon Sep 17 00:00:00 2001 From: Patrick Adams Date: Thu, 17 Sep 2026 15:48:50 +0200 Subject: [PATCH 13/13] Add on_output callback to Reconstructor.reconstruct() Allows saving images/scores incrementally per output step (e.g. one HDF5 file per iteration) instead of only after the full reconstruction finishes. Co-Authored-By: Claude Sonnet 5 --- src/_spimage_reconstructor.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/_spimage_reconstructor.py b/src/_spimage_reconstructor.py index 496a86d..a0454e0 100644 --- a/src/_spimage_reconstructor.py +++ b/src/_spimage_reconstructor.py @@ -560,9 +560,15 @@ def _init_phaser(self): self._phaser_dirty = False self._log("Phaser initialized.","DEBUG") - def reconstruct(self): + def reconstruct(self, on_output=None): """ Performs a single reconstruction with the specified configuration and outputs a dictionary with the results. + + If \"on_output\" is given, it must be a callable accepting the keyword arguments + (iteration, images, scores). It is called every time images and/or scores are + written to the output, with \"images\" and/or \"scores\" set to None if not written + at that iteration. This can be used e.g. to save output incrementally (per step) + to disk instead of only after the full reconstruction has finished. """ self._prepare_reconstruction() if not self._ready: @@ -607,9 +613,15 @@ def reconstruct(self): iteration0_sup = self._iteration self._sp_phaser.sup_algorithm = self._support_algorithms[i_sup]["spimage_support_array"] self._log("Change of support algorithm to %s." % self._support_algorithms[i_sup]["type"],"INFO") + out_images = None + out_scores = None if self._iteration in self._out_iterations_images: [real_space[i_out_images,:,:],support[i_out_images,:,:]] = self._get_curr_model(shifted=False) [fourier_space[i_out_images,:,:],mask[i_out_images,:,:]] = self._get_curr_fmodel(shifted=False) + out_images = {"real_space":real_space[i_out_images], + "support":support[i_out_images], + "fourier_space":fourier_space[i_out_images], + "mask":mask[i_out_images]} i_out_images += 1 self._log("Outputting images.","DEBUG") if self._iteration in self._out_iterations_scores: @@ -617,8 +629,13 @@ def reconstruct(self): fourier_error[i_out_scores] = scores["fourier_error"] real_error[i_out_scores] = scores["real_error"] support_size[i_out_scores] = scores["support_size"] + out_scores = {"real_error":real_error[i_out_scores], + "fourier_error":fourier_error[i_out_scores], + "support_size":support_size[i_out_scores]} i_out_scores += 1 self._log("Outputting scores.","DEBUG") + if on_output is not None and (out_images is not None or out_scores is not None): + on_output(iteration=self._iteration, images=out_images, scores=out_scores) self._iteration = None out = {"iteration_index_images":self._out_iterations_images, "iteration_index_scores":self._out_iterations_scores, @@ -659,9 +676,15 @@ def reconstruct(self): iteration0_sup = self._iteration self._sp_phaser.sup_algorithm = self._support_algorithms[i_sup]["spimage_support_array"] self._log("Change of support algorithm to %s." % self._support_algorithms[i_sup]["type"],"INFO") + out_images = None + out_scores = None if self._iteration in self._out_iterations_images: [real_space[i_out_images,:,:,:],support[i_out_images,:,:,:]] = self._get_curr_model(shifted=False) [fourier_space[i_out_images,:,:,:],mask[i_out_images,:,:,:]] = self._get_curr_fmodel(shifted=False) + out_images = {"real_space":real_space[i_out_images], + "support":support[i_out_images], + "fourier_space":fourier_space[i_out_images], + "mask":mask[i_out_images]} i_out_images += 1 self._log("Outputting images.","DEBUG") if self._iteration in self._out_iterations_scores: @@ -669,8 +692,13 @@ def reconstruct(self): fourier_error[i_out_scores] = scores["fourier_error"] real_error[i_out_scores] = scores["real_error"] support_size[i_out_scores] = scores["support_size"] + out_scores = {"real_error":real_error[i_out_scores], + "fourier_error":fourier_error[i_out_scores], + "support_size":support_size[i_out_scores]} i_out_scores += 1 self._log("Outputting scores.","DEBUG") + if on_output is not None and (out_images is not None or out_scores is not None): + on_output(iteration=self._iteration, images=out_images, scores=out_scores) self._iteration = None out = {"iteration_index_images":self._out_iterations_images, "iteration_index_scores":self._out_iterations_scores,