ocesou / hooke

Automatically exported from code.google.com/p/hooke
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Numbers should be in scientific format #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Autopeak one forcecurve with some peaks
2. Try to read the output in the command line

What is the expected output? What do you see instead?
For example, this is the output that I obtain:
forces (pN) [70.221228491413939, 81.746428304937012, 117.83814977077844,
183.58709454715952, 237.72586033482031]
I would like to have:
forces (pN) [70.2, 81.7, 117.8, 183.5, 237.7]

What version of the product are you using? On what operating system?
Hooke 0.8.3 Gnu/Linux Kubuntu

Please provide any additional information below.

Original issue reported on code.google.com by fabrizio...@gmail.com on 29 Apr 2009 at 9:57

GoogleCodeExporter commented 8 years ago
A general mechanism for output precision could be useful, yes, but don't expect
improvements on it soon :)

Original comment by devicera...@gmail.com on 4 May 2009 at 2:44

GoogleCodeExporter commented 8 years ago

Original comment by devicera...@gmail.com on 4 May 2009 at 2:45

GoogleCodeExporter commented 8 years ago

Original comment by devicera...@gmail.com on 5 May 2009 at 5:32

GoogleCodeExporter commented 8 years ago
Found this thing:

sys.float_output_precision

that seems to answer the question. I will try to patch it soon.

Original comment by devicera...@gmail.com on 26 May 2009 at 4:27

GoogleCodeExporter commented 8 years ago
I have partially solved this problem with this routine:

      def print_prec(self, arr, prec):
         try:
           nparr=np.array(arr)
           np.set_printoptions(precision=prec)
       strvals=str(nparr)[1:-1]
           return strvals
         except:
           return "Error in the array"

This routine return a string with "prec" significative numbers.  So the code of
autopeak could be modify in this way:

        print 'Measurements for all peaks detected:'
        print 'contour (nm)', self.print_prec(c_lengths,0)
#and so on and so for...

This "implementation" give this (if the numbers doesn't correspond it's because 
I use
a different picoforce driver) output on the example curve:
Measurements for all peaks detected:
contour (nm)  111.  138.  163.  203.  231.  257.
sigma contour (nm)  2.38  3.22  4.62  6.34  6.7   1.03
p (nm)  0.13  0.24  0.41  0.24  0.24  0.29
sigma p (nm)  0.02   0.055  0.138  0.07   0.076  0.028
forces (pN)  212.  160.  135.  151.  193.  703.
slopes (N/m)  0.0154  0.0137  0.0068  0.0099  0.0128  0.0586

My main problem is that, for every value (force, slope, contour...) you have to
specify the precision in the code... So I don't know if it is a good thing to
implement this solution.   I need a feedback from you.

Original comment by fabrizio...@gmail.com on 12 Feb 2010 at 12:49

GoogleCodeExporter commented 8 years ago
The traditional print formatting is not more than enough here?

>>> print "Number with 2 decimals: %.2f" % 10.1234
50.12

Original comment by albertog...@gmail.com on 13 Feb 2010 at 1:18

GoogleCodeExporter commented 8 years ago
The 50 is a bad copy&paste, ejem

Original comment by albertog...@gmail.com on 13 Feb 2010 at 1:19

GoogleCodeExporter commented 8 years ago
Maybe I am wrong but this is what I obtain from my python shell:
>>> a=numpy.arange(0,1,0.00000134526763)
>>> print a[2]
2.69053526e-06
>>> print " %.2f" %a[2]
 0.00

With set_printoptions(precision=1)
print a[0:20]
[  0.0e+00   1.3e-06   2.7e-06   4.0e-06   5.4e-06   6.7e-06   8.1e-06
   9.4e-06   1.1e-05   1.2e-05   1.3e-05   1.5e-05   1.6e-05   1.7e-05
   1.9e-05   2.0e-05   2.2e-05   2.3e-05   2.4e-05   2.6e-05]

Tell me...

