Exemple #1
0
 def setup(self):
     reload(pysat.instruments.pysat_testing)
     '''Runs before every method to create a clean testing setup.'''
     self.testInst = pysat.Instrument('pysat', 'testing', '', 
                                      clean_level='clean',
                                      update_files=True,
                                      sim_multi_file_left=True,
                                      pad={'minutes':5},
                                      multi_file_day=True)
Exemple #2
0
 def setup(self):
     reload(pysat.instruments.pysat_testing)
     """Runs before every method to create a clean testing setup."""
     self.testInst = pysat.Instrument('pysat',
                                      'testing',
                                      '',
                                      clean_level='clean',
                                      update_files=True,
                                      sim_multi_file_left=True,
                                      pad={'minutes': 5})
     self.rawInst = pysat.Instrument('pysat',
                                     'testing',
                                     '',
                                     clean_level='clean',
                                     update_files=True,
                                     sim_multi_file_left=True)
     self.testInst.bounds = ('2008-01-01.nofile', '2010-12-31.nofile')
     self.rawInst.bounds = self.testInst.bounds
Exemple #3
0
 def test_custom_instrument_load(self):
     '''
     Test if the correct day is being loaded (End-to-End), 
     with no instrument file but routines are passed.
     '''
     import pysat.instruments.pysat_testing as test
     testInst = pysat.Instrument(inst_module=test, tag='', clean_level='clean')
     testInst.load(2009,32)
     assert testInst.date == pds.datetime(2009,2,1)	
Exemple #4
0
 def test_custom_instrument_load_3(self):
     '''
     Test if an exception is thrown correctly if there is no 
     instrument file and supplied routines are incomplete.
     '''
     import pysat.instruments.pysat_testing as test
     del test.load
     testIn = pysat.Instrument(inst_module=test, tag='', clean_level='clean')
     testIn.load(2009,1)
Exemple #5
0
 def setup(self):
     reload(pysat.instruments.pysat_testing)
     """Runs before every method to create a clean testing setup."""
     self.testInst = pysat.Instrument('pysat',
                                      'testing',
                                      '',
                                      clean_level='clean',
                                      pad={'minutes': 5},
                                      update_files=True)
Exemple #6
0
 def setup(self):
     """Runs before every method to create a clean testing setup."""
     orbit_info = {'index': 'longitude', 'kind': 'longitude'}
     self.testInst = pysat.Instrument('pysat',
                                      'testing',
                                      clean_level='clean',
                                      orbit_info=orbit_info)
     self.testInst.bounds = (pysat.datetime(2008, 1,
                                            1), pysat.datetime(2008, 1, 31))
Exemple #7
0
 def setup(self):
     """Runs before every method to create a clean testing setup."""
     self.testInst = pysat.Instrument('pysat',
                                      'testing_xarray',
                                      clean_level='clean',
                                      orbit_info={'index': 'mlt'},
                                      update_files=True)
     self.testInst.custom_attach(filter_data)
     self.stime = pysat.instruments.pysat_testing._test_dates['']['']
Exemple #8
0
 def test_data_padding_all_samples_present(self):
     reload(pysat.instruments.pysat_testing)
     reload(pysat.instruments)
     te = pysat.Instrument('pysat', 'testing', '', pad={'minutes': 5})
     te.load(2009, 1, verifyPad=True)
     test_index = pds.date_range(te.data.index[0],
                                 te.data.index[-1],
                                 freq='S')
     assert (np.all(te.data.index == test_index))
Exemple #9
0
    def test_files_non_standard_file_format_template_misformatted_2(self):

        pysat.instruments.pysat_testing.list_files = list_files
        self.testInst = pysat.Instrument(
            inst_module=pysat.instruments.pysat_testing,
            clean_level='clean',
            file_format=15,
            update_files=True,
            temporary_file_list=self.temporary_file_list)
