2020import pandas as pd
2121
2222from .error import ParsingError
23- from .phyvars import FIELD_FILES_H5 , SFIELD_FILES_H5
23+ from .phyvars import FIELD_FILES_H5 , RPROF , SFIELD_FILES_H5
2424from .xdmf import XmlStream
2525
2626if typing .TYPE_CHECKING :
@@ -165,25 +165,24 @@ def _extract_rsnap_isteps(
165165 return isteps
166166
167167
168- def rprof (
169- rproffile : Path , colnames : list [str ]
170- ) -> tuple [dict [int , DataFrame ], DataFrame | None ]:
168+ def rprof (rproffile : Path ) -> tuple [dict [int , DataFrame ], DataFrame | None ]:
171169 """Extract radial profiles data.
172170
173- If `colnames` is too long, it will be truncated. If it is too short,
174- additional numeric column names from 0 to N-1 will be attributed to the N
175- extra columns present in `timefile`.
176-
177171 Args:
178172 rproffile: path of the rprof.dat file.
179- colnames: names of the variables expected in `rproffile`.
180173
181174 Returns:
182175 profs: a dict mapping istep to radial profiles.
183176 times: the time indexed by time steps.
184177 """
185178 if not rproffile .is_file ():
186179 return {}, None
180+
181+ with rproffile .open () as fid :
182+ colnames = fid .readline ().strip ().split ()
183+ if not colnames :
184+ colnames = list (RPROF .keys ())
185+
187186 data = pd .read_csv (
188187 rproffile ,
189188 sep = r"\s+" ,
@@ -213,17 +212,11 @@ def rprof(
213212 return all_data , df_times
214213
215214
216- def rprof_h5 (
217- rproffile : Path , colnames : list [str ]
218- ) -> tuple [dict [int , DataFrame ], DataFrame | None ]:
215+ def rprof_h5 (rproffile : Path ) -> tuple [dict [int , DataFrame ], DataFrame | None ]:
219216 """Extract radial profiles data.
220217
221- If `colnames` is too long, it will be truncated. If it is too short,
222- additional column names will be deduced from the content of the file.
223-
224218 Args:
225219 rproffile: path of the rprof.h5 file.
226- colnames: names of the variables expected in `rproffile`.
227220
228221 Returns:
229222 profs: a dict mapping istep to radial profiles.
@@ -235,13 +228,13 @@ def rprof_h5(
235228 data = {}
236229 with h5py .File (rproffile , "r" ) as h5f :
237230 dnames = sorted (dname for dname in h5f .keys () if dname .startswith ("rprof_" ))
238- h5names = h5f ["names" ].asstr ()[len ( colnames ) : ]
231+ colnames = h5f ["names" ].asstr ()[() ]
239232 for dname in dnames :
240233 dset = h5f [dname ]
241234 arr = dset [()]
242235 istep = dset .attrs ["istep" ]
243236 step_cols = list (colnames )
244- _tidy_names (step_cols , arr .shape [1 ], h5names ) # check shape
237+ _tidy_names (step_cols , arr .shape [1 ]) # check shape
245238 data [istep ] = pd .DataFrame (arr , columns = step_cols )
246239 isteps .append ((istep , dset .attrs ["time" ]))
247240
0 commit comments