def run_impl(self):
        # get the global config and init configs
        shebang, block_shape, roi_begin, roi_end, block_list_path = self.global_config_values(True)
        self.init(shebang)

        # get shape and make block config
        shape = vu.get_shape(self.input_path, self.input_key)
        if len(shape) == 4:
            shape = shape[1:]

        # load the watershed config
        ws_config = self.get_task_config()

        # require output dataset
        # TODO read chunks from config
        chunks = tuple(bs // 2 for bs in block_shape)
        with vu.file_reader(self.output_path) as f:
            f.require_dataset(self.output_key, shape=shape, chunks=chunks,
                              compression='gzip', dtype='uint64')

        # update the config with input and output paths and keys
        # as well as block shape
        ws_config.update({'input_path': self.input_path, 'input_key': self.input_key,
                          'output_path': self.output_path, 'output_key': self.output_key,
                          'block_shape': block_shape})

        blocking = nt.blocking([0, 0, 0], list(shape), list(block_shape))
        block_lists = vu.make_checkerboard_block_lists(blocking, roi_begin, roi_end)
        for pass_id, block_list in enumerate(block_lists):
            ws_config['pass'] = pass_id
            self._ws_pass(block_list, ws_config, 'pass_%i' % pass_id)
Пример #2
0
    def run_impl(self):
        shebang, block_shape, roi_begin, roi_end = self.global_config_values()
        self.init(shebang)

        # get shape and make block config
        shape = vu.get_shape(self.input_path, self.input_key)
        assert len(shape) == 4, "Need 4d input for MWS"
        n_channels = shape[0]
        shape = shape[1:]

        # TODO make optional which channels to choose
        assert len(self.offsets) == n_channels,\
            "%i, %i" % (len(self.offsets), n_channels)
        assert all(len(off) == 3 for off in self.offsets)

        config = self.get_task_config()
        config.update({'input_path': self.input_path, 'input_key': self.input_key,
                       'output_path': self.output_path, 'output_key': self.output_key,
                       'block_shape': block_shape, 'offsets': self.offsets,
                       'halo': self.halo, 'tmp_folder': self.tmp_folder})

        # check if we have a mask and add to the config if we do
        if self.mask_path != '':
            assert self.mask_key != ''
            config.update({'mask_path': self.mask_path, 'mask_key': self.mask_key})

        # get chunks
        chunks = config.pop('chunks', None)
        if chunks is None:
            chunks = tuple(bs // 2 for bs in block_shape)
        # clip chunks
        chunks = tuple(min(ch, sh) for ch, sh in zip(chunks, shape))

        # make output dataset
        compression = config.pop('compression', 'gzip')
        with vu.file_reader(self.output_path) as f:
            f.require_dataset(self.output_key,  shape=shape, dtype='uint64',
                              compression=compression, chunks=chunks)

        blocking = nt.blocking([0, 0, 0], list(shape), list(block_shape))
        block_lists = vu.make_checkerboard_block_lists(blocking, roi_begin, roi_end)

        # we need the max-block-id to write out max-label-id later
        max_block_id = max([max(bl) for bl in block_lists])
        config.update({'max_block_id': max_block_id})

        for pass_id, block_list in enumerate(block_lists):
            config['pass'] = pass_id
            self._mws_pass(block_list, config, 'pass_%i' % pass_id)
Пример #3
0
    def run_impl(self):
        # get the global config and init configs
        shebang, block_shape, roi_begin, roi_end, block_list_path = self.global_config_values(True)
        self.init(shebang)

        # get shape and make block config
        shape = vu.get_shape(self.input_path, self.input_key)
        if len(shape) == 4:
            shape = shape[1:]

        # load the watershed config
        ws_config = self.get_task_config()

        # require output dataset
        # TODO read chunks from config
        chunks = tuple(bs // 2 for bs in block_shape)
        with vu.file_reader(self.output_path) as f:
            f.require_dataset(self.output_key, shape=shape, chunks=chunks,
                              compression='gzip', dtype='uint64')

        # update the config with input and output paths and keys
        # as well as block shape
        ws_config.update({'input_path': self.input_path, 'input_key': self.input_key,
                          'output_path': self.output_path, 'output_key': self.output_key,
                          'block_shape': block_shape})
        if self.mask_path != '':
            assert self.mask_key != ''
            ws_config.update({'mask_path': self.mask_path, 'mask_key': self.mask_key})

        # check if we run a 2-pass watershed
        is_2pass = ws_config.pop('two_pass', False)

        # run 2 passes of watersheds with checkerboard pattern
        # for the blocks
        if is_2pass:

            assert block_list_path is None, "Can't rerun watersheds if 2-pass is activated"

            # retries for two pass watershed are too complicated now
            # this could be fixed if we seperate the passes in two different
            # task instances
            self.allow_retry = False

            assert 'halo' in ws_config, "Need halo for two-pass wlatershed"
            self._write_log("run two pass watershed")
            blocking = nt.blocking([0, 0, 0], list(shape), list(block_shape))
            blocks_1, blocks_2 = vu.make_checkerboard_block_lists(blocking, roi_begin, roi_end)
            n_jobs = min(len(blocks_1), self.max_jobs)
            ws_config['pass'] = 1
            self._watershed_pass(n_jobs, blocks_1, ws_config, 'pass1')
            ws_config['pass'] = 2
            self._watershed_pass(n_jobs, blocks_2, ws_config, 'pass2')
        # run single pass watershed with all blocks in block_list
        else:
            self._write_log("run one pass watershed")
            if self.n_retries == 0:
                block_list = vu.blocks_in_volume(shape, block_shape, roi_begin, roi_end,
                                                 block_list_path=block_list_path)
            else:
                block_list = self.block_list
                self.clean_up_for_retry(block_list)
            self._write_log('scheduling %i blocks to be processed' % len(block_list))
            n_jobs = min(len(block_list), self.max_jobs)
            self._watershed_pass(n_jobs, block_list, ws_config)