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.
|
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.') |
Currently the class
trajpyaccepts either a csv file or a numpy array for initialising the object. However, we can improve this by implementing a parser withfunctools.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.
singledispatchoffers an elegant way for this implementation.trajpy/trajpy/trajpy.py
Lines 27 to 35 in 8381bed