Ejemplo n.º 1
0
    def interpolate(self, x_axis, y_axis, update=False, **kwargs):
        """Wrapper method to interpolate data at entire grid specified
            by the axes passed.

        Args:
            x_axis (float): Same es as constructor.
            y_axis (float): Same es as constructor.
            update (bool): If True data and axis saved in this instance
                will be overriden with interpolation result. If False
                interpolate will only return the result but data will
                stay unchanged.
            **kwargs: See interpolate_points.

        Returns:
            (PlotData): PlotData object with the interpolated data.
        """

        points = np.array(list(it.product(y_axis, x_axis)))
        new_data = self.interpolate_points(
            points[:, 1], points[:, 0], **kwargs)
        new_data = np.array(new_data, dtype=np.float64).reshape(
            len(y_axis), len(x_axis))

        if update:
            self.data, self.x_axis, self.y_axis = new_data, x_axis, y_axis
            self.range, self.step_size = range_from_axes(x_axis, y_axis)

            return self

        else:
            range_, _ = range_from_axes(x_axis, y_axis)
            new_plot_data = PlotData(new_data, range_)

            return new_plot_data
Ejemplo n.º 2
0
    def __init__(self, data, range_):
        """
        Args:
            data (float): 2D array of numbers with at least 2 elements
                in each dimension. Can contain NaN values.
            range_ (float): List of two lists containing the min and max
                value of x_axis and y_axis respectively. Can not contain
                NaN values and min value as to be strictly smaller than
                max value. (e.g. [[x_min, x_max], [y_min, y_max]])

        Public Attributes:
            data (float): See args.
            range (float): See args.
            x_axis (float): 1D array for the first axis of the data.
            y_axis (float): 1D array for the second axis of the data.
            step_size (float) : List of step sizes for each axes.
        """

        # Set data
        self.data = np.array(data, dtype=np.float64)

        if (self.data.ndim != 2 or len(self.data) < 2 or
                len(self.data[0]) < 2):
            raise TypeError('data has to be 2D array with at least 2 ' +
                            'elements in each dimension')

        else:
            self.data[~ np.isfinite(self.data)] = np.nan

        # Set range
        self.range = np.array(range_, dtype=np.float64)

        if self.range.shape != (2, 2):
            raise TypeError('range has to be of shape (2, 2)')

        if not np.isfinite(self.range).all():
            raise ValueError('range can only have finite values')

        # Set axes
        self.x_axis = axis_from_range(self.range[0], self.data.shape[1])
        self.y_axis = axis_from_range(self.range[1], self.data.shape[0])

        # Set step_size
        _, self.step_size = range_from_axes(self.x_axis, self.y_axis)