Пример #1
0
def wave_note_write (infile=None, note='', wav=None, outfile=None, safe=True):
    '''
    Writes the note section of the specified wave.
    To this purpose, wave is read from 'wfile' if not an existing
    wave is already specified by the 'wav' parameter.
    The wave is written back to 'wfile', if not a different output
    file is specified by the 'outfile' parameter.
    '''

    if outfile is not None:
        outfile_name = outfile.name if hasattr(outfile, 'name') else outfile

    if infile is not None:
        infile_name = infile.name if hasattr (infile, 'name') else infile

    if wav is None:
        wav = ig.wave_read (infile_name, note_parse=False)

    if safe:
        # write the wave (using an intermediary temporary file)
        with NamedTemporaryFile (delete=False) as tmp:
            tmp.close()
            ig.wave_write (wav, tmp.name, note=note)
            os.rename (tmp.name, outfile_name)
    else:
        ig.wave_write (wav, outfile_name)
Пример #2
0
def arpes_save (wav, param):
    '''
    Saves (a processed) wave according to command line specifications from 'param'
    '''

    from tempfile import NamedTemporaryFile
    
    # output
    if (param.output == '--'):
        param.output = sys.stdout

    elif param.output == '---':
        param.output = param.input.name
        
    elif param.output is None:
        pindex = param.input.name.rfind('.')
        if pindex < 0:
            pindex = len(param.input.name)-1
        base = param.input.name[0:pindex]
        ext  = param.input.name[pindex:]
        param.output = base + ("_ky"*param.deg2ky) + ("_fdd"*param.norm_fdd) + ext
        
    print "Writing: %s" % param.output

    if (param.output == param.input.name) and param.safe:
        with NamedTemporaryFile (delete=False) as tmp:
            tmp.close()
            igor.wave_write (wav, tmp.name)
            os.rename (tmp.name, param.output)
    else:
        igor.wave_write (wav, param.output)
Пример #3
0
def wave_dim_main (param):
    '''
    wave_dim entry routine (intrinsic dimension scaling manipulation)
    '''

    if param.output is None:
        param.output = param.input

    for fin, fout in zip(param.input, param.output):
        wav = ig.wave_read(fin)
        wav_save = False

        # prepare list of dimensions to be processed (defaults to: all)
        if param.dim is None:
            param.dim = range(wav.ndim)

        # set attribute / increase attribute
        if param.set is not None:
            wav_save = True
            [ setattr (wav.dim[i], param.set[0], eval(param.set[1]))
              for i in param.dim ]

        # increase attribute -- special case of "set"
        elif param.inc is not None:
            wav_save = True
            [ setattr (wav.dim[i], param.inc[0],
                       getattr(wav.dim[i], param.inc[0]) + eval(param.inc[1]))
              for i in param.dim ]

        # read attribute
        elif param.read is not None:
            [ pprint (getattr(wav.dim[i], param.read))
              for i in param.dim ]
        
        # print note (param.nprint)
        else:        
            print string.join([ str(d) for d in wav.dim ], '\n')

        # re-write the wave, if modifications were performed
        if wav_save:
            wav_name = fout.name if hasattr(fout, "close") else fout
            if param.safe:
                with NamedTemporaryFile (delete=False) as tmp:
                    tmp.close()
                    ig.wave_write (wav, tmp.name)
                    os.rename (tmp.name, wav_name)
            else:
                ig.wave_write (wav, wav_name)