Example #1
0
    def validate_filepath(self):
        """Fix the broken filenames in FluoView experiment files.

        The FluoView software usually stores corrupted filenames in its
        experiment description files, that have a missing suffix, e.g.

            Slide1sec001\\Slide1sec001.oib

        whereas the correct filename would be

            Slide1sec001\\Slide1sec001_01.oib

        This function attempts to fix this by checking if the supplied path is
        actually existing and trying the default suffix if not. Raises an
        IOError exception if no corresponding file can be found.

        Returns
        -------
        storage : pathtools.parse_path
        """
        fpath = self.storage
        ext = fpath['ext']
        log.debug("Validating file path: %s" % fpath)
        if not exists(fpath['full']):
            fpath = parse_path(fpath['orig'].replace(ext, '_01' + ext))
            log.debug("Trying next path: %s" % fpath['full'])
        if not exists(fpath['full']):
            raise IOError("Can't find file: %s" % fpath)
        return fpath
Example #2
0
def gen_stitching_macro_code(experiment, pfx, path='', tplpath='', opts={}):
    """Generate code in ImageJ's macro language to stitch the mosaics.

    Take two template files ("head" and "body") and generate an ImageJ
    macro to stitch the mosaics. Using the splitted templates allows for
    setting default values in the head that can be overridden in this
    generator method (the ImageJ macro language doesn't have a command to
    check if a variable is set or not, it just exits with an error).

    Parameters
    ----------
    experiment : volpy.experiment.MosaicExperiment
        The object containing all information about the mosaic.
    pfx : str
        The prefix for the two template files, will be completed with the
        corresponding suffixes "_head.ijm" and "_body.ijm".
    path : str
        The path to use as input directory *INSIDE* the macro.
    tplpath : str
        The path to a directory or zip file containing the templates.
    opts : dict (optional)
        A dict with key-value pairs to be put into the macro between the head
        and body to override the macro's default settings.
        NOTE: the values are placed literally in the macro code, this means
        that strings have to be quoted, e.g. opts['foo'] = '"bar baz"'

    Returns
    -------
    ijm : list(str) or str
        The generated macro code as a list of str (one str per line) or as
        a single long string if requested via the "flat" parameter.
    """
    # pylint: disable-msg=E1103
    #   the type of 'ijm' is not correctly inferred by pylint and it complains
    # by default templates are expected in a subdir of the current package:
    if (tplpath == ''):
        tplpath = join(dirname(__file__), 'ijm_templates')
        log.debug('Looking for template directory: %s' % tplpath)
        if not exists(tplpath):
            tplpath += '.zip'
            log.debug('Looking for template directory: %s' % tplpath)
    if not exists(tplpath):
        raise IOError("Template directory can't be found!")
    log.info('Template directory: %s' % tplpath)
    ijm = []
    try:
        import imcf
        ijm.append('// Generated by %s (%s).\n\n' % (__name__, imcf.VERSION))
    except ImportError:
        pass
    ijm += readtxt(pfx + '_head.ijm', tplpath)
    ijm.append('\n')

    ijm.append('name = "%s";\n' % experiment.infile['dname'])
    # windows path separator (in)sanity:
    path = path.replace('\\', '\\\\')
    ijm.append('input_dir="%s";\n' % path)
    ijm.append('use_batch_mode = true;\n')
    for option, value in opts.items():
        ijm.append('%s = %s;\n' % (option, value))

    # If the overlap is below a certain level (5 percent), we disable
    # computing the actual positions and subpixel accuracy:
    if (experiment[0].get_overlap('pct') < 5.0):
        ijm.append('compute = false;\n')

    ijm.append('\n')
    ijm += readtxt(pfx + '_body.ijm', tplpath)
    log.debug('--- ijm ---\n%s\n--- ijm ---' % ijm)
    return(ijm)