Exemple #10
0
 def test_data_padding(self):
     reload(pysat.instruments.pysat_testing)
     reload(pysat.instruments)
     te = pysat.Instrument('pysat', 'testing', '', pad={'minutes': 5})
     te.load(2009, 1, verifyPad=True)
     assert ((te.data.index[0] == te.date - pds.DateOffset(minutes=5)) &
             (te.data.index[-1] == te.date +
              pds.DateOffset(hours=23, minutes=59, seconds=59) +
              pds.DateOffset(minutes=5)))
Exemple #11
0
 def setup(self):
     insts = []
     for i in range(2):
         r_date = pysat.datetime(2009, 1, i+1)
         insts.append(pysat.Instrument('pysat', 'testing',
                                       clean_level='clean',
                                       root_date=r_date))
     self.testC = pysat.Constellation(instruments=insts)
     self.bounds = (pysat.datetime(2008, 1, 1), pysat.datetime(2008, 1, 3))
Exemple #12
0
    def test_orbit_w_bad_orbit_info(self, info):
        """ Test orbit failure on iteration with orbit initialization
        """
        self.in_kwargs['orbit_info'] = info
        self.testInst = pysat.Instrument(*self.in_args, **self.in_kwargs)
        self.testInst.load(date=self.stime)

        with pytest.raises(ValueError):
            self.testInst.orbits.next()
Exemple #13
0
    def test_instrument_has_no_files(self):
        import pysat.instruments.pysat_testing

        pysat.instruments.pysat_testing.list_files = list_files
        inst = pysat.Instrument(platform='pysat',
                                name='testing',
                                update_files=True)
        re_load(pysat.instruments.pysat_testing)
        assert (inst.files.files.empty)
Exemple #14
0
 def setup(self):
     """Runs before every method to create a clean testing setup."""
     self.testInst = pysat.Instrument('pysat', 'testing2D',
                                      clean_level='clean')
     self.testInst.bounds = (pysat.datetime(2008, 1, 1),
                             pysat.datetime(2008, 1, 3))
     self.dname = 'alt_profiles'
     self.test_vals = np.arange(50) * 1.2
     self.test_fracs = np.arange(50) / 50.0
Exemple #15
0
 def setup(self):
     '''Runs before every method to create a clean testing setup.'''
     info = {'index': 'latitude', 'kind': 'polar'}
     self.testInst = pysat.Instrument('pysat',
                                      'testing',
                                      '86400',
                                      clean_level='clean',
                                      orbit_info=info)
     self.testInst.custom.add(filter_data, 'modify')
Exemple #16
0
def prep_dir(inst=None):

    if inst is None:
        inst = pysat.Instrument(platform='pysat', name='testing')
    # create data directories
    try:
        os.makedirs(inst.files.data_path)
    except OSError:
        pass
Exemple #17
0
 def setup(self):
     """Runs before every method to create a clean testing setup."""
     # Load a test instrument
     self.testInst = pysat.Instrument('pysat',
                                      'testing2d_xarray',
                                      sat_id='12',
                                      clean_level='clean')
     self.testInst.load(2009, 1)
     self.Npts = len(self.testInst['uts'])
