MesaLogDir¶
161 |MesaLogDir is a class that contains information about the LOGS directory as a 162 | whole. In addition to giving easy access to the history data, you can easily 163 | find profiles by profile number, model number, or by selecting according to a 164 | more flexible history criteria.
165 |-
168 |
-
169 | class
mesa_reader.
MesaLogDir
(log_path='LOGS', profile_prefix='profile', profile_suffix='data', history_file='history.data', index_file='profiles.index', memoize_profiles=True)[source]¶
170 | Structure providing access to both history and profile output from MESA
171 |Provides access for accessing the history and profile data of a MESA run 172 | by linking profiles to the history through model numbers.
173 |174 |
197 |175 | 176 | 177 | 195 | 196 |Parameters: 194 |-
178 |
- log_path (str, optional) – Path to the logs directory, default is ‘LOGS’ 179 |
- profile_prefix (str, optional) – Prefix before profile number in profile file names, default is 180 | ‘profile’ 181 |
- profile_suffix (str, optional) – Suffix after profile number and period for profile file names, default 182 | is ‘data’ 183 |
- history_file (str, optional) – Name of the history file in the logs directory, default is 184 | ‘history.data’ 185 |
- index_file (str, optional) – Name of the profiles index file in the logs directory, default is 186 | ‘profiles.index’ 187 |
- memoize_profiles (bool, optional) – Determines whether or not profiles will be “memo-ized”, default is 188 | True. If memoized, once a profile is called into existence, it is saved 189 | so that it need not be read in again. Good for quick, clean, repeated 190 | access of a profile, but bad for reading in many profiles for one-time 191 | uses as it will hog memory. 192 |
-
198 |
-
199 |
log_path
¶
200 | str – Path to the logs directory; used (re-)reading data in
201 |
-
204 |
-
205 |
profile_prefix
¶
206 | str – Prefix before profile number in profile file names
207 |
-
210 |
-
211 |
profile_suffix
¶
212 | str – Suffix after profile number and period for profile file names
213 |
-
216 |
-
217 |
history_file
¶
218 | str – Base name (not path) of the history file in the logs directory
219 |
-
222 |
-
223 |
index_file
¶
224 | str – Base name (not path) of the profiles index file in the logs directory
225 |
-
228 |
-
229 |
memoize_profiles
¶
230 | bool – Determines whether or not profiles will be “memo-ized”. Setting this 231 | after initialization will not delete profiles from memory. It will 232 | simply start/stop memoizing them. To clear out memoized profiles, 233 | re-read the data with self.read_logs()
234 |
-
237 |
-
238 |
history_path
¶
239 | str – Path to the history data file
240 |
-
243 |
-
244 |
index_path
¶
245 | str – Path to the profile index file
246 |
-
249 |
-
250 |
history
¶
251 | mesa_reader.MesaData – MesaData object containing history information from self.history_path
252 |
-
255 |
-
256 |
history_data
¶
257 | mesa_reader.MesaData – Alias for self.history
258 |
-
261 |
-
262 |
profiles
¶
263 | mesa_reader.MesaProfileIndex – MesaProfileIndex from profiles in self.index_path
264 |
-
267 |
-
268 |
profile_numbers
¶
269 | numpy.ndarray – Result of calling self.profiles.profile_numbers. Just the profile 270 | numbers of the simulation in order of corresponding model numbers.
271 |
-
274 |
-
275 |
model_numbers
¶
276 | numpy.ndarray – Result of calling self.profiles.model_numbers. Just the model numbers 277 | of the simulations that have corresponding profiles in ascending order.
278 |
-
281 |
-
282 |
profile_dict
¶
283 | dict – Stores MesaData objects from profiles. Keys to this dictionary are 284 | profile numbers, so presumably self.profile_dict(5) would yield the 285 | MesaData object obtained from the file profile5.data (assuming 286 | reasonable defaults) if such a profile was ever accessed. Will remain 287 | empty if memoization is shut off.
288 |
-
291 |
-
292 |
have_profile_with_model_number
(m_num)[source]¶
293 | Checks to see if a model number has a corresponding profile number.
294 |295 |
307 |296 | 297 | 298 | 300 |Parameters: m_num (int) – model number to be checked 299 | 303 |Returns: True if the model number is in self.model_numbers, otherwise 301 | False. 302 | 305 | 306 |Return type: bool 304 |
-
310 |
-
311 |
have_profile_with_profile_number
(p_num)[source]¶
312 | Checks to see if a given number is a valid profile number.
313 |314 |
326 |315 | 316 | 317 | 319 |Parameters: p_num (int) – profile number to be checked 318 | 322 |Returns: True if profile number is in self.profile_numbers, otherwise 320 | False. 321 | 324 | 325 |Return type: bool 323 |
-
329 |
-
330 |
model_with_profile_number
(p_num)[source]¶
331 | Converts a profile number to a corresponding model number
332 |333 |
344 |334 | 335 | 336 | 338 |Parameters: p_num (int) – profile number to be converted 337 | 340 |Returns: model number that corresponds to p_num. 339 | 342 | 343 |Return type: int 341 |
-
347 |
-
348 |
profile_data
(model_number=-1, profile_number=-1)[source]¶
349 | Generate or retrieve MesaData from a model or profile number.
350 |If both a model number and a profile number is given, the model number 351 | takes precedence. If neither are given, the default is to return a 352 | MesaData object of the last profile (biggest model number). In either 353 | case, this generates (if it doesn’t already exist) or retrieves (if it 354 | has already been generated and memoized) a MesaData object from the 355 | corresponding profile data.
356 |357 |
377 |358 | 359 | 360 | 369 |Parameters: 368 |-
361 |
- model_number (int, optional) – model number for the profile MesaData object desired. Default is 362 | -1, corresponding to the last model number. 363 |
- profile_number (int, optional) – profile number for the profile MesaData object desired. Default is 364 | -1, corresponding to the last model number. If both model_number 365 | and profile_number are given, profile_number is ignored. 366 |
372 |Returns: 371 |Data for profile with desired model/profile number.
370 | 375 | 376 |Return type: 373 | 374 |
-
380 |
-
381 |
profile_with_model_number
(m_num)[source]¶
382 | Converts a model number to a corresponding profile number
383 |384 |
395 |385 | 386 | 387 | 389 |Parameters: m_num (int) – model number to be converted 388 | 391 |Returns: profile number that corresponds to m_num. 390 | 393 | 394 |Return type: int 392 |
-
398 |
-
399 |
read_logs
()[source]¶
400 | Read (or re-read) data from the history and profile index.
401 |Reads in self.history_path and self.index_file for use in getting 402 | history data and profile information. This is automatically called at 403 | instantiation, but can be recalled by the user if for some reason the 404 | data needs to be refreshed (for instance, after changing some of the 405 | reader methods to read in specially-formatted output.)
406 |407 |
416 |408 | 409 | 410 | 412 |Returns: 411 | 414 | 415 |Return type: None 413 |417 |421 |Note
418 |This, if called after initialization, will empty self.profile_dict, 419 | erasing all memo-ized profiles.
420 |
-
424 |
-
425 |
select_models
(f, *keys)[source]¶
426 | Yields model numbers for profiles that satisfy a given criteria.
427 |Given a function f of various time-domain (history) variables, 428 | *keys (i.e., categories in self.history.bulk_names), filters 429 | self.model_numbers and returns all model numbers that satisfy the 430 | criteria.
431 |432 |
457 |433 | 434 | 435 | 445 |Parameters: 444 |-
436 |
- f (function) – A function of the same number of parameters as strings given for 437 | keys that returns a boolean. Should evaluate to True when 438 | condition is met and False otherwise. 439 |
- keys (str) – Name of data categories from self.history.bulk_names whose values 440 | are to be used in the arguments to f, in the same order that they 441 | appear as arguments in f. 442 |
449 |Returns: 448 |Array of model numbers that have corresponding profiles where the 446 | condition given by f is True.
447 | 452 |Return type: 451 |numpy.ndarray
450 | 455 | 456 |Raises: 454 |
453 |KeyError
– If any of the keys are invalid history keys.Examples
458 |464 |463 |>>> l = MesaLogDir() 459 | >>> def is_old_and_bright(age, log_lum): 460 | >>> return age > 1e9 and log_lum > 3 461 | >>> m_nums = l.select_models(is_old_and_bright, 'star_age', 'log_L') 462 |
Here, m_nums will contain all model numbers that have profiles where 465 | the age is greater than a billion years and the luminosity is greater 466 | than 1000 Lsun, provided that ‘star_age’ and ‘log_L’ are in 467 | self.history.bulk_names.
468 |
\ 689 | Sort by:\ 690 | best rated\ 691 | newest\ 692 | oldest\ 693 |
\ 694 |\ 698 |
Add a comment\ 700 | (markup):
\ 701 |``code``
, \ 704 | code blocks:::
and an indented block after blank line