def test_combine_kp_no_time(self): """Test combine_kp failure when no times are provided""" combo_in = {kk: self.combine[kk] for kk in ['standard_inst', 'recent_inst', 'forecast_inst']} with pytest.raises(ValueError): kp_ap.combine_kp(combo_in) del combo_in
def test_combine_kp_inst_time(self): """Test combine_kp when times are provided through the instruments""" combo_in = { kk: self.combine[kk] for kk in ['standard_inst', 'recent_inst', 'forecast_inst'] } combo_in['standard_inst'].load(date=self.combine['start']) combo_in['recent_inst'].load(date=self.test_day) combo_in['forecast_inst'].load(date=self.test_day) combo_in['stop'] = combo_in['forecast_inst'].index[-1] kp_inst = kp_ap.combine_kp(**combo_in) assert kp_inst.index[0] >= self.combine['start'] # kp_inst contains times up to 21:00:00, coombine['stop'] is midnight assert kp_inst.index[-1].date() <= self.combine['stop'].date() assert len(kp_inst.data.columns) == 1 assert kp_inst.data.columns[0] == 'Kp' assert np.isnan(kp_inst.meta['Kp'][kp_inst.meta.labels.fill_val]) assert len(kp_inst['Kp'][np.isnan(kp_inst['Kp'])]) == 0 del combo_in, kp_inst
def test_combine_kp_one(self): """ Test combine_kp failure when only one instrument is provided""" # Load a test instrument testInst = pysat.Instrument() testInst.data = pds.DataFrame({'Kp': np.arange(0, 4, 1.0 / 3.0)}, index=[dt.datetime(2009, 1, 1) + pds.DateOffset(hours=3 * i) for i in range(12)]) testInst.meta = pysat.Meta() testInst.meta['Kp'] = {testInst.meta.labels.fill_val: np.nan} combo_in = {"standard_inst": testInst} with pytest.raises(ValueError): kp_ap.combine_kp(combo_in) del combo_in, testInst
def test_combine_kp_no_data(self): """Test combine_kp when no data is present for specified times""" combo_in = {kk: self.combine['forecast_inst'] for kk in ['standard_inst', 'recent_inst', 'forecast_inst']} combo_in['start'] = dt.datetime(2014, 2, 19) combo_in['stop'] = dt.datetime(2014, 2, 24) kp_inst = kp_ap.combine_kp(**combo_in) assert kp_inst.data.isnull().all()["Kp"] del combo_in, kp_inst
def test_combine_kp_no_recent(self): """Test combine_kp when recent data is not provided""" combo_in = {kk: self.combine[kk] for kk in self.combine.keys() if kk != 'recent_inst'} kp_inst = kp_ap.combine_kp(**combo_in) assert kp_inst.index[0] >= self.combine['start'] assert kp_inst.index[-1] < self.combine['stop'] assert len(kp_inst.data.columns) == 1 assert kp_inst.data.columns[0] == 'Kp' assert (kp_inst.meta['Kp'][kp_inst.meta.labels.fill_val] == self.combine['fill_val']) assert (kp_inst['Kp'] == self.combine['fill_val']).any() del kp_inst, combo_in
def test_combine_kp_all(self): """Test combine_kp when all input is provided""" kp_inst = kp_ap.combine_kp(**self.combine) assert kp_inst.index[0] >= self.combine['start'] assert kp_inst.index[-1] < self.combine['stop'] assert len(kp_inst.data.columns) == 1 assert kp_inst.data.columns[0] == 'Kp' # Fill value is defined by combine assert(kp_inst.meta['Kp'][kp_inst.meta.labels.fill_val] == self.combine['fill_val']) assert (kp_inst['Kp'] != self.combine['fill_val']).all() del kp_inst
def test_combine_kp_none(self): """ Test combine_kp failure when no input is provided""" with pytest.raises(ValueError): kp_ap.combine_kp()