def __init__(self, lats, lons, times, values, variable=None, name=""): '''Default Dataset constructor :param lats: One dimensional numpy array of unique latitude values. :type lats: numpy array :param lons: One dimensional numpy array of unique longitude values. :type lons: numpy array :param times: One dimensional numpy array of unique python datetime objects. :type times: numpy array :param values: Three dimensional numpy array of parameter values with shape [timesLength, latsLength, lonsLength]. :type values: numpy array :param variable: Name of the value variable. :type variable: string :param name: An optional string name for the Dataset. :type variable: string :raises: ValueError ''' self._validate_inputs(lats, lons, times, values) lats, lons, values = utils.normalize_lat_lon_values(lats, lons, values) self.lats = lats self.lons = lons self.times = times self.values = values self.variable = variable self.name = name
def test_lats_reversed(self): lons2 = np.arange(-180, 180) lats, lons, values = utils.normalize_lat_lon_values(self.lats[::-1], lons2, self.values[:, ::-1, :]) np.testing.assert_array_equal(lats, self.lats) np.testing.assert_array_equal(values, self.values)
def test_shift_and_reversed(self): expected_vals = np.array([[10, 11, 8, 9], [6, 7, 4, 5], [2, 3, 0, 1]]) lats, lons, values = utils.normalize_lat_lon_values(self.lats2[::-1], self.lons2, self.values2) np.testing.assert_array_equal(values, expected_vals)
def test_lons_greater_than_180(self): self.lons = np.array([190, 210, 230, 250]) self.lats = np.array([-30, 0, 30]) self.values = np.arange(12).reshape(3, 4) expected_lons = np.array([-170, -150, -130, -110]) expected_values = np.array([[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11]]) lats, lons, values = utils.normalize_lat_lon_values(self.lats, self.lons, self.values) np.testing.assert_array_equal(lons, expected_lons) np.testing.assert_array_equal(expected_values, values)
def __init__(self, lats, lons, times, values, variable=None, units=None, origin=None, name=""): '''Default Dataset constructor :param lats: One dimensional numpy array of unique latitude values. :type lats: :class:`numpy.ndarray` :param lons: One dimensional numpy array of unique longitude values. :type lons: :class:`numpy.ndarray` :param times: One dimensional numpy array of unique python datetime objects. :type times: :class:`numpy.ndarray` :param values: Three dimensional numpy array of parameter values with shape [timesLength, latsLength, lonsLength]. :type values: :class:`numpy.ndarray` :param variable: Name of the value variable. :type variable: :mod:`string` :param units: Name of the value units :type units: :mod:`string` :param name: An optional string name for the Dataset. :type name: :mod:`string` :param origin: An optional object used to specify information on where this dataset was loaded from. :type origin: :class:`dict` :raises: ValueError ''' self._validate_inputs(lats, lons, times, values) lats, lons, values = utils.normalize_lat_lon_values(lats, lons, values) self.lats = lats self.lons = lons self.times = times self.values = values self.variable = variable self.units = units self.name = name self.origin = origin
def test_lons_reversed(self): self.lats = np.arange(-10, 10) self.lons = np.arange(40) times = np.array([datetime.datetime(2000, x, 1) for x in range(1, 7)]) flat_array = np.arange(len(times) * len(self.lats) * len(self.lons)) self.variable = flat_array.reshape(len(times), len(self.lats), len(self.lons)) lats, lons, values = utils.normalize_lat_lon_values(self.lats, self.lons[::-1], self.values[:, ::, ::-1]) np.testing.assert_array_equal(lats, self.lats) np.testing.assert_array_equal(values, self.values) np.testing.assert_array_equal(lons, self.lons)
def test_full_lons_shift(self): lats, lons, values = utils.normalize_lat_lon_values(self.lats, self.lons, self.values) np.testing.assert_array_equal(lons, np.arange(-180, 180))