-
Notifications
You must be signed in to change notification settings - Fork 47
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
crop c3d #321
Comments
I started writing a Python code but at least one dimension is not well informed. Traceback (most recent call last):
|
are these two variables supposed to be the same?
|
Hello there! The script you provided seems slightly complicated... so I feel I may have oversimplified what you are trying to achieve. As far as I am concerned the following snippet does what you need. Can you confirm that I am not oversimplifying? import ezc3d
import numpy as np
file_path = "PATH_TO_C3D.c3d"
start_time = 2.955
end_time = 4.977
# Read the c3d file
c3d = ezc3d.c3d(file_path)
# Rewrite important parameters and the data only keeping the labelled markers that don't start with "*"
labels = c3d["parameters"]["POINT"]["LABELS"]["value"]
descriptions = c3d["parameters"]["POINT"]["DESCRIPTIONS"]["value"]
indices_to_keep = [i for i, lab in enumerate(labels) if not lab.startswith("*")]
c3d["parameters"]["POINT"]["LABELS"]["value"] = [labels[i] for i in indices_to_keep]
c3d["parameters"]["POINT"]["DESCRIPTIONS"]["value"] = [descriptions[i] for i in indices_to_keep]
# Change the data accondingly
c3d["data"]["points"] = c3d["data"]["points"][:, indices_to_keep, :]
del c3d["data"]["meta_points"] # Let ezc3d do the job for the meta_points
# Change the time parameters
start_point_idx = int(np.floor(start_time * c3d["parameters"]["POINT"]["RATE"]["value"]))
end_point_idx = int(np.ceil(end_time * c3d["parameters"]["POINT"]["RATE"]["value"]))
c3d["header"]["points"]["first_frame"] = start_point_idx
c3d["header"]["points"]["last_frame"] = end_point_idx
# Save the modified file with a new name
c3d["parameters"]["ANALOG"]["UNITS"]["value"] = [] # This seems like a bug in ezc3d, as it should not be a problem
c3d.write("new_modified.c3d")
# Read the new file
c3d_copied = ezc3d.c3d("new_modified.c3d") |
Than you. Your approach will not reduce much the size of the c3d (all data are still inside).
|
That is correct, most of these NEED to be very precise, so ezc3d won't let the user set them as they please, it will be updated to ensure internal consistency. The "starting" flag won't reduce the size of the data as 0.00 will be registered, for the non values. If you want to reduce the data, you must also remove the data points before the starting index. If you do so, you must reset the first_frame to 0 though |
@pariterre, I let you decide if you want to put an example to crop (and not change the start - end) a c3d file in the python example and you may close this issue. |
by the way, thank you for the help. |
Done in #324 |
For posterity:
This was not a bug, it was because the underlying c3d had unsupported value formatting from the 35th element. This is why we had to remove the values. |
Hi @pariterre,
Could you please provide a Python example for cropping a c3d and save it in another file?
Mickael
The text was updated successfully, but these errors were encountered: