/doc/sphinx/example-acoustics-1d/makeplots.py

http://github.com/clawpack/clawpack-4.x
Python | 56 lines | 34 code | 13 blank | 9 comment | 2 complexity | f2cc40f64b71f2c8f860081e7033b67a MD5 | raw file

✨ Summary
  1. """
  2. Create plots corresponding to each sample setplot function. Search for all
  3. files of the form setplot_*.py and loop over them.
  4. Also create .rst files for each example. The doc string for each setplot
  5. file should start with at title underlined with ===, followed by a brief
  6. description. These are used in the rst file, which also includes the
  7. setplot function itself and a pointer to the plots directory.
  8. """
  9. import os, glob, re
  10. from pyclaw.plotters.plotclaw import plotclaw
  11. thisdir = os.path.split(os.getcwd())[1]
  12. os.system('make .plots') # ensure output files and sample plots exist
  13. os.system('make .htmls') # ensure html files exist
  14. filenames = glob.glob('setplot_*.py')
  15. spnames = []
  16. for setplotfile in filenames:
  17. print '=== Making plots using ',setplotfile
  18. regexp = re.compile(r'setplot_(?P<spname>.*).py')
  19. result = regexp.search(setplotfile)
  20. spname = result.group('spname')
  21. spnames.append(spname)
  22. plotdir = 'plots_%s' % spname
  23. plotclaw(outdir="_output", plotdir=plotdir, setplot=setplotfile)
  24. for spname in spnames:
  25. setplotfile = 'setplot_%s.py' % spname
  26. rstfile_name = 'plotexample-acou-1d-%s' % spname
  27. print '=== Making rst file %s.rst' % rstfile_name
  28. rstfile = open('../%s.rst' % rstfile_name, 'w')
  29. setplot_lines = open(setplotfile,'r').read()
  30. regexp = re.compile(r'"""(?P<descr>.*?)""" (?P<rest>.*)', \
  31. re.DOTALL)
  32. result = regexp.search(setplot_lines)
  33. setplot_descr = result.group('descr')
  34. setplot_rest = result.group('rest')
  35. setplot_rest = setplot_rest.replace('\n','\n ',1000)
  36. rstfile.write(""".. _%s: \n%s \n\n""" % (rstfile_name, setplot_descr))
  37. rstfile.write("Example generating data: `$CLAW/doc/sphinx/%s/README.html <../%s/README.html>`_\n\n" \
  38. % (thisdir, thisdir))
  39. rstfile.write("Resulting plots: `$CLAW/doc/sphinx/%s/plots_%s/_PlotIndex.html <../%s/plots_%s/_PlotIndex.html>`_\n\n::\n" \
  40. % (thisdir, spname, thisdir, spname))
  41. rstfile.write(setplot_rest)
  42. rstfile.close()