def export_marker(marker: Mapping[str, Iterable[Tuple[str, str]]], fname: str, defaultpath: Optional[bool] = True): """Export marker pairs to json-File. Parameters ---------- marker Marker pairs as from :func:`~pypairs.pairs.sandbag` fname Name of the json-File in the writedir (see settings) defaultpath Use settings.writedir as root. Default: True """ if defaultpath: fpath = settings.writedir + fname else: fpath = fname try: write_dict_to_json(marker, fpath) logg.hint("marker pairs written to: " + str(fpath)) except IOError as e: msg = "could not write to {}.".format(fpath) + \ "Please verify that the path exists and is writable. Or change `writedir` via `pypairs.settings.writedir`" logg.error(msg) logg.error(str(e))
def load_pandas(fname): """Load DataFrame or Series""" try: return pd.read_csv(fname, index_col=0) except OSError as e: logg.error("could not load cached files {}".format(fname)) logg.error(str(e))
def save_pandas(fname, data): """Save DataFrame or Series""" if isinstance(data, DataFrame): try: data.to_csv(fname, header=True) except IOError as e: logg.warn("could not store cache to {}".format(fname)) logg.warn(str(e)) else: logg.error("could not save object, `data` must be DataFrame")
def load_marker(fname: str, defaultpath: Optional[bool] = True): """Export marker pairs to json-File. Parameters ---------- fname Name of the json-File to write to defaultpath Use settings.writedir as root. Default: True """ if defaultpath: fpath = settings.writedir + fname else: fpath = fname try: marker = read_dict_from_json(fpath) except IOError: logg.error( "could not read from {}.\n Please verify that the path exists and is writable." .format(fpath)) return None if settings.verbosity > 2: count_total = 0 count_str = [] for m, p in marker.items(): c = len(p) count_total += c count_str.append("\t{}: {}".format(m, c)) logg.hint("loaded {} marker pairs".format(count_total)) for s in count_str: logg.hint(s) return marker
def parallel_njit(func: Callable[[], Any], jitted: Optional[bool] = True) -> Callable[[], Any]: """Dynamic decorator for jit-compiled functions. Adds parallel=True if settings.n_jobs > 1 """ if jitted is False or settings.enable_jit is False: logg.warn( 'staring uncompiled processing. Should only be used for debug and testing!' ) return func if settings.n_jobs > 1: if is_win32() is False: logg.hint('staring parallel processing with {} threads'.format( settings.n_jobs)) return njit(func, parallel=True, fastmath=settings.enable_fastmath) else: logg.error( 'n_jobs is set to {} but multiprocessing is not supported for your platform! ' 'falling back to single core... '.format(settings.n_jobs)) return njit(func, fastmath=settings.enable_fastmath) else: logg.hint('staring processing with 1 thread') return njit(func, fastmath=settings.enable_fastmath)