def get_recent_f107_data(today=dt.datetime.today()): """ Get today's F10.7 forecasts and historic 30-day record from SWPC Parameters ---------- today : (dt.datetime) Today's datetime (default=dt.datetime.today()) Returns ------- f107_inst : (pysat.Instrument) pysat Instrument object containing the last 30 days of F10.7 and the 3-day forcast """ # Initialize the instrument objects standard_inst = pysat.Instrument('sw', 'f107', 'daily') forecast_inst = pysat.Instrument('sw', 'f107', 'forecast') # Download today's files standard_inst.download() forecast_inst.download() # Load today's data standard_inst.load(date=today) forecast_inst.load(date=today) # Combine the standard and forecast data into a single instrument f107_inst = sw_methods.combine_f107(standard_inst, forecast_inst) return f107_inst
def get_historic_f107_data(stime, etime): """ Get historic F10.7 for a specified range of dates Parameters ---------- stime : (dt.datetime) Start time etime : (dt.datetime) End time Returns ------- f107_inst : (pysat.Instrument) pysat Instrument object containing the desired date range """ # Initialize the instrument objects all_inst = pysat.Instrument('sw', 'f107', 'all') prelim_inst = pysat.Instrument('sw', 'f107', 'prelim') # Download the most recent historic file and desired preliminary data all_inst.download() prelim_inst.download(start=stime, stop=etime) # Combine the historic and preliminary data into a single instrument # for the desired range f107_inst = sw_methods.combine_f107(all_inst, prelim_inst, start=stime, stop=etime) return f107_inst
def test_combine_f107_all(self): """Test combine_f107 when all input is provided with '' and '45day'""" f107_inst = sw_meth.combine_f107(self.combineInst[''], self.combineInst['45day'], **self.combineTimes) assert f107_inst.index[0] >= self.combineTimes['start'] assert f107_inst.index[-1] < self.combineTimes['stop'] assert len(f107_inst.data.columns) == 1 assert f107_inst.data.columns[0] == 'f107' del f107_inst
def test_combine_f107_no_data(self): """Test combine_f107 when no data is present for specified times""" combo_in = { kk: self.combineInst['forecast'] for kk in ['standard_inst', 'forecast_inst'] } combo_in['start'] = pysat.datetime(2014, 2, 19) combo_in['stop'] = pysat.datetime(2014, 2, 24) f107_inst = sw_meth.combine_f107(**combo_in) assert f107_inst.data.isnull().all()["f107"] del combo_in, f107_inst
def test_combine_f107_inst_time(self): """Test combine_f107 with times provided through datasets""" self.combineInst['all'].load(date=self.combineTimes['start']) self.combineInst['forecast'].load(date=self.test_day) f107_inst = sw_meth.combine_f107(self.combineInst['all'], self.combineInst['forecast']) assert f107_inst.index[0] == dt.datetime(1947, 2, 13) assert f107_inst.index[-1] <= self.combineTimes['stop'] assert len(f107_inst.data.columns) == 1 assert f107_inst.data.columns[0] == 'f107' del f107_inst