def test_ref_val(self): """checks that we pick the correct reference value for all lon points.""" x = q.DiurnalLocalTimeStatistics(self.test_data, self.time_axis, self.timestep, self.lons) lsf = q.LongitudeSamplingFunction(24 * u.hour / self.timestep, 13 * u.hour) i_lons = lsf.get_index(self.lons) + 4 result = np.empty((len(i_lons), )) for i in range(len(i_lons)): result[i] = self.test_data[i, i_lons[i]] self.assertTrue(np.all(result == x.ref_val())) # now switch test data so that there's more land points than time points # and the axes are reversed self.test_data = np.arange(100 * 16).reshape(16, 100) self.time_axis = 0 self.lons = np.arange(100) * 2 * u.deg - 135 * u.deg x = q.DiurnalLocalTimeStatistics(self.test_data, self.time_axis, self.timestep, self.lons) lsf = q.LongitudeSamplingFunction(24 * u.hour / self.timestep, 13 * u.hour) i_lons = lsf.get_index(self.lons) + 4 result = np.empty((len(i_lons), )) for i in range(len(i_lons)): result[i] = self.test_data[i_lons[i], i] self.assertTrue(np.all(result == x.ref_val()))
def test_noon(self): samp_fn = q.LongitudeSamplingFunction(4., 12 * u.hour) lons = np.arange(-180, 180, 30) * u.deg test_ind = samp_fn.get_index(lons) delta_hours = (c.Angle(180 * u.deg - lons).wrap_at(360 * u.deg) / (15 * (u.deg / u.hour))) ind = np.trunc( (delta_hours / (6 * u.hour)).to(u.dimensionless_unscaled)) self.assertTrue(np.all(test_ind == ind.astype(int)))
def test_preceeding_day(self): """tests to ensure the correct data is returned""" x = q.DiurnalLocalTimeStatistics(self.test_data, self.time_axis, self.timestep, self.lons) lsf = q.LongitudeSamplingFunction(24 * u.hour / self.timestep, 13 * u.hour) i_lons = lsf.get_index(self.lons) result = np.empty((len(i_lons), 4)) for i in range(len(i_lons)): result[i, :] = self.test_data[i, i_lons[i] + 1:i_lons[i] + 5] self.assertTrue(np.all(result == x.get_preceeding_day()))
def test_mask(self): """test initialization of mask""" x = q.DiurnalLocalTimeStatistics(self.test_data, self.time_axis, self.timestep, self.lons) lsf = q.LongitudeSamplingFunction(24 * u.hour / self.timestep, 13 * u.hour) i_lons = lsf.get_index(self.lons) afternoon = i_lons[0] self.assertTrue(afternoon == 3) mask_test = [ not ((i > afternoon) and (i <= afternoon + 4)) for i in range(8) ] self.assertTrue(np.all(x.mask[0, :] == mask_test))
def test_index_units(self): samp_fn = q.LongitudeSamplingFunction(4, 12 * u.hour) lons = np.arange(-180, 180, 30) * u.deg test_ind = samp_fn.get_index(lons) self.assertEqual(test_ind.unit, u.dimensionless_unscaled)