Esempio n. 1
0
def validate(target_folder):
  f = File(target_folder)
  if len(File(target_folder).list(Filter())) > 0:
    yn = YesNoCancelDialog(IJ.getInstance(), "Warning!", "Target folder is not empty! May overwrite files! Continue?")
    if yn.yesPressed():
      return True
    else:
      return False
  return True
Esempio n. 2
0
def save_etc(imp, info, output_folder):
	"""handle saving output, final labelling and UI of what to do next"""
	dialog = GenericDialog("Marksl1 cell shape prescreen");
	dialog.addChoice("Vessel type: ", 
						info.get_vessel_types(), 
						info.get_vessel_type());
	dialog.addStringField("Channel 1 label: ", info.get_ch1_label());
	dialog.addStringField("Channel 2 label: ", info.get_ch2_label());
	dialog.addStringField("Experiment identifier: ", info.get_experiment_id());
	dialog.addStringField("Embryo identifier: ", info.get_embryo_id());
	dialog.setOKLabel("Save preprocessing");
	dialog.showDialog();
	info.set_vessel_type(dialog.getNextChoice());
	info.set_ch1_label(dialog.getNextString());
	info.set_ch2_label(dialog.getNextString());
	info.set_experiment_id(dialog.getNextString());
	info.set_embryo_id(dialog.getNextString());
	if dialog.wasCanceled():
		return "stop";
	if dialog.wasOKed():
		exsting_files = os.listdir(output_folder);
		r = re.compile(".*" + info.get_embryo_id() + " " + info.get_vessel_type() + ".*")
		fns = filter(r.match, exsting_files)
		numbers = list((int(s) for fn in fns for s in re.findall(r'\b\d+$', os.path.splitext(fn)[0])));
		append_digit = (max(numbers) + 1) if numbers else 1;
		ch1str = (info.get_ch1_label() + " ") if info.get_ch1_label() else "";
		ch2str = (info.get_ch2_label() + " ") if info.get_ch2_label() else "";
		expstr = (info.get_experiment_id() + " ") if info.get_experiment_id() else "";
		file_name = ("Cropped " + ch1str + ch2str + expstr + 
					"e" + str(info.get_embryo_id()) + " " + 
					info.get_vessel_type() + " " + 
					str(append_digit));
		FileSaver(imp).saveAsTiff(os.path.join(output_folder, (file_name + ".tif")));
		info.save_info_to_json(os.path.join(output_folder, (file_name + ".json")));
		continueDialog = YesNoCancelDialog(WM.getCurrentWindow(), 
											"Continue?", 
											"Continue with same input image or a new input image?", 
											"New image...", 
											"Same image");
		if continueDialog.cancelPressed():
			return "stop";
		if continueDialog.yesPressed():
			return "continue_newimage";
		return "continue_sameimage";
	return "stop";
#IL.wrap(img4D, "0-399").show()

showStack(img4D, title="%i-%i" % (first_timepoint, last_timepoint))


# Materialize (write to disk) the registered deconvolved stacks
targetDirN5 = os.path.join(targetDir, "deconvolved/n5/")
nameN5 = "%s_%i-%i_%ix%ix%ix%i" % (targetDir.split("/")[-2],
                                   first_timepoint, last_timepoint,
                                   img4D.dimension(0),
                                   img4D.dimension(1),
                                   img4D.dimension(2),
                                   img4D.dimension(3))

writeN5Volume = True
if not os.path.exists(targetDirN5):
  os.mkdir(targetDirN5)
else:
  writeN5Volume = False
  yn = YesNoCancelDialog(IJ.getInstance(), "Write N5",
                         "The N5 folder already exists: continue?")
  writeN5Volume = yn.yesPressed()

if writeN5Volume:
  print "N5 volume folder: ", targetDirN5
  print "N5 volume name: ", nameN5
  writeN5(img4D,
          targetDirN5,
          nameN5,
          [img4D.dimension(0), img4D.dimension(1), 5, 1])
Esempio n. 4
0
def check_fusion_settings(czi_path):
    """Check for fusion settings and asks confirmation to user if H5/XML fusion

    Parameters
    ----------
    czi_path : str
        Path to the CZI file

    Returns
    -------
    bool
        Bool for fusion
    str
        Method of RAM handling
    bool
        Bool for TIFF or H5/XML fusion
    """

    # Default values
    do_fusion = True
    fuse_tiff = True

    reader = ZeissCZIReader()
    m = DynamicMetadataOptions()
    m.setBoolean(ZeissCZIReader.ALLOW_AUTOSTITCHING_KEY, False)
    m.setBoolean(ZeissCZIReader.RELATIVE_POSITIONS_KEY, True)
    reader.setMetadataOptions(m)
    omeMeta = MetadataTools.createOMEXMLMetadata()
    reader.setMetadataStore(omeMeta)
    reader.setId(str(czi_path))

    nbr_tp = omeMeta.getTimestampAnnotationCount() + 1
    nbr_chnl = omeMeta.getChannelCount(0)

    # check the file size of the file to be fused and compare to the available RAM
    # h5_filesize = os.path.getsize(export_path_temp + ".h5")
    h5_filesize = os.path.getsize(czi_path) / 2
    free_memory = get_free_memory()

    print("h5 filesize " + convert_bytes(h5_filesize))
    print("free memory in ij " + convert_bytes(free_memory))

    # TODO: include in below calculation t_end, since only one t is fused at a time.
    if free_memory > (6 * h5_filesize / downsampling):
        ram_handling = "[Precompute Image]"
    else:
        ram_handling = "Virtual"
    print("fusion mode used " + str(ram_handling))

    # if autoselect_illuminations and nbr_ill > 1:
    #     ill_value = 2
    # else:
    #     ill_value = 1

    ram_requirement = 2 * h5_filesize / (nbr_tp * nbr_chnl * downsampling)
    print(ram_requirement)
    sufficient_ram = ram_requirement < free_memory / 10

    if not sufficient_ram:
        try:
            yn = YesNoCancelDialog(
                IJ.getInstance(),
                "Warning!",
                (
                    "File size is too big to use TIFF for fusion\n"
                    "Fusion will happen using H5/XML which might take weeks. Are you "
                    "sure you want to do fusion ?\n"
                    "All steps prior to fusion would still happen, allowing for manual "
                    "fusion and tile selection."
                ),
            )
            if yn.yesPressed():
                fuse_tiff = False
            else:
                do_fusion = False
        except Exception:
            # when running headless the above will raise a java.awt.HeadlessException,
            # so we simply fall back to the same behavior as if "No" was clicked:
            do_fusion = False
    return do_fusion, ram_handling, fuse_tiff