Exemple #1
0
    def get_callable(self, func):
        ''' Return the callable function given a function name. '''

        if func in dir(self.varspec):
            return self.varspec.__getattribute__(func)

        # Check datahandler.grib objects if a single word is provided
        if len(func.split('.')) == 1:

            funcs = []
            for attr in dir(grib):
                # pylint: disable=no-member
                if func in dir(grib.__getattribute__(attr)):
                    funcs.append(
                        grib.__getattribute__(attr).__dict__.get(func))
            return funcs

        if callable(utils.get_func(func)):
            return utils.get_func(func)

        raise ValueError('{func} is not a known callable function!')
Exemple #2
0
    def is_a_clev(clev):
        ''' Returns true for a clev that is a list, a range, or a callable function. '''

        if isinstance(clev, (list, np.ndarray)):
            return True

        if 'range' in clev.split('[')[0]:
            clean = lambda x: x.strip().split('-')[-1].replace('.', '1')
            items = clev.split(' ', 1)[1].strip('[').strip(']').split(',')
            nums = [clean(i).isnumeric() for i in items]
            return all(nums)

        return callable(utils.get_func(clev))
Exemple #3
0
def test_utils():
    ''' Test that utils works appropriately. '''

    assert callable(utils.get_func('conversions.k_to_c'))