def test_bin_data_type(self): """Test failure when median 1D is given non array-like bins """ avg.median2D(self.testInst, ['0', 'd', '24', 'c'], self.test_label, self.test_data, auto_bin=False)
def test_bin_data_type(self): """Test failure when a non array-like is given to median2D """ avg.median2D(self.testInst, ['1', 'a', '23', '10'], 'longitude', ['0', 'd', '24', 'c'], 'mlt', ['dummy1', 'dummy2', 'dummy3'], auto_bin=False)
def test_bin_data_depth(self): """Test failure when an array-like of length 1 is given to median2D """ avg.median2D(self.testInst, 1, 'longitude', 24, 'mlt', ['dummy1', 'dummy2', 'dummy3'], auto_bin=False)
def test_nonmonotonic_bins(self): """Test 2D median failure when provided with a non-monotonic bins """ avg.median2D(self.testInst, np.array([0., 300., 100.]), 'longitude', np.array([0., 24., 13.]), 'mlt', ['dummy1', 'dummy2', 'dummy3'], auto_bin=False)
def test_constellation_median2D(self): """ Test constellation implementation of 2D median""" for i in self.testC.instruments: i.bounds = self.bounds self.testI.bounds = self.bounds resultsC = avg.median2D(self.testC, [0., 360., 24], 'longitude', [0., 24., 24], 'mlt', ['dummy1', 'dummy2', 'dummy3']) resultsI = avg.median2D(self.testI, [0., 360., 24], 'longitude', [0., 24., 24], 'mlt', ['dummy1', 'dummy2', 'dummy3']) medC1 = resultsC['dummy1']['median'] medI1 = resultsI['dummy1']['median'] medC2 = resultsC['dummy2']['median'] medI2 = resultsI['dummy2']['median'] medC3 = resultsC['dummy3']['median'] medI3 = resultsI['dummy3']['median'] assert np.array_equal(medC1, medI1) assert np.array_equal(medC2, medI2) assert np.array_equal(medC3, medI3)
def test_basic_seasonal_median2D(self): """ Test basic seasonal 2D median""" results = avg.median2D(self.testInst, [0., 360., 24], 'longitude', [0., 24., 24], 'mlt', [self.dname]) # iterate over all # no variation in the median, all values should be the same test_vals = np.arange(50) * 1.2 for i, row in enumerate(results[self.dname]['median']): for j, item in enumerate(row): assert np.all(item == test_vals) for i, row in enumerate(results[self.dname]['avg_abs_dev']): for j, item in enumerate(row): assert np.all(item == 0)
def test_basic_seasonal_2Dmedian(self): """ Test the basic seasonal 2D median""" results = avg.median2D(self.testInst, [0., 360., 24], 'longitude', [0., 24., 24], 'mlt', [self.dname]) # iterate over all # no variation in the median, all values should be the same for i, row in enumerate(results[self.dname]['median']): for j, item in enumerate(row): assert np.all(item['density'] == self.test_vals) assert np.all(item['fraction'] == self.test_fracs) for i, row in enumerate(results[self.dname]['avg_abs_dev']): for j, item in enumerate(row): assert np.all(item['density'] == 0) assert np.all(item['fraction'] == 0)
def test_seasonal_average_uneven_bins(self): """ Test seasonal 2D median with uneven bins""" results = avg.median2D(self.testInst, np.linspace(0., 360., 25), 'longitude', np.linspace(0., 24., 25), 'mlt', ['dummy1', 'dummy2', 'dummy3'], auto_bin=False) dummy_val = results['dummy1']['median'] dummy_dev = results['dummy1']['avg_abs_dev'] dummy2_val = results['dummy2']['median'] dummy2_dev = results['dummy2']['avg_abs_dev'] dummy3_val = results['dummy3']['median'] dummy3_dev = results['dummy3']['avg_abs_dev'] dummy_x = results['dummy1']['bin_x'] dummy_y = results['dummy1']['bin_y'] # iterate over all y rows # value should be equal to integer value of mlt # no variation in the median, all values should be the same check = [] for i, y in enumerate(dummy_y[:-1]): assert np.all(dummy_val[i, :] == y.astype(int)) assert np.all(dummy_dev[i, :] == 0) for i, x in enumerate(dummy_x[:-1]): assert np.all(dummy2_val[:, i] == x / 15.0) assert np.all(dummy2_dev[:, i] == 0) for i, x in enumerate(dummy_x[:-1]): check.append( np.all(dummy3_val[:, i] == x / 15.0 * 1000.0 + dummy_y[:-1])) check.append(np.all(dummy3_dev[:, i] == 0)) # holds here because there are 32 days, no data is discarded, # each day holds same amount of data assert (self.testInst.data['dummy1'].size * 3 == sum( [sum(i) for i in results['dummy1']['count']])) assert np.all(check)
def test_2D_median(self): """ Test a 2D median calculation with a constellation""" for i in self.testC.instruments: i.bounds = self.bounds results = avg.median2D(self.testC, [0., 360., 24], 'longitude', [0., 24, 24], 'slt', ['uts']) dummy_val = results['uts']['median'] dummy_dev = results['uts']['avg_abs_dev'] dummy_y = results['uts']['bin_y'] # iterate over all y rows # value should be equal to integer value of mlt # no variation in the median, all values should be the same check = [] for i, y in enumerate(dummy_y[:-1]): check.append(np.all(dummy_val[i, :] == y.astype(int))) check.append(np.all(dummy_dev[i, :] == 0))
def test_heterogenous_constellation_median2D(self): """ Test the seasonal 2D median of a heterogeneous constellation """ for inst in self.testC: inst.bounds = self.bounds results = avg.median2D(self.testC, [0., 360., 24], 'longitude', [0., 24., 24], 'mlt', ['dummy1', 'dummy2', 'dummy3']) dummy_val = results['dummy1']['median'] dummy_dev = results['dummy1']['avg_abs_dev'] dummy2_val = results['dummy2']['median'] dummy2_dev = results['dummy2']['avg_abs_dev'] dummy3_val = results['dummy3']['median'] dummy3_dev = results['dummy3']['avg_abs_dev'] dummy_x = results['dummy1']['bin_x'] dummy_y = results['dummy1']['bin_y'] # iterate over all y rows # value should be equal to integer value of mlt # no variation in the median, all values should be the same check = [] for i, y in enumerate(dummy_y[:-1]): check.append(np.all(dummy_val[i, :] == y.astype(int))) check.append(np.all(dummy_dev[i, :] == 0)) for i, x in enumerate(dummy_x[:-1]): check.append(np.all(dummy2_val[:, i] == x / 15.0)) check.append(np.all(dummy2_dev[:, i] == 0)) for i, x in enumerate(dummy_x[:-1]): check.append( np.all(dummy3_val[:, i] == x / 15.0 * 1000.0 + dummy_y[:-1])) check.append(np.all(dummy3_dev[:, i] == 0)) assert np.all(check)