Skip to content

Instantly share code, notes, and snippets.

@shahpnmlab
Created September 17, 2024 12:58
Show Gist options
  • Save shahpnmlab/5589da84611c195642243ad2f9115445 to your computer and use it in GitHub Desktop.
Save shahpnmlab/5589da84611c195642243ad2f9115445 to your computer and use it in GitHub Desktop.
starfile writing example
import starfile
import pandas as pd
df_optics = pd.DataFrame({
'rlnOpticsGroup': [1],
"rlnOpticsGroupName": ["OpticsGroup1"],
'rlnSphericalAberration': [2.7],
'rlnVoltage': [300],
'rlnImagePixelSize': [5],
'rlnImageDimensionality': [3]
})
df_particles = pd.DataFrame({
"rlnCoordinateX": [1, 32, 456, 456456],
"rlnCoordinateY": [1231231, 12312312, 12312312, 123213],
"rlnCoordinateZ": [1231231, 12312312, 12312312, 123213],
"rlnOpticsGroup": [1, 1, 1, 1] # Assuming all particles belong to the same optics group
})
# Create a dictionary with both dataframes
star_data = {
'optics': df_optics,
'particles': df_particles
}
# Write the STAR file
starfile.write(star_data, "foo.star", overwrite=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment