Skip to content

Commit

Permalink
Merge pull request #185 from jonwright/master
Browse files Browse the repository at this point in the history
openmp threading defaults and fscan2d fixup
  • Loading branch information
jonwright authored Nov 22, 2023
2 parents 17ab635 + 6301cae commit 7cedbd3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 7 additions & 2 deletions ImageD11/cImageD11.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# import cImageD11 compiled module and patch the docstrings

import os
import struct
import warnings
from ImageD11 import cImageD11_docstrings

try:
from ImageD11._cImageD11 import *
import ImageD11._cImageD11
except ImportError:
print("Failed to import compiled C code for cImageD11 module")
print("Are you running from a source directory?")
Expand Down Expand Up @@ -37,7 +39,8 @@ def check_multiprocessing():
if hasattr(multiprocessing,"parent_process"):
parent = multiprocessing.parent_process()
# only for python 3.8 and up
cimaged11_omp_set_num_threads( 1 )
if parent is not None:
cimaged11_omp_set_num_threads( 1 )
# people wanting Nprocs * Mthreads need to reset after import
# OMP_NUM_THREADS is not going to work for them
# how are we going to remember this in the future??
Expand All @@ -52,7 +55,9 @@ def check_multiprocessing():
# Tell them about it.
warnings.warn(__doc__)


def cores_available():
""" Return the number of CPU cores you can use """
return len( os.sched_getaffinity( os.getpid() ) )

if cimaged11_omp_get_max_threads() == 0:
# The code was compiled without openmp
Expand Down
13 changes: 8 additions & 5 deletions ImageD11/sinograms/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,25 +242,28 @@ def guess_shape(self):
if title.split()[0] == 'fscan2d':
s0 = s['instrument/fscan_parameters/slow_npoints'][()]
s1 = s['instrument/fscan_parameters/fast_npoints'][()]
file_nums = np.arange( s0 * s1 ).reshape( (s0,s1) )
# slice notation means last frame+1 to be inclusive
self.scans = [ "%s::[%d:%d]"%( self.scans[0], row[0], row[-1]+1 )
for row in file_nums ]
elif title.split()[0] == 'f2scan':
# good luck ? Assuming rotation was the inner loop here:
step = s['instrument/fscan_parameters/step_size'][()]
s1 = int( np.round( 360 / step ) )
s0 = npts // s1
logging.warning("Dataset might need to be reshaped")
else:
s0 = 1
s1 = npts
# FIXME: we should reshape the omega/dty to match slow/fast points
# also modify self.scans to be '4.1::[start:end]'
if len(self.scans) > 1:
elif len(self.scans) > 1:
s0 = len(self.scans)
s1 = npts // s0
self.shape = s0, s1
if np.prod( self.shape ) != npts:
print("Warning: irregular scan - might be bugs in here")
print(npts, len(self.scans))
self.omega = np.array( self.omega )
self.dty = np.array(self.dty )
self.omega = np.array( self.omega ).reshape( self.shape )
self.dty = np.array( self.dty ).reshape( self.shape )
logging.info( 'sinogram shape = ( %d , %d ) imageshape = ( %d , %d)'%(
self.shape[0], self.shape[1], self.imageshape[0], self.imageshape[1] ) )

Expand Down

0 comments on commit 7cedbd3

Please sign in to comment.