Ejemplo n.º 1
0
    def key(pagenb):
        period = param_lists[pagenb][0]
        return period

    pagesgroups = psutils.groupbykey(pagenbs, key=key)
    print("\nMerging pages of pdf...")
    psutils.combine_pdf_pages(pdfname, pagesgroups, verbose=True)

    #Export pickle Louis

    print('Export to pickle')

    usersuffix = input("\nEnter suffix to append: [none]\n").strip()

    try:
        os.makedirs(TOMO_DIR)
    except:
        pass
    basename = os.path.basename(pickle_file).replace('FTAN',
                                                     '2-pass-tomography')
    outprefix = os.path.join(TOMO_DIR, os.path.splitext(basename)[0])

    if usersuffix:
        outprefix += '_{}'.format(usersuffix)
    picklename = outprefix + '.pickle'

    print("\nExporting final velocity maps to file: " + picklename)
    f = psutils.openandbackup(picklename, 'wb')
    pickle.dump(vmaps, f, protocol=2)
    f.close()
                     "beta = {5}, lambda = {6} ({7} paths)")
            title = title.format(period, GRID_STEPS[1], MINPECTSNRS[1],
                                 CORR_LENGTHS[1], ALPHAS[1],
                                 BETAS[1], LAMBDAS[1], len(v.paths))
            fig = v.plot(title=title, showplot=False)

            # appending fig to figures of period
            periodfigs.append(fig)

            # exporting figs to pdf
            for fig in periodfigs:
                pdf.savefig(fig)
                plt.close(fig)

    # closing pdf file
    pagenbs = range(pdf.get_pagecount())
    pdf.close()

    # merging pages of pdf with similar period
    key = lambda pagenb: int(pagenb / 3)  # grouping pages 0-1-2, then 3-4-5 etc.

    pagesgroups = psutils.groupbykey(pagenbs, key=key)
    print "\nMerging pages of pdf..."
    psutils.combine_pdf_pages(pdfname, pagesgroups, verbose=True)

    # exporting final maps (using pickle) as a dict:
    # {period: instance of pstomo.VelocityMap}
    print "\nExporting final velocity maps to file: " + picklename
    f = psutils.openandbackup(picklename, 'wb')
    pickle.dump(vmaps, f, protocol=2)
    f.close()