Skip to content

Commit

Permalink
Func. to convert old abund. file to new format
Browse files Browse the repository at this point in the history
  • Loading branch information
vg3095 committed Jul 12, 2017
1 parent fda1b11 commit 9043a33
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tardis/util.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Utilities for TARDIS

from astropy import units as u, constants
from pyne import nucname
import numexpr as ne
import numpy as np
import pandas as pd
import os
import yaml
import re
Expand Down Expand Up @@ -428,4 +430,19 @@ def quantity_linspace(start, stop, num, **kwargs):
raise ValueError('Both start and stop need to be quantities with a '
'unit attribute')

return np.linspace(start.value, stop.to(start.unit).value, num, **kwargs) * start.unit
return np.linspace(start.value, stop.to(start.unit).value, num, **kwargs) * start.unit


def convert_abundances_format(fname, delimiter='\s+'):
df = pd.read_csv(fname, delimiter=delimiter, comment='#', header=None)
#Drop shell column
df.drop(df.columns[0], axis=1, inplace=True)

#Creating Header rows of Element Symbol and Type of Element
header_df = pd.DataFrame([(nucname.name(i), 'E')
for i in range(1, df.shape[1] + 1)]).transpose()
#Align coloumns index with abundance dataframe
header_df.columns = header_df.columns + 1

# Adding header rows to top and return resultant DataFrame
return pd.concat([header_df, df])

0 comments on commit 9043a33

Please sign in to comment.