uid stringlengths 24 24 | split stringclasses 1
value | category stringclasses 2
values | content stringlengths 5 482k | signature stringlengths 1 14k | suffix stringlengths 1 482k | prefix stringlengths 9 14k | prefix_token_count int64 3 5.01k | prefix_token_budget int64 64 256 | element_token_count int64 1 292k | signature_token_count int64 1 5.01k | prefix_context_token_count int64 0 255 | repo stringlengths 7 112 | path stringlengths 4 208 | language stringclasses 1
value | name stringlengths 1 218 | qualname stringlengths 1 218 | start_line int64 1 26.7k | end_line int64 1 26.7k | signature_start_line int64 1 26.7k | signature_end_line int64 1 26.7k | source_hash stringlengths 40 40 | source_dataset stringclasses 1
value | source_split stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
6ed93d77bc5c3fd1354234dc | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imagej_confocal_series():
"""Test read ImageJ 25x2x400x400 ZCYX."""
fname = private_file('imagej/confocal-series.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byteorder == '>'
assert len(tif.pages) ==... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imagej_confocal_series():
| """Test read ImageJ 25x2x400x400 ZCYX."""
fname = private_file('imagej/confocal-series.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byteorder == '>'
assert len(tif.pages) == 50
assert len(tif.series) == 1 # hyperstack
# assert page properties
... | assert isinstance(data, numpy.ndarray)
assert data.shape == (57, 256, 256, 3)
assert data.dtype == numpy.uint8
assert tuple(data[18, 108, 97]) == (165, 157, 0)
assert_aszarr_method(series, data)
assert_aszarr_method(series, data, chunkmode='page')
# don't squeeze
... | 161 | 161 | 538 | 22 | 139 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_imagej_confocal_series | test_read_imagej_confocal_series | 8,375 | 8,424 | 8,375 | 8,376 | e550b395ded7b8a4fce05c7ec3cb382141947cd0 | bigcode/the-stack | train |
efb85b83aff90971ae36f5c7 | train | function | def test_func_hexdump():
"""Test hexdump function."""
# test hexdump function
data = binascii.unhexlify(
'49492a00080000000e00fe0004000100'
'00000000000000010400010000000001'
'00000101040001000000000100000201'
'03000100000020000000030103000100'
)
# one line
assert... | def test_func_hexdump():
| """Test hexdump function."""
# test hexdump function
data = binascii.unhexlify(
'49492a00080000000e00fe0004000100'
'00000000000000010400010000000001'
'00000101040001000000000100000201'
'03000100000020000000030103000100'
)
# one line
assert hexdump(data[:16]) == (
... | '
assert p['False'] is False
assert p['Filename'] == 'C:\\Users\\scanimage.cfg'
assert p['Float'] == 3.14
assert p['Float.E'] == 3.14
assert p['Float.Inf'] == float('inf')
# self.assertEqual(p['Float.NaN'], float('nan')) # can't compare NaN
assert p['Int'] == 10
assert p['StructObject']... | 251 | 251 | 838 | 7 | 243 | bioturing/tifffile | tests/test_tifffile.py | Python | test_func_hexdump | test_func_hexdump | 2,846 | 2,899 | 2,846 | 2,846 | 92869e09a0b4964912a332c4169faab855830b08 | bigcode/the-stack | train |
3f771f20371817acc8af9a25 | train | function | @pytest.mark.skipif(SKIP_CODECS, reason=REASON)
def test_write_volumetric_striped_png():
"""Test write tiled volume using an image compressor."""
data = random_data(numpy.uint8, (15, 63, 95, 3))
with TempFileName('volumetric_striped_png') as fname:
imwrite(
fname,
data,
... | @pytest.mark.skipif(SKIP_CODECS, reason=REASON)
def test_write_volumetric_striped_png():
| """Test write tiled volume using an image compressor."""
data = random_data(numpy.uint8, (15, 63, 95, 3))
with TempFileName('volumetric_striped_png') as fname:
imwrite(
fname,
data,
photometric=RGB,
volumetric=True,
rowsperstrip=32,
... |
assert len(page.dataoffsets) == 15
assert len(page.databytecounts) == 15
assert page.samplesperpixel == 1
image = tif.asarray()
assert_array_equal(data, image)
assert_aszarr_method(tif, image)
assert__str__(tif)
@pytest.mark.skipif(SKI... | 92 | 92 | 307 | 24 | 68 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_volumetric_striped_png | test_write_volumetric_striped_png | 12,464 | 12,497 | 12,464 | 12,465 | 9a7c360e1c204427849ba8b6003d54518705ef7e | bigcode/the-stack | train |
7e06ad1920e067b3e0d999e8 | train | function | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_ome_multi_channel():
"""Test read OME multi channel image."""
# 2D (3 channels)
fname = public_file('OME/bioformats-artificial/multi-channel.ome.tiff')
with TiffFile(fname) as tif:
assert tif.is_ome
assert tif.byteorder == '>'... | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_ome_multi_channel():
| """Test read OME multi channel image."""
# 2D (3 channels)
fname = public_file('OME/bioformats-artificial/multi-channel.ome.tiff')
with TiffFile(fname) as tif:
assert tif.is_ome
assert tif.byteorder == '>'
assert len(tif.pages) == 3
assert len(tif.series) == 1
# a... | 1, 167, 439, 1)
assert series.get_axes(False) == 'TCZYXS'
# assert data
data = tif.asarray()
assert isinstance(data, numpy.ndarray)
assert data.shape == (167, 439)
assert data.dtype == numpy.int8
assert data[158, 428] == 91
assert_aszarr_method(tif, data)... | 117 | 117 | 392 | 21 | 96 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_ome_multi_channel | test_read_ome_multi_channel | 7,092 | 7,129 | 7,092 | 7,093 | 7913e14af6619792e779972b57b7814f2beda58e | bigcode/the-stack | train |
14ee29d7e1104629b9b8a0ad | train | function | def test_write_contiguous():
"""Test contiguous mode."""
data = random_data(numpy.uint8, (5, 4, 219, 301, 3))
with TempFileName('write_contiguous') as fname:
with TiffWriter(fname, bigtiff=True) as tif:
for i in range(data.shape[0]):
tif.write(data[i], contiguous=True, ph... | def test_write_contiguous():
| """Test contiguous mode."""
data = random_data(numpy.uint8, (5, 4, 219, 301, 3))
with TempFileName('write_contiguous') as fname:
with TiffWriter(fname, bigtiff=True) as tif:
for i in range(data.shape[0]):
tif.write(data[i], contiguous=True, photometric=RGB)
# asse... | assert len(series._pages) == 1
assert len(series.pages) == 6
assert series.offset is not None
assert series.shape == shape
image = tif.asarray()
assert_array_equal(image.shape, shape)
assert_aszarr_method(tif, image)
assert__str__(tif)... | 75 | 75 | 250 | 6 | 69 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_contiguous | test_write_contiguous | 12,609 | 12,632 | 12,609 | 12,609 | 437ab1d3f141c8f78f433041ea37685589df75f6 | bigcode/the-stack | train |
4516647cf28105d9c8fea43a | train | function | @pytest.mark.skipif(
SKIP_PRIVATE or SKIP_CODECS or not imagecodecs.JPEG, reason=REASON
)
def test_read_zif():
"""Test read Zoomable Image Format ZIF."""
fname = private_file('zif/ZoomifyImageExample.zif')
with TiffFile(fname) as tif:
# assert tif.is_zif
assert len(tif.pages) == 5
... | @pytest.mark.skipif(
SKIP_PRIVATE or SKIP_CODECS or not imagecodecs.JPEG, reason=REASON
)
def test_read_zif():
| """Test read Zoomable Image Format ZIF."""
fname = private_file('zif/ZoomifyImageExample.zif')
with TiffFile(fname) as tif:
# assert tif.is_zif
assert len(tif.pages) == 5
assert len(tif.series) == 1
for page in tif.pages:
assert page.description == (
... |
image = tif.asarray(series=0, level=5)
assert image.shape == (2789, 2677, 3)
assert image[300, 400, 1] == 206
assert_aszarr_method(series, image, level=5)
assert_aszarr_method(series, image, level=5, chunkmode='page')
assert__str__(tif)
@pytest.mark.skipif(
SKIP_PRIV... | 121 | 121 | 404 | 34 | 87 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_zif | test_read_zif | 9,239 | 9,274 | 9,239 | 9,242 | ce8b506ca5b44e452f6bb9b0613f37cba30323e6 | bigcode/the-stack | train |
ee5c71f61eae2d0c2c77ecc4 | train | function | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_gimp_u2():
"""Test read uint16 with horizontal predictor by GIMP."""
fname = public_file('tifffile/gimp_u2.tiff')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
assert page.compression == ADOBE... | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_gimp_u2():
| """Test read uint16 with horizontal predictor by GIMP."""
fname = public_file('tifffile/gimp_u2.tiff')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
assert page.compression == ADOBE_DEFLATE
assert page.photometric == RGB
assert page.predi... | 7100)
assert data[2350, 3550] == 56341
assert_aszarr_method(tif, data, series=1)
assert__str__(tif)
@pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_gimp_u2():
| 64 | 64 | 198 | 21 | 43 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_gimp_u2 | test_read_gimp_u2 | 3,845 | 3,862 | 3,845 | 3,846 | 626d7f6a1437456ee39053ee8876b8b7e74c62ea | bigcode/the-stack | train |
744ab091c421cdc2c8cd4468 | train | function | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_ZARR, reason=REASON)
def test_read_zarr_multifile():
"""Test read multifile OME-TIFF with zarr."""
fname = public_file('OME/multifile/multifile-Z1.ome.tiff')
with TiffFile(fname) as tif:
image = tif.asarray()
store = tif.aszarr()
try:
data ... | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_ZARR, reason=REASON)
def test_read_zarr_multifile():
| """Test read multifile OME-TIFF with zarr."""
fname = public_file('OME/multifile/multifile-Z1.ome.tiff')
with TiffFile(fname) as tif:
image = tif.asarray()
store = tif.aszarr()
try:
data = zarr.open(store, mode='r')
assert_array_equal(image, data)
del data
fin... | zarr()
try:
data = zarr.open(store, mode='r')
assert_array_equal(image, data)
del data
finally:
store.close()
@pytest.mark.skipif(SKIP_PUBLIC or SKIP_ZARR, reason=REASON)
def test_read_zarr_multifile():
| 64 | 64 | 121 | 27 | 37 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_zarr_multifile | test_read_zarr_multifile | 9,456 | 9,468 | 9,456 | 9,457 | 06ac53dd0269c56ef39fe747383fcc6fddf9ce6d | bigcode/the-stack | train |
fec09864fb844331f38e9794 | train | function | @pytest.mark.skipif(
SKIP_PUBLIC or SKIP_CODECS or not imagecodecs.WEBP, reason=REASON
)
def test_read_webp():
"""Test read WebP compression."""
fname = public_file('GDAL/tif_webp.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
assert page.compre... | @pytest.mark.skipif(
SKIP_PUBLIC or SKIP_CODECS or not imagecodecs.WEBP, reason=REASON
)
def test_read_webp():
| """Test read WebP compression."""
fname = public_file('GDAL/tif_webp.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
assert page.compression == WEBP
assert page.photometric == RGB
assert page.planarconfig == CONTIG
assert page... | 512)
assert data.dtype == numpy.uint8
assert data[273, 426] == 151
assert_aszarr_method(tif, data)
assert__str__(tif)
@pytest.mark.skipif(
SKIP_PUBLIC or SKIP_CODECS or not imagecodecs.WEBP, reason=REASON
)
def test_read_webp():
| 79 | 79 | 265 | 35 | 44 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_webp | test_read_webp | 5,032 | 5,057 | 5,032 | 5,035 | 0ae102f9fa5320fb26e9418aea60a8139934c175 | bigcode/the-stack | train |
47363ee27b6c09aa21134bc5 | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_LARGE, reason=REASON)
@pytest.mark.parametrize('tiled', [False, True])
def test_sequence_tiled(tiled):
"""Test FileSequence with tiled OME-TIFFs."""
# Dataset from https://github.com/tlambert03/tifffolder/issues/2
ptrn = re.compile(
r'\[(?P<U>\d+) x (?P<V>\d+... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_LARGE, reason=REASON)
@pytest.mark.parametrize('tiled', [False, True])
def test_sequence_tiled(tiled):
| """Test FileSequence with tiled OME-TIFFs."""
# Dataset from https://github.com/tlambert03/tifffolder/issues/2
ptrn = re.compile(
r'\[(?P<U>\d+) x (?P<V>\d+)\].*(C)(\d+).*(Z)(\d+)', re.IGNORECASE
)
fnames = private_file('TiffSequenceTiled/*.tif', expand=False)
tifs = TiffSequence(fnames,... | )
assert data.flags['C_CONTIGUOUS']
assert data.shape == (16, 24, 2, 2, 2, 520, 696)
assert data.dtype == numpy.uint16
assert data[8, 12, 1, 0, 1, 256, 519] == 1579
if not SKIP_ZARR:
with tifs.aszarr() as store:
assert_array_equal(data, zarr.open(store, mode='r'))
@pytest.mark.sk... | 148 | 149 | 498 | 38 | 110 | bioturing/tifffile | tests/test_tifffile.py | Python | test_sequence_tiled | test_sequence_tiled | 14,160 | 14,195 | 14,160 | 14,162 | 3e12fc117efd5aa0885a3f09082b90f6ab4cbae1 | bigcode/the-stack | train |
d98ad50e54474652fab93c0f | train | function | @pytest.mark.skipif(SKIP_CODECS or not imagecodecs.ZSTD, reason=REASON)
def test_write_compression_zstd():
"""Test write ZSTD compression."""
data = WRITE_DATA
with TempFileName('compression_zstd') as fname:
imwrite(fname, data, compression=ZSTD, photometric=RGB)
assert_valid_tiff(fname)
... | @pytest.mark.skipif(SKIP_CODECS or not imagecodecs.ZSTD, reason=REASON)
def test_write_compression_zstd():
| """Test write ZSTD compression."""
data = WRITE_DATA
with TempFileName('compression_zstd') as fname:
imwrite(fname, data, compression=ZSTD, photometric=RGB)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
... | s) == 9
image = tif.asarray()
assert_array_equal(data, image)
assert_aszarr_method(tif, image)
assert__str__(tif)
@pytest.mark.skipif(SKIP_CODECS or not imagecodecs.ZSTD, reason=REASON)
def test_write_compression_zstd():
| 68 | 68 | 229 | 29 | 39 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_compression_zstd | test_write_compression_zstd | 10,851 | 10,873 | 10,851 | 10,852 | e72eb52a9cac28bf5ed5154cd0f524b4c338aa38 | bigcode/the-stack | train |
0324428ad0d73dcc9f657938 | train | function | def test_write_is_shaped():
"""Test files are written with shape."""
with TempFileName('is_shaped') as fname:
imwrite(fname, random_data(numpy.uint8, (4, 5, 6, 3)), photometric=RGB)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 4
p... | def test_write_is_shaped():
| """Test files are written with shape."""
with TempFileName('is_shaped') as fname:
imwrite(fname, random_data(numpy.uint8, (4, 5, 6, 3)), photometric=RGB)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 4
page = tif.pages[0]
... | series.shape == shape
assert len(series._pages) == 1
assert len(series.pages) == 1
data = tif.asarray()
assert data.shape == shape
assert_aszarr_method(tif, data)
assert_aszarr_method(tif, data, chunkmode='page')
assert__str__(tif)
def... | 81 | 81 | 272 | 7 | 74 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_is_shaped | test_write_is_shaped | 10,230 | 10,257 | 10,230 | 10,230 | 5f021234c54425c7a74ed0b2d04a88a1974e61c9 | bigcode/the-stack | train |
6bf878d8f3f3b512ae2867ed | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_andor_light_sheet_512p():
"""Test read Andor."""
# 12113x13453, uint16
fname = private_file('andor/light sheet 512px.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 100
assert l... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_andor_light_sheet_512p():
| """Test read Andor."""
# 12113x13453, uint16
fname = private_file('andor/light sheet 512px.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 100
assert len(tif.series) == 1
assert tif.is_andor
# assert page properties
... | .shape == (1552, 2080, 4)
assert series.dtype == numpy.uint8
assert series.axes == 'YXS'
assert not series.is_multifile
# assert data
data = tif.asarray()
assert data.shape == (1552, 2080, 4)
assert_aszarr_method(tif, data)
assert__str__(tif)
@pytest.mark.... | 110 | 110 | 367 | 24 | 86 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_andor_light_sheet_512p | test_read_andor_light_sheet_512p | 8,052 | 8,087 | 8,052 | 8,053 | d18c5ca6a86d3aa71f7d8ff9914443a675ca823d | bigcode/the-stack | train |
266e1492b95db2a8c4997bc0 | train | function | def test_issue_svs_doubleheader():
"""Test svs_description_metadata for SVS with double header."""
# https://github.com/cgohlke/tifffile/pull/88
assert svs_description_metadata(
'Aperio Image Library v11.2.1\r\n'
'2220x2967 -> 574x768 - ;Aperio Image Library v10.0.51\r\n'
'46920x330... | def test_issue_svs_doubleheader():
| """Test svs_description_metadata for SVS with double header."""
# https://github.com/cgohlke/tifffile/pull/88
assert svs_description_metadata(
'Aperio Image Library v11.2.1\r\n'
'2220x2967 -> 574x768 - ;Aperio Image Library v10.0.51\r\n'
'46920x33014 [0,100 46000x32914] (256x256) JP... | .pages[0].tags['XResolution'].value == (
4294967295,
579475,
)
def test_issue_omexml_micron():
"""Test OME-TIFF can be created with micron character in XML."""
# https://forum.image.sc/t/micro-character-in-omexml-from-python/53578/4
with TempFileName('issue_ome... | 189 | 189 | 630 | 8 | 181 | bioturing/tifffile | tests/test_tifffile.py | Python | test_issue_svs_doubleheader | test_issue_svs_doubleheader | 1,357 | 1,399 | 1,357 | 1,357 | f2911a4e2b199eb30b5af57f6d3450a4380049ad | bigcode/the-stack | train |
932386815ef8dbef3abdf2d8 | train | function | def test_write_invalid_planar_rgb():
"""Test write planar RGB with 2 samplesperpixel."""
data = random_data(numpy.uint8, (2, 219, 301))
with pytest.raises(ValueError):
with TempFileName('invalid_planar_rgb') as fname:
imwrite(fname, data, photometric=RGB, planarconfig=SEPARATE)
# def... | def test_write_invalid_planar_rgb():
| """Test write planar RGB with 2 samplesperpixel."""
data = random_data(numpy.uint8, (2, 219, 301))
with pytest.raises(ValueError):
with TempFileName('invalid_planar_rgb') as fname:
imwrite(fname, data, photometric=RGB, planarconfig=SEPARATE)
# default to pages
with TempFileName('... | len(tif.pages) == 1
assert tif.series[0].axes == 'YXS'
page = tif.pages[0]
assert page.is_contiguous
assert page.planarconfig == CONTIG
assert page.photometric != RGB
assert page.imagewidth == 301
assert page.imagelength == 219
... | 125 | 125 | 418 | 8 | 117 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_invalid_planar_rgb | test_write_invalid_planar_rgb | 11,318 | 11,359 | 11,318 | 11,318 | e33487f6d182b93b238687213943d8c8646546c8 | bigcode/the-stack | train |
7870918fa25a0a04b6b9ccbc | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_depend_czifile():
"""Test czifile.CziFile."""
# TODO: test LZW compressed czi file
from czifile import CziFile
fname = private_file('czi/pollen.czi')
with CziFile(fname) as czi:
assert czi.shape == (1, 1, 104, 365, 364, 1)
as... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_depend_czifile():
| """Test czifile.CziFile."""
# TODO: test LZW compressed czi file
from czifile import CziFile
fname = private_file('czi/pollen.czi')
with CziFile(fname) as czi:
assert czi.shape == (1, 1, 104, 365, 364, 1)
assert czi.axes == 'TCZYX0'
# verify data
data = czi.asarray()... | '
)
with CmapFile(fname, mode='r') as cmap:
assert_array_equal(
cmap['map00000']['data00000'], data.squeeze()[:, 0, :, :]
)
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_depend_czifile():
| 64 | 64 | 192 | 20 | 44 | bioturing/tifffile | tests/test_tifffile.py | Python | test_depend_czifile | test_depend_czifile | 14,268 | 14,283 | 14,268 | 14,269 | 32efe92c0d412a85639526468be1a35c9ef70333 | bigcode/the-stack | train |
6fbca5dd5196720ffe5afb9b | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_ome_samplesperpixel_mismatch(caplog):
"""Test read OME with SamplesPerPixel mismatch: OME=1, TIFF=4."""
# https://forum.image.sc/t/ilastik-refuses-to-load-image-file/48541/1
fname = private_file('OME/MismatchSamplesPerPixel.ome.ti... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_ome_samplesperpixel_mismatch(caplog):
| """Test read OME with SamplesPerPixel mismatch: OME=1, TIFF=4."""
# https://forum.image.sc/t/ilastik-refuses-to-load-image-file/48541/1
fname = private_file('OME/MismatchSamplesPerPixel.ome.tif')
with TiffFile(fname) as tif:
assert tif.is_ome
assert tif.byteorder == '<'
assert le... | numpy.ndarray)
assert data.shape == (196, 171)
assert data.dtype == numpy.uint16
assert data[0, 0] == 1904
assert_aszarr_method(page, data)
assert_aszarr_method(page, data, chunkmode='page')
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASO... | 101 | 101 | 338 | 31 | 70 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_ome_samplesperpixel_mismatch | test_read_ome_samplesperpixel_mismatch | 8,019 | 8,049 | 8,019 | 8,020 | c2221f0ee24cda9b7442809f3f77f18be49ad3cf | bigcode/the-stack | train |
c7b5908a91acf3ccd1ff63cf | train | function | def test_class_tifftags():
"""Test TiffTags interface."""
data = random_data(numpy.uint8, (21, 31))
with TempFileName('class_tifftags') as fname:
imwrite(fname, data, description='test', software=False)
with TiffFile(fname) as tif:
tags = tif.pages[0].tags
# assert ... | def test_class_tifftags():
| """Test TiffTags interface."""
data = random_data(numpy.uint8, (21, 31))
with TempFileName('class_tifftags') as fname:
imwrite(fname, data, description='test', software=False)
with TiffFile(fname) as tif:
tags = tif.pages[0].tags
# assert len(tags) == 14
... | tag.overwrite('inl')
assert tag.valueoffset != t305.valueoffset
assert t305.valueoffset == valueoffset
# inline - > erase
with TiffFile(fname, mode='r+b') as tif:
tag = tif.pages[0].tags[305]
assert tag.value == 'inl'
assert tag.valueoffset =... | 175 | 175 | 584 | 7 | 168 | bioturing/tifffile | tests/test_tifffile.py | Python | test_class_tifftags | test_class_tifftags | 1,881 | 1,943 | 1,881 | 1,881 | 63a1df1f6ce4ee359543c609b27d5c1d5a4d11a5 | bigcode/the-stack | train |
4cba6705662c13055f038d7b | train | function | @pytest.mark.parametrize('dt', [None, True, datetime, '2019:01:30 04:05:37'])
def test_write_datetime_tag(dt):
"""Test write datetime tag."""
arg = dt
if dt is datetime:
arg = datetime.datetime.now()
data = random_data(numpy.uint8, (31, 32))
with TempFileName('datetime') as fname:
im... | @pytest.mark.parametrize('dt', [None, True, datetime, '2019:01:30 04:05:37'])
def test_write_datetime_tag(dt):
| """Test write datetime tag."""
arg = dt
if dt is datetime:
arg = datetime.datetime.now()
data = random_data(numpy.uint8, (31, 32))
with TempFileName('datetime') as fname:
imwrite(fname, data, datetime=arg)
with TiffFile(fname) as tif:
if dt is None:
... | 0b100
assert page.is_mrc == subfiletype & 0b1000
assert_array_equal(data, page.asarray())
assert__str__(tif)
@pytest.mark.parametrize('dt', [None, True, datetime, '2019:01:30 04:05:37'])
def test_write_datetime_tag(dt):
| 72 | 72 | 240 | 34 | 38 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_datetime_tag | test_write_datetime_tag | 10,394 | 10,420 | 10,394 | 10,395 | f744bf3fc5b88484d0a9de49fd15cc886ce6df6a | bigcode/the-stack | train |
4d2236d62f1568477c64c80b | train | function | def test_write_resolution_rational():
"""Test write rational Resolution tag."""
data = random_data(numpy.uint8, (1, 219, 301))
resolution = ((300, 1), (300, 1))
with TempFileName('resolution_rational') as fname:
imwrite(fname, data, resolution=resolution)
assert_valid_tiff(fname)
... | def test_write_resolution_rational():
| """Test write rational Resolution tag."""
data = random_data(numpy.uint8, (1, 219, 301))
resolution = ((300, 1), (300, 1))
with TempFileName('resolution_rational') as fname:
imwrite(fname, data, resolution=resolution)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
... | '].value == (92, 1)
assert tif.pages[1].tags['XResolution'].value == (92, 1)
assert tif.pages[1].tags['YResolution'].value == (92, 1)
assert__str__(tif)
def test_write_resolution_rational():
| 64 | 64 | 141 | 7 | 57 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_resolution_rational | test_write_resolution_rational | 10,483 | 10,493 | 10,483 | 10,483 | 5bd28de166a781b838a882e180b32b1ffcdc697f | bigcode/the-stack | train |
f3486d4c8234c5e3bf5dbeb7 | train | function | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_write_roundtrip_openfile():
"""Test write and read using open file."""
pad = b'0' * 7
data = imread(public_file('tifffile/generic_series.tif'))
with TempFileName('roundtrip_openfile') as fname:
with open(fname, 'wb') as fh:
... | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_write_roundtrip_openfile():
| """Test write and read using open file."""
pad = b'0' * 7
data = imread(public_file('tifffile/generic_series.tif'))
with TempFileName('roundtrip_openfile') as fname:
with open(fname, 'wb') as fh:
fh.write(pad)
imwrite(fh, data, photometric=RGB)
fh.write(pad)
... | .tif'))
with TempFileName('roundtrip_filename') as fname:
imwrite(fname, data, photometric=RGB)
assert_array_equal(imread(fname), data)
@pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_write_roundtrip_openfile():
| 64 | 64 | 144 | 26 | 38 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_roundtrip_openfile | test_write_roundtrip_openfile | 10,152 | 10,164 | 10,152 | 10,153 | 9a3a78a0b7943f69cd6ffd8d0081fe6da3cdca8c | bigcode/the-stack | train |
a042248970dfa631ec72efa7 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imagej_graphite():
"""Test read ImageJ 1024x593 float32."""
fname = private_file('imagej/graphite1-1024.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byteorder == '>'
assert len(tif.pages) == 1
... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imagej_graphite():
| """Test read ImageJ 1024x593 float32."""
fname = private_file('imagej/graphite1-1024.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byteorder == '>'
assert len(tif.pages) == 1
assert len(tif.series) == 1
# assert page properties
page = tif.... | tif.pages.pages[2] == 8001073
assert tif.pages.pages[-1] == 8008687
assert_aszarr_method(series, data)
assert_aszarr_method(series, data, chunkmode='page')
# don't squeeze
data = tif.asarray(squeeze=False)
assert data.shape == (1, 25, 2, 400, 400, 1)
assert_aszar... | 130 | 130 | 434 | 21 | 109 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_imagej_graphite | test_read_imagej_graphite | 8,427 | 8,465 | 8,427 | 8,428 | c19eff0150a6c48e4618eb328bee7a17bd2b9507 | bigcode/the-stack | train |
3e9fac03bfc2a56b282d79d4 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_stk_diatoms3d():
"""Test read MetaMorph STK time-series."""
fname = private_file('stk/diatoms3d.stk')
with TiffFile(fname) as tif:
assert tif.is_stk
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert le... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_stk_diatoms3d():
| """Test read MetaMorph STK time-series."""
fname = private_file('stk/diatoms3d.stk')
with TiffFile(fname) as tif:
assert tif.is_stk
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert len(tif.series) == 1
# assert page properties
page = tif.pages[0]
... | # assert series properties
series = tif.series[0]
assert series.shape == (11, 128, 160, 3)
assert series.dtype == numpy.uint8
assert series.axes == 'ZYXS'
# assert data
data = tif.asarray()
assert isinstance(data, numpy.ndarray)
assert data.shape == (11, ... | 165 | 165 | 551 | 24 | 141 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_stk_diatoms3d | test_read_stk_diatoms3d | 6,308 | 6,358 | 6,308 | 6,309 | 493f5ea31a32f34921de00306e192a234be9b91c | bigcode/the-stack | train |
40e3f40b4d0836ad7b1e8b1b | train | function | def test_issue_sampleformat_default():
"""Test SampleFormat are not written for UINT."""
data = random_data(numpy.uint8, (256, 256, 4))
with TempFileName('sampleformat_default') as fname:
imwrite(fname, data, photometric=RGB)
with TiffFile(fname) as tif:
tags = tif.pages[0].tags
... | def test_issue_sampleformat_default():
| """Test SampleFormat are not written for UINT."""
data = random_data(numpy.uint8, (256, 256, 4))
with TempFileName('sampleformat_default') as fname:
imwrite(fname, data, photometric=RGB)
with TiffFile(fname) as tif:
tags = tif.pages[0].tags
'SampleFormat' not in tags
... | File(fname) as tif:
tags = tif.pages[0].tags
assert tags['SampleFormat'].value == (2, 2, 2, 2)
assert tags['ExtraSamples'].value == (2,)
assert__str__(tif)
def test_issue_sampleformat_default():
| 64 | 64 | 111 | 7 | 57 | bioturing/tifffile | tests/test_tifffile.py | Python | test_issue_sampleformat_default | test_issue_sampleformat_default | 598 | 607 | 598 | 598 | c8c02e520790e65c4dd07c769eced12f90dd998f | bigcode/the-stack | train |
a6e4b70e6d7cc9f257e485fc | train | function | def test_issue_pages_iterator():
"""Test iterating over pages in series."""
data = random_data(numpy.int8, (8, 219, 301))
with TempFileName('page_iterator') as fname:
imwrite(fname, data[0])
imwrite(
fname,
data,
photometric=MINISBLACK,
append=... | def test_issue_pages_iterator():
| """Test iterating over pages in series."""
data = random_data(numpy.int8, (8, 219, 301))
with TempFileName('page_iterator') as fname:
imwrite(fname, data[0])
imwrite(
fname,
data,
photometric=MINISBLACK,
append=True,
metadata={'axes... | .mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_issue_pages_number():
"""Test number of pages."""
fname = public_file('tifffile/100000_pages.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 100000
assert__str__(tif, 0)
def test_issue_pages_iterator():
| 81 | 81 | 271 | 6 | 75 | bioturing/tifffile | tests/test_tifffile.py | Python | test_issue_pages_iterator | test_issue_pages_iterator | 826 | 857 | 826 | 826 | 65f5c2e96a311605bf87324b922393ffa3f74eb1 | bigcode/the-stack | train |
fa87d4141138fe05a26d0bb6 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_issue_infinite_loop():
"""Test infinite loop reading more than two tags of same code in IFD."""
# Reported by D. Hughes on 2019.7.26
# the test file is corrupted but should not cause infinite loop
fname = private_file('gdk-pixbuf/bug784903-overfl... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_issue_infinite_loop():
| """Test infinite loop reading more than two tags of same code in IFD."""
# Reported by D. Hughes on 2019.7.26
# the test file is corrupted but should not cause infinite loop
fname = private_file('gdk-pixbuf/bug784903-overflow-dimensions.tiff')
with TiffFile(fname) as tif:
page = tif.pages[0]... | ):
imread(fname, key=0, pages=[1, 2])
with pytest.raises(TypeError):
with TiffFile(fname, pages=[1, 2]) as tif:
pass
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_issue_infinite_loop():
| 64 | 64 | 129 | 20 | 43 | bioturing/tifffile | tests/test_tifffile.py | Python | test_issue_infinite_loop | test_issue_infinite_loop | 483 | 492 | 483 | 484 | 609edbd3ee4f58bb7154b7493c993b21b8f65b55 | bigcode/the-stack | train |
2394f31cb3fdca0159dd836c | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_vips():
"""Test read 347x641 RGB, bigtiff, pyramid, tiled, produced by VIPS."""
fname = private_file('vips.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 4
assert len(tif.series) =... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_vips():
| """Test read 347x641 RGB, bigtiff, pyramid, tiled, produced by VIPS."""
fname = private_file('vips.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 4
assert len(tif.series) == 1
# assert page properties
page = tif.pages[0]
... |
assert page.tags['ImageDepth'].value == 14 # bogus
assert page.bitspersample == 16
assert page.samplesperpixel == 1
# assert series properties
series = tif.series[0]
assert series.shape == (14, 256, 256)
assert series.dtype == numpy.int16
assert series.a... | 123 | 123 | 411 | 19 | 104 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_vips | test_read_vips | 3,989 | 4,029 | 3,989 | 3,990 | bc0a26253d3ff995363ec922f3c728f6002c1125 | bigcode/the-stack | train |
a3a026b06ddc08c3e20326f3 | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_LARGE or SKIP_PYPY, reason=REASON)
def test_read_huge_ps5_memmap():
"""Test read 30000x30000 float32 contiguous."""
# TODO: segfault on pypy3.7-v7.3.5rc2-win64
fname = private_file('large/huge_ps5.tif')
with TiffFile(fname) as tif:
assert tif.byteorder ==... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_LARGE or SKIP_PYPY, reason=REASON)
def test_read_huge_ps5_memmap():
| """Test read 30000x30000 float32 contiguous."""
# TODO: segfault on pypy3.7-v7.3.5rc2-win64
fname = private_file('large/huge_ps5.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert len(tif.series) == 1
# assert page properties
... | )
assert data.flags['C_CONTIGUOUS']
assert data.shape == (512, 512, 3)
assert data.dtype == numpy.uint16
assert_array_equal(data[256, 256], (46259, 16706, 18504))
assert_aszarr_method(tif, data, series=0)
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE or SKIP_LARGE o... | 115 | 115 | 384 | 34 | 81 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_huge_ps5_memmap | test_read_huge_ps5_memmap | 5,355 | 5,388 | 5,355 | 5,356 | 231cde307106d0d02bb0fa957040eeeea4900245 | bigcode/the-stack | train |
59c6656119489fe1fc92d8af | train | function | def test_write_volumetric_tiled():
"""Test write tiled volume."""
data = random_data(numpy.uint8, (253, 64, 96))
with TempFileName('volumetric_tiled') as fname:
imwrite(fname, data, tile=(64, 64, 64))
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pa... | def test_write_volumetric_tiled():
| """Test write tiled volume."""
data = random_data(numpy.uint8, (253, 64, 96))
with TempFileName('volumetric_tiled') as fname:
imwrite(fname, data, tile=(64, 64, 64))
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pa... | assert_array_equal(
data[::3, ::3, ::3], tif.asarray(series=2, level=1)
)
assert_aszarr_method(tif, data[::3, ::3, ::3], series=2, level=1)
assert__str__(tif)
def test_write_volumetric_tiled():
| 73 | 73 | 244 | 9 | 64 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_volumetric_tiled | test_write_volumetric_tiled | 12,258 | 12,282 | 12,258 | 12,258 | 401fc5ccdf8f6aa6390eb6db76df1b58143b38bd | bigcode/the-stack | train |
3a6c1a76f7754e069757e18a | train | function | def assert_file_flags(tiff_file):
"""Access all flags of TiffFile."""
for flag in FILE_FLAGS:
getattr(tiff_file, flag)
| def assert_file_flags(tiff_file):
| """Access all flags of TiffFile."""
for flag in FILE_FLAGS:
getattr(tiff_file, flag)
| random numpy array."""
# TODO: use nd noise
if dtype == '?':
return numpy.random.rand(*shape) < 0.5
data = numpy.random.rand(*shape) * 255
data = data.astype(dtype)
return data
def assert_file_flags(tiff_file):
| 64 | 64 | 33 | 8 | 55 | bioturing/tifffile | tests/test_tifffile.py | Python | assert_file_flags | assert_file_flags | 313 | 316 | 313 | 313 | 6ba0e56c0dae48d4da488cc663c423531fae5071 | bigcode/the-stack | train |
6be467c5545b0750f86675c5 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_ycbcr_subsampling():
"""Test fail YCBCR with subsampling."""
fname = private_file('ycbcr_subsampling.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 2
page = tif.pages[0]
assert page.compression == NONE
... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_ycbcr_subsampling():
| """Test fail YCBCR with subsampling."""
fname = private_file('ycbcr_subsampling.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 2
page = tif.pages[0]
assert page.compression == NONE
assert page.photometric == YCBCR
assert page.planarconfig == CONTIG
... | .bitspersample == 8
assert page.samplesperpixel == 3
# assert data
with pytest.raises(NotImplementedError):
page.asarray()
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_ycbcr_subsampling():
| 64 | 64 | 168 | 22 | 42 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_ycbcr_subsampling | test_read_ycbcr_subsampling | 4,774 | 4,791 | 4,774 | 4,775 | 2d2a8fda45b19b7211c8cc93e7412f120f517123 | bigcode/the-stack | train |
ef32789acb21f89cf214c66d | train | function | def test_func_create_output():
"""Test create_output function."""
shape = (16, 17)
dtype = numpy.uint16
# None
a = create_output(None, shape, dtype)
assert_array_equal(a, numpy.zeros(shape, dtype))
# existing array
b = create_output(a, a.shape, a.dtype)
assert a is b.base
# 'memm... | def test_func_create_output():
| """Test create_output function."""
shape = (16, 17)
dtype = numpy.uint16
# None
a = create_output(None, shape, dtype)
assert_array_equal(a, numpy.zeros(shape, dtype))
# existing array
b = create_output(a, a.shape, a.dtype)
assert a is b.base
# 'memmap'
a = create_output('memm... | fname, data, photometric=RGB, description=comment, metadata=None
)
assert comment == tiffcomment(fname)
comment = 'changed comment'
tiffcomment(fname, comment)
assert comment == tiffcomment(fname)
assert_valid_tiff(fname)
def test_func_create_output():
| 64 | 64 | 190 | 6 | 58 | bioturing/tifffile | tests/test_tifffile.py | Python | test_func_create_output | test_func_create_output | 3,221 | 3,242 | 3,221 | 3,221 | a725f0d838fd0b3f0e842c3c00783aecf2a8a179 | bigcode/the-stack | train |
67910eadb2acf3e04addc2fe | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_sequence_glob_pattern():
"""Test TiffSequence with glob pattern without axes pattern."""
fname = private_file('TiffSequence/*.tif')
tifs = TiffSequence(fname, pattern=None)
assert len(tifs) == 10
assert tifs.shape == (10,)
... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_sequence_glob_pattern():
| """Test TiffSequence with glob pattern without axes pattern."""
fname = private_file('TiffSequence/*.tif')
tifs = TiffSequence(fname, pattern=None)
assert len(tifs) == 10
assert tifs.shape == (10,)
assert tifs.axes == 'I'
data = tifs.asarray()
assert isinstance(data, numpy.ndarray)
a... | , 9)
files = [BytesIO(), BytesIO()]
for buffer in files:
imwrite(buffer, data)
with pytest.raises(TypeError):
imread(files)
@pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_sequence_glob_pattern():
| 64 | 64 | 190 | 25 | 39 | bioturing/tifffile | tests/test_tifffile.py | Python | test_sequence_glob_pattern | test_sequence_glob_pattern | 14,033 | 14,049 | 14,033 | 14,034 | 35fbf57d82e7842b0d60608e85026711dfba8cad | bigcode/the-stack | train |
61c52708913d02b5a6246699 | train | function | @pytest.mark.skipif(SKIP_LARGE, reason=REASON)
def test_write_volumetric_striped_contig_rgb_empty():
"""Test write empty 6D array as contig RGB volumes."""
shape = (2, 3, 15, 63, 95, 3)
with TempFileName('volumetric_striped_contig_rgb_empty') as fname:
with TiffWriter(fname) as tif:
tif.... | @pytest.mark.skipif(SKIP_LARGE, reason=REASON)
def test_write_volumetric_striped_contig_rgb_empty():
| """Test write empty 6D array as contig RGB volumes."""
shape = (2, 3, 15, 63, 95, 3)
with TempFileName('volumetric_striped_contig_rgb_empty') as fname:
with TiffWriter(fname) as tif:
tif.write(
shape=shape,
dtype=numpy.uint8,
volumetric=Tru... | , image)
# assert iterating over series.pages
data = data.reshape(6, 15, 63, 95, 3)
for i, page in enumerate(series.pages):
image = page.asarray()
assert_array_equal(data[i], image)
assert_aszarr_method(page, image)
assert__... | 102 | 102 | 340 | 27 | 75 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_volumetric_striped_contig_rgb_empty | test_write_volumetric_striped_contig_rgb_empty | 12,571 | 12,606 | 12,571 | 12,572 | 6821c89763da52d47ab9c3ec51d1f0da095a9e32 | bigcode/the-stack | train |
b4eabdccf66f8c749236a524 | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_ome_samplesperpixel():
"""Test read OME image stack with SamplesPerPixel>1."""
# Reported by Grzegorz Bokota on 2019.1.30
fname = private_file('OME/test_samplesperpixel.ome.tif')
with TiffFile(fname) as tif:
assert tif... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_ome_samplesperpixel():
| """Test read OME image stack with SamplesPerPixel>1."""
# Reported by Grzegorz Bokota on 2019.1.30
fname = private_file('OME/test_samplesperpixel.ome.tif')
with TiffFile(fname) as tif:
assert tif.is_ome
assert tif.byteorder == '>'
assert len(tif.pages) == 6
assert len(tif... |
data = tif.asarray()
assert data.shape == (3, 720, 1280)
assert data.dtype == numpy.uint8
assert data[1, 158, 428] == 253
assert_aszarr_method(tif, data)
assert_aszarr_method(tif, data, chunkmode='page')
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE or SKIP... | 109 | 109 | 365 | 27 | 82 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_ome_samplesperpixel | test_read_ome_samplesperpixel | 7,755 | 7,786 | 7,755 | 7,756 | fb71546092206f7c73d1ae232d682578e99e2927 | bigcode/the-stack | train |
49f1d3c8c03f71d150849abf | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_12bit():
"""Test read 12 bit images."""
fname = private_file('12bit.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 1000
assert len(tif.series) == 1
# assert ... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_12bit():
| """Test read 12 bit images."""
fname = private_file('12bit.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 1000
assert len(tif.series) == 1
# assert page properties
page = tif.pages[0]
assert not page.is_contiguous
... |
data = tif.asarray(series=i)
assert isinstance(data, numpy.ndarray)
assert data.flags['C_CONTIGUOUS']
assert data.shape == shape
assert data.dtype == numpy.uint8
assert_aszarr_method(tif, data, series=i)
assert__str__(tif)
@pytest.mark... | 91 | 91 | 305 | 25 | 66 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_12bit | test_read_12bit | 4,667 | 4,696 | 4,667 | 4,668 | 9c61a8195bef33c3a6f980371227f01cd761f1e6 | bigcode/the-stack | train |
9a85a1378dc8f3f6079f5b87 | train | function | def random_data(dtype, shape):
"""Return random numpy array."""
# TODO: use nd noise
if dtype == '?':
return numpy.random.rand(*shape) < 0.5
data = numpy.random.rand(*shape) * 255
data = data.astype(dtype)
return data
| def random_data(dtype, shape):
| """Return random numpy array."""
# TODO: use nd noise
if dtype == '?':
return numpy.random.rand(*shape) < 0.5
data = numpy.random.rand(*shape) * 255
data = data.astype(dtype)
return data
| private test file(s)."""
return data_file(pathname, base, expand=expand)
def public_file(pathname, base=PUBLIC_DIR, expand=True):
"""Return path to public test file(s)."""
return data_file(pathname, base, expand=expand)
def random_data(dtype, shape):
| 64 | 64 | 66 | 7 | 57 | bioturing/tifffile | tests/test_tifffile.py | Python | random_data | random_data | 303 | 310 | 303 | 303 | 08aa3ed9beba63929c8062b70543fd47425b2594 | bigcode/the-stack | train |
45e44b96c33b604735088ba5 | train | function | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_write_roundtrip_bytesio():
"""Test write and read using BytesIO."""
pad = b'0' * 7
data = imread(public_file('tifffile/generic_series.tif'))
buf = BytesIO()
buf.write(pad)
imwrite(buf, data, photometric=RGB)
buf.write(pa... | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_write_roundtrip_bytesio():
| """Test write and read using BytesIO."""
pad = b'0' * 7
data = imread(public_file('tifffile/generic_series.tif'))
buf = BytesIO()
buf.write(pad)
imwrite(buf, data, photometric=RGB)
buf.write(pad)
buf.seek(len(pad))
assert_array_equal(imread(buf), data)
| =RGB)
fh.write(pad)
with open(fname, 'rb') as fh:
fh.seek(len(pad))
assert_array_equal(imread(fh), data)
@pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_write_roundtrip_bytesio():
| 64 | 64 | 112 | 26 | 38 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_roundtrip_bytesio | test_write_roundtrip_bytesio | 10,167 | 10,177 | 10,167 | 10,168 | 5bc78ac481ac5f774dff740b81f3b0895909c735 | bigcode/the-stack | train |
21bfc1fc4006c969d5ef57dc | train | function | def test_func_byteorder_compare():
"""Test byteorder_isnative function."""
assert byteorder_compare('<', '<')
assert byteorder_compare('>', '>')
assert byteorder_compare('=', '=')
assert byteorder_compare('|', '|')
assert byteorder_compare('>', '|')
assert byteorder_compare('<', '|')
ass... | def test_func_byteorder_compare():
| """Test byteorder_isnative function."""
assert byteorder_compare('<', '<')
assert byteorder_compare('>', '>')
assert byteorder_compare('=', '=')
assert byteorder_compare('|', '|')
assert byteorder_compare('>', '|')
assert byteorder_compare('<', '|')
assert byteorder_compare('|', '>')
... | .byteorder)
assert byteorder_isnative('=')
if sys.byteorder == 'little':
assert byteorder_isnative('<')
assert not byteorder_isnative('>')
else:
assert byteorder_isnative('>')
assert not byteorder_isnative('<')
def test_func_byteorder_compare():
| 64 | 64 | 136 | 7 | 57 | bioturing/tifffile | tests/test_tifffile.py | Python | test_func_byteorder_compare | test_func_byteorder_compare | 2,399 | 2,414 | 2,399 | 2,399 | f5118467163eb7f4776e094ac85a75e99b80a1a5 | bigcode/the-stack | train |
bbde2072ecd87cee374b618a | train | function | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_embed_tif_openfile_seek():
"""Test embedded TIFF from seeked file handle."""
with open(EMBED_NAME, 'rb') as fh:
fh.seek(EMBED_OFFSET)
with TiffFile(fh, size=EMBED_SIZE) as tif:
assert_embed_tif(tif)
| @pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_embed_tif_openfile_seek():
| """Test embedded TIFF from seeked file handle."""
with open(EMBED_NAME, 'rb') as fh:
fh.seek(EMBED_OFFSET)
with TiffFile(fh, size=EMBED_SIZE) as tif:
assert_embed_tif(tif)
| 'rb') as fh:
with TiffFile(fh, offset=EMBED_OFFSET, size=EMBED_SIZE) as tif:
assert_embed_tif(tif)
@pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_embed_tif_openfile_seek():
| 64 | 64 | 85 | 27 | 37 | bioturing/tifffile | tests/test_tifffile.py | Python | test_embed_tif_openfile_seek | test_embed_tif_openfile_seek | 13,951 | 13,957 | 13,951 | 13,952 | 53364be4fb7e0880839f677ba63766e9b04bdbe5 | bigcode/the-stack | train |
e9b5775ab90506caeecc5eea | train | function | def test_issue_imread_kwargs():
"""Test that is_flags are handled by imread."""
data = random_data(numpy.uint16, (5, 63, 95))
with TempFileName('issue_imread_kwargs') as fname:
with TiffWriter(fname) as tif:
for image in data:
tif.write(image) # create 5 series
a... | def test_issue_imread_kwargs():
| """Test that is_flags are handled by imread."""
data = random_data(numpy.uint16, (5, 63, 95))
with TempFileName('issue_imread_kwargs') as fname:
with TiffWriter(fname) as tif:
for image in data:
tif.write(image) # create 5 series
assert_valid_tiff(fname)
... | read(fname)
with TiffWriter(fname) as tif:
with pytest.warns(DeprecationWarning):
tif.save([[0]])
imread(fname)
# from tifffile import decodelzw
# from tifffile import decode_lzw
def test_issue_imread_kwargs():
| 64 | 64 | 139 | 7 | 56 | bioturing/tifffile | tests/test_tifffile.py | Python | test_issue_imread_kwargs | test_issue_imread_kwargs | 436 | 447 | 436 | 436 | 3bcc4857a570e267153bcd8b5277da9f12106642 | bigcode/the-stack | train |
eb0809617b09ae72f9a9a10b | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_lzw_ycbcr_subsampling():
"""Test fail LZW compression with subsampling."""
fname = private_file('lzw/lzw_ycbcr_subsampling.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
a... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_lzw_ycbcr_subsampling():
| """Test fail LZW compression with subsampling."""
fname = private_file('lzw/lzw_ycbcr_subsampling.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
assert page.compression == LZW
assert page.photometric == YCBCR
assert page.planarconfig... | image[4200, 2550, 3] == 255
assert_aszarr_method(tif, image)
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_lzw_ycbcr_subsampling():
| 64 | 64 | 180 | 29 | 35 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_lzw_ycbcr_subsampling | test_read_lzw_ycbcr_subsampling | 4,754 | 4,771 | 4,754 | 4,755 | d0a9e0966ef7fd17fe884ee38738f9b002e5b159 | bigcode/the-stack | train |
3f4ce5ca1695f25bd7f74ae5 | train | function | def test_write_compression_deflate_level():
"""Test write ZLIB compression with level."""
data = WRITE_DATA
with TempFileName('compression_deflate_level') as fname:
imwrite(fname, data, compression=(ADOBE_DEFLATE, 9), photometric=RGB)
assert_valid_tiff(fname)
with TiffFile(fname) as ... | def test_write_compression_deflate_level():
| """Test write ZLIB compression with level."""
data = WRITE_DATA
with TempFileName('compression_deflate_level') as fname:
imwrite(fname, data, compression=(ADOBE_DEFLATE, 9), photometric=RGB)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
... | assert page.rowsperstrip == 108
assert len(page.dataoffsets) == 9
image = tif.asarray()
assert_array_equal(data, image)
assert_aszarr_method(tif, image)
assert__str__(tif)
def test_write_compression_deflate_level():
| 64 | 64 | 201 | 9 | 55 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_compression_deflate_level | test_write_compression_deflate_level | 10,804 | 10,823 | 10,804 | 10,804 | 72cea6bbf38d28ca1d3cb8c00818fd975dec2217 | bigcode/the-stack | train |
dcff4c55f6e432d44739a829 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_tvips_tietz_16bit():
"""Test read TVIPS metadata."""
# file provided by Marco Oster on 10/26/2016
fname = private_file('tvips/test_tietz_16bit.tif')
with TiffFile(fname) as tif:
assert tif.is_tvips
tvips = tif.tvips_metadata
... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_tvips_tietz_16bit():
| """Test read TVIPS metadata."""
# file provided by Marco Oster on 10/26/2016
fname = private_file('tvips/test_tietz_16bit.tif')
with TiffFile(fname) as tif:
assert tif.is_tvips
tvips = tif.tvips_metadata
assert tvips['Magic'] == 0xAAAAAAAA
assert tvips['ImageFolder'] == '... | 31, 56, 103746)
assert_aszarr_method(page)
assert_aszarr_method(page, chunkmode='page')
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_tvips_tietz_16bit():
| 64 | 64 | 146 | 25 | 39 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_tvips_tietz_16bit | test_read_tvips_tietz_16bit | 9,020 | 9,031 | 9,020 | 9,021 | f7277aed78bb2c21e5d34edeff793a9ac8124805 | bigcode/the-stack | train |
437af61858a5c85426540f3a | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imagej_invalid_hyperstack():
"""Test read bad ImageJ hyperstack."""
# file claims to be a hyperstack but is not stored as such
# produced by OME writer
# reported by Taras Golota on 10/27/2016
fname = private_file('imagej/X0.ome.CTZ.perm... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imagej_invalid_hyperstack():
| """Test read bad ImageJ hyperstack."""
# file claims to be a hyperstack but is not stored as such
# produced by OME writer
# reported by Taras Golota on 10/27/2016
fname = private_file('imagej/X0.ome.CTZ.perm.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byte... | .shape == (173, 173)
assert data.dtype == numpy.dtype('>u2')
assert data[94, 34] == 1257
assert_aszarr_method(series, data)
assert_aszarr_method(series, data, chunkmode='page')
assert__str__(tif)
del data
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imag... | 94 | 94 | 316 | 23 | 70 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_imagej_invalid_hyperstack | test_read_imagej_invalid_hyperstack | 8,664 | 8,693 | 8,664 | 8,665 | 861d24cadfcf43cf78507ae2380da5db88e5612b | bigcode/the-stack | train |
a80da36aebda78446c84f3c7 | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_lzma():
"""Test read LZMA compression."""
# 512x512, uint8, lzma compression
fname = private_file('lzma.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert l... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_lzma():
| """Test read LZMA compression."""
# 512x512, uint8, lzma compression
fname = private_file('lzma.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert len(tif.series) == 1
# assert page properties
page = tif.pages[0]
... | 1024, 0] == 246
assert image[512, 1024, 1] == 245
assert image[512, 1024, 2] == 245
assert_decode_method(tif.pages[3], image)
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_lzma():
| 89 | 89 | 297 | 25 | 64 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_lzma | test_read_lzma | 4,999 | 5,029 | 4,999 | 5,000 | bec4ece957ad37bb2576935e98638b79ffc71e1a | bigcode/the-stack | train |
d277d75e1febfd5ba4241f3c | train | function | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_subifds_array():
"""Test read SubIFDs."""
fname = public_file('Tiff-Library-4J/IFD struct/SubIFDs array E.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
# make sure no pyramid was detected
assert len(tif.se... | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_subifds_array():
| """Test read SubIFDs."""
fname = public_file('Tiff-Library-4J/IFD struct/SubIFDs array E.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
# make sure no pyramid was detected
assert len(tif.series) == 5
assert tif.series[0].shape == (1500, 2000, 3)
assert... | ALMetadata>')
# assert series properties
series = tif.series[0]
assert series.shape == (3, 220, 279)
assert series.dtype == numpy.float64
assert series.axes == 'SYX'
# assert data
data = tif.asarray()
assert isinstance(data, numpy.ndarray)
assert d... | 169 | 169 | 566 | 21 | 148 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_subifds_array | test_read_subifds_array | 5,629 | 5,684 | 5,629 | 5,630 | ebdf0f9d4b86e7579242df8f3a8786984cee219e | bigcode/the-stack | train |
2b4382ab91550e0656ec845f | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imagej_fluorescentcells():
"""Test read ImageJ three channels."""
fname = private_file('imagej/FluorescentCells.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byteorder == '>'
assert len(tif.pages) == ... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imagej_fluorescentcells():
| """Test read ImageJ three channels."""
fname = private_file('imagej/FluorescentCells.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byteorder == '>'
assert len(tif.pages) == 3
assert len(tif.series) == 1
# assert page properties
page = tif.... | .asarray()
assert isinstance(data, numpy.ndarray)
assert data.shape == (56, 256, 256, 3)
assert data.dtype == numpy.uint8
assert tuple(data[55, 151, 112]) == (209, 8, 58)
assert_aszarr_method(series, data)
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON... | 101 | 101 | 337 | 24 | 77 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_imagej_fluorescentcells | test_read_imagej_fluorescentcells | 8,547 | 8,580 | 8,547 | 8,548 | c10b8c525867ae3b8669ffb3488fb6da4e73cf3c | bigcode/the-stack | train |
baf87cfd9e23ba56bd66e5eb | train | function | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_embed_mm_openfile():
"""Test embedded MicroManager TIFF from file handle."""
with open(EMBED_NAME, 'rb') as fh:
with TiffFile(fh, offset=EMBED_OFFSET1, size=EMBED_SIZE1) as tif:
assert_embed_micromanager(tif)
| @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_embed_mm_openfile():
| """Test embedded MicroManager TIFF from file handle."""
with open(EMBED_NAME, 'rb') as fh:
with TiffFile(fh, offset=EMBED_OFFSET1, size=EMBED_SIZE1) as tif:
assert_embed_micromanager(tif)
| MicroManager TIFF from file name."""
with TiffFile(EMBED_NAME, offset=EMBED_OFFSET1, size=EMBED_SIZE1) as tif:
assert_embed_micromanager(tif)
@pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_embed_mm_openfile():
| 64 | 64 | 80 | 20 | 44 | bioturing/tifffile | tests/test_tifffile.py | Python | test_embed_mm_openfile | test_embed_mm_openfile | 13,984 | 13,989 | 13,984 | 13,985 | 48aff56990f05429ed6c6002830962eb388ec809 | bigcode/the-stack | train |
d692971759f6f0544988fa7e | train | function | @pytest.mark.parametrize(
'axes, autoaxes, shape, storedshape, dimorder',
[
('YX', 'YX', (32, 32), (1, 1, 1, 32, 32, 1), 'XYCZT'),
('YXS', 'YXS', (32, 32, 1), (1, 1, 1, 32, 32, 1), 'XYCZT'),
('SYX', 'SYX', (1, 32, 32), (1, 1, 1, 32, 32, 1), 'XYCZT'),
('YXS', 'YXS', (32, 32, 3), (... | @pytest.mark.parametrize(
'axes, autoaxes, shape, storedshape, dimorder',
[
('YX', 'YX', (32, 32), (1, 1, 1, 32, 32, 1), 'XYCZT'),
('YXS', 'YXS', (32, 32, 1), (1, 1, 1, 32, 32, 1), 'XYCZT'),
('SYX', 'SYX', (1, 32, 32), (1, 1, 1, 32, 32, 1), 'XYCZT'),
('YXS', 'YXS', (32, 32, 3), (... | """Test OmeXml class."""
dtype = numpy.uint8
if not metadata and dimorder != 'XYCZT':
pytest.xfail('')
metadata = dict(axes=axes) if metadata else dict()
omexml = OmeXml()
omexml.addimage(dtype, shape, storedshape, **metadata)
if not SKIP_WIN:
assert '\n ' in str(omexml)
... | @pytest.mark.parametrize(
'axes, autoaxes, shape, storedshape, dimorder',
[
('YX', 'YX', (32, 32), (1, 1, 1, 32, 32, 1), 'XYCZT'),
('YXS', 'YXS', (32, 32, 1), (1, 1, 1, 32, 32, 1), 'XYCZT'),
('SYX', 'SYX', (1, 32, 32), (1, 1, 1, 32, 32, 1), 'XYCZT'),
('YXS', 'YXS', (32, 32, 3), (... | 756 | 256 | 961 | 756 | 0 | bioturing/tifffile | tests/test_tifffile.py | Python | test_class_omexml | test_class_omexml | 2,086 | 2,147 | 2,086 | 2,125 | f24354ab111c06c4af2271a752f013e5eda5aa27 | bigcode/the-stack | train |
3f45620f8467ca0b4cbbe124 | train | function | def test_write_append():
"""Test append to existing TIFF file."""
data = random_data(numpy.uint8, (21, 31))
with TempFileName('append') as fname:
with TiffWriter(fname) as tif:
pass
with TiffFile(fname) as tif:
assert len(tif.pages) == 0
assert__str__(tif)... | def test_write_append():
| """Test append to existing TIFF file."""
data = random_data(numpy.uint8, (21, 31))
with TempFileName('append') as fname:
with TiffWriter(fname) as tif:
pass
with TiffFile(fname) as tif:
assert len(tif.pages) == 0
assert__str__(tif)
with TiffWriter... | , 31))
with TempFileName('imwrite_append') as fname:
imwrite(fname, data, metadata=None)
for _ in range(3):
imwrite(fname, data, append=True, metadata=None)
a = imread(fname)
assert a.shape == (4, 21, 31)
assert_array_equal(a[3], data)
def test_write_append():
| 84 | 84 | 283 | 5 | 79 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_append | test_write_append | 10,068 | 10,100 | 10,068 | 10,068 | 5e7109e6ae31e6b5ae48e911d388a3070ccb7dc9 | bigcode/the-stack | train |
98d6efae59d5977b0c659e11 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imagej_bat_cochlea_volume():
"""Test read ImageJ 114 images, no frames, slices, channels specified."""
fname = private_file('imagej/bat-cochlea-volume.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byteorder =... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_imagej_bat_cochlea_volume():
| """Test read ImageJ 114 images, no frames, slices, channels specified."""
fname = private_file('imagej/bat-cochlea-volume.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byteorder == '>'
assert len(tif.pages) == 114
assert len(tif.series) == 1
# ass... | round(abs(data[443, 656] - 2203.040771484375), 7) == 0
assert_aszarr_method(series, data)
# don't squeeze
data = tif.asarray(squeeze=False)
assert data.shape == (1, 1, 1, 593, 1024, 1)
assert_aszarr_method(series, data, squeeze=False)
assert__str__(tif)
@pytest.mark.skip... | 120 | 120 | 403 | 25 | 95 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_imagej_bat_cochlea_volume | test_read_imagej_bat_cochlea_volume | 8,468 | 8,506 | 8,468 | 8,469 | 1e0a8dca036e62128e5d7514ad96a3a6d0bc845f | bigcode/the-stack | train |
f21930def7a3d07e9c45db44 | train | function | def test_write_tiled_contig():
"""Test write contig tiles."""
data = random_data(numpy.uint8, (219, 301, 3))
with TempFileName('tiled_contig') as fname:
imwrite(fname, data, tile=(96, 64), photometric=RGB)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(t... | def test_write_tiled_contig():
| """Test write contig tiles."""
data = random_data(numpy.uint8, (219, 301, 3))
with TempFileName('tiled_contig') as fname:
imwrite(fname, data, tile=(96, 64), photometric=RGB)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page... | width == 64
assert page.tilelength == 96
assert page.samplesperpixel == 4
image = tif.asarray()
assert_array_equal(data, image)
assert_aszarr_method(tif, image)
assert__str__(tif)
def test_write_tiled_contig():
| 65 | 65 | 217 | 8 | 57 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_tiled_contig | test_write_tiled_contig | 12,025 | 12,046 | 12,025 | 12,025 | 2f8a18869a203433fc453b079bdc61a72f80abef | bigcode/the-stack | train |
a9011b5f0569131b3a7db553 | train | function | def test_func_reshape_axes():
"""Test reshape_axes function."""
assert reshape_axes('YXS', (219, 301, 1), (219, 301, 1)) == 'YXS'
assert reshape_axes('YXS', (219, 301, 3), (219, 301, 3)) == 'YXS'
assert reshape_axes('YXS', (219, 301, 1), (219, 301)) == 'YX'
assert reshape_axes('YXS', (219, 301, 1), ... | def test_func_reshape_axes():
| """Test reshape_axes function."""
assert reshape_axes('YXS', (219, 301, 1), (219, 301, 1)) == 'YXS'
assert reshape_axes('YXS', (219, 301, 3), (219, 301, 3)) == 'YXS'
assert reshape_axes('YXS', (219, 301, 1), (219, 301)) == 'YX'
assert reshape_axes('YXS', (219, 301, 1), (219, 1, 1, 301, 1)) == 'YQQXS... | 2, 16, 2, 2),
[
(0, 0, 0, 0, 0),
(2, 0, 0, 1, 0),
(23, 0, 15, 1, 1),
(23, 1, 15, 1, 0),
],
# (1, 0, 97, 1, 1),
)
def test_func_reshape_axes():
| 105 | 105 | 351 | 7 | 98 | bioturing/tifffile | tests/test_tifffile.py | Python | test_func_reshape_axes | test_func_reshape_axes | 2,519 | 2,535 | 2,519 | 2,519 | 180cb7c0fc46784c7797d82566cecc3f16aeeb0b | bigcode/the-stack | train |
63886c7276713052a255972c | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_ome_multi_image_nouuid():
"""Test read single-file, multi-image OME without UUID."""
fname = private_file(
'OMETIFF.jl/singles/181003_multi_pos_time_course_1_MMStack.ome.tif'
)
with TiffFile(fname) as tif:
assert tif.is_ome
... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_ome_multi_image_nouuid():
| """Test read single-file, multi-image OME without UUID."""
fname = private_file(
'OMETIFF.jl/singles/181003_multi_pos_time_course_1_MMStack.ome.tif'
)
with TiffFile(fname) as tif:
assert tif.is_ome
assert tif.byteorder == '<'
assert len(tif.pages) == 20
assert len... | assert series.shape == shape
assert series.dtype == numpy.uint8
assert series.axes == axes
assert not series.is_multifile
# assert data
data = tif.asarray(series=i)
assert isinstance(data, numpy.ndarray)
assert data.shape ==... | 111 | 111 | 371 | 24 | 87 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_ome_multi_image_nouuid | test_read_ome_multi_image_nouuid | 7,547 | 7,583 | 7,547 | 7,548 | 1ed2eff205e0b924a77869176712d22bf2a217fc | bigcode/the-stack | train |
7bb11ace72edf08f96f65e53 | train | function | def test_class_omexml_multiimage():
"""Test OmeXml class with multiple images."""
omexml = OmeXml(description='multiimage')
omexml.addimage(
numpy.uint8, (32, 32, 3), (1, 1, 1, 32, 32, 3), name='preview'
)
omexml.addimage(
numpy.float32, (4, 256, 256), (4, 1, 1, 256, 256, 1), name='1... | def test_class_omexml_multiimage():
| """Test OmeXml class with multiple images."""
omexml = OmeXml(description='multiimage')
omexml.addimage(
numpy.uint8, (32, 32, 3), (1, 1, 1, 32, 32, 3), name='preview'
)
omexml.addimage(
numpy.float32, (4, 256, 256), (4, 1, 1, 256, 256, 1), name='1'
)
omexml.addimage('bool', ... | assert 'TheC="0" TheZ="2" TheT="0" PositionZ="4.0"' in xml
if SKIP_PYPY:
pytest.xfail('lxml bug?')
assert_valid_omexml(xml)
assert '\n ' in str(omexml)
def test_class_omexml_multiimage():
| 77 | 77 | 258 | 10 | 67 | bioturing/tifffile | tests/test_tifffile.py | Python | test_class_omexml_multiimage | test_class_omexml_multiimage | 2,270 | 2,285 | 2,270 | 2,270 | cc7a8521bb07404c5483b136dfd620b557332f63 | bigcode/the-stack | train |
3a6b62495a039931a50e10a7 | train | function | def test_write_tiled():
"""Test write tiled."""
data = random_data(numpy.uint16, (219, 301))
with TempFileName('tiled') as fname:
imwrite(fname, data, tile=(96, 64))
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pa... | def test_write_tiled():
| """Test write tiled."""
data = random_data(numpy.uint16, (219, 301))
with TempFileName('tiled') as fname:
imwrite(fname, data, tile=(96, 64))
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
asser... | .tilewidth == 64
assert page.tilelength == 96
assert page.samplesperpixel == 3
image = tif.asarray()
assert_array_equal(data, image)
assert_aszarr_method(tif, image)
assert__str__(tif)
def test_write_tiled():
| 64 | 64 | 203 | 6 | 58 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_tiled | test_write_tiled | 11,974 | 11,995 | 11,974 | 11,974 | 96278b02b2abefe229bdd2ed03fe1bc3f95d234b | bigcode/the-stack | train |
0efc660060a123c50b6cdc1d | train | function | @pytest.mark.skipif(SKIP_ZARR, reason=REASON)
def test_write_numcodecs():
"""Test write zarr with numcodecs.Tiff."""
from tifffile import numcodecs
data = numpy.arange(256 * 256 * 3, dtype=numpy.uint16).reshape(256, 256, 3)
numcodecs.register_codec()
compressor = numcodecs.Tiff(
bigtiff=Tru... | @pytest.mark.skipif(SKIP_ZARR, reason=REASON)
def test_write_numcodecs():
| """Test write zarr with numcodecs.Tiff."""
from tifffile import numcodecs
data = numpy.arange(256 * 256 * 3, dtype=numpy.uint16).reshape(256, 256, 3)
numcodecs.register_codec()
compressor = numcodecs.Tiff(
bigtiff=True,
photometric=MINISBLACK,
planarconfig=CONTIG,
co... | '
)
from imagecodecs.numcodecs import register_codecs
register_codecs()
za = zarr.open(mapper, mode='r')
assert_array_equal(za[:], data)
@pytest.mark.skipif(SKIP_ZARR, reason=REASON)
def test_write_numcodecs():
| 65 | 65 | 217 | 21 | 44 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_numcodecs | test_write_numcodecs | 13,019 | 13,043 | 13,019 | 13,020 | 6261f20804e8b17c26b9ff102e621aeb2b643eb4 | bigcode/the-stack | train |
fe6fed232883f5035c16d3d1 | train | function | def assert_fsspec(url, data, target_protocol='http'):
"""Assert fsspec ReferenceFileSystem from local http server."""
mapper = fsspec.get_mapper(
'reference://', fo=url, target_protocol=target_protocol
)
zobj = zarr.open(mapper, mode='r')
if isinstance(zobj, zarr.Group):
assert_array... | def assert_fsspec(url, data, target_protocol='http'):
| """Assert fsspec ReferenceFileSystem from local http server."""
mapper = fsspec.get_mapper(
'reference://', fo=url, target_protocol=target_protocol
)
zobj = zarr.open(mapper, mode='r')
if isinstance(zobj, zarr.Group):
assert_array_equal(zobj[0][:], data)
assert_array_equal(zo... | range(105), series=2).reshape(data1.shape)
)
assert_array_equal(
data1[0],
imread(fname, key=slice(107, 122)).reshape(data1[0].shape),
)
def assert_fsspec(url, data, target_protocol='http'):
| 64 | 64 | 138 | 14 | 50 | bioturing/tifffile | tests/test_tifffile.py | Python | assert_fsspec | assert_fsspec | 12,859 | 12,870 | 12,859 | 12,859 | 6d4223876287b1f74a8df7fcba4804fe66be7cdf | bigcode/the-stack | train |
39250a5aca2607666fa1b39b | train | function | def test_write_imagej_append():
"""Test write ImageJ file consecutively."""
data = numpy.empty((256, 1, 256, 256), dtype=numpy.uint8)
data[:] = numpy.arange(256, dtype=numpy.uint8).reshape(-1, 1, 1, 1)
with TempFileName('imagej_append') as fname:
with TiffWriter(fname, imagej=True) as tif:
... | def test_write_imagej_append():
| """Test write ImageJ file consecutively."""
data = numpy.empty((256, 1, 256, 256), dtype=numpy.uint8)
data[:] = numpy.arange(256, dtype=numpy.uint8).reshape(-1, 1, 1, 1)
with TempFileName('imagej_append') as fname:
with TiffWriter(fname, imagej=True) as tif:
for image in data:
... |
image = tif.asarray(out='memmap')
assert_array_equal(data.squeeze(), image.squeeze())
del image
# assert iterating over series.pages
data = data.reshape(210, 49, 61, 3)
for i, page in enumerate(series.pages):
image = page.asarray()... | 102 | 102 | 342 | 7 | 95 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_imagej_append | test_write_imagej_append | 13,306 | 13,341 | 13,306 | 13,306 | 079169f6fa3eac31b56de7287165d29be5e83710 | bigcode/the-stack | train |
badfd9b030aa8b7be69ea8e0 | train | function | def test_write_extratags():
"""Test write extratags."""
data = random_data(numpy.uint8, (2, 219, 301))
description = 'Created by TestTiffWriter\nLorem ipsum dolor...'
pagename = 'Page name'
extratags = [
(270, 's', 0, description, True),
('PageName', 's', 0, pagename, False),
... | def test_write_extratags():
| """Test write extratags."""
data = random_data(numpy.uint8, (2, 219, 301))
description = 'Created by TestTiffWriter\nLorem ipsum dolor...'
pagename = 'Page name'
extratags = [
(270, 's', 0, description, True),
('PageName', 's', 0, pagename, False),
(50001, 'b', 1, b'1', True)... | FileName('write_bytes_str') as fname:
imwrite(
fname,
data,
description=micron,
software=micron,
extratags=[(50001, 's', 8, micron, True)],
)
with TiffFile(fname) as tif:
page = tif.pages[0]
assert page.descripti... | 123 | 123 | 413 | 7 | 116 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_extratags | test_write_extratags | 10,279 | 10,308 | 10,279 | 10,279 | b30ef0984314961947e2e6fbb368a29eee0c24d0 | bigcode/the-stack | train |
dd58fbe3a7dd5ff220070902 | train | function | def test_write_contig_extrasample():
"""Test write grayscale with contig extrasamples."""
data = random_data(numpy.uint8, (219, 301, 2))
with TempFileName('contig_extrasample') as fname:
imwrite(fname, data, planarconfig=CONTIG)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
... | def test_write_contig_extrasample():
| """Test write grayscale with contig extrasamples."""
data = random_data(numpy.uint8, (219, 301, 2))
with TempFileName('contig_extrasample') as fname:
imwrite(fname, data, planarconfig=CONTIG)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1... | 301
assert page.imagelength == 219
assert page.samplesperpixel == 1
image = tif.asarray()
assert_array_equal(data, image)
assert_aszarr_method(tif, image)
assert__str__(tif)
def test_write_contig_extrasample():
| 64 | 64 | 190 | 9 | 55 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_contig_extrasample | test_write_contig_extrasample | 11,728 | 11,746 | 11,728 | 11,728 | e9d06784410de24a3aafee1f701fb87aeeebd3fd | bigcode/the-stack | train |
1210e7c731ea3f30985576eb | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_scanimage_metadata():
"""Test read ScanImage metadata."""
fname = private_file('ScanImage/TS_UnitTestImage_BigTIFF.tif')
with open(fname, 'rb') as fh:
frame_data, roi_data, version = read_scanimage_metadata(fh)
assert version == 3
... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_scanimage_metadata():
| """Test read ScanImage metadata."""
fname = private_file('ScanImage/TS_UnitTestImage_BigTIFF.tif')
with open(fname, 'rb') as fh:
frame_data, roi_data, version = read_scanimage_metadata(fh)
assert version == 3
assert frame_data['SI.hChannels.channelType'] == ['stripe', 'stripe']
assert ro... | third series
series = tif.series[2]
assert series.shape == (4, 8, 946, 993)
assert_aszarr_method(series)
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_scanimage_metadata():
| 64 | 64 | 122 | 20 | 44 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_scanimage_metadata | test_read_scanimage_metadata | 6,891 | 6,899 | 6,891 | 6,892 | 941067552c1c4fe248e0f7161428541df8b9e222 | bigcode/the-stack | train |
8a61e96c78ed5907fd49d4ea | train | function | @pytest.mark.skipif(
SKIP_PRIVATE or SKIP_CODECS or not imagecodecs.JPEG, reason=REASON
)
@pytest.mark.xfail # TODO: should pass once strip generators are supported
def test_write_geotiff_copy():
"""Test write a copy of striped, compressed GeoTIFF."""
def strips(page):
# return iterator over compr... | @pytest.mark.skipif(
SKIP_PRIVATE or SKIP_CODECS or not imagecodecs.JPEG, reason=REASON
)
@pytest.mark.xfail # TODO: should pass once strip generators are supported
def test_write_geotiff_copy():
| """Test write a copy of striped, compressed GeoTIFF."""
def strips(page):
# return iterator over compressed tiles in page
assert not page.is_tiled
fh = page.parent.filehandle
for offset, bytecount in zip(page.dataoffsets, page.databytecounts):
fh.seek(offset)
... | 1
assert len(tif.pages[0].pages) == 2
assert 'InterColorProfile' in tif.pages[0].tags
assert tif.pages[0].tags['ImageDepth'].value == 1
levels_ = tif.series[0].levels
assert len(levels_) == len(levels)
for level, level_ in ... | 172 | 172 | 574 | 52 | 120 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_geotiff_copy | test_write_geotiff_copy | 13,731 | 13,796 | 13,731 | 13,735 | 12e3ec77031b8d2e46b4508347a08160f639cb7d | bigcode/the-stack | train |
7fb29dfb9f8d69c997585a63 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_write_imagej_ijmetadata_tag():
"""Test write and read IJMetadata tag."""
fname = private_file('imagej/IJMetadata.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byteorder == '>'
assert len(tif.pages) == 3
... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_write_imagej_ijmetadata_tag():
| """Test write and read IJMetadata tag."""
fname = private_file('imagej/IJMetadata.tif')
with TiffFile(fname) as tif:
assert tif.is_imagej
assert tif.byteorder == '>'
assert len(tif.pages) == 3
assert len(tif.series) == 1
data = tif.asarray()
ijmetadata = tif.p... | def test_write_imagej_metadata():
"""Test write additional ImageJ metadata."""
data = numpy.empty((4, 256, 256), dtype=numpy.uint16)
data[:] = numpy.arange(256 * 256, dtype=numpy.uint16).reshape(1, 256, 256)
with TempFileName('imagej_metadata') as fname:
imwrite(fname, data, imagej=True, metadat... | 174 | 174 | 583 | 23 | 151 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_imagej_ijmetadata_tag | test_write_imagej_ijmetadata_tag | 13,139 | 13,197 | 13,139 | 13,140 | 90d947e713efffc41318e42b8df38aaac3543238 | bigcode/the-stack | train |
f72d37528788fd3313d8cc7d | train | function | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
@pytest.mark.parametrize('tile', [False, True])
@pytest.mark.parametrize(
'codec',
[
'deflate',
'lzma',
'packbits',
'zstd', # TODO: 'lzw'
'webp',
'png',
'jpeg',
'jpegxl',
'jpeg... | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
@pytest.mark.parametrize('tile', [False, True])
@pytest.mark.parametrize(
'codec',
[
'deflate',
'lzma',
'packbits',
'zstd', # TODO: 'lzw'
'webp',
'png',
'jpeg',
'jpegxl',
'jpeg... | """Test write various compression."""
if mode in ('gray', 'planar') and codec == 'webp':
pytest.xfail("WebP doesn't support grayscale or planar mode")
level = {'webp': -1, 'jpeg': 99}.get(codec, None)
tile = (16, 16) if tile else None
data = numpy.load(public_file('tifffile/rgb.u1.npy'))
... | ['C_CONTIGUOUS']
assert_array_equal(data.squeeze(), image.squeeze())
if not SKIP_ZARR:
with imread(fname, aszarr=True) as store:
data = zarr.open(store, mode='r')
assert_array_equal(data, image)
assert shape == image.shape
... | 213 | 213 | 711 | 126 | 87 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_codecs | test_write_codecs | 9,597 | 9,677 | 9,597 | 9,615 | abf4f39e574e077f108d2157824d51a62717bc3e | bigcode/the-stack | train |
29a9df55a877f83df292b1c9 | train | function | def test_filehandle_write_bytesio_offset():
"""Test write to FileHandle from BytesIO with offset."""
pad = b'abcd'
value = b'123456789'
buf = BytesIO()
buf.write(pad)
with FileHandle(buf) as fh:
fh.write(value)
buf.write(pad)
# assert buffer
buf.seek(len(pad))
assert buf.... | def test_filehandle_write_bytesio_offset():
| """Test write to FileHandle from BytesIO with offset."""
pad = b'abcd'
value = b'123456789'
buf = BytesIO()
buf.write(pad)
with FileHandle(buf) as fh:
fh.write(value)
buf.write(pad)
# assert buffer
buf.seek(len(pad))
assert buf.read(len(value)) == value
buf.seek(2)
... | ():
"""Test write to FileHandle from BytesIO."""
value = b'123456789'
buf = BytesIO()
with FileHandle(buf) as fh:
fh.write(value)
buf.seek(0)
assert buf.read() == value
def test_filehandle_write_bytesio_offset():
| 64 | 64 | 126 | 9 | 54 | bioturing/tifffile | tests/test_tifffile.py | Python | test_filehandle_write_bytesio_offset | test_filehandle_write_bytesio_offset | 3,432 | 3,446 | 3,432 | 3,432 | aa326a85f26a99214f746d1c2b3b8c1765369566 | bigcode/the-stack | train |
55b3c4dd11c1ea208a5f824a | train | function | def test_issue_pathlib():
"""Test support for pathlib.Path."""
data = random_data(numpy.uint16, (219, 301))
with TempFileName('pathlib') as fname:
fname = pathlib.Path(fname)
assert isinstance(fname, os.PathLike)
# imwrite
imwrite(fname, data)
# imread
im = im... | def test_issue_pathlib():
| """Test support for pathlib.Path."""
data = random_data(numpy.uint16, (219, 301))
with TempFileName('pathlib') as fname:
fname = pathlib.Path(fname)
assert isinstance(fname, os.PathLike)
# imwrite
imwrite(fname, data)
# imread
im = imread(fname)
assert... | /issues/24
data = numpy.asarray(random_data(numpy.uint8, (31, 33)), order='F')
with TempFileName('fcontiguous') as fname:
imwrite(fname, data, compression=ADOBE_DEFLATE)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
assert_array_e... | 107 | 107 | 359 | 6 | 101 | bioturing/tifffile | tests/test_tifffile.py | Python | test_issue_pathlib | test_issue_pathlib | 990 | 1,033 | 990 | 990 | 92b6d7e011c601898a84d70937057c517f9644dc | bigcode/the-stack | train |
7779c57161602240323f4893 | train | function | @pytest.mark.skipif(
SKIP_PRIVATE or SKIP_CODECS or not imagecodecs.JPEG, reason=REASON
)
def test_read_philips():
"""Test read Philips DP pyramid."""
# https://camelyon17.grand-challenge.org/Data/
fname = private_file('PhilipsDP/test_001.tif')
with TiffFile(fname) as tif:
assert len(tif.ser... | @pytest.mark.skipif(
SKIP_PRIVATE or SKIP_CODECS or not imagecodecs.JPEG, reason=REASON
)
def test_read_philips():
| """Test read Philips DP pyramid."""
# https://camelyon17.grand-challenge.org/Data/
fname = private_file('PhilipsDP/test_001.tif')
with TiffFile(fname) as tif:
assert len(tif.series) == 1
assert len(tif.pages) == 9
assert tif.is_philips
assert tif.philips_metadata.endswith... | .shape == (350, 467, 3)
assert image.dtype == numpy.uint8
assert image[300, 400, 1] == 48
assert_aszarr_method(tif, image, series=1)
assert_aszarr_method(tif, image, series=1, chunkmode='page')
assert__str__(tif)
@pytest.mark.skipif(
SKIP_PRIVATE or SKIP_CODECS or not imageco... | 114 | 114 | 382 | 35 | 79 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_philips | test_read_philips | 9,203 | 9,236 | 9,203 | 9,206 | f7358be0031fe6a82c18de4368dd7bb5cfd6d266 | bigcode/the-stack | train |
239df6bfed62ed09d8a97f78 | train | function | def test_issue_deprecated_import():
"""Test deprecated functions can still be imported."""
from tifffile import imsave # noqa
with TempFileName('issue_deprecated_import') as fname:
with pytest.warns(DeprecationWarning):
imsave(fname, [[0]])
imread(fname)
with TiffWriter... | def test_issue_deprecated_import():
| """Test deprecated functions can still be imported."""
from tifffile import imsave # noqa
with TempFileName('issue_deprecated_import') as fname:
with pytest.warns(DeprecationWarning):
imsave(fname, [[0]])
imread(fname)
with TiffWriter(fname) as tif:
with pyt... | _IMPORTED
def test_issue_version_mismatch():
"""Test 'tifffile.__version__' matches docstrings."""
ver = ':Version: ' + tifffile.__version__
assert ver in __doc__
assert ver in tifffile.__doc__
def test_issue_deprecated_import():
| 63 | 64 | 99 | 7 | 56 | bioturing/tifffile | tests/test_tifffile.py | Python | test_issue_deprecated_import | test_issue_deprecated_import | 419 | 430 | 419 | 419 | e89f64bdbab5dbd144521d885532b53b078d14f4 | bigcode/the-stack | train |
30430468e325bd7d666999b8 | train | function | def test_func_pformat_hexdump():
"""Test pformat function with unprintable bytes."""
value = binascii.unhexlify(
'49492a00080000000e00fe0004000100'
'00000000000000010400010000000001'
'00000101040001000000000100000201'
'03000100000020000000030103000100'
)
assert pformat(v... | def test_func_pformat_hexdump():
| """Test pformat function with unprintable bytes."""
value = binascii.unhexlify(
'49492a00080000000e00fe0004000100'
'00000000000000010400010000000001'
'00000101040001000000000100000201'
'03000100000020000000030103000100'
)
assert pformat(value, height=1, width=60) == (
... | height=1, width=60) == (
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX'
)
assert (
pformat(value, height=8, width=60)
== r"""
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWX
""".strip()
)
# YZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
def test_func_pformat_he... | 94 | 95 | 318 | 9 | 85 | bioturing/tifffile | tests/test_tifffile.py | Python | test_func_pformat_hexdump | test_func_pformat_hexdump | 3,033 | 3,054 | 3,033 | 3,033 | d4725a56ffa266a46ef296ba551227f9db9bbc6e | bigcode/the-stack | train |
46f24d1d648167f8c0b04380 | train | function | @pytest.mark.skipif(
SKIP_PRIVATE or SKIP_LARGE or SKIP_CODECS or SKIP_ZARR, reason=REASON
)
@pytest.mark.parametrize('version', [1]) # 0,
def test_write_fsspec_sequence(version):
"""Test write fsspec for multi-file sequence."""
# https://bbbc.broadinstitute.org/BBBC006
categories = {'p': {chr(i + 97):... | @pytest.mark.skipif(
SKIP_PRIVATE or SKIP_LARGE or SKIP_CODECS or SKIP_ZARR, reason=REASON
)
@pytest.mark.parametrize('version', [1]) # 0,
def test_write_fsspec_sequence(version):
| """Test write fsspec for multi-file sequence."""
# https://bbbc.broadinstitute.org/BBBC006
categories = {'p': {chr(i + 97): i for i in range(25)}}
ptrn = r'(?:_(z)_(\d+)).*_(?P<p>[a-z])(?P<a>\d+)(?:_(s)(\d))(?:_(w)(\d))'
fnames = private_file('BBBC/BBBC006_v1_images_z_00/*.tif')
fnames += privat... | sspec(
URL + filename + f'.v{version}.s4.json', data1
)
if register_codecs is not None:
register_codecs('imagecodecs_jpeg', verbose=False)
assert_fsspec(
URL + filename + f'.v{version}.s4.... | 132 | 132 | 441 | 54 | 78 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_fsspec_sequence | test_write_fsspec_sequence | 12,976 | 13,016 | 12,976 | 12,980 | d701a0cd33782c8fe00284c8bad1e26e9c34929b | bigcode/the-stack | train |
0f225e51f9d9b6c5f8203362 | train | function | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_gimp_f2():
"""Test read float16 with horizontal predictor by GIMP."""
fname = public_file('tifffile/gimp_f2.tiff')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
assert page.compression == ADOB... | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_gimp_f2():
| """Test read float16 with horizontal predictor by GIMP."""
fname = public_file('tifffile/gimp_f2.tiff')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
assert page.compression == ADOBE_DEFLATE
assert page.photometric == RGB
assert page.pred... | 110], (0.35565534, 0.26402164, 0.6280674)
)
assert_aszarr_method(tif, image)
assert__str__(tif)
@pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_gimp_f2():
| 66 | 66 | 220 | 21 | 45 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_gimp_f2 | test_read_gimp_f2 | 3,887 | 3,907 | 3,887 | 3,888 | 03830ca49c51b030da2d0d2d0dd1254357990de5 | bigcode/the-stack | train |
33639f8d7769f1743f892812 | train | function | def test_issue_omexml_micron():
"""Test OME-TIFF can be created with micron character in XML."""
# https://forum.image.sc/t/micro-character-in-omexml-from-python/53578/4
with TempFileName('issue_omexml_micron', ext='.ome.tif') as fname:
imwrite(
fname,
[[0]],
met... | def test_issue_omexml_micron():
| """Test OME-TIFF can be created with micron character in XML."""
# https://forum.image.sc/t/micro-character-in-omexml-from-python/53578/4
with TempFileName('issue_omexml_micron', ext='.ome.tif') as fname:
imwrite(
fname,
[[0]],
metadata={'PhysicalSizeX': 1.0, 'Ph... | .824413635355, 7411.824413635355))
with TiffFile(fname) as tif:
assert tif.pages[0].tags['XResolution'].value == (
4294967295,
579475,
)
def test_issue_omexml_micron():
| 64 | 64 | 155 | 10 | 54 | bioturing/tifffile | tests/test_tifffile.py | Python | test_issue_omexml_micron | test_issue_omexml_micron | 1,339 | 1,354 | 1,339 | 1,339 | ec4e2744db39df360b9e884aed7fdf5e74106b23 | bigcode/the-stack | train |
44ee5264675b8049b8c6d10e | train | function | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_read_quad_lzw():
"""Test read 384x512 RGB uint8 old style LZW."""
fname = public_file('libtiff/quad-lzw-compat.tiff')
with TiffFile(fname) as tif:
assert tif.byteorder == '>'
assert len(tif.pages) == 1
assert len... | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_read_quad_lzw():
| """Test read 384x512 RGB uint8 old style LZW."""
fname = public_file('libtiff/quad-lzw-compat.tiff')
with TiffFile(fname) as tif:
assert tif.byteorder == '>'
assert len(tif.pages) == 1
assert len(tif.series) == 1
# assert page properties
page = tif.pages[0]
as... | assert data.flags['C_CONTIGUOUS']
assert data.shape == (192, 256, 3)
assert data.dtype == numpy.uint16
assert tuple(data[100, 140, :]) == (48895, 65279, 48895)
assert__str__(tif)
@pytest.mark.skipif(SKIP_PUBLIC or SKIP_CODECS, reason=REASON)
def test_read_quad_lzw():
| 92 | 92 | 309 | 25 | 67 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_quad_lzw | test_read_quad_lzw | 4,210 | 4,239 | 4,210 | 4,211 | 86db9d9ab1db494c4719310f0c658374f626fdbe | bigcode/the-stack | train |
3bf520abe51603f2ff8fe71e | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_lsm_earpax2isl11():
"""Test read LSM: TZCYX (1, 19, 3, 512, 512) uint8, RGB, LZW."""
fname = private_file('lsm/earpax2isl11.lzw.lsm')
with TiffFile(fname) as tif:
assert tif.is_lsm
assert tif.byteorder == '<'
... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_lsm_earpax2isl11():
| """Test read LSM: TZCYX (1, 19, 3, 512, 512) uint8, RGB, LZW."""
fname = private_file('lsm/earpax2isl11.lzw.lsm')
with TiffFile(fname) as tif:
assert tif.is_lsm
assert tif.byteorder == '<'
assert len(tif.pages) == 38
assert len(tif.series) == 2
# assert page propertie... | Time'] == 19
assert tags['DimensionChannels'] == 2
# assert lsm_scan_info tags
tags = tif.lsm_metadata['ScanInformation']
assert tags['ScanMode'] == 'Stack'
assert tags['User'] == 'zjfhe'
assert len(tags['Tracks']) == 3
assert len(tags['Tracks'][0]['DataChannels']... | 244 | 244 | 815 | 31 | 213 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_lsm_earpax2isl11 | test_read_lsm_earpax2isl11 | 6,038 | 6,109 | 6,038 | 6,039 | 77134f85abd7361b0e89f1695153777c9ef85027 | bigcode/the-stack | train |
6b631a27b9204de8f601726b | train | function | @pytest.mark.skipif(
SKIP_PUBLIC or SKIP_CODECS or not imagecodecs.JPEG12, reason=REASON
)
def test_read_jpeg12_mandril():
"""Test read JPEG 12-bit compression."""
# JPEG 12-bit
fname = private_file('jpeg/jpeg12_mandril.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
pa... | @pytest.mark.skipif(
SKIP_PUBLIC or SKIP_CODECS or not imagecodecs.JPEG12, reason=REASON
)
def test_read_jpeg12_mandril():
| """Test read JPEG 12-bit compression."""
# JPEG 12-bit
fname = private_file('jpeg/jpeg12_mandril.tif')
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
page = tif.pages[0]
assert page.compression == JPEG
assert page.photometric == YCBCR
assert page.imagewid... | == (79, 230, 222, 77)
assert_aszarr_method(tif, data)
# assert_decode_method(page)
assert__str__(tif)
@pytest.mark.skipif(
SKIP_PUBLIC or SKIP_CODECS or not imagecodecs.JPEG12, reason=REASON
)
def test_read_jpeg12_mandril():
| 78 | 78 | 263 | 39 | 39 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_jpeg12_mandril | test_read_jpeg12_mandril | 4,878 | 4,902 | 4,878 | 4,881 | e3e75c1323c7248af5dabf9e44525ea23bd4f73a | bigcode/the-stack | train |
a484f2b627b9ebd8f721c941 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_pilatus_gibuf2():
"""Test read Pilatus."""
fname = private_file('TvxPilatus/GIbuf2_A9_18_001_0009.tiff')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert tif.is_pilatus
# ... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_pilatus_gibuf2():
| """Test read Pilatus."""
fname = private_file('TvxPilatus/GIbuf2_A9_18_001_0009.tiff')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert tif.is_pilatus
# assert page properties
page = tif.pages[0]
assert page.imagewidth... | 07
assert attr['Silicon'] == 0.000320
assert_aszarr_method(page)
assert_aszarr_method(page, chunkmode='page')
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_pilatus_gibuf2():
| 69 | 69 | 233 | 24 | 45 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_pilatus_gibuf2 | test_read_pilatus_gibuf2 | 8,963 | 8,983 | 8,963 | 8,964 | fe93ddbd26fd358b57aa0dbf62909af82a9f09b6 | bigcode/the-stack | train |
6f5894ee7a85792c49a7d580 | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_write_cfa():
"""Test write uncompressed CFA image."""
# TODO: write a valid TIFF/EP file
data = imread(
private_file('DNG/cinemadng/M14-1451_000085_cDNG_uncompressed.dng')
)
extratags = [
(271, 's', 4, 'Make', F... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_write_cfa():
| """Test write uncompressed CFA image."""
# TODO: write a valid TIFF/EP file
data = imread(
private_file('DNG/cinemadng/M14-1451_000085_cDNG_uncompressed.dng')
)
extratags = [
(271, 's', 4, 'Make', False),
(272, 's', 5, 'Model', False),
(33421, 'H', 2, (2, 2), False), ... | iguous
assert page.planarconfig == SEPARATE
assert page.photometric == RGB
assert page.imagewidth == 301
assert page.imagelength == 219
assert page.samplesperpixel == 8
assert len(page.extrasamples) == 5
assert page.extrasamples[0] == U... | 133 | 133 | 446 | 24 | 109 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_cfa | test_write_cfa | 11,904 | 11,940 | 11,904 | 11,905 | 021d41a4dcba17eb64f3c0e61e5a470b6c0fe005 | bigcode/the-stack | train |
a6aca23822b5508701b69ced | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_ome_nikon(caplog):
"""Test read bad OME by Nikon."""
# OME-XML references only first image
# received from E. Gratton
fname = private_file('OME/Nikon-cell011.ome.tif')
with TiffFile(fname) as tif:
assert tif.is_ome
assert... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_ome_nikon(caplog):
| """Test read bad OME by Nikon."""
# OME-XML references only first image
# received from E. Gratton
fname = private_file('OME/Nikon-cell011.ome.tif')
with TiffFile(fname) as tif:
assert tif.is_ome
assert tif.byteorder == '<'
assert len(tif.pages) == 1000
assert len(tif... | assert series.dtype == numpy.uint16
assert series.axes == 'CYX'
assert not series.is_multifile
# assert data
data = tif.asarray()
assert data.shape == (4, 7506, 7506)
assert data.dtype == numpy.uint16
assert tuple(data[:, 2684, 2684]) == (496, 657, 7106, 469)
... | 151 | 151 | 505 | 23 | 128 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_ome_nikon | test_read_ome_nikon | 7,896 | 7,944 | 7,896 | 7,897 | aef6b1b791e16103b9e36de80b2306fa6e2e7a09 | bigcode/the-stack | train |
73423126506a6d0e52bba747 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_scanimage_bigtiff():
"""Test read ScanImage BigTIFF."""
# https://github.com/cgohlke/tifffile/issues/29
fname = private_file('ScanImage/area1__00001.tif')
with TiffFile(fname) as tif:
assert tif.is_scanimage
assert len(tif.pa... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_scanimage_bigtiff():
| """Test read ScanImage BigTIFF."""
# https://github.com/cgohlke/tifffile/issues/29
fname = private_file('ScanImage/area1__00001.tif')
with TiffFile(fname) as tif:
assert tif.is_scanimage
assert len(tif.pages) == 162
assert len(tif.series) == 1
# assert page properties
... |
# description tags
metadata = scanimage_description_metadata(page.description)
assert metadata['scanimage.SI5.VERSION_MAJOR'] == 5
# assert data
data = tif.asarray()
assert data[5979, 256, 256] == 71
data = frame.asarray()
assert data[256, 256] == 71
... | 118 | 118 | 394 | 22 | 96 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_scanimage_bigtiff | test_read_scanimage_bigtiff | 7,016 | 7,050 | 7,016 | 7,017 | 8d800a6c3ee43fa6ba57850427b53b87b9cdf587 | bigcode/the-stack | train |
f2378e92c9657bbe352ce1ea | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_epics_attrib():
"""Test read EPICS."""
fname = private_file('epics/attrib.tif')
with TiffFile(fname) as tif:
assert tif.is_epics
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert len(tif.series) == 1
... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_epics_attrib():
| """Test read EPICS."""
fname = private_file('epics/attrib.tif')
with TiffFile(fname) as tif:
assert tif.is_epics
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert len(tif.series) == 1
# assert series properties
series = tif.series[0]
assert... | .tags['Model'].value == 'PILATUS 100K-S, S/N 1-0299,'
attr = pilatus_description_metadata(page.description)
assert attr['Filter_transmission'] == 1.0
assert attr['Silicon'] == 0.000320
assert_aszarr_method(page)
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
... | 99 | 99 | 333 | 21 | 78 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_epics_attrib | test_read_epics_attrib | 8,986 | 9,017 | 8,986 | 8,987 | e6c92f563354fd22a32f7532803791678085e9a2 | bigcode/the-stack | train |
26d016d5735e95d5aaa5e33c | train | function | @pytest.mark.parametrize('contiguous', [True, False])
def test_write_ome_manual(contiguous):
"""Test writing OME-TIFF manually."""
data = numpy.random.randint(0, 255, (19, 31, 21), numpy.uint8)
with TempFileName(f'write_ome__manual{int(contiguous)}.ome') as fname:
with TiffWriter(fname) as tif:
... | @pytest.mark.parametrize('contiguous', [True, False])
def test_write_ome_manual(contiguous):
| """Test writing OME-TIFF manually."""
data = numpy.random.randint(0, 255, (19, 31, 21), numpy.uint8)
with TempFileName(f'write_ome__manual{int(contiguous)}.ome') as fname:
with TiffWriter(fname) as tif:
# sucessively write image data to TIFF pages
# disable tifffile from wr... | ample == 8
assert page.samplesperpixel == 1
# assert series properties
series = tif.series[0]
assert series.shape == (7, 5, 167, 439)
assert series.dtype == numpy.int8
assert series.axes == 'TZYX'
# assert data
assert_array_... | 127 | 127 | 424 | 21 | 106 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_ome_manual | test_write_ome_manual | 13,601 | 13,646 | 13,601 | 13,602 | 5b40bc0de835839c78f9fd84dafd400ebf69c11e | bigcode/the-stack | train |
7627b898e9e369dac826bed7 | train | function | @pytest.mark.parametrize('repeats', [1, 2])
@pytest.mark.parametrize('series', [1, 2])
@pytest.mark.parametrize('subifds', [0, 1, 2])
@pytest.mark.parametrize('compressed', [False, True])
@pytest.mark.parametrize('tiled', [False, True])
@pytest.mark.parametrize('ome', [False, True])
def test_write_subidfs(ome, tiled, c... | @pytest.mark.parametrize('repeats', [1, 2])
@pytest.mark.parametrize('series', [1, 2])
@pytest.mark.parametrize('subifds', [0, 1, 2])
@pytest.mark.parametrize('compressed', [False, True])
@pytest.mark.parametrize('tiled', [False, True])
@pytest.mark.parametrize('ome', [False, True])
def test_write_subidfs(ome, tiled, c... | """Test writing SubIFDs."""
if repeats > 1 and (compressed or tiled or ome):
pytest.xfail('contiguous not working with compression, tiles, ome')
data = [
(numpy.random.rand(5, 64, 64) * 1023).astype(numpy.uint16),
(numpy.random.rand(5, 32, 32) * 1023).astype(numpy.uint16),
(... | empty = numpy.empty((0, 0), dtype)
if repeat > 1:
for i in range(repeat):
assert_array_equal(image[i], empty)
assert_array_equal(zimage[i], empty)
else:
assert_array_equal(image.squeez... | 256 | 256 | 854 | 98 | 157 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_subidfs | test_write_subidfs | 9,907 | 9,991 | 9,907 | 9,913 | 0a280094ada5e19592910746fd01276689a54d63 | bigcode/the-stack | train |
8b4ff6fa0236a072ef811a80 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_issue_bad_description(caplog):
"""Test page.description is empty when ImageDescription is not ASCII."""
# ImageDescription is not ASCII but bytes
fname = private_file('stk/cells in the eye2.stk')
with TiffFile(fname) as tif:
page = tif.pa... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_issue_bad_description(caplog):
| """Test page.description is empty when ImageDescription is not ASCII."""
# ImageDescription is not ASCII but bytes
fname = private_file('stk/cells in the eye2.stk')
with TiffFile(fname) as tif:
page = tif.pages[0]
assert page.description == ''
assert__str__(tif)
assert 'coerc... | circular IFD raises error."""
fname = public_file('Tiff-Library-4J/IFD struct/Circular E.tif')
with pytest.raises(TiffFileError):
imread(fname)
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_issue_bad_description(caplog):
| 64 | 64 | 109 | 21 | 43 | bioturing/tifffile | tests/test_tifffile.py | Python | test_issue_bad_description | test_issue_bad_description | 560 | 569 | 560 | 561 | 3ba6265f00e8a60ab96a984ae2bbcc21e513f203 | bigcode/the-stack | train |
a1deedcc14c30240a6996501 | train | function | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_ome_single_channel():
"""Test read OME image."""
# 2D (single image)
# OME-TIFF reference images from
# https://www.openmicroscopy.org/site/support/ome-model/ome-tiff
fname = public_file('OME/bioformats-artificial/single-channel.ome.tif')... | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_ome_single_channel():
| """Test read OME image."""
# 2D (single image)
# OME-TIFF reference images from
# https://www.openmicroscopy.org/site/support/ome-model/ome-tiff
fname = public_file('OME/bioformats-artificial/single-channel.ome.tif')
with TiffFile(fname) as tif:
assert tif.is_ome
assert tif.byteo... | .TIFF_FORMAT_VERSION'] == 3
assert metadata['RoiGroups']['imagingRoiGroup']['ver'] == 1
assert 'Description' not in metadata
# assert page offsets are correct
assert tif.pages[-1].offset == 84527590 # not 84526526 (calculated)
# read image data
assert_aszarr_method(tif)
... | 114 | 114 | 381 | 21 | 93 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_ome_single_channel | test_read_ome_single_channel | 7,053 | 7,089 | 7,053 | 7,054 | c950d787fcd15f8b07a3c442280f0704adb0e37b | bigcode/the-stack | train |
366523aa0800835824034b7c | train | function | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_ZARR, reason=REASON)
def test_read_zarr():
"""Test read TIFF with zarr."""
fname = public_file('imagecodecs/gray.u1.tif')
with TiffFile(fname) as tif:
image = tif.asarray()
store = tif.aszarr()
try:
data = zarr.open(store, mode='r')
... | @pytest.mark.skipif(SKIP_PUBLIC or SKIP_ZARR, reason=REASON)
def test_read_zarr():
| """Test read TIFF with zarr."""
fname = public_file('imagecodecs/gray.u1.tif')
with TiffFile(fname) as tif:
image = tif.asarray()
store = tif.aszarr()
try:
data = zarr.open(store, mode='r')
assert_array_equal(image, data)
del data
finally:
store.close(... | = tif.pages[-1].tags['MicroManagerMetadata'].value
assert meta['Axes']['repetition'] == 2
assert meta['Axes']['exposure'] == 3
@pytest.mark.skipif(SKIP_PUBLIC or SKIP_ZARR, reason=REASON)
def test_read_zarr():
| 64 | 64 | 107 | 24 | 39 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_zarr | test_read_zarr | 9,441 | 9,453 | 9,441 | 9,442 | ec7c3b6cd77d61dcb2a9f8ab85b9f022902c0849 | bigcode/the-stack | train |
b72280f854e4d7f394bea0a9 | train | function | @pytest.mark.skipif(
SKIP_PUBLIC or SKIP_CODECS or not imagecodecs.JPEG2K, reason=REASON
)
def test_read_svs_jp2k_33003_1():
"""Test read Aperio SVS slide, JP2000 and LZW."""
fname = private_file('AperioSVS/JP2K-33003-1.svs')
with TiffFile(fname) as tif:
assert tif.is_svs
assert not tif.... | @pytest.mark.skipif(
SKIP_PUBLIC or SKIP_CODECS or not imagecodecs.JPEG2K, reason=REASON
)
def test_read_svs_jp2k_33003_1():
| """Test read Aperio SVS slide, JP2000 and LZW."""
fname = private_file('AperioSVS/JP2K-33003-1.svs')
with TiffFile(fname) as tif:
assert tif.is_svs
assert not tif.is_scanimage
assert len(tif.pages) == 6
assert len(tif.series) == 4
for page in tif.pages:
sv... | assert page.compression == LZW
assert page.shape == (463, 387, 3)
metadata = svs_description_metadata(page.description)
assert 'label 387x463' in metadata['Header']
assert_aszarr_method(page)
assert__str__(tif)
@pytest.mark.skipif(
SKIP_PUBLIC or SKIP_CODECS or not imagecode... | 107 | 107 | 358 | 45 | 62 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_svs_jp2k_33003_1 | test_read_svs_jp2k_33003_1 | 6,769 | 6,803 | 6,769 | 6,772 | 4927c8b8385dd82f8aa012a76b17e2dc5a486743 | bigcode/the-stack | train |
bd1d109fa9f89140fe4c50d9 | train | function | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_pygame_icon():
"""Test read 128x128 RGBA uint8 PackBits."""
fname = private_file('pygame_icon.tiff')
with TiffFile(fname) as tif:
assert tif.byteorder == '>'
assert len(tif.pages) == 1
assert len(tif.series... | @pytest.mark.skipif(SKIP_PRIVATE or SKIP_CODECS, reason=REASON)
def test_read_pygame_icon():
| """Test read 128x128 RGBA uint8 PackBits."""
fname = private_file('pygame_icon.tiff')
with TiffFile(fname) as tif:
assert tif.byteorder == '>'
assert len(tif.pages) == 1
assert len(tif.series) == 1
# assert page properties
page = tif.pages[0]
assert page.photo... | # assert data
data = page.asrgb(uint8=False)
assert isinstance(data, numpy.ndarray)
assert data.flags['C_CONTIGUOUS']
assert data.shape == (480, 320, 3)
assert data.dtype == numpy.uint16
assert tuple(data[64, 64, :]) == (65535, 52171, 63222)
assert__str__(tif)
@p... | 115 | 115 | 385 | 26 | 89 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_pygame_icon | test_read_pygame_icon | 4,449 | 4,482 | 4,449 | 4,450 | 8a376b8138d49c598d6d6c2fde52946a7330481b | bigcode/the-stack | train |
d802e0380ccb80522e3d76bc | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
@pytest.mark.parametrize('fname', ['sample1.orf', 'sample1.rw2'])
def test_read_rawformats(fname, caplog):
"""Test parse unsupported RAW formats."""
fname = private_file(f'RAWformats/{fname}')
with TiffFile(fname) as tif:
assert 'RAW format' in caplog... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
@pytest.mark.parametrize('fname', ['sample1.orf', 'sample1.rw2'])
def test_read_rawformats(fname, caplog):
| """Test parse unsupported RAW formats."""
fname = private_file(f'RAWformats/{fname}')
with TiffFile(fname) as tif:
assert 'RAW format' in caplog.text
assert__str__(tif)
| = page.asarray()
assert_aszarr_method(page, image)
assert__str__(tif)
@pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
@pytest.mark.parametrize('fname', ['sample1.orf', 'sample1.rw2'])
def test_read_rawformats(fname, caplog):
| 64 | 64 | 91 | 42 | 22 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_rawformats | test_read_rawformats | 3,952 | 3,959 | 3,952 | 3,954 | 71ede4ec95f94766ea24efee316348789284cff8 | bigcode/the-stack | train |
a3ffd123fa44b0ee8e251808 | train | function | def test_write_extrasamples_contig_rgb():
"""Test write contig RGB with extrasamples."""
data = random_data(numpy.uint8, (219, 301, 8))
with TempFileName('extrasamples_contig') as fname:
imwrite(fname, data, photometric=RGB)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
... | def test_write_extrasamples_contig_rgb():
| """Test write contig RGB with extrasamples."""
data = random_data(numpy.uint8, (219, 301, 8))
with TempFileName('extrasamples_contig') as fname:
imwrite(fname, data, photometric=RGB)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
... | perpixel == 4
assert page.extrasamples[0] == UNASSALPHA
image = tif.asarray()
assert_array_equal(data, image)
assert_aszarr_method(tif, image)
assert__str__(tif)
def test_write_extrasamples_contig_rgb():
| 64 | 64 | 215 | 10 | 54 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_extrasamples_contig_rgb | test_write_extrasamples_contig_rgb | 11,858 | 11,878 | 11,858 | 11,858 | 6d5e1406691773c6fd2fa1098a8ed33cababadce | bigcode/the-stack | train |
628e33693629e5635ae02fc0 | train | function | def test_write_extrasamples_assocalpha():
"""Test write RGB with assocalpha extrasample."""
data = random_data(numpy.uint8, (219, 301, 4))
with TempFileName('extrasamples_assocalpha') as fname:
imwrite(fname, data, photometric=RGB, extrasamples=ASSOCALPHA)
assert_valid_tiff(fname)
wi... | def test_write_extrasamples_assocalpha():
| """Test write RGB with assocalpha extrasample."""
data = random_data(numpy.uint8, (219, 301, 4))
with TempFileName('extrasamples_assocalpha') as fname:
imwrite(fname, data, photometric=RGB, extrasamples=ASSOCALPHA)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
ass... | page.samplesperpixel == 5
assert page.extrasamples == (0, 0)
image = tif.asarray()
assert_array_equal(data, image)
assert_aszarr_method(tif, image)
assert__str__(tif)
def test_write_extrasamples_assocalpha():
| 64 | 64 | 202 | 10 | 54 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_extrasamples_assocalpha | test_write_extrasamples_assocalpha | 11,453 | 11,471 | 11,453 | 11,453 | 444ef8644e24e59a01e1e1539d9306efa47de7d1 | bigcode/the-stack | train |
0d54dab50b2eff7e0d1ed7ed | train | function | def test_func_reshape_nd():
"""Test reshape_nd function."""
assert reshape_nd(numpy.empty(0), 2).shape == (1, 0)
assert reshape_nd(numpy.empty(1), 3).shape == (1, 1, 1)
assert reshape_nd(numpy.empty((2, 3)), 3).shape == (1, 2, 3)
assert reshape_nd(numpy.empty((2, 3, 4)), 3).shape == (2, 3, 4)
a... | def test_func_reshape_nd():
| """Test reshape_nd function."""
assert reshape_nd(numpy.empty(0), 2).shape == (1, 0)
assert reshape_nd(numpy.empty(1), 3).shape == (1, 1, 1)
assert reshape_nd(numpy.empty((2, 3)), 3).shape == (1, 2, 3)
assert reshape_nd(numpy.empty((2, 3, 4)), 3).shape == (2, 3, 4)
assert reshape_nd((0,), 2) ==... | assert byteorder_compare('|', '<')
assert byteorder_compare('=', '|')
assert byteorder_compare('|', '=')
if sys.byteorder == 'little':
assert byteorder_compare('<', '=')
else:
assert byteorder_compare('>', '=')
def test_func_reshape_nd():
| 64 | 64 | 202 | 7 | 57 | bioturing/tifffile | tests/test_tifffile.py | Python | test_func_reshape_nd | test_func_reshape_nd | 2,417 | 2,427 | 2,417 | 2,417 | 42b6d627263eaefaf8c42e7cb5cbe9f45c3ad140 | bigcode/the-stack | train |
0d288b51af13f845e5ece410 | train | function | def test_write_pyramids():
"""Test write two pyramids to shaped file."""
data = random_data(numpy.uint8, (31, 64, 96, 3))
with TempFileName('pyramids') as fname:
with TiffWriter(fname) as tif:
# use pages
tif.write(data, tile=(16, 16), photometric=RGB)
# interrupt... | def test_write_pyramids():
| """Test write two pyramids to shaped file."""
data = random_data(numpy.uint8, (31, 64, 96, 3))
with TempFileName('pyramids') as fname:
with TiffWriter(fname) as tif:
# use pages
tif.write(data, tile=(16, 16), photometric=RGB)
# interrupt pyramid, e.g. thumbnail
... | * 3 * 4 * 16 * 16, dtype=numpy.uint16)
data = data.reshape((2 * 3 * 4, 16, 16))
def tiles():
for i in range(data.shape[0]):
yield data[i]
with TempFileName('write_tile_iter_separate') as fname:
imwrite(
fname,
tiles(),
shape=(2, 43, 61),
... | 256 | 256 | 894 | 7 | 249 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_pyramids | test_write_pyramids | 12,169 | 12,255 | 12,169 | 12,169 | 31be9ad9765fceead833fc1110ba29927f4f42c6 | bigcode/the-stack | train |
c35c848991b54e65473fb548 | train | function | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_lsb2msb():
"""Test read fillorder=lsb2msb, 2 series."""
# http://lists.openmicroscopy.org.uk/pipermail/ome-users
# /2015-September/005635.html
fname = private_file('test_lsb2msb.tif')
with TiffFile(fname) as tif:
assert tif.byt... | @pytest.mark.skipif(SKIP_PRIVATE, reason=REASON)
def test_read_lsb2msb():
| """Test read fillorder=lsb2msb, 2 series."""
# http://lists.openmicroscopy.org.uk/pipermail/ome-users
# /2015-September/005635.html
fname = private_file('test_lsb2msb.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 2
assert len(tif.se... | .tif')
with TiffFile(fname) as tif:
page = tif.pages[0]
assert page.photometric == MINISWHITE
assert_array_equal(tif.asarray(), 15 - data)
assert__str__(tif)
# inverted and reversed
fname = public_file('pillow/tiff_gray_2_4_bpp/hopper4IR.tif')
with TiffFile(fname) as tif:... | 153 | 153 | 511 | 22 | 131 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_lsb2msb | test_read_lsb2msb | 3,794 | 3,842 | 3,794 | 3,795 | 737cab20dd471656f075c535c5df10f1a11daca9 | bigcode/the-stack | train |
a53bd0de66bb2651e7d75565 | train | function | def test_write_pixel():
"""Test write single pixel."""
data = numpy.zeros(1, dtype=numpy.uint8)
with TempFileName('pixel') as fname:
imwrite(fname, data)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
assert tif.series[0].axes... | def test_write_pixel():
| """Test write single pixel."""
data = numpy.zeros(1, dtype=numpy.uint8)
with TempFileName('pixel') as fname:
imwrite(fname, data)
assert_valid_tiff(fname)
with TiffFile(fname) as tif:
assert len(tif.pages) == 1
assert tif.series[0].axes == 'Y'
page... | str__(tif)
def test_write_zero_size():
"""Test write zero size array no longer fails."""
# with pytest.raises(ValueError):
with pytest.warns(UserWarning):
with TempFileName('empty') as fname:
imwrite(fname, numpy.empty(0))
def test_write_pixel():
| 64 | 64 | 195 | 5 | 59 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_pixel | test_write_pixel | 11,206 | 11,226 | 11,206 | 11,206 | 2d9610c7c08c98292f98eb7a8e6a9140f8aea512 | bigcode/the-stack | train |
da355c14462593e8c4cb4b57 | train | function | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_caspian():
"""Test read 3x220x279 float64, RGB, deflate, GDAL."""
fname = public_file('juicypixels/caspian.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert len(tif.series) ==... | @pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def test_read_caspian():
| """Test read 3x220x279 float64, RGB, deflate, GDAL."""
fname = public_file('juicypixels/caspian.tif')
with TiffFile(fname) as tif:
assert tif.byteorder == '<'
assert len(tif.pages) == 1
assert len(tif.series) == 1
# assert page properties
page = tif.pages[0]
a... | assert data.flags['C_CONTIGUOUS']
assert data.shape == (6976, 4992, 3)
assert data.dtype == numpy.uint8
assert tuple(data[2229, 1080, :]) == (164, 164, 164)
assert_aszarr_method(tif, data)
del data
assert__str__(tif)
@pytest.mark.skipif(SKIP_PUBLIC, reason=REASON)
def te... | 102 | 102 | 340 | 20 | 82 | bioturing/tifffile | tests/test_tifffile.py | Python | test_read_caspian | test_read_caspian | 5,595 | 5,626 | 5,595 | 5,596 | 3283d10ab8f313b64b115a6644eb6c056de68c23 | bigcode/the-stack | train |
a8906dd8adc279d201f69e51 | train | function | def test_write_2d_as_rgb():
"""Test write RGB color palette as RGB image."""
# image length should be 1
data = numpy.arange(3 * 256, dtype=numpy.uint16).reshape(256, 3) // 3
with TempFileName('2d_as_rgb_contig') as fname:
imwrite(fname, data, photometric=RGB)
assert_valid_tiff(fname)
... | def test_write_2d_as_rgb():
| """Test write RGB color palette as RGB image."""
# image length should be 1
data = numpy.arange(3 * 256, dtype=numpy.uint16).reshape(256, 3) // 3
with TempFileName('2d_as_rgb_contig') as fname:
imwrite(fname, data, photometric=RGB)
assert_valid_tiff(fname)
with TiffFile(fname) as... | assert page.imagewidth == 1
assert page.imagelength == 1
assert page.samplesperpixel == 1
image = tif.asarray()
assert_array_equal(data, image)
assert_aszarr_method(tif, image)
assert__str__(tif)
def test_write_2d_as_rgb():
| 70 | 70 | 236 | 9 | 61 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_2d_as_rgb | test_write_2d_as_rgb | 11,250 | 11,271 | 11,250 | 11,250 | d9e7d2d0f194ea4b50159f909fa9e999618082d7 | bigcode/the-stack | train |
79f3df6633279129994722bf | train | function | def test_write_description_tag():
"""Test write two description tags."""
data = random_data(numpy.uint8, (2, 219, 301))
description = 'Created by TestTiffWriter\nLorem ipsum dolor...'
with TempFileName('description_tag') as fname:
imwrite(fname, data, description=description)
assert_vali... | def test_write_description_tag():
| """Test write two description tags."""
data = random_data(numpy.uint8, (2, 219, 301))
description = 'Created by TestTiffWriter\nLorem ipsum dolor...'
with TempFileName('description_tag') as fname:
imwrite(fname, data, description=description)
assert_valid_tiff(fname)
with TiffFil... | tif.pages[0].tags['DateTime'].value == arg.strftime(
'%Y:%m:%d %H:%M:%S'
)
else:
assert tif.pages[0].tags['DateTime'].value == dt
assert__str__(tif)
def test_write_description_tag():
| 64 | 64 | 157 | 6 | 58 | bioturing/tifffile | tests/test_tifffile.py | Python | test_write_description_tag | test_write_description_tag | 10,423 | 10,435 | 10,423 | 10,423 | 7b7c4937101ae5cbf28c306e57813271aa077a47 | bigcode/the-stack | train |
61fd87857f4f2bf437476599 | train | function | def test_class_filecache():
"""Test FileCache class."""
with TempFileName('class_filecache') as fname:
cache = FileCache(3)
with open(fname, 'wb') as fh:
fh.close()
# create 6 handles, leaving only first one open
handles = []
for i in range(6):
f... | def test_class_filecache():
| """Test FileCache class."""
with TempFileName('class_filecache') as fname:
cache = FileCache(3)
with open(fname, 'wb') as fh:
fh.close()
# create 6 handles, leaving only first one open
handles = []
for i in range(6):
fh = FileHandle(fname)
... | dtype='uint16'),
numpy.arange(0, 2**16, 2**8, dtype='uint16'),
numpy.arange(0, 2**16, 2**8, dtype='uint16'),
]
)
metadata = {'min': 0.0, 'max': 1.0, 'Properties': {'CurrentLUT': 'cyan'}}
with TempFileName('issue_imagej_colormap') as fname:
imwrite(
fname,... | 214 | 214 | 716 | 6 | 207 | bioturing/tifffile | tests/test_tifffile.py | Python | test_class_filecache | test_class_filecache | 1,688 | 1,780 | 1,688 | 1,688 | dc7020ebbe9e2951aac554fd4fd12bfe50c1ba43 | bigcode/the-stack | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.