本文整理汇总了Python中vigra.defaultAxistags函数的典型用法代码示例。如果您正苦于以下问题:Python defaultAxistags函数的具体用法?Python defaultAxistags怎么用?Python defaultAxistags使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defaultAxistags函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setupOutputs
def setupOutputs(self):
self.fileNameList = []
globStrings = self.globstring.value
# Parse list into separate globstrings and combine them
for globString in sorted(globStrings.split("//")):
self.fileNameList += sorted(glob.glob(globString))
num_files = len(self.fileNameList)
if len(self.fileNameList) == 0:
self.stack.meta.NOTREADY = True
return
try:
self.info = vigra.impex.ImageInfo(self.fileNameList[0])
self.slices_per_file = vigra.impex.numberImages(self.fileNameList[0])
except RuntimeError:
raise OpStackLoader.FileOpenError(self.fileNameList[0])
slice_shape = self.info.getShape()
X, Y, C = slice_shape
if self.slices_per_file == 1:
# If this is a stack of 2D images, we assume xy slices stacked along z
Z = num_files
shape = (Z, Y, X, C)
axistags = vigra.defaultAxistags('zyxc')
else:
# If it's a stack of 3D volumes, we assume xyz blocks stacked along t
T = num_files
Z = self.slices_per_file
shape = (T, Z, Y, X, C)
axistags = vigra.defaultAxistags('tzyxc')
self.stack.meta.shape = shape
self.stack.meta.axistags = axistags
self.stack.meta.dtype = self.info.getDtype()
示例2: setUp
def setUp(self):
self.data2d = numpy.zeros((3, 3, 3))
self.data2d[:, :, 0] = 1
self.data2d[:, :, 1] = 2
self.data2d[:, :, 2] = 3
self.data2d = self.data2d.view(vigra.VigraArray)
self.data2d.axistags = vigra.defaultAxistags("xyc")
self.data3d = numpy.zeros((3, 3, 3, 3))
self.data3d[:, :, :, 0] = 1
self.data3d[:, :, :, 1] = 2
self.data3d[:, :, :, 2] = 3
self.data3d = self.data3d.view(vigra.VigraArray)
self.data3d.axistags = vigra.defaultAxistags("xyzc")
self.data_bad_channel = numpy.zeros((3, 3, 3, 3))
self.data_bad_channel[:, :, 0, :] = 1
self.data_bad_channel[:, :, 1, :] = 2
self.data_bad_channel[:, :, 2, :] = 3
self.data_bad_channel = self.data_bad_channel.view(vigra.VigraArray)
self.data_bad_channel.axistags = vigra.defaultAxistags("xycz")
示例3: _get_template_dataset_infos
def _get_template_dataset_infos(self, input_axes=None):
"""
Sometimes the default settings for an input file are not suitable (e.g. the axistags need to be changed).
We assume the LAST non-batch input in the workflow has settings that will work for all batch processing inputs.
Here, we get the DatasetInfo objects from that lane and store them as 'templates' to modify for all batch-processing files.
"""
template_infos = {}
# If there isn't an available dataset to use as a template
if len(self.dataSelectionApplet.topLevelOperator.DatasetGroup) == 0:
num_roles = len(self.dataSelectionApplet.topLevelOperator.DatasetRoles.value)
for role_index in range(num_roles):
template_infos[role_index] = DatasetInfo()
template_infos[role_index].axistags = vigra.defaultAxistags(input_axes)
return template_infos
# Use the LAST non-batch input file as our 'template' for DatasetInfo settings (e.g. axistags)
template_lane = len(self.dataSelectionApplet.topLevelOperator.DatasetGroup) - 1
opDataSelectionTemplateView = self.dataSelectionApplet.topLevelOperator.getLane(template_lane)
for role_index, info_slot in enumerate(opDataSelectionTemplateView.DatasetGroup):
if info_slot.ready():
template_infos[role_index] = info_slot.value
else:
template_infos[role_index] = DatasetInfo()
if input_axes:
# Support the --input_axes arg to override input axis order, same as DataSelection applet.
template_infos[role_index].axistags = vigra.defaultAxistags(input_axes)
return template_infos
示例4: setupOutputs
def setupOutputs(self):
self.fileNameList = self.expandGlobStrings(self.globstring.value)
num_files = len(self.fileNameList)
if len(self.fileNameList) == 0:
self.stack.meta.NOTREADY = True
return
try:
self.info = vigra.impex.ImageInfo(self.fileNameList[0])
self.slices_per_file = vigra.impex.numberImages(self.fileNameList[0])
except RuntimeError as e:
logger.error(str(e))
raise OpStackLoader.FileOpenError(self.fileNameList[0])
slice_shape = self.info.getShape()
X, Y, C = slice_shape
if self.slices_per_file == 1:
# If this is a stack of 2D images, we assume xy slices stacked along z
Z = num_files
shape = (Z, Y, X, C)
axistags = vigra.defaultAxistags('zyxc')
else:
# If it's a stack of 3D volumes, we assume xyz blocks stacked along t
T = num_files
Z = self.slices_per_file
shape = (T, Z, Y, X, C)
axistags = vigra.defaultAxistags('tzyxc')
self.stack.meta.shape = shape
self.stack.meta.axistags = axistags
self.stack.meta.dtype = self.info.getDtype()
示例5: testChangeBlockshape_masked
def testChangeBlockshape_masked(self):
logger.info("Generating sample data...")
sampleData = numpy.indices((100, 200, 150), dtype=numpy.float32).sum(0)
sampleData = sampleData.view(numpy.ma.masked_array)
sampleData.set_fill_value(numpy.float32(numpy.nan))
sampleData[0] = numpy.ma.masked
graph = Graph()
opData = OpArrayPiper(graph=graph)
opData.Input.meta.has_mask = True
opData.Input.meta.axistags = vigra.defaultAxistags("xyz")
opData.Input.setValue(sampleData)
op = OpCompressedCache(parent=None, graph=graph)
# logger.debug("Setting block shape...")
op.BlockShape.setValue([100, 75, 50])
op.Input.connect(opData.Output)
assert op.Output.ready()
slicing = numpy.s_[0:100, 50:150, 75:150]
expectedData = sampleData[slicing]
# logger.debug("Requesting data...")
readData = op.Output[slicing].wait()
# logger.debug("Checking data...")
assert (
(readData == expectedData).all()
and (readData.mask == expectedData.mask).all()
and (
(readData.fill_value == expectedData.fill_value)
| (numpy.isnan(readData.fill_value) & numpy.isnan(expectedData.fill_value))
).all()
), "Incorrect output!"
# Now change the blockshape and the input and try again...
sampleDataWithChannel = sampleData[..., None]
opData.Input.meta.axistags = vigra.defaultAxistags("xyzc")
opData.Input.setValue(sampleDataWithChannel)
op.BlockShape.setValue([45, 33, 40, 1])
assert op.Output.ready()
slicing = numpy.s_[60:70, 50:110, 60:120, 0:1]
expectedData = sampleDataWithChannel[slicing]
# logger.debug("Requesting data...")
readData = op.Output[slicing].wait()
# logger.debug("Checking data...")
assert (
(readData == expectedData).all()
and (readData.mask == expectedData.mask).all()
and (
(readData.fill_value == expectedData.fill_value)
| (numpy.isnan(readData.fill_value) & numpy.isnan(expectedData.fill_value))
).all()
), "Incorrect output!"
示例6: setupOutputs
def setupOutputs(self):
# assert len(self.Input.meta.shape) == 1
self.Output.meta.shape = (self.Input.meta.shape[0], 1)
self.Output.meta.dtype = np.float32
self.Output.meta.axistags = vigra.defaultAxistags('tc')
self.Valid.meta.shape = self.Output.meta.shape[:1]
self.Valid.meta.axistags = vigra.defaultAxistags('t')
self.Valid.meta.dtype = np.uint8
示例7: setUp
def setUp(self):
if 'TRAVIS' in os.environ:
# This test takes a long time, so skip it on Travis-CI.
import nose
raise nose.SkipTest
self.scaleZ = 2
self.scales = [0.3, 0.7, 1, 1.6, 3.5, 5.0, 10.0]
self.featureIds = [ 'GaussianSmoothing', 'LaplacianOfGaussian',\
'GaussianGradientMagnitude',
'DifferenceOfGaussians',
'StructureTensorEigenvalues',
'HessianOfGaussianEigenvalues' ]
#setup the data
self.nx = 50
self.ny = 50
self.nz = 50
self.data3d = numpy.zeros((self.nx, self.ny, self.nz, 1), dtype=numpy.float32)
for i in range(self.data3d.shape[2]):
self.data3d[:, :, i, 0]=i
newRangeZ = self.scaleZ*(self.nz-1)+1
self.data3dInterp = vigra.sampling.resizeVolumeSplineInterpolation(self.data3d.squeeze(), \
shape=(self.nx, self.ny, newRangeZ))
self.data3dInterp = self.data3dInterp.reshape(self.data3dInterp.shape + (1,))
self.data3d = self.data3d.view(vigra.VigraArray)
self.data3d.axistags = vigra.VigraArray.defaultAxistags(4)
self.data3dInterp = self.data3dInterp.view(vigra.VigraArray)
self.data3dInterp.axistags = vigra.VigraArray.defaultAxistags(4)
self.randomData = (numpy.random.random((self.nx, self.ny, self.nz, 1))).astype(numpy.float32)
self.randomDataInterp = vigra.sampling.resizeVolumeSplineInterpolation(self.randomData.squeeze(), \
shape = (self.nx, self.ny, newRangeZ))
self.randomDataInterp = self.randomDataInterp.reshape(self.randomDataInterp.shape+(1,))
self.randomData = self.randomData.view(vigra.VigraArray).astype(numpy.float32)
self.randomData.axistags = vigra.defaultAxistags(4)
self.randomDataInterp = self.randomDataInterp.view(vigra.VigraArray)
self.randomDataInterp.axistags = vigra.defaultAxistags(4)
#data without channels
self.dataNoChannels = self.randomData.squeeze()
self.dataNoChannels = self.dataNoChannels.view(vigra.VigraArray)
self.dataNoChannels.axistags = vigra.defaultAxistags(3, noChannels=True)
#setup the feature selection
rows = 6
cols = 7
self.selectedFeatures = []
#only test 1 feature 1 sigma setup for now
for i in range(rows):
for j in range(cols):
features = numpy.zeros((rows,cols), dtype=bool)
features[i, j]=True
self.selectedFeatures.append(features)
示例8: setupOutputs
def setupOutputs(self):
window = self.WindowSize.value
self.Output.meta.shape = (self.Input.meta.shape[0], window)
self.Output.meta.axistags = vigra.defaultAxistags('tc')
self.Output.meta.dtype = self.Input.meta.dtype
self.Valid.meta.shape = (self.Input.meta.shape[0],)
self.Valid.meta.axistags = vigra.defaultAxistags('t')
self.Valid.dtype = np.uint8
示例9: setupOutputs
def setupOutputs(self):
assert (len(self.Input.meta.shape) <= 2 or
np.prod(self.Input.meta.shape[1:]) == 1)
self.Output.meta.shape = (self.Input.meta.shape[0], 1)
self.Output.meta.axistags = vigra.defaultAxistags('tc')
self.Output.meta.dtype = np.float32
self.Valid.meta.shape = (self.Input.meta.shape[0],)
self.Valid.meta.axistags = vigra.defaultAxistags('t')
self.Valid.meta.dtype = np.uint8
示例10: test_2d_vigra_along_z
def test_2d_vigra_along_z(self):
"""Test if 2d files generated through vigra are recognized correctly"""
# Prepare some data set for this case
data = numpy.random.randint(0, 255, (20, 100, 200, 3)).astype(numpy.uint8)
axistags = vigra.defaultAxistags("yxc")
expected_axistags = vigra.defaultAxistags("zyxc")
h5_op = OpStreamingH5N5SequenceReaderM(graph=self.graph)
n5_op = OpStreamingH5N5SequenceReaderM(graph=self.graph)
tempdir = tempfile.TemporaryDirectory()
try:
for sliceIndex, zSlice in enumerate(data):
testDataH5FileName = f"{tempdir.name}/test-{sliceIndex:02d}.h5"
testDataN5FileName = f"{tempdir.name}/test-{sliceIndex:02d}.n5"
# Write the dataset to an hdf5 and a n5 file
# (Note: Don't use vigra to do this, which may reorder the axes)
h5File = h5py.File(testDataH5FileName)
n5File = z5py.N5File(testDataN5FileName)
try:
h5File.create_group("volume")
n5File.create_group("volume")
h5File["volume"].create_dataset("subvolume", data=zSlice)
n5File["volume"].create_dataset("subvolume", data=zSlice)
# Write the axistags attribute
current_path = "volume/subvolume"
h5File[current_path].attrs["axistags"] = axistags.toJSON()
n5File[current_path].attrs["axistags"] = axistags.toJSON()
finally:
h5File.close()
n5File.close()
# Read the data with an operator
hdf5GlobString = f"{tempdir.name}/test-*.h5/volume/subvolume"
n5GlobString = f"{tempdir.name}/test-*.n5/volume/subvolume"
h5_op.SequenceAxis.setValue("z")
n5_op.SequenceAxis.setValue("z")
h5_op.GlobString.setValue(hdf5GlobString)
n5_op.GlobString.setValue(n5GlobString)
assert h5_op.OutputImage.ready()
assert n5_op.OutputImage.ready()
assert h5_op.OutputImage.meta.axistags == expected_axistags
assert n5_op.OutputImage.meta.axistags == expected_axistags
numpy.testing.assert_array_equal(
h5_op.OutputImage.value[5:10, 50:100, 100:150], data[5:10, 50:100, 100:150]
)
numpy.testing.assert_array_equal(
n5_op.OutputImage.value[5:10, 50:100, 100:150], data[5:10, 50:100, 100:150]
)
finally:
h5_op.cleanUp()
n5_op.cleanUp()
示例11: setupOutputs
def setupOutputs(self):
self.fileNameList = self.expandGlobStrings(self.globstring.value)
num_files = len(self.fileNameList)
if len(self.fileNameList) == 0:
self.stack.meta.NOTREADY = True
return
try:
self.info = vigra.impex.ImageInfo(self.fileNameList[0])
self.slices_per_file = vigra.impex.numberImages(self.fileNameList[0])
except RuntimeError as e:
logger.error(str(e))
raise OpStackLoader.FileOpenError(self.fileNameList[0]) from e
slice_shape = self.info.getShape()
X, Y, C = slice_shape
if self.slices_per_file == 1:
if self.SequenceAxis.ready():
sequence_axis = str(self.SequenceAxis.value)
assert sequence_axis in "tzc"
else:
sequence_axis = "z"
# For stacks of 2D images, we assume xy slices
if sequence_axis == "c":
shape = (X, Y, C * num_files)
axistags = vigra.defaultAxistags("xyc")
else:
shape = (num_files, Y, X, C)
axistags = vigra.defaultAxistags(sequence_axis + "yxc")
else:
if self.SequenceAxis.ready():
sequence_axis = self.SequenceAxis.value
assert sequence_axis in "tzc"
else:
sequence_axis = "t"
if sequence_axis == "z":
axistags = vigra.defaultAxistags("ztyxc")
elif sequence_axis == "t":
axistags = vigra.defaultAxistags("tzyxc")
else:
axistags = vigra.defaultAxistags("czyx")
# For stacks of 3D volumes, we assume xyz blocks stacked along
# sequence_axis
if sequence_axis == "c":
shape = (num_files * C, self.slices_per_file, Y, X)
else:
shape = (num_files, self.slices_per_file, Y, X, C)
self.stack.meta.shape = shape
self.stack.meta.axistags = axistags
self.stack.meta.dtype = self.info.getDtype()
示例12: test_3d_vigra_along_t
def test_3d_vigra_along_t(self):
"""Test if 3d volumes generated through vigra are recognized correctly"""
# Prepare some data set for this case
data = numpy.random.randint(0, 255, (10, 15, 50, 100, 3)).astype(numpy.uint8)
axistags = vigra.defaultAxistags("zyxc")
expected_axistags = vigra.defaultAxistags("tzyxc")
h5_op = OpStreamingH5N5SequenceReaderS(graph=self.graph)
n5_op = OpStreamingH5N5SequenceReaderS(graph=self.graph)
try:
testDataH5FileName = f"{self.tempdir_normalized_name}/test.h5"
testDataN5FileName = f"{self.tempdir_normalized_name}/test.n5"
# Write the dataset to an hdf5 file
# (Note: Don't use vigra to do this, which may reorder the axes)
h5File = h5py.File(testDataH5FileName)
n5File = z5py.N5File(testDataN5FileName)
try:
h5File.create_group("volumes")
n5File.create_group("volumes")
internalPathString = "subvolume-{sliceIndex:02d}"
for sliceIndex, tSlice in enumerate(data):
subpath = internalPathString.format(sliceIndex=sliceIndex)
h5File["volumes"].create_dataset(subpath, data=tSlice)
n5File["volumes"].create_dataset(subpath, data=tSlice)
# Write the axistags attribute
current_path = "volumes/{}".format(subpath)
h5File[current_path].attrs["axistags"] = axistags.toJSON()
n5File[current_path].attrs["axistags"] = axistags.toJSON()
finally:
h5File.close()
n5File.close()
# Read the data with an operator
hdf5GlobString = f"{testDataH5FileName}/volumes/subvolume-*"
n5GlobString = f"{testDataN5FileName}/volumes/subvolume-*"
h5_op.SequenceAxis.setValue("t")
n5_op.SequenceAxis.setValue("t")
h5_op.GlobString.setValue(hdf5GlobString)
n5_op.GlobString.setValue(n5GlobString)
assert h5_op.OutputImage.ready()
assert n5_op.OutputImage.ready()
assert h5_op.OutputImage.meta.axistags == expected_axistags
assert n5_op.OutputImage.meta.axistags == expected_axistags
numpy.testing.assert_array_equal(h5_op.OutputImage.value, data)
numpy.testing.assert_array_equal(n5_op.OutputImage.value, data)
finally:
h5_op.cleanUp()
n5_op.cleanUp()
示例13: setUp
def setUp(self):
self.delta = numpy.zeros((19, 19, 19, 1), dtype=numpy.float32)
self.delta[9, 9, 9, 0]=1
self.delta = self.delta.view(vigra.VigraArray)
self.delta.axistags = vigra.defaultAxistags(4)
self.dataShape = ((100, 100, 100, 1))
self.randomData = (numpy.random.random(self.dataShape) * 100).astype(int)
self.randomData = self.randomData.view(vigra.VigraArray)
self.randomData.axistags = vigra.defaultAxistags(4)
self.anisotropicSigmas = [(3, 3, 1), (1.6, 1.6, 1)]
self.isotropicSigmasTuple = [(3, 3, 3), (1, 1, 1)]
self.isotropicSigmas = [3, 1]
示例14: test1
def test1(self):
superpixels = generate_random_voronoi((100,200), 200)
superpixels.axistags = vigra.defaultAxistags('yx')
feature_names = ['edgeregion_edge_regionradii']
rag = Rag( superpixels )
acc = EdgeRegionEdgeAccumulator(rag, feature_names)
features_df = rag.compute_features(None, feature_names, accumulator_set=[acc])
radii = features_df[features_df.columns.values[2:]].values
assert (radii[:,0] >= radii[:,1]).all()
# Transpose superpixels and check again
# Should match (radii are sorted by magnitude).
superpixels.axistags = vigra.defaultAxistags('xy')
rag = Rag( superpixels )
acc = EdgeRegionEdgeAccumulator(rag, feature_names)
transposed_features_df = rag.compute_features(None, feature_names, accumulator_set=[acc])
transposed_radii = transposed_features_df[transposed_features_df.columns.values[2:]].values
assert (transposed_features_df[['sp1', 'sp1']].values == features_df[['sp1', 'sp1']].values).all()
DEBUG = False
if DEBUG:
count_features = rag.compute_features(None, ['standard_edge_count', 'standard_sp_count'])
import pandas as pd
combined_features_df = pd.merge(features_df, transposed_features_df, how='left', on=['sp1', 'sp2'], suffixes=('_orig', '_transposed'))
combined_features_df = pd.merge(combined_features_df, count_features, how='left', on=['sp1', 'sp2'])
problem_rows = np.logical_or(np.isclose(radii[:, 0], transposed_radii[:, 0]) != 1,
np.isclose(radii[:, 1], transposed_radii[:, 1]) != 1)
problem_df = combined_features_df.loc[problem_rows][sorted(list(combined_features_df.columns))]
print(problem_df.transpose())
debug_sp = np.zeros_like(superpixels, dtype=np.uint8)
for sp1 in problem_df['sp1'].values:
debug_sp[superpixels == sp1] = 128
for sp2 in problem_df['sp2'].values:
debug_sp[superpixels == sp2] = 255
vigra.impex.writeImage(debug_sp, '/tmp/debug_sp.png', dtype='NATIVE')
# The first axes should all be close.
# The second axes may differ somewhat in the case of purely linear edges,
# so we allow a higher tolerance.
assert np.isclose(radii[:,0], transposed_radii[:,0]).all()
assert np.isclose(radii[:,1], transposed_radii[:,1], atol=0.001).all()
示例15: setup
def setup(self):
graph = Graph()
op = OpCompressedUserLabelArray(graph=graph)
arrayshape = (1,100,100,10,1)
op.inputs["shape"].setValue( arrayshape )
blockshape = (1,10,10,10,1) # Why doesn't this work if blockshape is an ndarray?
op.inputs["blockShape"].setValue( blockshape )
op.eraser.setValue(100)
op.Input.meta.axistags = vigra.defaultAxistags('txyzc')
op.Input.meta.has_mask = True
dummyData = numpy.zeros(arrayshape, dtype=numpy.uint8)
dummyData = numpy.ma.masked_array(dummyData, mask=numpy.ma.getmaskarray(dummyData), fill_value=numpy.uint8(0), shrink=False)
op.Input.setValue( dummyData )
slicing = sl[0:1, 1:15, 2:36, 3:7, 0:1]
inDataShape = slicing2shape(slicing)
inputData = ( 3*numpy.random.random(inDataShape) ).astype(numpy.uint8)
inputData = numpy.ma.masked_array(inputData, mask=numpy.ma.getmaskarray(inputData), fill_value=numpy.uint8(0), shrink=False)
inputData[:, 0] = numpy.ma.masked
op.Input[slicing] = inputData
data = numpy.ma.zeros(arrayshape, dtype=numpy.uint8, fill_value=numpy.uint8(0))
data[slicing] = inputData
self.op = op
self.slicing = slicing
self.inData = inputData
self.data = data