carnisj / bcdi

BCDI: tools for pre(post)-processing Bragg coherent X-ray diffraction imaging data
Other
23 stars 17 forks source link

[BUG] Problem with calculation of spatial resolution when holes in the electronic density #271

Closed mirichard-S closed 2 years ago

mirichard-S commented 2 years ago

Describe the bug During the postprocessing, if the electronic density has holes (due to defects for instance), the calculation of the spatial resolution does not work. The program finds several limits for the particle and it fails.

Error image

IndexError                                 Traceback (most recent call last)
File/gpfs/easy/data/id01/inhouse/corentin/venv/gwaihir_coco/lib/python3.8/site-packages/ipywidgets/widgets/interaction.py:257, ininteractive.update(self, *args)
255      value=  widget.get_interact_value()
256      self.kwargs[widget._kwarg]=  value
--> 257  self.result=  self.f(**self.kwargs)
258  show_inline_matplotlib_plots()
259  if  self.auto_displayand  self.resultis  not  None:

File/gpfs/easy/data/id01/inhouse/corentin/venv/gwaihir_coco/lib/python3.8/site-packages/gwaihir/gui/gui.py:4833, inInterface.initialize_postprocessing(self, unused_label_averaging, sort_method, correlation_threshold, unused_label_FFT, phasing_binning, original_size, preprocessing_binning, output_size, keep_size, fix_voxel, unused_label_disp_strain, data_frame, save_frame, ref_axis_q, isosurface_strain, strain_method, phase_offset, phase_offset_origin, offset_method, centering_method, unused_label_refraction, correct_refraction, optical_path_method, dispersion, absorption, threshold_unwrap_refraction, unused_label_options, simulation, invert_phase, flip_reconstruction, phase_ramp_removal, threshold_gradient, save_raw, save_support, save, debug, roll_modes, unused_label_data_vis, align_axis, ref_axis, axis_to_align, strain_range, phase_range, grey_background, tick_spacing, tick_direction, tick_length, tick_width, unused_label_average, averaging_space, threshold_avg, unused_label_apodize, apodize, apodization_window, half_width_avg_phase, apodization_mu, apodization_sigma, apodization_alpha, unused_label_strain, strain_folder, reconstruction_files, run_strain)
4830  args["time"]=  f"{datetime.now()}"
4832  # Run function
-> 4833  run_postprocessing(prm=args)
4834  gutil.hash_print("End of script")
4836  # Get data from saved file

File/gpfs/easy/data/id01/inhouse/corentin/venv/gwaihir_coco/lib/python3.8/site-packages/bcdi/postprocessing/postprocessing_runner.py:160, inrun(prm)
157      # until all processes in the queue are done.
158  else:
159      for  scan_idxin  range(nb_scans):
--> 160          result=  process_scan(scan_idx=scan_idx,prm=prm)
161          util.move_log(result)

File/gpfs/easy/data/id01/inhouse/corentin/venv/gwaihir_coco/lib/python3.8/site-packages/bcdi/postprocessing/process_scan.py:1048, inprocess_scan(scan_idx, prm)
1043  gc.collect()
1045  ################################
1046  # plot linecuts of the results #
1047  ################################
-> 1048  gu.fit_linecut(
1049  array=amp,
1050  fit_derivative=True,
1051  filename=setup.detector.savedir+"linecut_amp.png",
1052  voxel_sizes=voxel_size,
1053  label="modulus",
1054  )
1056  ##############################
1057  # plot slices of the results #
1058  ##############################
1059  pixel_spacing=  [prm["tick_spacing"]/  voxfor  voxin  voxel_size]

File/gpfs/easy/data/id01/inhouse/corentin/venv/gwaihir_coco/lib/python3.8/site-packages/bcdi/graph/graph_utils.py:1137, infit_linecut(array, indices, fit_derivative, support_threshold, voxel_sizes, filename, label)
1130              result[f"dimension_{idx}"][f"param_{peak_id}"]=  {
1131                  "amp": fit_result.params[f"amp_{peak_id}"].value,
1132                  "sig": fit_result.params[f"sig_{peak_id}"].value,
1133                  "cen": fit_result.params[f"cen_{peak_id}"].value,
1134              }
1136  # plot the cut and optionally the fits
-> 1137  plot_linecut(
1138  linecuts=result,filename=filename,voxel_sizes=voxel_sizes,label=label
1139  )
1140  return  result

File/gpfs/easy/data/id01/inhouse/corentin/venv/gwaihir_coco/lib/python3.8/site-packages/bcdi/graph/graph_utils.py:2027, inplot_linecut(linecuts, filename, voxel_sizes, label)
2025  if  subkey.startswith("derivative"):
2026      index=  int(subkey[-1])
-> 2027      (line1,)=  axes[idx][index].plot(
2028          linecuts[key][subkey][0]*  factor,
2029          linecuts[key][subkey][1],
2030          ".b",
2031          label="derivative",
2032      )
2033      (line2,)=  axes[idx][index].plot(
2034          linecuts[key][f"fit_{index}"][0]*  factor,
2035          linecuts[key][f"fit_{index}"][1],
2036          "-r",
2037          label="gaussian fit",
2038      )
2039      axes[idx][index].set_xlabel(labels.get(key, key))

IndexError: index 2 is out of bounds for axis 0 with size 2
DSimonne commented 2 years ago

@mirichard-S j'ai créé une branche (voir pull request)

le mieux serait que tu modifies le code dans ton bcdi comme j'ai fait, que tu l'installes et ensuite vérifie si ça fonctionne =)

DSimonne commented 2 years ago

Comme ça: https://github.com/carnisj/bcdi/pull/272/files

DSimonne commented 2 years ago

Tu peux tester avec : /data/id01/inhouse/david/p9.dev/bin/python et juste lancer bcdi_strain.py avec le fichier de config que tu avais.