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

Add method to read dials reflection data into pandas dataframe #1914

Open
graeme-winter opened this issue Nov 5, 2021 · 2 comments
Open
Labels
stale issues that have not seen activity for a while

Comments

@graeme-winter
Copy link
Contributor

Perhaps starting from something like this:

import sys

from dials.array_family import flex
import pandas as pd

r = flex.reflection_table.from_file(sys.argv[1])

data = { } 

for k in r.keys():
    if hasattr(r[k], "as_numpy_array"):
        a = r[k].as_numpy_array()
        if len(a.shape) == 1:
            data[k] = a
        else:
            for n in range(a.shape[1]):
                data[f"{k}_{n}"] = a[:,n]
    else:
        print(f"Cannot convert {k} to numpy")

df = pd.DataFrame(data, columns=[k for k in data])

having reflections.as_pandas_dataframe() or something could be handy for the general user.

I welcome comments.

@JBGreisman
Copy link

This sort of thing would be pretty useful to me -- I had briefly looked into reading .refl files for reciprocalspaceship: rs-station/reciprocalspaceship#78. The linked issue may have a few useful snippets to look at.

I find it quite useful to work with reflection data in this sort of format, and this proposed method would support converting to a reciprocalspaceship.DataSet object because that constructor can take a pandas.DataFrame (along with spacegroup, unitcell, etc) to instantiate a DataSet object. I think this would be a great method to add to the reflection_table.

@stale
Copy link

stale bot commented May 5, 2022

This issue has been automatically marked as stale because it has not had recent activity. The label will be removed automatically if any activity occurs. Thank you for your contributions.

@stale stale bot added the stale issues that have not seen activity for a while label May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale issues that have not seen activity for a while
Projects
None yet
Development

No branches or pull requests

2 participants