setup.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import os
  2. from pathlib import Path
  3. import shutil
  4. import glob
  5. def setup_folders(num_vincs=6, num_sites=6):
  6. """
  7. DESCRIPTION:
  8. Sets up directory structure for storing plotfiles.
  9. CALLING SEQUENCE:
  10. setup_folders(num_vincs=6, num_sites=6)
  11. KEYWORDS:
  12. ## num_vincs: number of velocity increments (default 6; +0-5 km/s)
  13. ## num_sites: number of specific collision sites (default 6)
  14. Directory Structure:
  15. Plots
  16. - all_ejecta
  17. - vincs_separate
  18. - 0vinc
  19. - all_planets
  20. - per_planet
  21. - cols_v_time
  22. - cols_v_time_fits
  23. - inc_v_a
  24. - e_v_a
  25. - 1vinc
  26. - 2vinc
  27. ...
  28. ...
  29. - vincs_compared
  30. - histograms
  31. - cols_v_time
  32. - inc_v_a
  33. - e_v_a
  34. - specific_collision_sites
  35. - site1
  36. - vincs_separate
  37. - 0vinc
  38. - all_planets
  39. - per_planet
  40. - cols_v_time
  41. - cols_v_time_fits
  42. - inc_v_a
  43. - e_v_a
  44. - 1vinc
  45. - 2vinc
  46. ...
  47. ...
  48. - vincs_compared
  49. - histograms
  50. - cols_v_time
  51. - inc_v_a
  52. - e_v_a
  53. - site2
  54. ...
  55. ...
  56. - single_ejecta
  57. - 0vinc
  58. - 1vinc
  59. ...
  60. ...
  61. """
  62. object_names = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
  63. parent = os.getcwd()
  64. plotspath = parent + "/Plots"
  65. all_ejecta_path = plotspath + "/all_ejecta"
  66. specific_sites_path = plotspath + "/specific_collision_sites"
  67. single_ejecta_path = plotspath + "/single_ejecta"
  68. #create Plots directory
  69. Path(plotspath).mkdir(parents=True, exist_ok=True)
  70. #create all_ejecta folder
  71. Path(all_ejecta_path).mkdir(parents=True, exist_ok=True)
  72. #populate all_ejecta_folder:
  73. ###1. vincs_separate folder
  74. Path(all_ejecta_path + "/vincs_separate").mkdir(parents=True, exist_ok=True)
  75. for i in range(num_vincs):
  76. #make vincs_separate
  77. vinc_folder = all_ejecta_path + "/vincs_separate/" + str(i) + "vinc"
  78. Path(vinc_folder).mkdir(parents=True, exist_ok=True)
  79. #make all_planets
  80. Path(vinc_folder + "/all_planets").mkdir(parents=True, exist_ok=True)
  81. Path(vinc_folder + "/all_planets/inc_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  82. Path(vinc_folder + "/all_planets/e_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  83. #make and populate per_planet
  84. per_p_folder = vinc_folder + "/per_planet"
  85. Path(per_p_folder).mkdir(parents=True, exist_ok=True)
  86. Path(per_p_folder + "/cols_v_time").mkdir(parents=True, exist_ok=True)
  87. Path(per_p_folder + "/cols_v_time_fits").mkdir(parents=True, exist_ok=True)
  88. Path(per_p_folder + "/inc_v_a").mkdir(parents=True, exist_ok=True)
  89. Path(per_p_folder + "/e_v_a").mkdir(parents=True, exist_ok=True)
  90. for o in object_names[1:]:
  91. Path(per_p_folder + "/inc_v_a/" + o + "_inc_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  92. Path(per_p_folder + "/e_v_a/" + o + "_e_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  93. Path(per_p_folder + "/inc_v_a/remaining_inc_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  94. Path(per_p_folder + "/e_v_a/remaining_e_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  95. Path(per_p_folder + "/inc_v_a/esc_inc_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  96. Path(per_p_folder + "/e_v_a/esc_e_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  97. Path(per_p_folder + "/inc_v_a/mixed_inc_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  98. Path(per_p_folder + "/e_v_a/mixed_e_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  99. ###2. vincs_compared folder
  100. Path(all_ejecta_path + "/vincs_compared").mkdir(parents=True, exist_ok=True)
  101. Path(all_ejecta_path + "/vincs_compared/histograms").mkdir(parents=True, exist_ok=True)
  102. Path(all_ejecta_path + "/vincs_compared/cols_v_time").mkdir(parents=True, exist_ok=True)
  103. Path(all_ejecta_path + "/vincs_compared/inc_v_a").mkdir(parents=True, exist_ok=True)
  104. Path(all_ejecta_path + "/vincs_compared/e_v_a").mkdir(parents=True, exist_ok=True)
  105. #create specific_collision_sites folder
  106. Path(specific_sites_path).mkdir(parents=True, exist_ok=True)
  107. #populate specific_collision_sites folder
  108. for j in range(num_sites):
  109. #folder for each site
  110. site_path = specific_sites_path + "/site" + str(j)
  111. Path(site_path).mkdir(parents=True, exist_ok=True)
  112. #1. vincs_separate folder
  113. for i in range(num_vincs):
  114. #make vincs_separate
  115. vinc_folder = site_path + "/vincs_separate/" + str(i) + "vinc"
  116. Path(vinc_folder).mkdir(parents=True, exist_ok=True)
  117. #make all_planets
  118. Path(vinc_folder + "/all_planets").mkdir(parents=True, exist_ok=True)
  119. Path(vinc_folder + "/all_planets/inc_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  120. Path(vinc_folder + "/all_planets/e_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  121. #make and populate per_planet
  122. per_p_folder = vinc_folder + "/per_planet"
  123. Path(per_p_folder).mkdir(parents=True, exist_ok=True)
  124. Path(per_p_folder + "/cols_v_time").mkdir(parents=True, exist_ok=True)
  125. Path(per_p_folder + "/cols_v_time_fits").mkdir(parents=True, exist_ok=True)
  126. Path(per_p_folder + "/inc_v_a").mkdir(parents=True, exist_ok=True)
  127. Path(per_p_folder + "/e_v_a").mkdir(parents=True, exist_ok=True)
  128. for o in object_names[1:]:
  129. Path(per_p_folder + "/inc_v_a/" + o + "_inc_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  130. Path(per_p_folder + "/e_v_a/" + o + "_e_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  131. Path(per_p_folder + "/inc_v_a/remaining_inc_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  132. Path(per_p_folder + "/e_v_a/remaining_e_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  133. Path(per_p_folder + "/inc_v_a/esc_inc_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  134. Path(per_p_folder + "/e_v_a/esc_e_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  135. Path(per_p_folder + "/inc_v_a/mixed_inc_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  136. Path(per_p_folder + "/e_v_a/mixed_e_v_a_snapshots").mkdir(parents=True, exist_ok=True)
  137. ###2. vincs_compared folder
  138. Path(site_path + "/vincs_compared").mkdir(parents=True, exist_ok=True)
  139. Path(site_path + "/vincs_compared/histograms").mkdir(parents=True, exist_ok=True)
  140. Path(site_path + "/vincs_compared/cols_v_time").mkdir(parents=True, exist_ok=True)
  141. Path(site_path + "/vincs_compared/inc_v_a").mkdir(parents=True, exist_ok=True)
  142. Path(site_path + "/vincs_compared/e_v_a").mkdir(parents=True, exist_ok=True)
  143. #create single_ejecta_path folder
  144. Path(single_ejecta_path).mkdir(parents=True, exist_ok=True)
  145. #populate
  146. for i in range(num_vincs):
  147. Path(single_ejecta_path + '/' + str(i) + 'vinc').mkdir(parents=True, exist_ok=True)
  148. def sort_data(num_vincs=6):
  149. """
  150. DESCRIPTION:
  151. Sorts data folders in Ejecta_Simulation_Data by vinc.
  152. CALLING SEQUENCE:
  153. sort_data(num_vincs=6)
  154. KEYWORDS:
  155. ## num_vincs: number of velocity increments (default 6; +0-5 km/s)
  156. """
  157. parent = os.getcwd()
  158. folders = sorted(glob.glob(parent + '/Ejecta_Simulation_Data/5000e*'))
  159. for i in range(num_vincs):
  160. Path(parent + '/Ejecta_Simulation_Data/'+str(i)+'vinc').mkdir(parents=True, exist_ok=True)
  161. for folder in folders:
  162. vincnum = folder.split('/')[-1].split('_')[2][0]
  163. shutil.move(folder, parent + '/Ejecta_Simulation_Data/' + str(vincnum) + 'vinc')