Dyntools: Dealing with many .OUT files when converting to .csv
Hi everybody, I'm running into errors when dealing with large numbers of .OUT files. I'm trying to convert a large number of .OUT files to .csv files for further processing in python. I use the code below, and I'm working in Spyder.
At a certain point, the following error messages start popping up:
All file units in use. genroe_con01_02.out (RWFIL)
(genroe_con01_02.out is one of the filenames) The error message pops up for all subsequent files. It seems like the problems start after 64 (2^6) files. which suggests that some kind of register is filling up. Though I have also seen 66 files being processed. Removing all variables and restarting the program will not do the trick, the only option is to restart the kernel.
edit: I have also noticed that after removing all variables and restarting, I'm also unable to load other PSSE files, receiving the error messages below. Again, requiring to restart the kernel.
All file units in use. PSSEcasedata.cnv (OpnApplFil/OPNPTI)
All file units in use. PSSEcasedata.snp (OpnApplFil/OPNPTI)
Has anybody come across this problem before?
files = os.listdir(os.curdir)
for filename in files:
if filename.endswith(".out"):
output_obj = dyntools.CHNF(filename)
output_obj.csvout(channels='', csvfile='', outfile='', ntimestep=1)
del output_obj
Just curious, would you have the same problem if you use "txtout" instead of "csvout"?
Thanks for the suggestion. I have given it a try, but see similar results. The problem arrises when reading the out-file. It seems like some process is keeping track of the out-files that have been read, even while the object is deleted.
Also, it seems like the problems start after 64 (2^6) files. which suggests that some kind of register fills up. Though I have also seen 66 files being processed. (I'll edit this in the question.)
Ok, see my answer (run the codes outside PSSE). Multiprocessing might help. By the way, I think the OUT file sizes may be related to either 64 files or 66 files.
It might be worthwhile to look into the `pandas` library. I find that it makes managing data with tags (i.e. .out file name, channel name, and channel number) a lot easier, and it has some export to .csv methods built in.