1import yt
2
3yt.enable_parallelism()
4
5# Enable parallelism in the script (assuming it was called with
6# `mpirun -np <n_procs>` )
7yt.enable_parallelism()
8
9# By using wildcards such as ? and * with the load command, we can load up a
10# Time Series containing all of these datasets simultaneously.
11ts = yt.load("enzo_tiny_cosmology/DD????/DD????")
12
13# Calculate and store density extrema for all datasets along with redshift
14# in a data dictionary with entries as tuples
15
16# Create an empty dictionary
17data = {}
18
19# Iterate through each dataset in the Time Series (using piter allows it
20# to happen in parallel automatically across available processors)
21for ds in ts.piter():
22    ad = ds.all_data()
23    extrema = ad.quantities.extrema(("gas", "density"))
24
25    # Fill the dictionary with extrema and redshift information for each dataset
26    data[ds.basename] = (extrema, ds.current_redshift)
27
28# Sort dict by keys
29data = {k: v for k, v in sorted(data.items())}
30
31# Print out all the values we calculated.
32print("Dataset      Redshift        Density Min      Density Max")
33print("---------------------------------------------------------")
34for key, val in data.items():
35    print(
36        "%s       %05.3f          %5.3g g/cm^3   %5.3g g/cm^3"
37        % (key, val[1], val[0][0], val[0][1])
38    )
39