[Mesa-users] Fwd: History format
amber lauer
amberlauer at gmail.com
Mon Oct 14 14:40:19 EDT 2019
The output data files in MESA are pretty malleable by spreadsheet editors
as-is, you don't really need to change anything. Most Excel clones have the
option to specify the field delimiter, which can be any text character,
including the usual ones. Also, in my experience it's useful to leave the
first five lines for reference. You can usually set these as "column names"
or something like that to leave them out of spreadsheet manipulation. In my
experience the only real manipulation I ever have to do is fix misalignment
of column headers and column data, they can sometimes be off by one left or
right. Now, if you are looking to use the .csv format in some other data
analysis package, such as R, my suggestions may not be useful, or at least
harder to use.
=================================
Dr. Amber Lauer
Postdoctoral Researcher
Triangle Universities Nuclear Lab
Duke University
amber.lauer at tunl.duke.edu <amber.lauer at duke.edu>
On Wed, Oct 9, 2019 at 5:57 AM Bergerson Van Hallen via Mesa-users <
mesa-users at lists.mesastar.org> wrote:
>
> ---------- 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
>> >
>> >
>
> _______________________________________________
> mesa-users at lists.mesastar.org
> https://lists.mesastar.org/mailman/listinfo/mesa-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.mesastar.org/pipermail/mesa-users/attachments/20191014/88deb97d/attachment.html>
More information about the Mesa-users
mailing list