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

[WIP] lightweight refactoring #84

Open
wants to merge 4 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
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "nsls2ptycho/core/ptycho"]
path = nsls2ptycho/core/ptycho
[submodule "nsls2ptycho/backend/ptycho"]
path = nsls2ptycho/backend/ptycho
url = ../ptycho.git
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include nsls2ptycho/core/ptycho/*.cubin
include nsls2ptycho/backend/ptycho/*.cubin
2 changes: 2 additions & 0 deletions nsls2ptycho/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import nsls2ptycho.backend
import nsls2ptycho.core
import nsls2ptycho.databroker
import nsls2ptycho.ui
from ._version import __version__

Expand Down
Empty file added nsls2ptycho/backend/__init__.py
Empty file.
1 change: 0 additions & 1 deletion nsls2ptycho/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import nsls2ptycho.core.ptycho
import nsls2ptycho.core.widgets
File renamed without changes.
2 changes: 1 addition & 1 deletion nsls2ptycho/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
mpi4py.rc.initialize = False
from mpi4py import MPI

from nsls2ptycho.core.ptycho.utils import split
from nsls2ptycho.backend.ptycho.utils import split


# DEPRECARED: migrated to nsls2ptycho.core.widgets.mplcanvas
Expand Down
2 changes: 1 addition & 1 deletion nsls2ptycho/core/widgets/mplcanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import numpy as np
from PIL import Image

from nsls2ptycho.core.ptycho.utils import split
from nsls2ptycho.backend.ptycho.utils import split


def load_image_pil(path):
Expand Down
11 changes: 6 additions & 5 deletions nsls2ptycho/core/ptycho_recon.py → nsls2ptycho/core/workers.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from PyQt5 import QtCore
from datetime import datetime
from nsls2ptycho.core.ptycho_param import Param
import sys, os
import pickle # dump param into disk
import subprocess # call mpirun from shell
from fcntl import fcntl, F_GETFL, F_SETFL
from os import O_NONBLOCK
import numpy as np
import traceback

from nsls2ptycho.core.databroker_api import load_metadata, save_data
import numpy as np
from PyQt5 import QtCore

from nsls2ptycho.core.ptycho_param import Param
from nsls2ptycho.core.utils import use_mpi_machinefile, set_flush_early
from nsls2ptycho.databroker import load_metadata, save_data


class PtychoReconWorker(QtCore.QThread):
Expand Down Expand Up @@ -81,7 +82,7 @@ def _parse_one_line(self):

def recon_api(self, param:Param, update_fcn=None):
# "1" is just a placeholder to be overwritten soon
mpirun_command = ["mpirun", "-n", "1", "python", "-W", "ignore", "-m","nsls2ptycho.core.ptycho.recon_ptycho_gui"]
mpirun_command = ["mpirun", "-n", "1", "python", "-W", "ignore", "-m","nsls2ptycho.backend.ptycho.recon_ptycho_gui"]

if param.mpi_file_path == '':
if param.gpu_flag:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


# ***************************** "Public API" *****************************
# The following functions must exist in nsls2ptycho/core/*_databroker.py,
# The following functions must exist in nsls2ptycho.databroker,
# but the function signatures do not need to agree across modules
# (obviously, it is impossible for all beamlines to have the same setup).
# - load_metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


# ***************************** "Public API" *****************************
# The following functions must exist in nsls2ptycho/core/*_databroker.py,
# The following functions must exist in nsls2ptycho.databroker,
# but the function signatures do not need to agree across modules
# (obviously, it is impossible for all beamlines to have the same setup).
# - load_metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


# ***************************** "Public API" *****************************
# The following functions must exist in nsls2ptycho/core/*_databroker.py,
# The following functions must exist in nsls2ptycho.databroker,
# but the function signatures do not need to agree across modules
# (obviously, it is impossible for all beamlines to have the same setup).
# - load_metadata
Expand All @@ -22,7 +22,7 @@


def _load_HXN():
import nsls2ptycho.core.HXN_databroker as hxn_databroker
from . import HXN_databroker as hxn_databroker
global load_metadata, save_data, get_single_image, get_detector_names, db
load_metadata = hxn_databroker.load_metadata
save_data = hxn_databroker.save_data
Expand All @@ -33,7 +33,7 @@ def _load_HXN():


def _load_CSX():
import nsls2ptycho.core.CSX_databroker as csx_databroker
from . import CSX_databroker as csx_databroker
global load_metadata, save_data, get_single_image, get_detector_names, db
load_metadata = csx_databroker.load_metadata
save_data = csx_databroker.save_data
Expand Down
10 changes: 5 additions & 5 deletions nsls2ptycho/ptycho_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
from nsls2ptycho.ui import ui_ptycho
from nsls2ptycho.core.utils import clean_shared_memory, get_mpi_num_processes, parse_range
from nsls2ptycho.core.ptycho_param import Param
from nsls2ptycho.core.ptycho_recon import PtychoReconWorker, PtychoReconFakeWorker, HardWorker
from nsls2ptycho.core.ptycho_qt_utils import PtychoStream
from nsls2ptycho.core.workers import PtychoReconWorker, PtychoReconFakeWorker, HardWorker
from nsls2ptycho.core.qt_utils import PtychoStream
from nsls2ptycho.core.widgets.list_widget import ListWidget
from nsls2ptycho.core.widgets.mplcanvas import load_image_pil
from nsls2ptycho.core.ptycho.utils import parse_config
from nsls2ptycho.backend.ptycho.utils import parse_config
from nsls2ptycho._version import __version__

# databroker related
from nsls2ptycho.core.databroker_api import db, load_metadata, get_single_image, get_detector_names, beamline_name
from nsls2ptycho.databroker import db, load_metadata, get_single_image, get_detector_names, beamline_name

from nsls2ptycho.reconStep_gui import ReconStepWindow
from nsls2ptycho.roi_gui import RoiWindow
Expand Down Expand Up @@ -570,7 +570,7 @@ def start(self, batch_mode=False):
else:
self._scan_points[0] *= -1.*self.param.x_direction
self._scan_points[1] *= self.param.y_direction
# borrowed from nsls2ptycho/core/ptycho_recon.py
# borrowed from nsls2ptycho/core/workers.py
if self.param.mpi_file_path == '':
if self.param.gpu_flag:
num_processes = str(len(self.param.gpus))
Expand Down
4 changes: 2 additions & 2 deletions nsls2ptycho/roi_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import numpy as np
from nsls2ptycho.core.widgets.imgTools import find_outlier_pixels, find_brightest_pixels, rm_outlier_pixels
from nsls2ptycho.core.ptycho_recon import HardWorker
from nsls2ptycho.core.workers import HardWorker
from nsls2ptycho.core.widgets.badpixel_dialog import BadPixelDialog
from nsls2ptycho.core.databroker_api import save_data
from nsls2ptycho.databroker import save_data


class RoiWindow(QtWidgets.QMainWindow, ui_roi.Ui_MainWindow):
Expand Down
20 changes: 13 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
from glob import glob
extensions = []
# this doesn't work because setuptools doesn't support glob pattern...
#extensions = [Extension("*", ["nsls2ptycho/core/ptycho/*.c"])]
for filename in glob("nsls2ptycho/core/ptycho/*.c"):
#extensions = [Extension("*", ["nsls2ptycho/backend/ptycho/*.c"])]
for filename in glob("nsls2ptycho/backend/ptycho/*.c"):
mod = os.path.basename(filename)[:-2]
extensions.append(Extension("nsls2ptycho.core.ptycho."+mod, [filename]))
extensions.append(Extension("nsls2ptycho.backend.ptycho."+mod, [filename]))
else:
extensions = cythonize("nsls2ptycho/core/ptycho/*.pyx")
extensions = cythonize("nsls2ptycho/backend/ptycho/*.pyx")

# see if PyQt5 is already installed --- pip and conda use different names...
try:
Expand All @@ -39,7 +39,7 @@

# for generating .cubin files
# TODO: add a flag to do this only if GPU support is needed?
import nsls2ptycho.core.ptycho.build_cuda_source as bcs
import nsls2ptycho.backend.ptycho.build_cuda_source as bcs
cubin_path = bcs.compile()

# if GPU support is needed, check if cupy exists
Expand Down Expand Up @@ -71,10 +71,16 @@
setup(name=NAME,
version=__version__,
#packages=find_packages(),
packages=["nsls2ptycho", "nsls2ptycho.core", "nsls2ptycho.ui", "nsls2ptycho.core.ptycho", "nsls2ptycho.core.widgets"],
packages=["nsls2ptycho",
"nsls2ptycho.core",
"nsls2ptycho.backend",
"nsls2ptycho.backend.ptycho",
"nsls2ptycho.databroker",
"nsls2ptycho.core.widgets",
"nsls2ptycho.ui"],
entry_points={
'gui_scripts': ['run-ptycho = nsls2ptycho.ptycho_gui:main'],
'console_scripts': ['run-ptycho-backend = nsls2ptycho.core.ptycho.recon_ptycho_gui:main']
'console_scripts': ['run-ptycho-backend = nsls2ptycho.backend.ptycho.recon_ptycho_gui:main']
},
install_requires=REQUIREMENTS,
#extras_require={'GPU': 'cupy'}, # this will build cupy from source, may not be the best practice!
Expand Down