Original comment by fabrizio...@gmail.com on 18 Feb 2010 at 10:37

GoogleCodeExporter commented 8 years ago
Ahum, of course if you are going to use those extreme exponents you need 
scientific
notation and the %.2f does not cut it.

Anyway, the output of your way looks good enough, if your problem is what 
precision
you should assume, the way that would please my high school physics teacher 
would be
to relate that precision to the standard errors, I will give an example with 
your
sample data:

contour (nm)  111.  138.  163.  203.  231.  257.
sigma contour (nm)  2.38  3.22  4.62  6.34  6.7   1.03

Giving decimals for contour under the sigma does not make much sense, so the
precision should be:

math.ceil(math.log(contour/sigma,10)) = 2.0 (its 2 for any of the cases up). So 
you
should give contour with 2 decimals precision (remember, in exp notation!, 
that's
1.11e-7 m or 1.11e2 nm, not 111.xx nm) and sigma just rounded to the nm. If you 
feel
you want more precision put an extra decimal for everything just in case.

For forces and slopes you don't have sigmas, I would take 1pN for force (you 
will
never get more precise than that) and for the slopes 1pN/1nm (1e-3 N/m)

Original comment by glacie...@gmail.com on 19 Feb 2010 at 8:42

GoogleCodeExporter commented 8 years ago
Upper post is mine, I forgot to login properly.

Original comment by albertog...@gmail.com on 19 Feb 2010 at 8:45

GoogleCodeExporter commented 8 years ago
I would like to implement that function because it is enough precise for the
scientific notations, and I think it is also flexible.  The formula that you 
have
suggest for the precision is completely correct but I would use an easier 
approach.

What do (all of) you think about something like this?

        print 'Measurements for all peaks detected:'
        print 'contour (nm)', self.print_prec(c_lengths,0)
        print 'sigma contour (nm)',self.print_prec(sigma_c_lengths,0)
        print 'p (nm)',self.print_prec(p_lengths,2)
        print 'sigma p (nm)',self.print_prec(sigma_p_lengths,2)
        print 'forces (pN)',self.print_prec(forces,0)
        print 'slopes (N/m)',self.print_prec(slopes,4)

This give for the example curve:

contour (nm)  111.  138.  163.  203.  231.  257.
sigma contour (nm)  2.  3.  5.  6.  7.  1.
p (nm)  0.13  0.24  0.41  0.24  0.24  0.29
sigma p (nm)  0.02  0.05  0.14  0.07  0.08  0.03
forces (pN)  212.  160.  135.  151.  193.  703.
slopes (N/m)  0.015  0.014  0.007  0.01   0.013  0.059

This, for me, seem more readable.   We can also use this printing function in 
other
case where the scientific notation is needed.

Original comment by fabrizio...@gmail.com on 23 Feb 2010 at 10:10

GoogleCodeExporter commented 8 years ago
Ping?

Original comment by fabrizio...@gmail.com on 25 Mar 2010 at 10:37

GoogleCodeExporter commented 8 years ago
Sorry if I continue to push you under this topic but the scientific 
representation is
important.  In many outputs the number of digits are too many.  If you do a 
distance
it came out with values like "57.1181952525 nm"...
This have to be changed. I can do the changes if you agree.

Original comment by fabrizio...@gmail.com on 28 Apr 2010 at 9:45

GoogleCodeExporter commented 8 years ago
I thought you already committed the changes! :) Feel free to commit a patch.

Original comment by devicera...@gmail.com on 28 Apr 2010 at 3:55

GoogleCodeExporter commented 8 years ago
Many output has been corrected with r268.

(autopeak, force, distance, forcebase)

There are other output that have to be corrected, work in progress however.

Original comment by fabrizio...@gmail.com on 7 May 2010 at 9:10

GoogleCodeExporter commented 8 years ago
Almost all output has been corrected. I decrease the priority

Original comment by fabrizio...@gmail.com on 12 May 2010 at 8:47