File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -253,19 +253,36 @@ def read_dndz(file_path):
253253
254254 Returns
255255 -------
256- list :
256+ np.array :
257257 redshift bin centers
258- list :
258+ np.array :
259259 number densities
260- list :
261- redshift bin edges
260+ np.array :
261+ redshift bin edges; one less than centers and density arrays
262262
263263 """
264- dat = ascii .read (file_path , format = "commented_header" )
264+ try :
265+ # Expecting header line "# z dn_dz"
266+ dat = ascii .read (file_path , format = "commented_header" )
267+ missing = [col for col in ("z" , "dn_dz" ) if col not in dat .dtype .names ]
268+ if missing :
269+ raise ValueError (
270+ f"Missing columns in dndz path { file_path } : { missing } "
271+ )
272+ except :
273+ # No header line
274+ dat = ascii .read (file_path )
275+ dat .rename_column ("col1" , "z" )
276+ dat .rename_column ("col2" , "dn_dz" )
277+
278+ # Remove last n(z) value which should be zero, to match bin centers
279+ tolerance = 1e-5
280+ if dat ["dn_dz" ][- 1 ] / sum (dat ["dn_dz" ]) > tolerance :
281+ raise ValueError ("dn_dz at last z-edge = {dat['dn_dz'][-1]}, no zero" )
265282
266- # Remove last n(z) value which is zero, to match bin centers
267283 nz = dat ["dn_dz" ][:- 1 ]
268284 z_edges = dat ["z" ]
285+
269286 z_centers = bin_edges2centers (z_edges )
270287
271288 return z_centers , nz , z_edges
You can’t perform that action at this time.
0 commit comments