Exemple #18
0
def filter_geomag(inst, min_kp=0, max_kp=9, filter_time=24, kp_inst=None):
    """Filters pysat.Instrument data for given time after Kp drops below gate.

    Parameters
    ----------
    inst : pysat.Instrument
        Instrument with non-Kp data to be filtered by geomagnetic activity
    min_kp : float
        Minimum Kp value allowed. Kp values below this filter the data in
        inst (default=0)
    max_kp : float
        Maximum Kp value allowed. Kp values above this filter the data in
        inst (default=9)
    filter_time : int
        Number of hours to filter data after Kp drops below max_kp (default=24)
    kp_inst : pysat.Instrument or NoneType
        Kp pysat.Instrument object with or without data already loaded. If None,
        will load GFZ historic kp data for the instrument date (default=None)

    Note
    ----
    Loads Kp data for the same timeframe covered by inst and sets inst.data to
    NaN for times when Kp > max_kp or Kp < min_kp and for filter_time after Kp
    drops below max_kp.

    Default max and min values accept all Kp, so changing only one will cause
    the filter to act as a high- or low-pass function.

    This routine is written for standard Kp data (tag=''), not the forecast or
    recent data.  However, it will work with these Kp data if they are supplied.

    This routine is designed to be used with the 'modify' flag if applied as
    a custom routine.

    """
    # Load the desired data
    if kp_inst is None:
        kp_inst = pysat.Instrument(inst_module=pysat_sw.instruments.sw_kp,
                                   tag='',
                                   pad=pds.DateOffset(days=1))

    if kp_inst.empty:
        kp_inst.load(date=inst.date, verifyPad=True)

    # Begin filtering, starting at the beginning of the instrument data
    sel_data = kp_inst[(inst.date -
                        pds.DateOffset(days=1)):(inst.date +
                                                 pds.DateOffset(days=1))]
    ind, = np.where((sel_data['Kp'] > max_kp) | (sel_data['Kp'] < min_kp))
    for lind in ind:
        sind = sel_data.index[lind]
        eind = sind + pds.DateOffset(hours=filter_time)
        inst[sind:eind] = np.nan
        inst.data = inst.data.dropna(axis=0, how='all')

    return
Exemple #19
0
def filter_geoquiet(sat,
                    maxKp=None,
                    filterTime=None,
                    kpData=None,
                    kp_inst=None):
    """Filters pysat.Instrument data for given time after Kp drops below gate.
    
    Loads Kp data for the same timeframe covered by sat and sets sat.data to
    NaN for times when Kp > maxKp and for filterTime after Kp drops below maxKp.
    
    Parameters
    ----------
    sat : pysat.Instrument
        Instrument to be filtered
    maxKp : float
        Maximum Kp value allowed. Kp values above this trigger
        sat.data filtering.
    filterTime : int
        Number of hours to filter data after Kp drops below maxKp
    kpData : pysat.Instrument (optional)
        Kp pysat.Instrument object with data already loaded
    kp_inst : pysat.Instrument (optional)
        Kp pysat.Instrument object ready to load Kp data.Overrides kpData.
        
    Returns
    -------
    None : NoneType
        sat Instrument object modified in place
        
    """
    if kp_inst is not None:
        kp_inst.load(date=sat.date, verifyPad=True)
        kpData = kp_inst
    elif kpData is None:
        kp = pysat.Instrument('sw', 'kp', pad=pds.DateOffset(days=1))
        kp.load(date=sat.date, verifyPad=True)
        kpData = kp

    if maxKp is None:
        maxKp = 3 + 1. / 3.

    if filterTime is None:
        filterTime = 24

    # now the defaults are ensured, let's do some filtering
    # date of satellite data
    date = sat.date
    selData = kpData[date - pds.DateOffset(days=1):date +
                     pds.DateOffset(days=1)]
    ind, = np.where(selData['kp'] >= maxKp)
    for lind in ind:
        sat.data[selData.index[lind]:(
            selData.index[lind] + pds.DateOffset(hours=filterTime))] = np.NaN
        sat.data = sat.data.dropna(axis=0, how='all')

    return
Exemple #20
0
 def setup(self):
     re_load(pysat.instruments.pysat_testing)
     """Runs before every method to create a clean testing setup."""
     self.testInst = pysat.Instrument('pysat',
                                      'testing_xarray',
                                      clean_level='clean',
                                      update_files=True,
                                      sim_multi_file_right=True,
                                      pad={'minutes': 5},
                                      multi_file_day=True)
Exemple #21
0
 def setup(self):
     re_load(pysat.instruments.pysat_testing)
     """Runs before every method to create a clean testing setup."""
     self.testInst = pysat.Instrument('pysat',
                                      'testing_xarray',
                                      sat_id='10',
                                      clean_level='clean',
                                      malformed_index=True,
                                      update_files=True,
                                      strict_time_flag=True)
