Pythonized interval for easy output to yaml
482950
def interval(best,lo=np.nan,hi=np.nan):
    
    return [float(best),[float(lo),float(hi)]]
189743
def build_from_yamlfile(yamlfile):
        
        d = yaml.load(open(yamlfile))
        return MktimeFilterDict(d['aliases'], d['selections'])
219254
async def spaceout(source, interval):
    
    timeout = 0
    loop = asyncio.get_event_loop()
    async with streamcontext(source) as streamer:
        async for item in streamer:
            delta = timeout - loop.time()
            delay = delta if delta > 0 else 0
            await asyncio.sleep(delay)
            yield item
            timeout = loop.time() + interval
808793
def parse_yaml(self, y):
        ''''''
        self.x = int(y['x'])
        self.y = int(y['y'])
        self.height = int(y['height'])
        self.width = int(y['width'])
        self.direction = dir.from_string(y['direction'])
        return self
623528
def print_yaml(o):
    """"""
    print(yaml.dump(o, default_flow_style=False, indent=4, encoding='utf-8'))
905204
def timed (log=sys.stderr, limit=2.0):
    """"""
    return lambda func: timeit(func, log, limit)
143044
def safe_dump(data, stream=None, **kwds):
    """"""
    return yaml.dump(data, stream=stream, Dumper=ODYD, **kwds)
645721
def write_yaml (self, data, encoding=None, errors=None, newline=None, **kwargs):
        
        import yaml

        with self.open (mode='wt', encoding=encoding, errors=errors, newline=newline) as f:
            return yaml.dump (data, stream=f, **kwargs)
78162
def yaml_to_str(data: Mapping) -> str:
    
    return yaml.dump(data, Dumper=ruamel.yaml.RoundTripDumper)
245612
def run_analysis(self, argv):
        """"""
        args = self._parser.parse_args(argv)

        if is_null(args.config):
            raise ValueError("Config yaml file must be specified")
        if is_null(args.rand_config):
            raise ValueError(
                "Random direction config yaml file must be specified")
        config = load_yaml(args.config)
        rand_config = load_yaml(args.rand_config)

        wcsgeom = self._make_wcsgeom_from_config(config)
        dir_dict = self._build_skydir_dict(wcsgeom, rand_config)

        if is_not_null(args.outfile):
            write_yaml(dir_dict, args.outfile)
107960
def run(path, timer=False, repeat=3, number=10000, precision=2):
    
    code = extractAtCyther(path)
    if not code:
        output = "There was no '@cyther' code collected from the " \
                 "file '{}'\n".format(path)
        # TODO This should use a result, right?
        return {'returncode': 0, 'output': output}

    module_directory = os.path.dirname(path)
    module_name = os.path.splitext(os.path.basename(path))[0]
    setup_string = SETUP_TEMPLATE.format(module_directory, module_name, '{}')

    if timer:
        string = TIMER_TEMPLATE.format(setup_string, code, repeat,
                                       number, precision, '{}')
    else:
        string = setup_string + code

    script = os.path.join(os.path.dirname(__file__), 'script.py')
    with open(script, 'w+') as file:
        file.write(string)

    response = call(['python', script])
    return response
1013190
def output(data, **kwargs):  # pylint: disable=unused-argument
    '''
    
    '''

    params = {}
    if 'output_indent' not in __opts__:
        # default indentation
        params.update(default_flow_style=False)
    elif __opts__['output_indent'] >= 0:
        # custom indent
        params.update(default_flow_style=False,
                      indent=__opts__['output_indent'])
    else:  # no indentation
        params.update(default_flow_style=True,
                      indent=0)
    try:
        return salt.utils.yaml.safe_dump(data, **params)
    except Exception as exc:
        import pprint
        log.exception(
            'Exception %s encountered when trying to serialize %s',
            exc, pprint.pformat(data)
        )
435003
def _interval_split(interval, only=None, context=None, event_re=re.compile("[A-Z][0-9]+")):
    
    def split_event(event):
        "Helper to parse events."
        kind, val = event[:1], event[1:]
        try:
            return kind, float(val)
        except (TypeError, ValueError):
            return None, 0

    if hasattr(interval, "fetch"):
        interval = interval.fetch("custom_activations")
    ##import sys; print >>sys.stderr, "!!!!!isplit", interval, event_re.findall(interval)

    return list(reversed([split_event(i) for i in event_re.findall(interval) if not only or i.startswith(only)]))
1050260
def intervals(start, end, interval):
    
    interval = _seconds_or_timedelta(interval)
    current_timestamp = start
    while current_timestamp.epoch < end.epoch:
        yield current_timestamp

        current_timestamp = current_timestamp.add(
            seconds=interval.total_seconds()
        )
1254959
def dump(data, stream=None, **kwargs):
    '''
    
    '''
    if 'allow_unicode' not in kwargs:
        kwargs['allow_unicode'] = True
    return yaml.dump(data, stream, **kwargs)
389640
def make_yaml_patterns():
    " "
    kw = any("keyword", [r":|>|-|\||\[|\]|[A-Za-z][\w\s\-\_ ]+(?=:)"])
    links = any("normal", [r"#:[^\n]*"])
    comment = any("comment", [r"#[^\n]*"])
    number = any("number",
                 [r"\b[+-]?[0-9]+[lL]?\b",
                  r"\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b",
                  r"\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b"])
    sqstring = r"(\b[rRuU])?'[^'\\\n]*(\\.[^'\\\n]*)*'?"
    dqstring = r'(\b[rRuU])?"[^"\\\n]*(\\.[^"\\\n]*)*"?'
    string = any("string", [sqstring, dqstring])
    return "|".join([kw, string, number, links, comment, 
                     any("SYNC", [r"\n"])])
1135807
def _preprocess_yml(path):
    """"""
    with open(path) as f:
        tmp_yaml = f.read()
    return re.sub(r"unicode", "str", tmp_yaml)