-
Notifications
You must be signed in to change notification settings - Fork 7
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
Refactoring the way data is returned in panedr #33
Changes from 10 commits
c484bef
48085f3
e700706
18e68c9
967807e
d69ae9e
09b8e9e
3b708d1
20d5e39
52857ad
ce812c5
692ccad
6ef2f84
2659211
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,8 @@ | |
import sys | ||
import itertools | ||
import time | ||
import pandas | ||
import numpy as np | ||
|
||
|
||
#Index for the IDs of additional blocks in the energy file. | ||
#Blocks can be added without sacrificing backward and forward | ||
|
@@ -75,7 +76,7 @@ | |
Enxnm = collections.namedtuple('Enxnm', 'name unit') | ||
ENX_VERSION = 5 | ||
|
||
__all__ = ['edr_to_df'] | ||
__all__ = ['edr_to_df', 'edr_to_dict', 'read_edr'] | ||
|
||
|
||
class EDRFile(object): | ||
|
@@ -395,14 +396,14 @@ def edr_strings(data, file_version, n): | |
|
||
def is_frame_magic(data): | ||
"""Unpacks an int and checks whether it matches the EDR frame magic number | ||
|
||
Does not roll the reading position back. | ||
""" | ||
magic = data.unpack_int() | ||
return magic == -7777777 | ||
|
||
|
||
def edr_to_df(path, verbose=False): | ||
def read_edr(path, verbose=False): | ||
begin = time.time() | ||
edr_file = EDRFile(str(path)) | ||
all_energies = [] | ||
|
@@ -427,5 +428,27 @@ def edr_to_df(path, verbose=False): | |
end='', file=sys.stderr) | ||
print('\n{} frame read in {:.2f} seconds'.format(ifr, end - begin), | ||
file=sys.stderr) | ||
|
||
return all_energies, all_names, times | ||
|
||
|
||
def edr_to_df(path: str, verbose: bool = False): | ||
try: | ||
import pandas | ||
except ImportError: | ||
raise ImportError("""ERROR --- pandas was not found! | ||
pandas is required to use the `.edr_to_df()` | ||
functionality. Try installing it using pip, e.g.: | ||
python -m pip install pandas""") | ||
all_energies, all_names, times = read_edr(path, verbose=verbose) | ||
df = pandas.DataFrame(all_energies, columns=all_names, index=times) | ||
return df | ||
|
||
|
||
def edr_to_dict(path: str, verbose: bool = False): | ||
all_energies, all_names, times = read_edr(path, verbose=verbose) | ||
energy_dict = {} | ||
for idx, name in enumerate(all_names): | ||
energy_dict[name] = np.array( | ||
[all_energies[frame][idx] for frame in range(len(times))]) | ||
return energy_dict | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure that the "Time" key is in. I expect it to be, but I do not remember exactly how I treated it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Time" is part of all_names = [u'Time'] + [nm.name for nm in edr_file.nms]
[...]
all_energies.append([frame.t] + [ener.e for ener in frame.ener]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pandas | ||
numpy>=1.19.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IAlibay is bumping the version to 1.20.0 for MDAnalysis in MDAnalysis/mdanalysis#3737 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't impact things here so it wouldn't think it matters. If you want to raise numpy to 1.20 you'll have to drop py3.6. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should we prioritise here? Staying in-step with MDAnalysis' dependencies or keeping Py3.6? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't impact MDAnalysis if panedr supports a wider range of python & numpy versions, so IMHO it's fine to just leave it as-is. |
||
pbr |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ classifier = | |
test = | ||
six | ||
pytest | ||
pandas = | ||
pandas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a test for that, which means a pipeline that does not install pandas and a test that runs the function and asserts the exception is raised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BFedder you should be able to just use monkeypatch here to do this: https://github.com/MDAnalysis/mdanalysis/blob/3e249fe7173e68bb61d4ad7a2dfd316014760410/testsuite/MDAnalysisTests/utils/test_datafiles.py#L28-L38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added this test now