Exemple #22
0
 def setup(self):
     """Runs before every method to create a clean testing setup.
     """
     self.testInst = pysat.Instrument('pysat', 'testing', num_samples=10,
                                      clean_level='clean',
                                      update_files=False)
     self.out = ''
     self.log_capture = StringIO()
     pysat.logger.addHandler(logging.StreamHandler(self.log_capture))
     pysat.logger.setLevel(logging.WARNING)
Exemple #23
0
 def setup(self):
     """Runs before every method to create a clean testing setup.
     """
     self.testInst = pysat.Instrument('pysat', 'testing', num_samples=10,
                                      clean_level='clean',
                                      update_files=True)
     self.load_date = pysat.instruments.pysat_testing._test_dates['']['']
     self.testInst.load(date=self.load_date)
     self.custom_args = [2]
     self.out = None
Exemple #24
0
 def setup(self):
     """Runs before every method to create a clean testing setup."""
     info = {'index': 'mlt'}
     self.testInst = pysat.Instrument('pysat',
                                      'testing_xarray',
                                      '86400',
                                      clean_level='clean',
                                      orbit_info=info,
                                      update_files=True)
     self.testInst.custom.add(filter_data, 'modify')
 def setup(self):
     """
     All the data in dummy1 of testadd3 is the data in testadd1 + 10
     So the addition of testadd1 and testadd3 should be no more than 10 off from
     the addition of just testadd1
     TODO: actually check the math on this
     """
     self.testC = pysat.Constellation(name='test_add_similar')
     self.refC = pysat.Constellation(
         [pysat.Instrument('pysat', 'testadd1', clean_level='clean')])
Exemple #26
0
    def test_orbit_str(self):
        """ Test the Orbit string representation with data
        """
        self.in_kwargs['orbit_info'] = {'index': 'mlt'}
        self.testInst = pysat.Instrument(*self.in_args, **self.in_kwargs)
        self.testInst.load(date=self.stime)
        out_str = self.testInst.orbits.__str__()

        assert out_str.find("Orbit Settings") >= 0
        assert out_str.find("Orbit Lind: local time") < 0
Exemple #27
0
 def setup(self):
     """
     All the data in dummy1 of 'plus10' is the data in default + 10
     So the addition of 'ascend' and 'plus10' should be no
     more than 10 off from the addition of just 'ascend'
     TODO: actually check the math on this
     """
     self.testC = pysat.Constellation(name='test_add_similar')
     self.refC = pysat.Constellation(
         [pysat.Instrument('pysat', 'testing', tag='ascend')])
Exemple #28
0
    def test_bad_lon_name_calc_solar_local_time(self):
        """Test calc_solar_local_time with a bad longitude name."""

        self.py_inst = pysat.Instrument(platform='pysat', name="testing")
        self.py_inst.load(date=self.inst_time)

        with pytest.raises(ValueError):
            coords.calc_solar_local_time(self.py_inst,
                                         lon_name="not longitude",
                                         slt_name='slt')
 def setup(self):
     """Runs before every method to create a clean testing setup"""
     # Load a test instrument
     self.testInst = pysat.Instrument()
     self.testInst.data = pds.DataFrame({'f107': np.linspace(70, 200, 160)},
                                        index=[
                                            dt.datetime(2009, 1, 1) +
                                            pds.DateOffset(days=i)
                                            for i in range(160)
                                        ])
Exemple #30
0
 def test_basic_orbit_mean(self):
     """Test basic orbital mean"""
     orbit_info = {'kind': 'local time', 'index': 'mlt'}
     self.testInst = pysat.Instrument('pysat', 'testing',
                                      clean_level='clean',
                                      orbit_info=orbit_info)
     self.testInst.bounds = self.bounds2
     ans = avg.mean_by_orbit(self.testInst, 'mlt')
     # note last orbit is incomplete thus not expected to satisfy relation
     assert np.allclose(ans[:-1], np.ones(len(ans)-1)*12.0, 1.0E-2)