def test_convert_ap_to_kp_inf_input(self): """ Test conversion of ap to Kp where ap is Inf""" kp_out, kp_meta = sw_meth.convert_ap_to_kp(self.testInst['ap_inf']) # Assert original and coverted there and back Kp are equal assert all(kp_out[1:] == -1) # Assert the converted Kp meta data exists and is reasonable assert 'Kp' in kp_meta.keys() assert (kp_meta['Kp'][kp_meta.fill_label] == -1) del kp_out, kp_meta
def test_convert_ap_to_kp(self): """ Test conversion of ap to Kp""" sw_kp.convert_3hr_kp_to_ap(self.testInst) kp_out, kp_meta = sw_meth.convert_ap_to_kp(self.testInst['3hr_ap']) # Assert original and coverted there and back Kp are equal assert all(abs(kp_out - self.testInst.data['Kp']) < 1.0e-4) # Assert the converted Kp meta data exists and is reasonable assert 'Kp' in kp_meta.keys() assert (kp_meta['Kp'][kp_meta.fill_label] == -1) del kp_out, kp_meta
def get_f107_kp_ap(outfile, stime, etime): # Cast the date appropriately and determine if it is today or in the past if stime is None: stime = dt.datetime.today() istoday = stime.date() == dt.datetime.today().date() # Get the F10.7 and Kp data if istoday: f107_inst = get_recent_f107_data(today=stime) kp_inst = get_recent_kp_data(today=stime) else: f107_inst = get_historic_f107_data(stime, etime) kp_inst = get_historic_kp_data(stime, etime) # Combine the Kp and F10.7 data, ensuring the same temporal cadance f107_kp_inst = combine_f107_kp(f107_inst, kp_inst) # Calculate the F10.7a add_f107a(f107_kp_inst) # Add the 3-hourly ap and daily Ap to the Kp instrument pysat.instruments.sw_kp.convert_3hr_kp_to_ap(f107_kp_inst) sw_methods.calc_daily_Ap(f107_kp_inst, running_name="daily_ave_ap") # Get the 45-day predictions of Ap and F10.7 if forecast block is desired if istoday: ap_inst = pysat.Instrument('sw', 'f107', '45day') ap_inst.download() ap_inst.load(date=today) # Calculate the F10.7a add_f107a(ap_inst) # Add the Kp to the 45-day predictions of Ap ap_inst.data['Kp'], kp_meta = sw_methods.convert_ap_to_kp( ap_inst['ap'], ap_inst.meta['ap'].fill, ap_inst.meta['ap'].long_name, ) ap_inst.meta['Kp'] = kp_meta['Kp'] else: ap_inst = None # Write the output file write_solargeomag_file(outfile, f107_kp_inst, ap_inst) return f107_kp_inst, ap_inst
def test_convert_ap_to_kp_fill_val(self): """ Test conversion of ap to Kp with fill values""" # Set the first value to a fill value, then calculate ap fill_label = self.testInst.meta.fill_label self.testInst['Kp'][0] = self.testInst.meta['Kp'][fill_label] sw_kp.convert_3hr_kp_to_ap(self.testInst) kp_out, kp_meta = sw_meth.convert_ap_to_kp(self.testInst['3hr_ap'], \ fill_val=self.testInst.meta['Kp'][fill_label]) # Test non-fill ap values assert all(abs(kp_out[1:] - self.testInst.data['Kp'][1:]) < 1.0e-4) # Test the fill value in the data and metadata assert np.isnan(kp_out[0]) assert np.isnan(kp_meta['Kp'][fill_label]) del fill_label, kp_out, kp_meta