store results in subdirectory

defaults to postProc
This commit is contained in:
Martin Diehl 2019-05-07 13:30:05 +02:00
parent f3c77cde87
commit 1eaf67ad82
2 changed files with 20 additions and 5 deletions

View File

@ -20,6 +20,8 @@ parser = argparse.ArgumentParser()
#parser.add_argument('--version', action='version', version='%(prog)s {}'.format(scriptID)) #parser.add_argument('--version', action='version', version='%(prog)s {}'.format(scriptID))
parser.add_argument('filenames', nargs='+', parser.add_argument('filenames', nargs='+',
help='DADF5 files') help='DADF5 files')
parser.add_argument('-d','--dir', dest='dir',default='postProc',metavar='string',
help='name of subdirectory to hold output')
options = parser.parse_args() options = parser.parse_args()
@ -54,7 +56,13 @@ for filename in options.filenames:
data = np.concatenate((data,coords),1) data = np.concatenate((data,coords),1)
header+=' 1_pos 2_pos 3_pos' header+=' 1_pos 2_pos 3_pos'
np.savetxt('{}_inc{}.txt'.format(filename.split('.')[0],i),data,header=header,comments='') dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
try:
os.mkdir(dirname)
except FileExistsError:
pass
file_out = '{}_inc{:04d}.txt'.format(filename.split('.')[0],i)
np.savetxt(os.path.join(dirname,file_out),data,header=header,comments='')
results.active['increments'] = [inc] results.active['increments'] = [inc]
for label in options.labels: for label in options.labels:

View File

@ -21,6 +21,8 @@ parser = argparse.ArgumentParser()
#parser.add_argument('--version', action='version', version='%(prog)s {}'.format(scriptID)) #parser.add_argument('--version', action='version', version='%(prog)s {}'.format(scriptID))
parser.add_argument('filenames', nargs='+', parser.add_argument('filenames', nargs='+',
help='DADF5 files') help='DADF5 files')
parser.add_argument('-d','--dir', dest='dir',default='postProc',metavar='string',
help='name of subdirectory to hold output')
options = parser.parse_args() options = parser.parse_args()
@ -80,12 +82,17 @@ for filename in options.filenames:
if results.structured: if results.structured:
writer = vtk.vtkXMLRectilinearGridWriter() writer = vtk.vtkXMLRectilinearGridWriter()
dirname = os.path.abspath(os.path.join(os.path.dirname(filename),options.dir))
try:
os.mkdir(dirname)
except FileExistsError:
pass
file_out = '{}_inc{:04d}.{}'.format(filename.split('.')[0],i,writer.GetDefaultFileExtension())
writer.SetCompressorTypeToZLib() writer.SetCompressorTypeToZLib()
writer.SetDataModeToBinary() writer.SetDataModeToBinary()
writer.SetFileName(os.path.join(os.path.split(filename)[0], writer.SetFileName(os.path.join(dirname,file_out))
os.path.splitext(os.path.split(filename)[1])[0] +
'_inc{:04d}'.format(i) + # ToDo: adjust to length of increments
'.' + writer.GetDefaultFileExtension()))
if results.structured: if results.structured:
writer.SetInputData(rGrid) writer.SetInputData(rGrid)