Skip to content

Commit

Permalink
updated installation to include scikit-image, made minor changes to u…
Browse files Browse the repository at this point in the history
…nwrap functionality
  • Loading branch information
bfrosik committed May 24, 2023
1 parent c4d6d8a commit 3350031
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
4 changes: 4 additions & 0 deletions cohere-defaults/config_disp
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ crop = [.5, .5, .5]
// fractions of the image array dimensions assigned to cropped array dimensions
// default [1.0, 1.0, 1.0] meaning the whole array

unwrap = False
// if True the vts file will contain unwrapped phase in addition to
// phase and amplitude

make_twin = False
// switch to whether visualize twin image
23 changes: 17 additions & 6 deletions cohere-scripts/beamline_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, crop, geometry):
self.recipspace_uptodate = 0


def visualize(self, image, support, coh, save_dir, is_twin=False):
def visualize(self, image, support, coh, save_dir, unwrap=False, is_twin=False):
"""
Manages visualization process. Saves the results in a given directory in files: image.vts, support.vts, and coherence.vts. If is_twin then the saved files have twin prefix.
Parameters
Expand All @@ -83,6 +83,12 @@ def visualize(self, image, support, coh, save_dir, is_twin=False):
"""
save_dir = save_dir.replace(os.sep, '/')
arrays = {"imAmp": abs(image), "imPh": np.angle(image)}

# unwrap phase here
if unwrap:
from skimage import restoration
arrays['imUwPh'] = restoration.unwrap_phase(arrays['imPh'])

self.add_ds_arrays(arrays)
if is_twin:
self.write_directspace(save_dir + '/twin_image')
Expand Down Expand Up @@ -252,7 +258,7 @@ def write_recipspace(self, filename, **args):
print('saved file', filename)


def process_dir(instrument, config_map, rampups, crop, make_twin, res_dir_scan):
def process_dir(instrument, config_map, rampups, crop, unwrap, make_twin, res_dir_scan):
"""
Loads arrays from files in results directory. If reciprocal array exists, it will save reciprocal info in tif format. It calls the save_CX function with the relevant parameters.
Parameters
Expand Down Expand Up @@ -309,7 +315,7 @@ def process_dir(instrument, config_map, rampups, crop, make_twin, res_dir_scan):

crop = crop + [1.0] * (len(image.shape) - len(crop))
viz = CXDViz(crop, geometry)
viz.visualize(image, support, coh, save_dir)
viz.visualize(image, support, coh, save_dir, unwrap)

if make_twin:
image = np.conjugate(np.flip(image))
Expand All @@ -318,7 +324,7 @@ def process_dir(instrument, config_map, rampups, crop, make_twin, res_dir_scan):
image, support = ut.center(image, support)
if rampups > 1:
image = ut.remove_ramp(image, ups=rampups)
viz.visualize(image, support, coh, save_dir, True)
viz.visualize(image, support, coh, save_dir, unwrap, True)


def handle_visualization(experiment_dir, rec_id=None):
Expand Down Expand Up @@ -412,6 +418,11 @@ def handle_visualization(experiment_dir, rec_id=None):
else:
crop = []

if 'unwrap' in disp_config_map:
unwrap = disp_config_map['unwrap']
else:
unwrap = False

if 'results_dir' in disp_config_map:
results_dir = disp_config_map['results_dir'].replace(os.sep, '/')
elif separate:
Expand Down Expand Up @@ -447,9 +458,9 @@ def handle_visualization(experiment_dir, rec_id=None):
dirs = [[dir, last_scan] for dir in dirs]

if len(dirs) == 1:
process_dir(instrument, config_map, rampups, crop, make_twin, dirs[0])
process_dir(instrument, config_map, rampups, crop, unwrap, make_twin, dirs[0])
else:
func = partial(process_dir, instrument, config_map, rampups, crop, make_twin)
func = partial(process_dir, instrument, config_map, rampups, crop, unwrap, make_twin)
no_proc = min(cpu_count(), len(dirs))
with Pool(processes = no_proc) as pool:
pool.map_async(func, dirs)
Expand Down
16 changes: 15 additions & 1 deletion cohere-scripts/beamlines/aps_34idc/beam_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ def init(self, tabs, main_window):
self.make_twin = QCheckBox('make twin')
self.make_twin.setChecked(False)
layout.addWidget(self.make_twin)
self.unwrap = QCheckBox('include unwrapped phase')
self.unwrap.setChecked(False)
layout.addWidget(self.unwrap)
self.crop = QLineEdit()
layout.addRow("crop", self.crop)
self.rampups = QLineEdit()
Expand Down Expand Up @@ -414,7 +417,6 @@ def load_tab(self, conf_map):
# Do not update results dir, as it may point to a wrong experiment if
# it's loaded from another

# if parameters are configured, override the readings from spec file
if 'make_twin' in conf_map:
make_twin = conf_map['make_twin']
if make_twin:
Expand All @@ -424,6 +426,15 @@ def load_tab(self, conf_map):
else:
self.make_twin.setChecked(False)

if 'unwrap' in conf_map:
unwrap = conf_map['unwrap']
if unwrap:
self.unwrap.setChecked(True)
else:
self.unwrap.setChecked(False)
else:
self.unwrap.setChecked(False)

if 'crop' in conf_map:
self.crop.setText(str(conf_map['crop']).replace(" ", ""))
if 'rampups' in conf_map:
Expand All @@ -433,6 +444,7 @@ def load_tab(self, conf_map):
def clear_conf(self):
self.result_dir_button.setText('')
self.make_twin.setChecked(False)
self.unwrap.setChecked(False)
self.crop.setText('')
self.rampups.setText('')

Expand Down Expand Up @@ -472,6 +484,8 @@ def get_disp_config(self):
conf_map['results_dir'] = str(self.result_dir_button.text()).replace(os.sep, '/')
if self.make_twin.isChecked():
conf_map['make_twin'] = True
if self.unwrap.isChecked():
conf_map['unwrap'] = True
if len(self.crop.text()) > 0:
conf_map['crop'] = ast.literal_eval(str(self.crop.text()).replace('\n', ''))
if len(self.rampups.text()) > 0:
Expand Down
1 change: 1 addition & 0 deletions install_pkgs.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pip install xrayutilities
pip install psutil
pip install gputil
conda install pyqt
python -m pip install -U scikit-image
1 change: 1 addition & 0 deletions install_pkgs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ conda install xrayutilities -c conda-forge
conda install psutil -c conda-forge
conda install gputil -c conda-forge
conda install pyqt -c conda-forge
python -m pip install -U scikit-image

0 comments on commit 3350031

Please sign in to comment.