Advertisement
rasmit

Untitled

Jan 26th, 2024
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. # the minimal saving code
  2. analysis_fields = [
  3.     ("all", "metallicity_fraction"),
  4.     ("deposit", "all_mass"),
  5.     ("gas", "H2_mass"),
  6.     ("gas", "H2_fraction"),
  7.     ("gas", "temperature")
  8. ]
  9.  
  10. def save_halo_spheres(ts, halo_position_data):
  11.     ts_redshifts = get_ts_redshifts(ts)
  12.  
  13.     for halo_id, position_data in halo_position_data.items():
  14.         for redshift, position in position_data.items():
  15.             for ds_t in ts.piter():
  16.                 sp = ds_t.sphere([position[1], position[2], position[3]], position[0])
  17.                
  18.                 sp_dataset_name = str(halo_id).zfill(4)
  19.                 sp_dataset_num = str(r).zfill(4) # str(ts_redshift).replace(".", "-")
  20.                 sp.save_as_dataset(fn=f"./halo_data/halo_{sp_dataset_name}_{sp_dataset_num}",fields=analysis_fields) # save the data
  21.  
  22. # the minimal loading code
  23. def plotting():
  24.     halos_all = []
  25.  
  26.     for h in range(1091):
  27.         try:
  28.             halo_id = str(h).zfill(4)
  29.             halo_ts = yt.load(f"./halo_data/halo_{halo_id}_****.h5") # load the data
  30.             halos_all.append(halo_ts)
  31.         except FileNotFoundError:
  32.             print(f"No halo timeseries saved for halo {h}")
  33.    
  34.     figure_1(halos=halos_all)
  35.  
  36. def figure_1(halos):
  37.     for halo_ts in halos:
  38.         for halo_ds in halo_ts:
  39.             # both of these return errors
  40.             gas_density = halo_ds.r["gas", "density"]
  41.             ad = halo_ds.all_data()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement