Skip to content

Commit

Permalink
add overwrite to tbl writing and fix euler header issue
Browse files Browse the repository at this point in the history
  • Loading branch information
brisvag committed Jan 24, 2024
1 parent c870d2f commit 61d0553
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions cryohub/writing/tbl.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
from ..utils.generic import listify


def write_tbl(particles, file_path):
def write_tbl(particles, file_path, overwrite=False):
"""
write particle data to disk as a dynamo .tbl file
"""
particles = listify(particles)
file_path = Path(file_path)

if not file_path.suffix:
file_path = file_path.with_suffix(".tbl")

if file_path.exists() and not overwrite:
raise FileExistsError(file_path)

dataframes = []
for poseset in particles:
df = pd.DataFrame()
Expand All @@ -38,8 +44,8 @@ def write_tbl(particles, file_path):
if ori is not None:
rotvec = ori.inv().as_rotvec(degrees=True)
if np.allclose(rotvec[:, :2], 0):
# single angle world
df[Dynamo.EULER_HEADERS[2]] = rotvec[:, 2]
# single angle world (extra ":" after 2 is to match 2d shapes)
df[Dynamo.EULER_HEADERS[2]] = rotvec[:, 2:]
else:
df[Dynamo.EULER_HEADERS[3]] = ori.inv().as_euler(
Dynamo.EULER, degrees=True
Expand All @@ -58,6 +64,4 @@ def write_tbl(particles, file_path):

df = pd.concat(dataframes)

if not file_path.suffix:
file_path = file_path.with_suffix(".tbl")
dynamotable.write(df, file_path)

0 comments on commit 61d0553

Please sign in to comment.