def get_historic_kp_data(stime, etime): """ Get today's Kp forecasts and historic 30-day record from SWPC Parameters ---------- stime : (dt.datetime) Start time etime : (dt.datetime) End time Returns ------- kp_inst : (pysat.Instrument) pysat Instrument object containing the last 30 days of Kp and the 3-day forcast """ # Initialize the instrument objects standard_inst = pysat.Instrument('sw', 'kp', '') recent_inst = pysat.Instrument('sw', 'kp', 'recent') # Download today's files standard_inst.download(start=stime, stop=etime) recent_inst.download(start=stime, stop=etime) # Combine the data into a single instrument kp_inst = sw_methods.combine_kp(standard_inst=standard_inst, recent_inst=recent_inst, start=stime, stop=etime) return kp_inst
def get_recent_kp_data(today=dt.datetime.today()): """ Get today's Kp forecasts and historic 30-day record from SWPC Parameters ---------- today : (dt.datetime) Today's datetime (default=dt.datetime.today()) Returns ------- kp_inst : (pysat.Instrument) pysat Instrument object containing the last 30 days of Kp and the 3-day forcast """ # Initialize the instrument objects recent_inst = pysat.Instrument('sw', 'kp', 'recent') forecast_inst = pysat.Instrument('sw', 'kp', 'forecast') # Download today's files recent_inst.download() forecast_inst.download() # Load today's data recent_inst.load(date=today) forecast_inst.load(date=today) # Combine the data into a single instrument kp_inst = sw_methods.combine_kp(recent_inst=recent_inst, forecast_inst=forecast_inst) return kp_inst
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 = sw_meth.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.fill_label]) assert len(kp_inst['Kp'][np.isnan(kp_inst['Kp'])]) == 0 del combo_in, kp_inst
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'] = pysat.datetime(2014, 2, 19) combo_in['stop'] = pysat.datetime(2014, 2, 24) kp_inst = sw_meth.combine_kp(**combo_in) assert kp_inst.data.isnull().all()["Kp"] del combo_in, kp_inst
def test_combine_kp_all(self): """Test combine_kp when all input is provided""" kp_inst = sw_meth.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.fill_label] == self.combine['fill_val']) assert (kp_inst['Kp'] != self.combine['fill_val']).all() del kp_inst
def test_combine_kp_no_standard(self): """Test combine_kp when standard data is not provided""" combo_in = { kk: self.combine[kk] for kk in self.combine.keys() if kk != 'standard_inst' } kp_inst = sw_meth.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.fill_label] == self.combine['fill_val']) assert len( kp_inst['Kp'][kp_inst['Kp']] == self.combine['fill_val']) > 0 del kp_inst, combo_in