-
Notifications
You must be signed in to change notification settings - Fork 664
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
MemoryReader doesn't have a filename
attribute
#1027
Comments
Really we should have a Universe.clone or Universe.copy method that creates On Fri, 14 Oct 2016, 9:53 a.m. Max Linke, [email protected] wrote:
|
But the filename might still be interesting for the MemoryReader to know from where the data originally comes. |
I opened #1029 to discuss the copying of a universe. I'm would like some more feedback is the MemoryReader should hold some information about the original file used to load the data. @wouterboomsma and @mtiberti do you have an opinion on that? |
If I remember right, you can init a memoryreader with just a numpy array, so that's a nice corner case for someone to figure out too :) |
@kain88-de, It would be a bit odd to have a filename in the MemoryReader. At least in our use cases, we frequently construct MemoryReaders directly from a numpy array, or as a merge from different trajectories. For instance, we often use something like this to merge universes: def merge_universes(universes):
"""
Merge list of universes into one
Parameters
----------
`universes` : list of Universe objects
Returns
----------
Universe object
"""
for universe in universes:
universe.transfer_to_memory()
return mda.Universe(
universes[0].filename,
np.concatenate(tuple([e.trajectory.timeseries() for e in universes]),
axis=1),
format=MemoryReader) As @richardjgowers suggests, a
...which could of course also be hidden inside a
|
It might be handy if transfer_to_memory did store what the original filename was, and it doesn't cost anything to do it. But |
What if we give a name when the MemoryReader is constructed from a universe with known filename. If the MemoryReader is constructed from a array we set the filename to |
Yes, or something like 'numpy' On Mon, 17 Oct 2016, 10:01 p.m. Max Linke, [email protected] wrote:
|
I would prefer a more general |
Can we just decide to add (For context: The NamedStream class main reason for existence is to add an actual filename so that code can decide on the format of the stream. This is not needed here because the Reader API is known.) |
Sounds like a good compromise to have the filename attribute set when it makes sense. |
I haven't heard anything else so for right now so I conclude that the consensus is to
(Note on 3: The ChainReader will only give you the current trajectory filename without indication that there are other files in the chain.) EDIT: properly paraphrased #1027 (comment) |
I'd like to work on this. |
@richardjgowers From what I understand, a What I don't understand is
What I have seen in tests is something like this - Is |
Edit: Moved TODO list into Issue main body - RG @utkbansal Are you still interested in tackling this issue? |
I've moved the Issue goals into the main body of this issue so it's all in one (easy to find) place. Is it safe to have |
@richardjgowers It might break in a few places. But these places probably break already without us knowing. Anyway, it is better to have the API clearly defined so the rest of the code can adapt. Also, an attribute being |
Yeah it's definitely an improvement, just wondering if it's the best
solution. As long as we document in the API that the attribute might be
None then it's OK
…On Sun, 19 Mar 2017, 2:46 p.m. Jonathan Barnoud, ***@***.***> wrote:
@richardjgowers <https://github.com/richardjgowers> It might break in a
few places. But these places probably break already without us knowing.
Anyway, it is better to have the API clearly defined so the rest of the
code can adapt. Also, an attribute being None when not relevant looks
rather common in python.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1027 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AI0jB6hjUHO7iJvfdkYvBcI2vOkTzojfks5rnT_hgaJpZM4KWyBL>
.
|
@jbarnoud Sure, I'm happy to work on this. |
Is this also the correct solution if we change the underlying numpy arrays? I commonly write code to clone a universe like this |
Regarding #1027 (comment) : should we consider URI-style names: e.g
(And if we ever get streams working: EDIT: This does not really addess @kain88-de 's concern, though. Rather, when changing the underlying array of MemoryReader, the filename attribute should be set to |
@orbeckst I am a bit worried adding a protocol prefix would make the use of the attribute overly complicated. Indeed, it means adding a parsing step. Also, we would have to have the protocol bit in the filename for every reader. |
Yes, it would make it more complicated.
This is really not solving any immediate problem, so yes, ignore ;-). But I think it's worth thinking about eventually. |
@orbeckst, rather than overloading the filename string with extra info we could add a kwarg or an attribute to the readers. |
Fixes #1027 Changes made in this Pull Request: Adds filename attribute to MemoryReader Adds tests
Problem
When I need a real copy of an AtomGroup i usually do
This create a independent copy of the original universe. This is good to create references from a single Atomgroup argument in analysis functions. This doesn't work any more then the AtomGroup is a MemoryReader.
My main issue is that I can't create independent copies of atomgroups like I used to when I use the MemoryReader. There are two solutions for me. I can either create a completely independent copy another way or the MemoryReader still keeps a reference to the original file used to create it (but I admit that might be confusing).
Desired Implementation
filename
attribute to theMemoryReader
filename = None
if constructed from an array or another anonymous sourcefilename = <trajectory-filename>
if it comes from a universe with an associated trajectory filenameUniverse.transfer_to_memory
, set thefilename
attributefilename
attribute of aMemoryReader
instance built from an array isNone
filename
attribute of aMemoryReader
instance built viatransfer_to_memory
is the same as the source filenameHistory
filename
attribute #1027 (comment) (@orbeckst)The text was updated successfully, but these errors were encountered: