From 7fd837e7ece718416b99b466283119ebb19def59 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 22 Nov 2023 14:50:35 +0100 Subject: [PATCH 1/3] auto reshape for fscan2d --- ImageD11/sinograms/dataset.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ImageD11/sinograms/dataset.py b/ImageD11/sinograms/dataset.py index ee789967..73565b0f 100644 --- a/ImageD11/sinograms/dataset.py +++ b/ImageD11/sinograms/dataset.py @@ -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]"%( s, 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] ) ) From 7433105025c481a114acc5e3c20927786f5a0807 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 22 Nov 2023 15:26:10 +0100 Subject: [PATCH 2/3] setting threads only for multiprocessing --- ImageD11/cImageD11.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ImageD11/cImageD11.py b/ImageD11/cImageD11.py index cd3709e1..8a7241cb 100644 --- a/ImageD11/cImageD11.py +++ b/ImageD11/cImageD11.py @@ -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?") @@ -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?? @@ -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 From 6301cae421bcde219f2b9a5be30e515f8941dca9 Mon Sep 17 00:00:00 2001 From: Jonathan Wright Date: Wed, 22 Nov 2023 15:34:40 +0100 Subject: [PATCH 3/3] fixup fscan2d --- ImageD11/sinograms/dataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ImageD11/sinograms/dataset.py b/ImageD11/sinograms/dataset.py index 73565b0f..40f977e0 100644 --- a/ImageD11/sinograms/dataset.py +++ b/ImageD11/sinograms/dataset.py @@ -244,7 +244,7 @@ def guess_shape(self): 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]"%( s, row[0], row[-1]+1 ) + 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: