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)
def wave_note_read (wfile): ''' Returns the note section of the specified wave. ''' text = bytearray() wav = ig.wave_read (wfile, note_text=text, note_parse=False) return str(text)
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)
def wave_dump_main(param): ''' wave_dim entry routine (intrinsic dimension scaling manipulation) ''' for f in param.input: wav = ig.wave_read(f) if wav.ndim == 1: for x,val in zip(wav, wav.dim[0].range): print x, "\t", val elif wav.ndim == 2: for block, x in zip(wav, wav.dim[0].range): for val, y in zip(block, block.dim[0].range): print x, "\t", y, "\t", val print else: print "%s: dimension %d > 2, don't know what to do." % wav.ndim sys.exit(-1)