def find_padding(sample=default_sample): unpadded = CremiFile(cremi_path(sample=sample), "r") unpadded_raw = unpadded.read_raw() unpadded_shape_px = Coordinate(unpadded_raw.data.shape) padded = CremiFile(cremi_path(sample=sample, padded=True), "r") padded_raw = padded.read_raw() padded_shape_px = Coordinate(padded_raw.data.shape) fafb_res = Coordinate(unpadded_raw.resolution) data_shape_nm = unpadded_shape_px * fafb_res padding_px = math.ceil((padded_shape_px - unpadded_shape_px) / 2) padding_nm = padding_px * fafb_res print("shape (nm): {}".format(data_shape_nm)) print("padding (nm): {}".format(padding_nm)) print("l1 shape (px): {}".format(math.ceil(data_shape_nm / L1_RES))) print("l1 padding (px): {}".format(math.ceil(padding_nm / L1_RES)))
# Check the content of the datafile print "Has raw: " + str(file.has_raw()) print "Has neuron ids: " + str(file.has_neuron_ids()) print "Has clefts: " + str(file.has_clefts()) print "Has annotations: " + str(file.has_annotations()) # Read everything there is. # # If you are using the padded versions of the datasets (where raw is larger to # provide more context), the offsets of neuron_ids, clefts, and annotations tell # you where they are placed in nm relative to (0,0,0) of the raw volume. # # In other words, neuron_ids, clefts, and annotations are exactly the same # between the padded and unpadded versions, except for the offset attribute. raw = file.read_raw() neuron_ids = file.read_neuron_ids() clefts = file.read_clefts() annotations = file.read_annotations() print "Read raw: " + str(raw) + \ ", resolution " + str(raw.resolution) + \ ", offset " + str(raw.offset) + \ ("" if raw.comment == None else ", comment \"" + raw.comment + "\"") print "Read neuron_ids: " + str(neuron_ids) + \ ", resolution " + str(neuron_ids.resolution) + \ ", offset " + str(neuron_ids.offset) + \ ("" if neuron_ids.comment == None else ", comment \"" + neuron_ids.comment + "\"") print "Read clefts: " + str(clefts) + \
def Reading(filename, isTest=False): # # Read the data into dataset # print "Filename: ", filename # # with h5py.File('sample_A_20160501.hdf', 'r') as f: # with h5py.File(filename, 'r') as f: # print f["volumes"] # imageDataSet = f["volumes/raw"][:] # labelDataSet = f["volumes/labels/neuron_ids"][:] # imageDataSet = imageDataSet.astype(np.float32) # labelDataSet = labelDataSet.astype(np.float32) # return imageDataSet, labelDataSet file = CremiFile(filename, "r") print filename # Check the content of the datafile print "Has raw : " + str(file.has_raw()) print "Has neuron ids : " + str(file.has_neuron_ids()) print "Has clefts : " + str(file.has_clefts()) print "Has annotations : " + str(file.has_annotations()) # Read everything there is. # # If you are using the padded versions of the datasets (where raw is larger to # provide more context), the offsets of neuron_ids, clefts, and annotations tell # you where they are placed in nm relative to (0,0,0) of the raw volume. # # In other words, neuron_ids, clefts, and annotations are exactly the same # between the padded and unpadded versions, except for the offset attribute. raw = file.read_raw() if not isTest: neuron_ids = file.read_neuron_ids() clefts = file.read_clefts() annotations = file.read_annotations() print "Read raw: " + str(raw) + \ ", resolution " + str(raw.resolution) + \ ", offset " + str(raw.offset) + \ ("" if raw.comment == None else ", comment \"" + raw.comment + "\"") if not isTest: print "Read neuron_ids: " + str(neuron_ids) + \ ", resolution " + str(neuron_ids.resolution) + \ ", offset " + str(neuron_ids.offset) + \ ("" if neuron_ids.comment == None else ", comment \"" + neuron_ids.comment + "\"") # neuron_ids.offset will contain the starting point of neuron_ids inside the raw volume. # Note that these numbers are given in nm. # print "Read clefts: " + str(clefts) + \ # ", resolution " + str(clefts.resolution) + \ # ", offset " + str(clefts.offset) + \ # ("" if clefts.comment == None else ", comment \"" + clefts.comment + "\"") # print "Read annotations:" # for (id, type, location) in zip(annotations.ids(), annotations.types(), annotations.locations()): # print str(id) + " of type " + type + " at " + str(np.array(location)+np.array(annotations.offset)) # print "Pre- and post-synaptic partners:" # for (pre, post) in annotations.pre_post_partners: # print str(pre) + " -> " + str(post) with h5py.File(filename, 'r') as f: print f["volumes"] imageDataSet = f["volumes/raw"][:] if not isTest: labelDataSet = f["volumes/labels/neuron_ids"][:] imageDataSet = imageDataSet.astype(np.float32) if not isTest: labelDataSet = labelDataSet.astype(np.float32) if not isTest: return imageDataSet, labelDataSet return imageDataSet