@@ -674,127 +674,3 @@ def linear(cube, sample_points, extrapolation_mode='linear'):
674674
675675 scheme = Linear (extrapolation_mode )
676676 return cube .interpolate (sample_points , scheme )
677-
678-
679- def _interp1d_rolls_y ():
680- """
681- Determines if :class:`scipy.interpolate.interp1d` rolls its array `y` by
682- comparing the shape of y passed into interp1d to the shape of its internal
683- representation of y.
684-
685- SciPy v0.13.x+ no longer rolls the axis of its internal representation
686- of y so we test for this occurring to prevent us subsequently
687- extrapolating along the wrong axis.
688-
689- For further information on this change see, for example:
690- * https://github.com/scipy/scipy/commit/0d906d0fc54388464603c63119b9e35c9a9c4601
691- (the commit that introduced the change in behaviour).
692- * https://github.com/scipy/scipy/issues/2621
693- (a discussion on the change - note the issue is not resolved
694- at time of writing).
695-
696- """
697- y = np .arange (12 ).reshape (3 , 4 )
698- f = interp1d (np .arange (3 ), y , axis = 0 )
699- # If the initial shape of y and the shape internal to interp1d are *not*
700- # the same then scipy.interp1d rolls y.
701- return y .shape != f .y .shape
702-
703-
704- class Linear1dExtrapolator (object ):
705- """
706- Extension class to :class:`scipy.interpolate.interp1d` to provide linear extrapolation.
707-
708- See also: :mod:`scipy.interpolate`.
709-
710- .. deprecated :: 1.10
711-
712- """
713- roll_y = _interp1d_rolls_y ()
714-
715- def __init__ (self , interpolator ):
716- """
717- Given an already created :class:`scipy.interpolate.interp1d` instance, return a callable object
718- which supports linear extrapolation.
719-
720- .. deprecated :: 1.10
721-
722- """
723- self ._interpolator = interpolator
724- self .x = interpolator .x
725- # Store the y values given to the interpolator.
726- self .y = interpolator .y
727- """
728- The y values given to the interpolator object.
729-
730- .. note:: These are stored with the interpolator.axis last.
731-
732- """
733- # Roll interpolator.axis to the end if scipy no longer does it for us.
734- if not self .roll_y :
735- self .y = np .rollaxis (self .y , self ._interpolator .axis , self .y .ndim )
736-
737- def all_points_in_range (self , requested_x ):
738- """Given the x points, do all of the points sit inside the interpolation range."""
739- test = (requested_x >= self .x [0 ]) & (requested_x <= self .x [- 1 ])
740- if isinstance (test , np .ndarray ):
741- test = test .all ()
742- return test
743-
744- def __call__ (self , requested_x ):
745- if not self .all_points_in_range (requested_x ):
746- # cast requested_x to a numpy array if it is not already.
747- if not isinstance (requested_x , np .ndarray ):
748- requested_x = np .array (requested_x )
749-
750- # we need to catch the special case of providing a single value...
751- remember_that_i_was_0d = requested_x .ndim == 0
752-
753- requested_x = requested_x .flatten ()
754-
755- gt = np .where (requested_x > self .x [- 1 ])[0 ]
756- lt = np .where (requested_x < self .x [0 ])[0 ]
757- ok = np .where ( (requested_x >= self .x [0 ]) & (requested_x <= self .x [- 1 ]) )[0 ]
758-
759- data_shape = list (self .y .shape )
760- data_shape [- 1 ] = len (requested_x )
761- result = np .empty (data_shape , dtype = self ._interpolator (self .x [0 ]).dtype )
762-
763- # Make a variable to represent the slice into the resultant data. (This will be updated in each of gt, lt & ok)
764- interpolator_result_index = [slice (None , None )] * self .y .ndim
765-
766- if len (ok ) != 0 :
767- interpolator_result_index [- 1 ] = ok
768-
769- r = self ._interpolator (requested_x [ok ])
770- # Reshape the properly formed array to put the interpolator.axis last i.e. dims 0, 1, 2 -> 0, 2, 1 if axis = 1
771- axes = list (range (r .ndim ))
772- del axes [self ._interpolator .axis ]
773- axes .append (self ._interpolator .axis )
774-
775- result [interpolator_result_index ] = r .transpose (axes )
776-
777- if len (lt ) != 0 :
778- interpolator_result_index [- 1 ] = lt
779-
780- grad = (self .y [..., 1 :2 ] - self .y [..., 0 :1 ]) / (self .x [1 ] - self .x [0 ])
781- result [interpolator_result_index ] = self .y [..., 0 :1 ] + (requested_x [lt ] - self .x [0 ]) * grad
782-
783- if len (gt ) != 0 :
784- interpolator_result_index [- 1 ] = gt
785-
786- grad = (self .y [..., - 1 :] - self .y [..., - 2 :- 1 ]) / (self .x [- 1 ] - self .x [- 2 ])
787- result [interpolator_result_index ] = self .y [..., - 1 :] + (requested_x [gt ] - self .x [- 1 ]) * grad
788-
789- axes = list (range (len (interpolator_result_index )))
790- axes .insert (self ._interpolator .axis , axes .pop (axes [- 1 ]))
791- result = result .transpose (axes )
792-
793- if remember_that_i_was_0d :
794- new_shape = list (result .shape )
795- del new_shape [self ._interpolator .axis ]
796- result = result .reshape (new_shape )
797-
798- return result
799- else :
800- return self ._interpolator (requested_x )
0 commit comments