pyfas
pyfas copied to clipboard
tab data format
the tab.data dataframe is difficult to handle (properties as index), its structure should be changed
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.
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
Has this issue been addressed with https://github.com/gpagliuca/pyfas/pull/23?
Yes, it was
Cheers
Il giorno mer 26 apr 2023 alle ore 15:18 daniel-brett < @.***> ha scritto:
Has this issue been addressed with #23 https://github.com/gpagliuca/pyfas/pull/23?
— Reply to this email directly, view it on GitHub https://github.com/gpagliuca/pyfas/issues/12#issuecomment-1523409075, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD2WTVRC6D2XNHTBUU7YNI3XDEOC3ANCNFSM4CQ5NGUA . You are receiving this because you authored the thread.Message ID: @.***>