[Mesa-users] History format

Warrick Ball W.H.Ball at bham.ac.uk
Tue Oct 8 16:31:54 EDT 2019


Hi Bergerson,

I don't think MESA offers controls to do this but it shouldn't be 
difficult to edit the file afterwards using standard tools. e.g. The most 
natural to me would be to use `sed`.  I just found that this works:

     sed -e '1,5d' -e 's/\s\+/,/g' -e 's/^,//' history.data > history.csv

assuming you want the column names but not the global data.  Here's what 
each piece of the `sed` command does:

- 1,5d: deletes lines 1 to 5
- s/\s\+/,/g: replaces all instances of one or more whitespaces (\s\+) 
with a comma on each line
- s/^,//: replace a comma at the start of a line with nothing.

MESA histories and profiles are easy to read with Python.  The data for 
each point in the track can be loaded in Python using NumPy with something 
like

     import numpy as np
     history = np.genfromtxt('history.data', skip_header=5, dtype=None, names=True)

and then saved with something like

     np.savetxt('history.csv', history, delimiter=',', header=','.join(history.dtype.names))

although I think everything is converted to floats and the header line has 
a leading #.

You can probably use Pandas for more control over the CSV output, maybe by 
casting `history` as a Pandas DataFrame and using the `to_csv` function.

Finally, you could even just use Python to do something like the `sed` 
I started with:

     with open('history.data', 'r') as f:
         lines = f.readlines()

     with open('history.csv', 'w') as f:
         f.write('\n'.join([','.join(line.split()) for line in lines[5:]]))

Cheers,
Warrick


------------
Warrick Ball
Postdoc, School of Physics and Astronomy
University of Birmingham, Edgbaston, Birmingham B15 2TT
W.H.Ball at bham.ac.uk
+44 (0)121 414 4552


On Tue, 8 Oct 2019, mesa-users at lists.mesastar.org wrote:

> 
> Hi everyone!
> 
> I have one question about format in my file history.data. Can I save it (history) in .csv format? I saw how I can save this file in txt, but at moment, I need my history in .csv.
> 
> Thanks,
> 
> 
> Bergerson Van Hallen
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> Bergerson Van Hallen Vieira da SilvaPrograma de Pós Graduação em Física - Doutorado
> Universidade Estadual de Ponta Grossa
> Av. Carlos Cavalcanti, 4748 - Campus Uvaranas
> CEP 84030-900, Ponta Grossa, Paraná, Brasil
> Contato: + 55 44 98822 8987
> e-mail: bgerso at hotmail.com
> 
>


More information about the Mesa-users mailing list