/tests/imaging/test_plotStrike.py

https://github.com/MTgeophysics/mtpy
Python | 76 lines | 56 code | 14 blank | 6 comment | 3 complexity | 4701d722313b510517f5b3d84f31a32c MD5 | raw file
  1. import glob
  2. import os
  3. # configure matplotlib for testing
  4. import matplotlib.pyplot as plt
  5. from mtpy.imaging.plotstrike import PlotStrike
  6. from tests.imaging import ImageTestCase, ImageCompare
  7. edi_paths = [
  8. "data/edifiles",
  9. "examples/data/edi2",
  10. "examples/data/edi_files",
  11. "../MT_Datasets/3D_MT_data_edited_fromDuanJM",
  12. "../MT_Datasets/GA_UA_edited_10s-10000s",
  13. "data/edifiles2"
  14. ]
  15. class TestPlotStrike(ImageTestCase):
  16. pass
  17. def _test_gen(edi_path):
  18. def default(self):
  19. edi_file_list = glob.glob(os.path.join(edi_path, "*.edi"))
  20. pt_obj = PlotStrike(fn_list=edi_file_list, plot_yn='n', save_figure_path=self._temp_dir, fig_size=(8, 6), fig_dpi=100)
  21. pt_obj.plot()
  22. plt.pause(1)
  23. save_figure_name = "{}.png".format(default.__name__)
  24. save_figure_path = os.path.join(self._temp_dir, save_figure_name)
  25. pt_obj.save_plot(save_figure_path, file_format='png', close_plot='n')
  26. assert (os.path.isfile(save_figure_path))
  27. def rotation(self):
  28. edi_file_list = glob.glob(os.path.join(edi_path, "*.edi"))
  29. # change rotation
  30. pt_obj = PlotStrike(fn_list=edi_file_list, plot_yn='n', rot_z=90, fig_size=(8, 6), fig_dpi=100)
  31. pt_obj.plot()
  32. plt.pause(1)
  33. def type(self):
  34. edi_file_list = glob.glob(os.path.join(edi_path, "*.edi"))
  35. # plot type
  36. pt_obj = PlotStrike(fn_list=edi_file_list, plot_yn='n', plot_type=1, fig_size=(8, 6), fig_dpi=100)
  37. pt_obj.plot()
  38. plt.pause(1)
  39. def tipper(self):
  40. edi_file_list = glob.glob(os.path.join(edi_path, "*.edi"))
  41. # plot_tipper
  42. pt_obj = PlotStrike(fn_list=edi_file_list, plot_yn='n', plot_tipper='y', fig_size=(8, 6), fig_dpi=100)
  43. pt_obj.plot()
  44. plt.pause(1)
  45. def fold(self):
  46. edi_file_list = glob.glob(os.path.join(edi_path, "*.edi"))
  47. # fold
  48. pt_obj = PlotStrike(fn_list=edi_file_list, plot_yn='n', fold=False, fig_size=(8, 6), fig_dpi=100)
  49. pt_obj.plot()
  50. plt.pause(1)
  51. return default, rotation, type, tipper, fold
  52. # generate tests
  53. for edi_path in edi_paths:
  54. if os.path.isdir(edi_path):
  55. test_name = os.path.basename(edi_path)
  56. for _test_func in _test_gen(edi_path):
  57. _test_func.__name__ = "test_{test_name}_{plot_name}".format(
  58. test_name=test_name, plot_name=_test_func.__name__)
  59. setattr(
  60. TestPlotStrike,
  61. _test_func.__name__,
  62. ImageCompare(fig_size=(8, 6), savefig_kwargs={"dpi": 100}).__call__(_test_func))