diff --git a/apeer_ometiff_library/io.py b/apeer_ometiff_library/io.py index 956b537..3f11c1b 100755 --- a/apeer_ometiff_library/io.py +++ b/apeer_ometiff_library/io.py @@ -231,11 +231,8 @@ def write_ometiff(output_path, array, omexml_string = None, compression=None): if omexml_string is None: omexml_string = gen_xml(array) - try: - tifffile.imwrite(output_path, array, photometric = "minisblack", description=omexml_string, metadata=None, - compress=compression) - except struct.error: - tifffile.imwrite(output_path, array, photometric = "minisblack", description=omexml_string, metadata=None, - compress=compression, bigtiff=True) - - + data_limit_nbytes = 2 ** 32 + tiff_metadata_nbytes = 2 ** 25 + bigtiff = array.nbytes > data_limit_nbytes - tiff_metadata_nbytes + tifffile.imwrite(output_path, array, photometric="minisblack", description=omexml_string, metadata=None, + compress=compression, bigtiff=bigtiff)