def process_body(body_id): output_path = f'{output_dir}/{body_id}.{options["format"]}' if skip_existing and os.path.exists(output_path): return (body_id, 0, 0.0, 0, 'skipped', 0) with resource_mgr_client.access_context(input_config["server"], True, 1, 0): try: mutid = fetch_mutation_id(server, uuid, seg_instance, body_id) except HTTPError: # FIXME: Better to log the exception strings to a file return (body_id, 0, 0.0, 0, 'error-mutid', 0) try: tar_bytes = fetch_tarfile(server, uuid, tsv_instance, body_id) except HTTPError: # FIXME: Better to log the exception strings to a file return (body_id, 0, 0.0, 0, 'error-fetch', mutid) try: vertex_count, fraction, orig_vertices = \ decimate_existing_mesh( server, uuid, tsv_instance, body_id, options["decimation"], options["max-vertices"], options["rescale"], options["format"], output_path, tar_bytes=tar_bytes ) except: return (body_id, 0, 0.0, 0, 'error-generate', mutid) return (body_id, vertex_count, fraction, orig_vertices, 'success', mutid)
def test_fetch_mutation_id(labelmap_setup): dvid_server, dvid_repo, _merge_table_path, _mapping_path, _supervoxel_vol = labelmap_setup instance_info = DvidInstanceInfo(dvid_server, dvid_repo, 'segmentation') mut_id = fetch_mutation_id(*instance_info, 1) assert isinstance(mut_id, int)
def _test_extract_edges(labelmap_setup, force_dirty_mapping): """ Implementation for testing extract_edges(), starting either with a "clean" mapping (in which the body column is already correct beforehand), or a "dirty" mapping (in which the body column is not correct beforehand). """ dvid_server, dvid_repo, merge_table_path, mapping_path, _supervoxel_vol = labelmap_setup instance_info = DvidInstanceInfo(dvid_server, dvid_repo, 'segmentation') orig_merge_table = load_merge_table(merge_table_path, mapping_path, normalize=True) merge_graph = LabelmapMergeGraph(merge_table_path) merge_graph.apply_mapping(mapping_path) if force_dirty_mapping: # A little white-box manipulation here to ensure that the mapping is dirty merge_graph.merge_table_df['body'] = np.uint64(0) merge_graph.mapping[:] = np.uint64(0) # First test: If nothing has changed in DVID, we get all rows. # We should be able to repeat this with the same results # (Make sure the cache is repopulated correctly.) _mutid, dvid_supervoxels, edges, _scores = merge_graph.extract_edges( *instance_info, 1) assert (dvid_supervoxels == [1, 2, 3, 4, 5]).all() assert (orig_merge_table[['id_a', 'id_b']].values == edges).all().all(), \ f"Original merge table doesn't match fetched:\n{orig_merge_table}\n\n{edges}\n" # Now change the mapping in DVID and verify it is reflected in the extracted rows. # For this test, we'll cleave supervoxels [4,5] from the rest of the body. uuid = post_branch(dvid_server, dvid_repo, f'extract-rows-test-{force_dirty_mapping}', '') cleaved_body = post_cleave(dvid_server, uuid, 'segmentation', 1, [4, 5]) cleaved_mutid = fetch_mutation_id(dvid_server, uuid, 'segmentation', 1) if force_dirty_mapping: # A little white-box manipulation here to ensure that the mapping is dirty merge_graph.mapping.loc[2] = 0 merge_graph.merge_table_df['body'].values[0:2] = np.uint64(0) mutid, dvid_supervoxels, edges, _scores = merge_graph.extract_edges( dvid_server, uuid, 'segmentation', 1) assert (dvid_supervoxels == [1, 2, 3]).all() _cleaved_svs = set([4, 5]) assert (edges == orig_merge_table[[ 'id_a', 'id_b' ]].query('id_a not in @_cleaved_svs and id_b not in @_cleaved_svs') ).all().all() assert mutid == cleaved_mutid, "Expected cached mutation ID to match DVID" cleaved_mutid = fetch_mutation_id(dvid_server, uuid, 'segmentation', cleaved_body) # Check the other body mutid, dvid_supervoxels, edges, _scores = merge_graph.extract_edges( dvid_server, uuid, 'segmentation', cleaved_body) assert (edges == orig_merge_table[[ 'id_a', 'id_b' ]].query('id_a in @_cleaved_svs and id_b in @_cleaved_svs')).all().all() assert mutid == cleaved_mutid, "Expected cached mutation ID to match DVID"