parseCoefficients.py 942 B

1234567891011121314151617181920212223242526
  1. import numpy
  2. import os
  3. import re
  4. def parseCoefficients(fdir,outName):
  5. outlines=[]
  6. for s in numpy.arange(0.05,3,0.01):
  7. out='{:.2f}'.format(s)
  8. for c in ['alpha','beta']:
  9. fname='{}_coefficients_n=20_sigma={:.2f}.txt'.format(c,s)
  10. fpath=os.path.join(fdir,fname)
  11. #print('{}: {}'.format(fname,os.path.isfile(fpath)))
  12. with open(fpath,'r') as f:
  13. lines=f.read().splitlines()
  14. lines=[re.sub(r' *','',q) for q in lines]
  15. lines=[re.sub(r'E','e',q) for q in lines]
  16. qv=[float(q) for q in lines]
  17. #use Decimal, if you want to preserve all decimals
  18. #print('nread: {} {:.20f} {}'.format(len(qv),qv[0],lines[0]))
  19. out+=' '
  20. out+=' '.join(lines)
  21. #print(' '.join(lines))
  22. outlines.append(out)
  23. print('nlines {}'.format(len(outlines)))
  24. with open(os.path.join(fdir,outName),'w') as f:
  25. f.write('\n'.join(outlines))