Created
March 25, 2022 17:08
-
-
Save bbarad/e47f6ae3e8101fe0e9a47e6a81579c70 to your computer and use it in GitHub Desktop.
Adjust angles for all files in a folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adjust angles from imod alignment before warp import to allow flattening of tomograms | |
# Replaces imod's taSolution.log file with adjusted deltlts, while preserving the original file in taSolution.log.bak | |
# Author: Benjamin Barad 2022 | |
# Usage: | |
# cd WARPTOPFOLDER/imod | |
# python adjust_angles.py * | |
# Alternatively, instead of the wildcard individual tilt series folders can be specified. | |
import pandas as pd | |
from sys import argv | |
from os import path | |
import shutil | |
folders = argv[1:] | |
tilt_offset = 11 | |
file_header = ["view","rotation","tilt","deltilt","mag","dmag","skew","mean resid"] | |
for folder in folders: | |
filename = folder+"/taSolution.log" | |
if not path.exists(filename): | |
print("File not found:",filename) | |
continue | |
if not path.exists(filename+".bak"): | |
print("Saving backup file:",filename+".bak") | |
shutil.copyfile(filename,filename+".bak") | |
else: | |
print("Backup file already exists:",filename+".bak") | |
df = pd.read_csv(filename, index_col=0, skiprows=3, sep=None, skipinitialspace=True,header=None, names=file_header) | |
df["deltilt"] = df["deltilt"]+tilt_offset | |
df.to_csv(filename, sep=" ", index=True, header=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment