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

Implement new parser with singledispatch and move type handling from trajpy.__init__ #119

Open
phydev opened this issue Jul 25, 2023 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed maintainability
Milestone

Comments

@phydev
Copy link
Member

phydev commented Jul 25, 2023

Currently the class trajpy accepts either a csv file or a numpy array for initialising the object. However, we can improve this by implementing a parser with functools.singledispatch.

Since trajpy's aims to be a general framework for trajectory analysis, it is critical to put more work on the parser for providing broad support for different file formats. singledispatch offers an elegant way for this implementation.

trajpy/trajpy/trajpy.py

Lines 27 to 35 in 8381bed

if type(trajectory) == str:
trajectory = np.genfromtxt(trajectory, **params)
if type(trajectory) == np.ndarray:
self._t, self._r = trajectory[:, 0], trajectory[:, 1:]
elif type(trajectory) == tuple:
self._t, self._r = np.asarray(trajectory[0]), np.asarray(trajectory[1:])
else:
raise TypeError('trajectory receives an array or a filename as input.')

@phydev phydev added enhancement New feature or request help wanted Extra attention is needed maintainability labels Jul 25, 2023
@phydev phydev added this to the New parser milestone Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed maintainability
Projects
None yet
Development

No branches or pull requests

1 participant