FABLE-3DXRD / ImageD11

ImageD11 is a python code for identifying individual grains in spotty area detector X-ray diffraction images.
https://imaged11.readthedocs.io/
GNU General Public License v2.0
15 stars 25 forks source link

Running sinograms.properties.main on single scan causes AssertionError #212

Closed jadball closed 9 months ago

jadball commented 9 months ago

When segmenting and labelling data for a box-beam experiment with a single scan, we get an AssertionError when running sinograms.properties.main:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[29], line 3
      1 # generate peaks table
----> 3 ImageD11.sinograms.properties.main(ds.dsfile, ds.sparsefile, ds.pksfile, options={'algorithm': 'lmlabel', 'wtmax': 70000, 'save_overlaps': False})

File ~/Code/ImageD11/ImageD11/sinograms/properties.py:830, in main(dsname, sparsename, pkname, options)
    828 print('Nscans',nscans,'NPROC', NPROC)
    829 print('Options',options)
--> 830 peaks, ks, P, rmem = goforit(ds, sparsename, options)
    831 t('%d label and pair'%(len(rmem.pk_props[0])))
    832 if 'save_overlaps' in options and options['save_overlaps']:

File ~/Code/ImageD11/ImageD11/sinograms/properties.py:786, in goforit(ds, sparsename, options)
    783 out = []
    784 with mp.Pool(NPROC, initializer=process, 
    785            initargs=(qin, qshm, qresult, sparsename, ds.scans, options)) as pool:
--> 786     slices = get_start_end( len(ds.scans), NPROC )
    787     for i,(s,e) in enumerate(slices):
    788         qin.put((s,e))

File ~/Code/ImageD11/ImageD11/sinograms/properties.py:241, in get_start_end(n, p)
    230 """ For splitting up the scan row over processes
    231 n = number of jobs
    232 p = number of processes
   (...)
    238 overlap  01 12 23 34 45
    239 """
    240 overlaps = [ (i-1,i) for i in range(1,n) ]
--> 241 assert len(overlaps) >= p
    242 joins_per_job = np.zeros(p, int)
    243 for i,o in enumerate(overlaps):

AssertionError: 

The sbatch file was generated with the following call to sinograms.lima_segmenter.setup:

sbat = ImageD11.sinograms.lima_segmenter.setup(ds.dsfile,
                                               maskfile=end_pars["maskfile"],
                                               cut=end_pars["cut"],
                                               bgfile=end_pars["bgfile"],
                                               pixels_in_spot=end_pars["pixels_in_spot"])

Yielding the following (paths sanitized):

cut 13
howmany 100000
pixels_in_spot 3
maskfile (...)/mask.edf
bgfile (...)/background.edf
cores_per_job 8
files_per_core 8
total files to process 36 done 0
# Opened mask (...)/mask.edf  0.89 % pixels are active
jadball commented 9 months ago

In goforit() we have: https://github.com/FABLE-3DXRD/ImageD11/blob/7ebe6264bca003da127e0ea1338da491eb6c1b34/ImageD11/sinograms/properties.py#L786

In get_start_end() we have:

https://github.com/FABLE-3DXRD/ImageD11/blob/7ebe6264bca003da127e0ea1338da491eb6c1b34/ImageD11/sinograms/properties.py#L229-L241

When n = 1 (i.e when len(ds.scans) = 1) this will always generate an empty list for overlaps, hence the AssertionError.

jonwright commented 9 months ago

For one rotation scan I think this was the purpose of pks_table_from_scan( sparsefilename, ds, row )? You don't need a batch job unless you have a lot of scans to process. I think it is failing on the 4D overlaps, which kind of makes sense if you give it a 3D scan. The error message could be fixed up.

If you have fscan2d or f2scan then you should get ds.scans as a long list that is looking at slices inside the scan.

jadball commented 9 months ago

Thanks Jon! This is indeed resolved by using: pks_table = ImageD11.sinograms.properties.pks_table_from_scan(sparse_file, dataset, 0)