7
7
import unyt
8
8
import h5py
9
9
10
+ from astropy .cosmology .core import Cosmology
11
+ from astropy .cosmology import wCDM , FlatLambdaCDM
12
+
13
+
14
+
15
+
10
16
11
17
class VelociraptorUnits (object ):
12
18
"""
@@ -37,6 +43,7 @@ class VelociraptorUnits(object):
37
43
star_formation_rate : unyt .unyt_quantity
38
44
period : unyt .unyt_quantity
39
45
box_volume : unyt .unyt_quantity
46
+ cosmology : Cosmology
40
47
41
48
def __init__ (self , filename : str , disregard_units : bool = False ):
42
49
"""
@@ -126,6 +133,7 @@ def get_unit_dictionary(self):
126
133
127
134
self .cosmological = bool (attributes ["Cosmological_Sim" ])
128
135
self .comoving = bool (attributes ["Comoving_or_Physical" ])
136
+ self .cosmology = self .load_cosmology (handle )
129
137
130
138
# Period is comoving.
131
139
self .period = unyt .unyt_quantity (
@@ -142,3 +150,59 @@ def get_unit_dictionary(self):
142
150
setattr (self , name , unit )
143
151
144
152
return
153
+
154
+ def load_cosmology (self , handle : h5py .File ) -> Cosmology :
155
+ """
156
+ Save the (astropy) cosmology to a HDF5 dataset.
157
+
158
+ Parameters
159
+ ----------
160
+
161
+ handle: h5py.File
162
+ h5py file handle for the catalogue file.
163
+
164
+ Returns
165
+ -------
166
+
167
+ astropy.cosmology.Cosmology:
168
+ Astropy cosmology instance extracted from the HDF5 file.
169
+ Also sets ``self.cosmology``.
170
+
171
+ """
172
+
173
+ try :
174
+ group = handle ["Configuration" ].attrs
175
+ except :
176
+ return None
177
+
178
+ # Note that some of these are unused - commented out if not.
179
+ H0 = 100.0 * float (group ["h_val" ])
180
+ w_of_DE = float (group ["w_of_DE" ])
181
+ Omega_DE = float (group ["Omega_DE" ])
182
+ # Omega_Lambda = float(group["Omega_Lambda"])
183
+ Omega_b = float (group ["Omega_b" ])
184
+ # Omega_cdm = float(group["Omega_cdm"])
185
+ # Omega_k = float(group["Omega_k"])
186
+ Omega_m = float (group ["Omega_m" ])
187
+ # Omega_nu = float(group["Omega_nu"])
188
+ # Omega_r = float(group["Omega_r"])
189
+
190
+ if w_of_DE != - 1.0 :
191
+ cosmology = wCDM (
192
+ H0 = H0 ,
193
+ Om0 = Omega_m ,
194
+ Ode0 = Omega_DE ,
195
+ w0 = w_of_DE ,
196
+ Ob0 = Omega_b ,
197
+ )
198
+ else :
199
+ # No EoS
200
+ cosmology = FlatLambdaCDM (
201
+ H0 = H0 ,
202
+ Om0 = Omega_m ,
203
+ Ob0 = Omega_b ,
204
+ )
205
+
206
+ self .cosmology = cosmology
207
+
208
+ return cosmology
0 commit comments