66# Jan 2nd, 2025
77# version 1.0: updated on January 30, 2025
88# version 1.1: fixed a bug with ray origin on December 10, 2025
9+ # version 1.2: some clean-ups and ensure all print-outs go to .out file instead of .log file, April 12, 2026
910
1011import numpy as np
1112from matplotlib import pyplot as plt
3940from ImageD11 .nbGui .nb_utils import slurm_submit_and_wait
4041
4142econst = 12.3984
42- logging .basicConfig (level = logging .INFO , force = True )
43+ logging .basicConfig (
44+ level = logging .INFO ,
45+ stream = sys .stdout ,
46+ force = True
47+ )
4348os .environ ["JOBLIB_TEMP_FOLDER" ] = "/tmp_14_days/slurm/log"
4449
4550"""
@@ -380,14 +385,14 @@ def set_all(self):
380385 self .check_halfy ()
381386
382387 def check_halfy (self ):
383- #quick check to see if halfy is big enough
388+ # quick check to see if halfy is big enough to include all sample voxels to be illuminated
384389 if self .sample_mask is None :
385390 mask_tmp = (self .sample_input .DS ['labels' ] > - 1 ) & (~ np .isnan (self .sample_input .DS ['U' ][:, :, :, 0 , 0 ]))
386391 mask_tmp = np .transpose (mask_tmp , (2 , 1 , 0 ))
387392 else :
388393 mask_tmp = self .sample_mask
389394 center = (mask_tmp .shape [0 ]/ 2 , mask_tmp .shape [1 ]/ 2 )
390- radius = self .args ["halfy" ]/ np .mean (self .sample_input .DS ['voxel_size' ]) #radius covered by halfy, in pixels
395+ radius = self .args ["halfy" ]/ np .mean (self .sample_input .DS ['voxel_size' ]) # radius covered by halfy, [pixel]
391396 x = np .linspace (0 , mask_tmp .shape [0 ], mask_tmp .shape [1 ])
392397 y = np .linspace (0 , mask_tmp .shape [1 ], mask_tmp .shape [1 ])
393398 xv , yv = np .meshgrid (x , y )
@@ -396,8 +401,9 @@ def check_halfy(self):
396401 combine_mask = mask_circle * mask_tmp [:,:,0 ]
397402 if self .verbose >= 1 and np .sum (combine_mask )>= 1 :
398403 logging .warning ('****** WARNING ******' )
399- logging .warning ('half_y = {} is too small, you should increase it.' .format (self .args ["halfy" ]))
400-
404+ logging .info ('halfy = {} um is too small, you should increase to ~{:6f} um.' .format (self .args ["halfy" ],
405+ self .args ["halfy" ] + 2.5 * np .sum (combine_mask )/ (2 * np .pi * radius )* np .mean (self .sample_input .DS ['voxel_size' ])))
406+
401407 def set_beam (self ):
402408 """
403409 set the X-ray beam source, including beam energy, FWHM, flux, shape, source-to-sample distance, name etc.
@@ -406,7 +412,7 @@ def set_beam(self):
406412
407413 def set_sample (self ):
408414 """
409- set the sample properties: including the grain map, voxel size, .
415+ set the sample properties: including the grain map, voxel size, density, mass absorption .
410416 """
411417 self .sample_input = sample (self .sample_filename , min_misori = self .args ['min_misori' ], crystal_system = self .args ['crystal_system' ],
412418 remove_small_grains = self .args ['remove_small_grains' ], min_vol = self .args ['min_vol' ])
@@ -620,19 +626,23 @@ def generate_slurm_script(self, script_name="fwd_projector_slurm.sh"):
620626#SBATCH --mem-per-cpu=8000
621627#SBATCH --time=01:00:00
622628
629+ module load jupyter-slurm/2025.04.5
630+ echo "===== JOB START ====="
623631date
624- source /cvmfs/hpc.esrf.fr/software/packages/linux/x86_64/jupyter-slurm/latest/envs/jupyter-slurm/bin/activate
632+
625633log_path="{log_path}_${{SLURM_JOB_ID}}_${{SLURM_ARRAY_TASK_ID}}.log"
626634dty_file="{dty_file_list}"
627635dty_values=$(sed -n "${{SLURM_ARRAY_TASK_ID}}p" $dty_file)
628- echo "OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 PYTHONPATH={id11_code_path}" >> $log_path 2>&1
629- OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 PYTHONPATH={id11_code_path} \
636+ echo "OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 PYTHONPATH={id11_code_path}"
637+ OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 PYTHONPATH={id11_code_path}
638+ export PYTHONPATH={id11_code_path}
630639python3 -c "from ImageD11.forward_model import forward_projector; \
631640 fp = forward_projector.forward_projector(sample_filename='{sample_filename}', pars_filename='{pars_filename}', \
632641 phase_name='{phase_name}', output_folder='{output_folder}', gids_mask={gids_mask}, \
633642 verbose={verbose}, auto_set={auto_set}, detector_mask={detector_mask}, to_sparse={to_sparse}, \
634643 read_fwd_peaks_from_file={read_fwd_peaks_from_file}, **{args}); \
635- fp.run_series_dty([float(v) for v in '$dty_values'.split()])" >> $log_path 2>&1
644+ fp.run_series_dty([float(v) for v in '$dty_values'.split()])"
645+ echo "===== JOB END ====="
636646date""" .format (
637647 outfile_path = outfile_path ,
638648 errfile_path = errfile_path ,
@@ -780,6 +790,7 @@ def write_cf(self):
780790 def plot_cf (self , cf_type = '2d' , m = None ):
781791 """
782792 plot the sinogram of cf peaks, i.e. dty vs omega colored by peak intensity
793+ m is a boolen mask
783794 """
784795 plt .figure (figsize = (10 ,8 ))
785796 if cf_type == '2d' :
@@ -870,7 +881,7 @@ def forward_peaks_voxels(beam, sample, omega_angles, ucell, pars, dty=0.0,
870881 t0 = time .time ()
871882 results = Parallel (n_jobs = - 1 , backend = "loky" )(delayed (process_omega )(
872883 omega , mask , DS , beam , sample , pars , ucell , rot_step , ds_max , Lsam2det , args , verbose
873- ) for omega in tqdm (omega_angles , desc = "Processing omega angles" ))
884+ ) for omega in tqdm (omega_angles , desc = "Processing omega angles" , file = sys . stdout ))
874885 # # Regarding multiprocessing.Pool, tried chunk, shared memory etc, it does not help to improve the speed
875886 # set_tmp_dir()
876887 # with multiprocessing.Pool(processes=min(multiprocessing.cpu_count(), 24)) as pool:
0 commit comments