NewStrangeWorlds / FastChem

An ultra-fast equilibrium chemistry
https://newstrangeworlds.github.io/FastChem/
GNU General Public License v3.0
41 stars 17 forks source link

Reformat output header columns to fit number of data columns #6

Closed ELeeAstro closed 10 months ago

ELeeAstro commented 1 year ago

Currently the format of the chemistry.dat file header is as follows:

P (bar) T(k) n_ (cm-3) n_g (cm-3) m (u)

I propose removing the space between variables and their units e.g. P (bar) -> P(bar). This allows easier reading of the header and following data (by e.g. numpy) as the number of columns are now equal between the header and data.

daniel-kitzmann commented 1 year ago

Using the correct delimiter ('\t') when reading in the file should be enough, I think. I would also suggest to use pandas when reading in the file because it allows to directly use the header information. So, for example:

import pandas as pd

df = pd.read_table('chemistry.dat', sep=' *\t')

Then you can access the specific data columns by using their names, so for example H2O is addressed as

df['H2O1']

or if you want the data as a numpy array

h2o_data = np.array(df['H2O1'])

Let me know if this works for you or if the header should still be adjusted.

daniel-kitzmann commented 1 year ago

Reading in also works in Numpy when using the correct delimiter, by the way:

data = np.genfromtxt('chemistry.dat', names=True,, delimiter='\t')

daniel-kitzmann commented 10 months ago

I now changed the header format and removed the empty spaces for the C++ and the Python versions.