def setCurvatureKymographLUT(self, lut_string):
     from ij import IJ
     if lut_string in IJ.getLuts():
         self.curvature_kymograph_lut_string = lut_string
     else:
         raise ValueError(
             'Requested curvature kymograph LUT is not a valid IJ LUT')
 def setActinKymographLUT(self, lut_string):
     from ij import IJ
     if lut_string in IJ.getLuts():
         self.actin_kymograph_lut_string = lut_string
     else:
         raise ValueError(
             'Requested actin kymograph LUT is not a valid IJ LUT')
 def setCurvatureOverlayLUT(self, lut_string):
     from ij import IJ
     if lut_string in IJ.getLuts():
         self.curvature_overlay_lut_string = lut_string
     else:
         raise ValueError(
             'Requested curvature overlay LUT is not a valid IJ LUT')
def analysis_parameters_gui(rerun_analysis=False, params=None):
	"""GUI for setting analysis parameters at the start of a run. TODO: more effectively separate model and view"""
	if params is None:
		params = Parameters(load_last_params = True);
	dialog = GenericDialog("Analysis parameters");
	controls = [];
	if rerun_analysis:
		params.setUseSingleChannel(False);
		params.togglePerformUserQC(False);
		params.setDoInnerOuterComparison(False);

	controls.append(MyControlDefinition(u'Curvature length parameter (\u00b5m): ', 
									 MyControlDefinition.Numeric, 
									 round(params.curvature_length_um, 2), 
									 params.setCurvatureLengthUm));
	controls.append(MyControlDefinition(u'Width of region for intensity analysis (\u00b5m): ', 
									MyControlDefinition.Numeric, 
									round(params.intensity_profile_width_um, 2), 
									params.setIntensityProfileWidthUm))
	controls.append(MyControlDefinition("Threshold method: ",
									 MyControlDefinition.Choice, 
									 params.threshold_method, 
									 params.setThresholdMethod, 
									 choices=params.listThresholdMethods(), 
									 enabled=(not rerun_analysis)));
	controls.append(MyControlDefinition("Curvature overlay LUT: ", 
									 MyControlDefinition.Choice, 
									 params.curvature_overlay_lut_string, 
									 params.setCurvatureOverlayLUT, 
									 choices=IJ.getLuts()));
	controls.append(MyControlDefinition("Curvature kymograph LUT: ",
									 MyControlDefinition.Choice, 
									 params.curvature_kymograph_lut_string, 
									 params.setCurvatureKymographLUT, 
									 choices=IJ.getLuts()));
	controls.append(MyControlDefinition("Labelled species kymograph LUT: ", 
									 MyControlDefinition.Choice, 
									 params.actin_kymograph_lut_string, 
									 params.setActinKymographLUT, 
									 choices=IJ.getLuts()));
	controls.append(MyControlDefinition("Labelled species for intensity analysis: ", 
									 MyControlDefinition.String, 
									 params.labeled_species, 
									 params.setLabeledSpecies));
	controls.append(MyControlDefinition("Use intensity channel for segmentation too?", 
									 MyControlDefinition.Checkbox, 
									 params.use_single_channel, 
									 params.setUseSingleChannel, 
									 enabled=(not rerun_analysis)));
	controls.append(MyControlDefinition("Metadata source: ", 
									 MyControlDefinition.RadioButtonGroup, 
									 params.metadata_source, 
									 params.setMetadataSource, 
									 choices=["Image metadata", "Acquisition metadata"]));
	controls.append(MyControlDefinition("Constrain anchors close to manual selections?", 
									 MyControlDefinition.Checkbox, 
									 params.constrain_anchors, 
									 params.toggleConstrainAnchors, 
									 enabled=(not rerun_analysis)));
	controls.append(MyControlDefinition("Filter out negative curvatures", 
									 MyControlDefinition.Checkbox, 
									 params.filter_negative_curvatures, 
									 params.setFilterNegativeCurvatures));
	controls.append(MyControlDefinition("Account for photobleaching?", 
									 MyControlDefinition.Checkbox, 
									 params.photobleaching_correction, 
									 params.togglePhotobleachingCorrection));
	controls.append(MyControlDefinition("Perform quality control of membrane edges?", 
									 MyControlDefinition.Checkbox, 
									 params.perform_user_qc, 
									 params.togglePerformUserQC, 
									 enabled=(not rerun_analysis)));
	controls.append(MyControlDefinition("Perform quality control of background regions?", 
									 MyControlDefinition.Checkbox, 
									 params.qc_background_rois, 
									 params.toggleBackgroundQc));
	controls.append(MyControlDefinition("Perform spatial cropping?", 
									 MyControlDefinition.Checkbox, 
									 params.perform_spatial_crop, 
									 params.toggleSpatialCrop, 
									 enabled=(not rerun_analysis)));
	controls.append(MyControlDefinition("Perform time cropping?",
									 MyControlDefinition.Checkbox, 
									 params.perform_time_crop, 
									 params.toggleTimeCrop, 
									 enabled=(not rerun_analysis)));
	controls.append(MyControlDefinition("Close images on completion?", 
									 MyControlDefinition.Checkbox, 
									 params.close_on_completion, 
									 params.toggleCloseOnCompletion));
	controls.append(MyControlDefinition("Compare inner and outer curvature regions?", 
									 MyControlDefinition.Checkbox, 
									 params.inner_outer_comparison, 
									 params.setDoInnerOuterComparison, 
									 enabled=(not rerun_analysis)));
	for control in controls:
		control.addControl(dialog);
	dialog.showDialog();
	if dialog.wasCanceled():
		raise KeyboardInterrupt("Run canceled");

	numeric_controls = [c for c in controls if c.control_type==MyControlDefinition.Numeric];
	for nc, nf in zip(numeric_controls, dialog.getNumericFields()):
		nc.setter(float(nf.getText()));
	string_controls = [c for c in controls if c.control_type==MyControlDefinition.String];
	for sc, sf in zip(string_controls, dialog.getStringFields()):
		sc.setter(sf.getText());
	choice_controls = [c for c in controls if c.control_type==MyControlDefinition.Choice];
	for cc, cf in zip(choice_controls, dialog.getChoices()):
		cc.setter(cf.getSelectedItem());
	checkbox_controls = [c for c in controls if c.control_type==MyControlDefinition.Checkbox];
	for cbc, cbf in zip(checkbox_controls, dialog.getCheckboxes()):
		cbc.setter(cbf.getState());
	radiobuttongroup_controls = [c for c in controls if c.control_type==MyControlDefinition.RadioButtonGroup];
	for rbc in radiobuttongroup_controls:
		rbc.setter(rbc.checkboxes[[cb.getState() for cb in rbc.checkboxes].index(True)].getLabel());

	params.persistParameters();
	return params;