[SciPy-User] Can loadtxt do this: complex file format

François Beaubert francois.beaubert@univ-valenciennes...
Mon Nov 26 03:16:41 CST 2012


Thank you very much David for your kind answer !
I will try your suggestion for question 1.

Regarding question 2. I realized that my email client has messed up the 
formatting of my file.
This file is written like this:

# x 0 0.005
# y 0 0.0025
# z 0.3 0.3
# Time
100 (7.6e-05 -0.02 0.75) (0.06 -0.01 0.16)
200 (7.06e-05 -0.12 0.76) (0.07 -0.11 0.17)
300 (6.51e-05 -0.21 0.77) (0.72 -0.15 0.26)
400 (6.01e-05 -0.20 0.79) (0.05 -0.13 0.19)

I just want to plot my data versus time:
After the last line of the header (beginning with "#") the file is 
formatted like this:

* The first column is the time
* The 3 values in the first parentheses are the Ux, Uy and Uz velocity 
components on point 1 (coordinates x1, y1, z1)
* The 3 values enclosed in the second parentheses are the Ux,Uy and Uz 
velocity components for point 2, etc

So I have to read the first column (easy part) and the other ones but 
without the "(" and ")".
I'm wondering if loadtxt() can skip/remove the "(" and ")" chars to be 
able to read my data with something like :

time,Ux1,Uy1,Uz1,Ux2,Uy2,Uz2 = loadtxt(filename, comments='#', 
delimiter=None,converters=None, usecols=(0,1,2,3,4,5,6), unpack=True)

Do I have to first remove all the "(" and ")" in the file or can I use 
some tricky loadtxt() features to do this for me ?

Thank you very much for your help
Have a nice day
François

Le 24/11/2012 02:24, Daπid a écrit :
> Answering your first question: yes, you can use the arg "converters".
> I used it when I had to load data where the decimal separator was a
> comma for the first column and a dot for the rest of the file (a
> professional equipment, BTW).
>
> In your case, it would be something like (not tested):
>
> converters = {2: lambda s: float(s[1:)), 4: lambda s: float(s[:-1)),
> 5: lambda s: float(s[1:)), 7: lambda s: float(s[:-1)))
>
>
> I don't think I understand your second question. loadtxt will load the
> whole file, regardless of the number of columns or rows (and alocate
> memory dynamically).
>
>
>
> David.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: francois_beaubert.vcf
Type: text/x-vcard
Size: 464 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-user/attachments/20121126/99316c6e/attachment.vcf 


More information about the SciPy-User mailing list