Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tab data format #12

Open
gpagliuca opened this issue Sep 27, 2016 · 4 comments
Open

tab data format #12

gpagliuca opened this issue Sep 27, 2016 · 4 comments

Comments

@gpagliuca
Copy link
Owner

the tab.data dataframe is difficult to handle (properties as index), its structure should be changed

@kjeeetil
Copy link
Contributor

kjeeetil commented Feb 8, 2021

xarray provides a very convenient format for this type of data. if you pass a pandas dataframe with an appropriate multiindexed dataframe as input everything works out nicely:

tab=pyfas.tab.Tab("PVTtable.tab")
tab.export_all()

columns=tab.data["Property"].values
data=tab.data["values"].values

series={}
for i, array in enumerate(data): #cycles through each column in data, creating a pandas dataseries with properties as columns
series[columns[i]]=array

new_p=[]
new_t=[]

for p in tab.metadata['p_array'][0]:
new_t=new_t+list(tab.metadata['t_array'][0])
new_p=new_p+[p/1e5 for x in tab.metadata['p_array'][0]]

index=zip(new_p, new_t) #creates a list of tuples which can be used in a multiindex
index=pd.MultiIndex.from_tuples(index, names=["P", "T"]) #creates a multiindex with pressure and temperature

df=pd.DataFrame(series, index=index) #creates a dataframe from the tab data with pressure and temperature as index
da=df.to_xarray() #passes the dataframe to an xarray dataarray

The dataarray will have pressure and temperature as dimensions, and each column in the dataframe as a variable. The datarray allows you to do things like fast linear interpolation (e.g. da.interp(T=50, P=[50, 60, 70])["LIQUID DENSITY"]) which is extremely useful especially when comparing tables with different spacing between input parameters.

@gpagliuca
Copy link
Owner Author

gpagliuca commented Feb 9, 2021

thanks for the suggestion, it looks very interesting. Also here if you have the possibility a PR would be quite useful since you know xarray better than me

@daniel-brett
Copy link

Has this issue been addressed with #23?

@gpagliuca
Copy link
Owner Author

gpagliuca commented May 3, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants