|
10 | 10 |
|
11 | 11 | from ij import IJ # pylint: disable-msg=import-error |
12 | 12 | from ij.plugin import Duplicator, ImageCalculator, StackWriter |
| 13 | +from org.scijava.widget import TextWidget, WidgetStyle |
13 | 14 |
|
14 | 15 | from .. import pathtools |
15 | 16 | from ..log import LOG as log |
16 | 17 | from . import bioformats as bf |
17 | 18 | from . import prefs |
18 | 19 |
|
19 | | -from org.scijava.widget import WidgetStyle |
20 | | -from org.scijava.widget import TextWidget |
21 | | - |
22 | 20 |
|
23 | 21 | def show_status(msg): |
24 | 22 | """Update the ImageJ status bar and issue a log message. |
@@ -533,7 +531,9 @@ def write_ordereddict_to_csv(out_file, content): |
533 | 531 | dict_writer.writerows(content) |
534 | 532 |
|
535 | 533 |
|
536 | | -def save_image_in_format(imp, format, out_dir, series, pad_number, split_channels, suffix=""): |
| 534 | +def save_image_in_format( |
| 535 | + imp, format, out_dir, series, pad_number, split_channels, suffix="" |
| 536 | +): |
537 | 537 | """Save an ImagePlus object in the specified format. |
538 | 538 |
|
539 | 539 | This function provides flexible options for saving ImageJ images in various |
@@ -791,22 +791,32 @@ def save_script_parameters(destination, save_file_name="script_parameters.txt"): |
791 | 791 |
|
792 | 792 | timed_log("Saved script parameters to: %s" % out_path) |
793 | 793 |
|
794 | | -def convert_bytes(size): |
795 | | - """Convert size from bytes to a readable value. |
| 794 | + |
| 795 | +def bytes_to_human_readable(size): |
| 796 | + """Convert a byte count to a human-readable string using binary units. |
796 | 797 |
|
797 | 798 | Parameters |
798 | 799 | ---------- |
799 | 800 | size : int |
800 | | - Byte size |
| 801 | + Byte size (number of bytes). |
801 | 802 |
|
802 | 803 | Returns |
803 | 804 | ------- |
804 | 805 | str |
805 | | - Easy to read value with the correct unit |
| 806 | + Human-friendly size string, e.g. `"512.0 bytes"`, `"2.0 KB"`, |
| 807 | + `"1.0 MB"`. |
| 808 | +
|
| 809 | + Notes |
| 810 | + ----- |
| 811 | + - Uses powers of 1024 (KB = 1024 bytes). |
| 812 | + - Always returns a string with one decimal place and the unit. |
806 | 813 | """ |
807 | | - for x in ["bytes", "KB", "MB", "GB", "TB"]: |
| 814 | + |
| 815 | + for unit in ["bytes", "KB", "MB", "GB", "TB"]: |
808 | 816 | if size < 1024.0: |
809 | | - return "%3.1f %s" % (size, x) |
| 817 | + return "%3.1f %s" % (size, unit) |
810 | 818 | size /= 1024.0 |
811 | 819 |
|
812 | | - return size |
| 820 | + # If the value is larger than the largest unit, fall back to TB with |
| 821 | + # the current value (already divided accordingly). |
| 822 | + return "%3.1f %s" % (size, "TB") |
0 commit comments