Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTree CSV export #105

Merged
merged 1 commit into from Apr 7, 2013
Merged

TTree CSV export #105

merged 1 commit into from Apr 7, 2013

Conversation

cdeil
Copy link
Contributor

@cdeil cdeil commented Apr 5, 2013

It would be nice if it were easily possible to display or export TTree data (if possible after column and row selection) as CSV (comma-separated values).

@pwaller
Copy link
Member

pwaller commented Apr 4, 2013

How should we implement this? We could make a recarray and then convert it to a CSV, but that would we wasteful. However, it would be easy, and might be a good starting point. I'm not sure we want to(/can) support huge trees initially anyway.

Given a method of turning a TTree into a CSV this is pretty trivial to implement. Just look at scan.

@ghost ghost assigned cdeil Apr 4, 2013
@cdeil
Copy link
Contributor Author

cdeil commented Apr 4, 2013

I think TTree -> recarray -> CSV is fine for now ... for gigabytes you don't want CSV anyways.

Thanks for the link to scan, I'll give it a try tomorrow.

@pwaller
Copy link
Member

pwaller commented Apr 4, 2013

Sounds good to me, let me know how it goes :)

@cdeil
Copy link
Contributor Author

cdeil commented Apr 5, 2013

The WebOOT part was trivial ... now how do I generate the CSV?

I wanted to convert to a rootpy.tree.Tree and then call the csv method on it into a in-memory StringIO.

  • Am I allowed to use rootpy in weboot?
  • Is it possible to do the TTree -> Tree conversion in-memory or do I have to create a temp file?

@pwaller
Copy link
Member

pwaller commented Apr 5, 2013

Yes, you can use rootpy in weboot.

TTree -> Tree should be easy through tree = rootpy.asrootpy(ttree), so far as I know. @ndawe, comments?

@cdeil
Copy link
Contributor Author

cdeil commented Apr 5, 2013

I'll wait until rootpy/rootpy#251 is resolved before finishing this.

@cdeil
Copy link
Contributor Author

cdeil commented Apr 5, 2013

Still doesn't work. I get this in the browser when hitting toy_sigbkg.root/TreeB/!csv/a:

['var1', 'var2', 'var3', 'var4', 'weight']

[ (-2.7639870643615723, -1.4941457509994507, -1.616673231124878, -2.917888641357422, 0.10676071792840958)
 (-0.7001328468322754, -1.344607949256897, -0.8229119777679443, -1.3939814567565918, 0.892978310585022)
 (3.4071643352508545, 1.9969775676727295, 2.607431650161743, 3.4646029472351074, 0.001675486913882196)]

data = stream.read() is empty.

What am I doing wrong?

@cdeil
Copy link
Contributor Author

cdeil commented Apr 7, 2013

@pwaller I'd like to get this done. Can you try the URL toy_sigbkg.root/TreeB/!csv/a with this branch to see if the issue is at least reproducible?

@pwaller
Copy link
Member

pwaller commented Apr 7, 2013

@cdeil, okay, if you want to get a StringIO()'s contents, the function you want is stringio.getvalue(). That will give you the full contents of the buffer.

The reason .read() doesn't work is that .read() gets content from "the current file offset`. The current file offset moves with rights, therefore, it's right at the end of the buffer, where you read nothing.

HTH. Do you follow?

@cdeil
Copy link
Contributor Author

cdeil commented Apr 7, 2013

Ah ... stupid mistake ... thanks for checking!

The URL toy_sigbkg.root/TreeB/!csv now gives

var1,var2,var3,var4,weight
-2.76398706436,-1.494145751,-1.61667323112,-2.91788864136,0.106760717928
-0.700132846832,-1.34460794926,-0.822911977768,-1.39398145676,0.892978310585
3.40716433525,1.99697756767,2.60743165016,3.46460294724,0.00167548691388
...

and hsimple.root/ntuple/!csv works as well.

@pwaller Ready to merge?

pwaller added a commit that referenced this pull request Apr 7, 2013
@pwaller pwaller merged commit a157b37 into rootpy:master Apr 7, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants