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

FRQ: allow user to supply part of a trajectory as trajectory #43

Open
kay-ro opened this issue Jul 4, 2024 · 0 comments
Open

FRQ: allow user to supply part of a trajectory as trajectory #43

kay-ro opened this issue Jul 4, 2024 · 0 comments
Labels
module: base module: trajectory new feature New feature release: major Issues that need or may be better addressed in a major release status: to do Issues that someone needs to work on

Comments

@kay-ro
Copy link
Member

kay-ro commented Jul 4, 2024

Proposed new feature or change:

Rather than having to supply a full trajectory, it would be useful if the user also can only supply parts of it.

traj[:100:] or traj[::2] currently do not work because the required type in most functions is FieldTrajectory | ParticleTrajectory rather than list | iterable of Frame. If a subset of a trajectory is still returned as a trajectory, traj[i] should still return the ith frame and not a trajectory of length 1 (for compatibility!).

Implementation principle:

class A:
    def __init__(self, liste, sl=None):
        self.__liste=liste
        self.__allitems=np.arange(len(liste))
        if sl is None:
            self.__sl=slice(0,len(liste),1)
        else:
            self.__sl=sl
    def __getitem__(self, item):
        if isinstance(item, int):
            item = self.__allitems[self.__sl][item]
            return self.__liste[item]
        elif isinstance(item, slice):
            # -> convert slice to list
            # create class A from sl=sl-list[item]
            # (np.arange(100)[slice(0,10,1)])[slice(0,6,2)]
            return A(self.__liste, sl=item)
        elif isinstance(item, list):
            # create class A from sl=sl[item]
            return A(self.__liste, sl=item)
    def __iter__(self):
        for i in range(len(self.__liste[self.__sl])):
            yield self[i]
    def __len__(self):
        return len(self.__liste[self.__sl])

a = A(np.arange(0,100,1))

print(len(a), type(a), a[13])
b = a[[1,6,3]]
print(len(b), type(b), b[1])
c = b[::2]
print(len(c), type(c), c[13])
100 <class '__main__.A'> 13
3 <class '__main__.A'> 6
50 <class '__main__.A'> 26
@kay-ro kay-ro added new feature New feature release: major Issues that need or may be better addressed in a major release status: to do Issues that someone needs to work on module: base module: trajectory labels Jul 4, 2024
@hechtprojects hechtprojects added this to the release v2.0.0 milestone Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: base module: trajectory new feature New feature release: major Issues that need or may be better addressed in a major release status: to do Issues that someone needs to work on
Projects
None yet
Development

No branches or pull requests

2 participants