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

Trajectories should be exportable as CSV #2

Open
qgeissmann opened this issue Dec 8, 2015 · 1 comment
Open

Trajectories should be exportable as CSV #2

qgeissmann opened this issue Dec 8, 2015 · 1 comment
Assignees

Comments

@qgeissmann
Copy link
Contributor

Some users will want to export trajectories and work further with other tools.
For me it makes more sense to export them in a long (as opposed to wide) format.
Then, the headers of a multi trajectory csv will be name,time and value (possibly sensitivity data can be included).

@qgeissmann qgeissmann self-assigned this Dec 8, 2015
qgeissmann added a commit that referenced this issue Dec 8, 2015
@qgeissmann
Copy link
Contributor Author

For single trajectories:

trajectory = Trajectory([1, 2, 3, 4, 5, 6], [3, 2, 1,5, 2, 4], Moment([1], symbol='description'))
with open("my_file.csv","w") as out:
    trajectory.to_csv(out)

We get a file like this:

time,value
1.000000,3.000000
2.000000,2.000000
3.000000,1.000000
4.000000,5.000000
5.000000,2.000000
6.000000,4.000000

For collections:

tr1 = Trajectory([1, 2, 3, 4, 5, 6], [3, 2, 1, 5, 2, 4], Moment([1], symbol='y_1'))
tr2 = Trajectory([1, 2, 3, 4, 5, 6], [3, 2, 1, 5, 2, 4], Moment([1], symbol='y_2'))
tc = TrajectoryCollection([tr1,tr2])
with open("my_file.csv","w") as out:
    tc.to_csv(out)

Output looks like that:

description,time,value
y_1,1.000000,3.000000
y_1,2.000000,2.000000
y_1,3.000000,1.000000
y_1,4.000000,5.000000
y_1,5.000000,2.000000
y_1,6.000000,4.000000
y_2,1.000000,3.000000
y_2,2.000000,2.000000
y_2,3.000000,1.000000
y_2,4.000000,5.000000
y_2,5.000000,2.000000
y_2,6.000000,4.000000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant