I am trying to save files with changing names into a different folder than the script is:
save_field( './cycle_1_580-846/txt/"frame_" + str( 580 + j ) + "_to_" + str( 581 + j ) + ".txt"', "Data68_0" + str( 580 + j ) + ".tif", str( 580 + j ) + "_to_" + str( 581 + j ), scale = 1500, width = 0.0025)
Now for saving the filename with loop variable in it I followed this post .
I naively thought that using ' and " will solve the problem, however, if I do that, I get a file in the right folder but with a wrong name (in this case: "frame_" + str( 580 + j ) + "to" + str( 581 + j ) + ".txt) (I would want: frame_580_to_581.txt). If I do not set the path, I have no problem.
Is there a clever way to overcome this ?
Cheers!
EDIT j is just a certain range of files (in this case it is from 0 to 270, incremented by 1 )
maybe this will also help
def save_field( filename, background, new_file, **kw):
""" Saves quiver plot of the data stored in the file
Parameters
----------
filename : string
the absolute path of the text file
background : string
the absolute path of the background image file
new_file : string
the name and format of the new file (png preferred)
Key arguments : (additional parameters, optional)
*scale*: [None | float]
*width*: [None | float]
"""
a = np.loadtxt(filename)
pl.figure()
bg = mpimg.imread(background)
imgplot = pl.imshow(bg, origin = 'lower', cmap = cmps.gray)
pl.hold(True)
invalid = a[:,3].astype('bool')
valid = ~invalid
pl.quiver(a[invalid,0],a[invalid,1],a[invalid,2],a[invalid,3],color='r',**kw)
pl.quiver(a[valid,0],a[valid,1],a[valid,2],a[valid,3],color='r',**kw)
v = [0, 256, 0, 126]
axis(v)
pl.draw()
pl.savefig(new_file, bbox_inches='tight')