예제 #1
0
파일: plot.py 프로젝트: ickc/dautil-py
    def f_decorated(*args, **kwargs):
        filename = kwargs.pop('filename', None)

        if filename:
            makedirs(os.path.dirname(filename))

        ext = os.path.splitext(filename)[1][1:] if filename else None

        if ext in ('pdf', 'pgf'):
            # setup fonts using Latin Modern
            mpl.rcParams.update({
                "font.family": ["serif"],
                "font.serif": ["Latin Modern Roman"],
                "font.sans-serif": ["Latin Modern Sans"],
                "font.monospace": ["Latin Modern Mono"]
            })
        elif ext == 'png':
            mpl.rcParams.update({"savefig.dpi": 240})

        f(*args, **kwargs)

        if filename:
            if ext == "tikz":
                from matplotlib2tikz import save as tikz_save
                tikz_save(filename,
                          figureheight='\\figureheight',
                          figurewidth='\\figurewidth')
            else:
                plt.savefig(filename, bbox_inches='tight')
예제 #2
0
def get_pseudospectra_wrap(
    df_weights,
    df_nauto,
    tmask,
    pmask,
    tnorm,
    pnorm,
    pixel_size,
    lmax,
    n_x,
    h5_weight_basedir,
    h5_signal_basedir,
    weight_name,
    processes,
    compress_level,
    outdir,
    mapcase,
    name,
    isim,
    nullsplit,
    redirect=False,
    mode='multithreading',
):
    makedirs(outdir)
    filename = os.path.join(
        outdir, name if nullsplit is None else '_'.join((name, nullsplit)))
    outpath = filename + '.hdf5'
    if os.path.isfile(outpath):
        print('{} existed. Skipping...'.format(outpath))
        return
    df = get_pseudospectra_IO(
        df_weights,
        df_nauto,
        tmask,
        pmask,
        tnorm,
        pnorm,
        pixel_size,
        lmax,
        n_x,
        h5_weight_basedir,
        h5_signal_basedir,
        weight_name,
        processes,
        mapcase,
        name,
        isim,
        nullsplit,
        stdout=filename + '.out' if redirect else None,
        stderr=filename + '.err' if redirect else None,
        timeit_filename=filename + '.time',
        mode=mode,
    )
    df.to_hdf(outpath,
              'pseudospectra',
              format='table',
              complevel=compress_level,
              fletcher32=True)
    return
예제 #3
0
def main(args):
    makedirs(args.o)
    with h5py.File(args.first, "r") as f1:
        with h5py.File(args.second, "r") as f2:
            plot_h5diff(f1,
                        f2,
                        args.o,
                        prefix=os.path.splitext(os.path.basename(
                            args.first))[0],
                        verbose=args.verbose)
예제 #4
0
def convert(basedir, output, in_path, protocol=2):
    out_path = in_path.replace(basedir, output, 1)
    if os.path.isfile(out_path):
        print('{} existed, skip.'.format(out_path))
        return
    makedirs(os.path.dirname(out_path))

    with open(in_path, 'rb') as f:
        data = pickle.load(f) if PY2 else pickle.load(f, encoding='latin1')
    with open(out_path, 'wb') as f:
        pickle.dump(data, f, protocol=2)
    return