[Mesa-users] Fwd: History format

Bergerson Van Hallen bergersonvanhallen at gmail.com
Wed Oct 9 05:59:41 EDT 2019


---------- Forwarded message ---------
From: Bergerson Van Hallen <bergersonvanhallen at gmail.com>
Date: Wed, 9 Oct 2019, 00:16
Subject: Re: [Mesa-users] History format
To: Warrick Ball <W.H.Ball at bham.ac.uk>




Hi Warrik!

Thanks a lot for your suggestions! Now I can manipulate my history files
and yes:

"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."

I was looking for the possibility CSV output in history files because I saw
the easy manipulation with Pandas in my purpose.

Thanks once again,

Bergerson Van Hallen












*Bergerson Van Hallen Vieira da Silva*
Programa 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


On Tue, Oct 8, 2019 at 5:31 PM Warrick Ball <W.H.Ball at bham.ac.uk> wrote:

> 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
> >
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20191009/c12e7b04/attachment.html>


More information about the Mesa-users mailing list