Beispiel #1
0
    def _calc_centered_axes(self, plot_data):
        x_step_size = plot_data.step_size[0]
        centered_range = plot_data.range[0] + \
                         [-x_step_size / 2, x_step_size / 2]
        x = axis_from_range(centered_range, len(plot_data.x_axis) + 1)

        y_step_size = plot_data.step_size[1]
        centered_range = plot_data.range[1] + \
                         [-y_step_size / 2, y_step_size / 2]
        y = axis_from_range(centered_range, len(plot_data.y_axis) + 1)

        return x, y
    def get_axes(self):
        range_ = self.get_range()
        resolution = self.get_resolution()
        num = [
            step_size_to_num(range_[0], resolution[0]),
            step_size_to_num(range_[1], resolution[1])
        ]

        axes = [
            axis_from_range(range_[0], num[0]),
            axis_from_range(range_[1], num[1])
        ]

        return axes
Beispiel #3
0
    def __init__(self, label, units, range_, num):

        self.label = label
        self.units = units
        self.range = range_
        self.axis = axis_from_range(range_, num)
        self.stepsize = abs(self.axis[1] - self.axis[0])
        self.num = len(self.axis)
Beispiel #4
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)
Beispiel #5
0
    def set_axis_by_num(self, range_, num):
        """A convenience setter method to set an axis by defining the
        range and the number of grid points.

        Args:
            range_ (list): A list of min and max value.
            num (int): An integer denoting the number of grid points.
        """

        self.set_axis(axis_from_range(range_, num))
Beispiel #6
0
    def set_axis_by_step_size(self, range_, step_size):
        """A convenience setter method to set an axis by defining the
        range and the step size.

        Args:
            range_ (list): A list of min and max value.
            step_size (float): A number denoting the step size.
        """

        num = step_size_to_num(range_, step_size)
        self.set_axis(axis_from_range(range_, num))