pymgp.orbplot.rewrap#
- pymgp.orbplot.rewrap(t, x, method='rewrap', wrapat=[0, 360], verbose=0)[source]#
Rewrap cyclic data for plotting line segments.
Re-wrap cyclic data and insert breaks in lines so that when plotted the lines are properly terminated at the borders of the wrapping region. This function solves two issues with plotting lines for cyclic data:
the near vertical (or horizontal) line segments at the wraps,
lines do not extend to the wrapping boundaries (instead they take the opposite direction)
If unsolved, line plots on cyclic data can be misleading or unclear at best, while a scatter plot may not provide all the information.
This version corrects for wraps the ordinates (x) only.
- Parameters:
- t, xarray_like, float
The absissae (time) and ordinates (data)
- method{‘rewrap’, ‘unwrap’, split’, rewrap_nosplit’}, optional
- The rewrapping method. Defines what action is taken at a data wrap
- rewrapestimate time of wrap by interpolation from the data, and insert
the upper/lower wrap limits and ‘np.nan’ to cause a split in the line. The output arrays are larger than the the input arrays (3 additional data points per wrap)
- rewrap_noslitas with rewrap, but no ‘np.nan’ is inserted to split the
lines. The output arrays are larger than the the input arrays (2 additional data points per wrap)
- splitsplit the lines at a wrap by inserting ‘np.nan’. The output arrays
are larger than the the input arrays (1 additional data point per wrap)
unwrap : make the data continuous. The length of the arrays is unchanged
- wrapatlist, optional
List with the lower and upper wrap boundaries.
- verboseint, optional
Vebosity level.
- Returns:
- tout, xoutndarray, float
The absissae (time) and rewrapped ordinates (data) for plotting
- insndarray, int64
Index array for ‘np.insert’, can be applied to other arrays (‘z’) of similar shape with ‘zout = np.insert(z, ins, new_z_values_to_insert)’
See also
rewrap2d
Rewrap cyclic data in two dimensions (e.g. longitude and latitude).
Notes
The ouput should only be used for plotting purposes, as with some options interpolated data points and/or np.nan are inserted which could bias scientific analysis.
Examples
>>> x = np.array( [ 10., 100., 200, 300, 350, 45, 100, 180, 230, 160, 100, 10, 270, 150, 200, 300, 350, 45, 100, 200] ) >>> t = np.arange(x.size).astype(np.float64) >>> rewrap(t, x, method='rewrap') (array([ 0. , 1. , 2. , 3. , 4. , 4.18181818, 4.18181818, 4.18181818, 5. , 6. , 7. , 8. , 9. , 10. , 11. , 11.1 , 11.1 , 11.1 , 12. , 13. , 14. , 15. , 16. , 16.18181818, 16.18181818, 16.18181818, 17. , 18. , 19. ]), array([ 10., 100., 200., 300., 350., 360., nan, 0., 45., 100., 180., 230., 160., 100., 10., 0., nan, 360., 270., 150., 200., 300., 350., 360., nan, 0., 45., 100., 200.]), array([ 5, 12, 17, 5, 12, 17, 5, 12, 17], dtype=int64))
>>> rewrap(t, x, method='rewrap', wrapat=[-180, 180]) (array([ 0. , 1. , 1.8 , 1.8 , 1.8 , 2. , 3. , 4. , 5. , 6. , 7. , 7. , 7. , 7. , 8. , 8.71428571, 8.71428571, 8.71428571, 9. , 10. , 11. , 12. , 12.75 , 12.75 , 12.75 , 13. , 13.6 , 13.6 , 13.6 , 14. , 15. , 16. , 17. , 18. , 18.8 , 18.8 , 18.8 , 19. ]), array([ 10., 100., 180., nan, -180., -160., -60., -10., 45., 100., 180., nan, -180., -180., -130., -180., nan, 180., 160., 100., 10., -90., -180., nan, 180., 150., 180., nan, -180., -160., -60., -10., 45., 100., 180., nan, -180., -160.]), array([ 2, 7, 9, 13, 14, 19, 2, 7, 9, 13, 14, 19, 2, 7, 9, 13, 14, 19], dtype=int64))
>>> tout, xout, *_ = rewrap(t, x, method='rewrap') >>> plt.figure >>> plt.plot(t,x, linewidth='0.5', linestyle=':', color='r') >>> plt.scatter(t,x) >>> plt.plot(tout, xout)