Posted by
Adrian Daerr-2 on
Sep 10, 2009; 6:05pm
URL: http://imagej.273.s1.nabble.com/IJ-d2s-quirk-tp3691174p3691179.html
May I humbly suggest that this rounding mechanism be totally avoided at
least in the "List", "Save" and "Copy" options in profile plot windows,
or that there be at least an option that switches it off (quick and ugly
hack: if the requested number of decimal places is negative, never
truncate) ? I'd prefer to either always use scientific notation, or let
some java printf function decide which notation to use. If rounding
there has to be, it would be better to *always* truncate, and never
switch to scientific notation, because the resulting clipping can be
surprising and hard to detect, as in the following example.
Since version 1.39g, the plot profile window rounds to 9 decimal places
if the setting is less or equal 3, but this has only made the problem a
little less likely to occur. It can still be treacherous to export data,
if you run e.g.:
newImage("Untitled", "32-bit Ramp", 400, 400, 1);
run("Divide...", "value=100000000");
makeLine(0, 100, 105, 100);
run("Plot Profile");
you get this plot:
http://www.msc.univ-paris-diderot.fr/~daerr/tmp/Plot_of_ramp.tifso far so good. Now save the data with the "save" button, and plot it
using your favorite plotting program, and you will get:
http://www.msc.univ-paris-diderot.fr/~daerr/tmp/Plot_of_ramp_data.pngDid you expect this ? Imagine now data that almost always evolves in the
lower, correctly saved, linear part, but now and then has bigger values.
Then the clipping might go unnoticed for quite a while, and finding the
cause when you finally notice can be tough.
Don't trust "save" to really save your data without double-checking !
Adrian
On 10/09/09 17:36, Wayne Rasband wrote:
>> Hi again,
>>
>> I already note for some time, that IJ.ds2 has a "quirk"
>> for very small values, for example
>>
>> double small_value = 9.915e-6;
>> IJ.write(IJ.d2s (small_value, 2));
>>
>> will not output
>>
>> "0.00"
>>
>> but
>>
>> "9.915E-6"
>>
>> instead!
>>
>> Is this intended behaviour?
>
> IJ.d2s() automatically switches to scientific notation for very small
> values to prevent them from being misleadingly displayed in the Results
> table as zero. You can avoid the use of scientific notation by
> increasing the number of decimal places. Here is what you get
>
> 0 9.915E-6
> 1 9.915E-6
> 2 9.915E-6
> 3 9.915E-6
> 4 9.915E-6
> 5 9.915E-6
> 6 0.000010
> 7 0.0000099
> 8 0.00000992
> 9 0.000009915
>
> when you run this macro
>
> n = 9.915e-6;
> for (d=0; d<=9; d++)
> print(d2s(n,d));
>
> -wayne
>
> > Sometimes it might be useful to tell if a result is not exactly zero,
> but
> > *LARGER* numbers will nevertheless be rounded down to zero as for ex.
> 1e-3!