1616import pysat
1717
1818import pysatSpaceWeather as pysat_sw
19+ from pysatSpaceWeather .instruments .methods import general
1920from pysatSpaceWeather .instruments .methods import gfz
2021from pysatSpaceWeather .instruments .methods import swpc
2122
@@ -600,7 +601,9 @@ def combine_kp(standard_inst=None, recent_inst=None, forecast_inst=None,
600601 while itime < stop and inst_flag is not None :
601602 # Load and save the standard data for as many times as possible
602603 if inst_flag == 'standard' :
603- standard_inst .load (date = itime )
604+ # Test to see if data loading is needed
605+ if not np .any (standard_inst .index == itime ):
606+ standard_inst .load (date = itime )
604607
605608 if notes .find ("standard" ) < 0 :
606609 notes += " the {:} source ({:} to " .format (inst_flag ,
@@ -610,9 +613,23 @@ def combine_kp(standard_inst=None, recent_inst=None, forecast_inst=None,
610613 inst_flag = 'forecast' if recent_inst is None else 'recent'
611614 notes += "{:})" .format (itime .date ())
612615 else :
613- kp_times .extend (list (standard_inst .index ))
614- kp_values .extend (list (standard_inst ['Kp' ]))
615- itime = kp_times [- 1 ] + pds .DateOffset (hours = 3 )
616+ local_fill_val = standard_inst .meta [
617+ 'Kp' , standard_inst .meta .labels .fill_val ]
618+ good_times = ((standard_inst .index >= itime )
619+ & (standard_inst .index < stop ))
620+ good_vals = np .array ([
621+ not general .is_fill_val (val , local_fill_val )
622+ for val in standard_inst ['Kp' ][good_times ]])
623+ new_times = list (standard_inst .index [good_times ][good_vals ])
624+
625+ if len (new_times ) > 0 :
626+ kp_times .extend (new_times )
627+ kp_values .extend (list (
628+ standard_inst ['Kp' ][good_times ][good_vals ]))
629+ itime = kp_times [- 1 ] + pds .DateOffset (hours = 3 )
630+ else :
631+ inst_flag = 'forecast' if recent_inst is None else 'recent'
632+ notes += "{:})" .format (itime .date ())
616633
617634 # Load and save the recent data for as many times as possible
618635 if inst_flag == 'recent' :
@@ -637,18 +654,20 @@ def combine_kp(standard_inst=None, recent_inst=None, forecast_inst=None,
637654
638655 # Determine which times to save
639656 if recent_inst .empty :
640- good_vals = []
657+ new_times = []
641658 else :
642659 local_fill_val = recent_inst .meta [
643660 'Kp' , recent_inst .meta .labels .fill_val ]
644661 good_times = ((recent_inst .index >= itime )
645662 & (recent_inst .index < stop ))
646- good_vals = recent_inst ['Kp' ][good_times ] != local_fill_val
663+ good_vals = np .array ([
664+ not general .is_fill_val (val , local_fill_val )
665+ for val in recent_inst ['Kp' ][good_times ]])
666+ new_times = list (recent_inst .index [good_times ][good_vals ])
647667
648668 # Save output data and cycle time
649- if len (good_vals ):
650- kp_times .extend (list (
651- recent_inst .index [good_times ][good_vals ]))
669+ if len (new_times ) > 0 :
670+ kp_times .extend (new_times )
652671 kp_values .extend (list (
653672 recent_inst ['Kp' ][good_times ][good_vals ]))
654673 itime = kp_times [- 1 ] + pds .DateOffset (hours = 3 )
@@ -683,17 +702,21 @@ def combine_kp(standard_inst=None, recent_inst=None, forecast_inst=None,
683702 'Kp' , forecast_inst .meta .labels .fill_val ]
684703 good_times = ((forecast_inst .index >= itime )
685704 & (forecast_inst .index < stop ))
686- good_vals = forecast_inst ['Kp' ][
687- good_times ] != local_fill_val
705+ good_vals = np .array ([
706+ not general .is_fill_val (val , local_fill_val )
707+ for val in forecast_inst ['Kp' ][good_times ]])
688708
689709 # Save desired data
690710 new_times = list (forecast_inst .index [good_times ][good_vals ])
691- kp_times .extend (new_times )
692- new_vals = list (forecast_inst ['Kp' ][good_times ][good_vals ])
693- kp_values .extend (new_vals )
694711
695- # Cycle time
696- itime = kp_times [- 1 ] + pds .DateOffset (hours = 3 )
712+ if len (new_times ) > 0 :
713+ kp_times .extend (new_times )
714+ new_vals = list (forecast_inst ['Kp' ][good_times ][
715+ good_vals ])
716+ kp_values .extend (new_vals )
717+
718+ # Cycle time
719+ itime = kp_times [- 1 ] + pds .DateOffset (hours = 3 )
697720 notes += "{:})" .format (itime .date ())
698721
699722 inst_flag = None
0 commit comments