105 lines
5.5 KiB
Python
105 lines
5.5 KiB
Python
import sys
|
|
# sys.path.append(r'C:\Users\adabbate\Python_modules')
|
|
sys.path.append(r"C:\IPMBOLT\Toolbox\BOLT\toolbox")
|
|
sys.path.append(r"C:\IPMBOLT\Platform\oct-dist\install\Python")
|
|
|
|
|
|
import pandas as pd
|
|
|
|
class NodeExtractor:
|
|
def __init__(self, filename, sheetname, Closed_system=True):
|
|
self.filename = filename
|
|
self.sheetname = sheetname
|
|
self.Closed_system = Closed_system
|
|
self.nodes, self.streamID, self.stream_ori, self.conditions = self.Extract_node_res()
|
|
|
|
def Extract_node_res(self):
|
|
#Read MultiRun Sheet
|
|
xls = pd.read_excel(self.filename, sheet_name = self.sheetname, engine="openpyxl")
|
|
conditions = xls.iloc[0]
|
|
conditions = conditions.reset_index()
|
|
conditions = conditions[conditions.columns[1]]
|
|
conditions = conditions.drop(labels=[0,1,2,5,6,7,8,9,10,11,12])
|
|
xls = xls.drop(xls.index[0], axis = 0)
|
|
xls.columns = xls.iloc[1]
|
|
xls= xls.drop([2,3],axis=0)
|
|
|
|
nodes = xls[xls['Variable'].str.contains("Sub_node.summary.h|Sub_node.summary.x|Sub_node.summary.p|Sub_node.summary.T|Sub_node.summary.isOff", na=False)]
|
|
nodes = nodes.drop(nodes.columns[[0,1,2,5,6,7,8,9,10,11,12]],axis = 1)
|
|
ritemTransormed = pd.DataFrame()
|
|
replaceBlank = ritemTransormed#.dropna()
|
|
replaceBlank['Status'] = nodes.columns
|
|
replaceBlank.index = nodes.columns
|
|
replaceBlank['Conditions'] = conditions.values
|
|
nodes = pd.concat([replaceBlank.transpose(),nodes], axis=0)
|
|
nodes.columns = [*nodes.columns[0:2],*replaceBlank['Conditions'][2:].values]
|
|
|
|
nodes['Variable'] = nodes['Variable'][2:].apply(lambda x: x[::-1])
|
|
nodes['Name'] = nodes['Name'][2:].apply(lambda x: x[::-1])
|
|
nodes['Name.Variable'] = nodes['Variable']+'.'+nodes['Name']
|
|
|
|
S=nodes['Variable'].str.split('.')[2:]
|
|
|
|
nodes['Variable_name'] = nodes['Name.Variable'][2:].apply(lambda x: '.'.join(x.split('.')[:3])[::-1])
|
|
|
|
if len(S.min())>3:
|
|
nodes['Node_name'] = nodes['Name.Variable'][2:].apply(lambda x: '.'.join((x.split('.')[3:-1]))[::-1])
|
|
nodes['Module_name'] = nodes['Name.Variable'][2:].apply(lambda x: (x.split('.')[-1])[::-1])
|
|
else:
|
|
nodes['Node_name'] = nodes['Name.Variable'][2:].apply(lambda x: '.'.join((x.split('.')[3:]))[::-1])
|
|
nodes['Module_name'] = 'equipment'
|
|
|
|
nodes['Variable'] = nodes['Node_name']+'.'+nodes['Variable_name']
|
|
cols = list(nodes.columns)
|
|
cols = cols[-1:-4:-1] + cols[:-4]
|
|
nodes = nodes[cols].drop(['Name'], axis=1)
|
|
|
|
#Get Stream ID of each nodes
|
|
StreamID = xls[xls['Variable'].str.contains("streamID", na=False)]
|
|
|
|
# StreamID = StreamID.drop(StreamID.columns[16:],axis = 1)
|
|
StreamID = StreamID.drop(StreamID.columns[[0,1,2,5,6,7,8,9,10,11,12]],axis = 1)
|
|
Stream_ori = StreamID
|
|
nodes_lst = nodes['Node_name'].drop_duplicates().dropna()
|
|
# if Closed_system:
|
|
# StreamID = StreamID[StreamID['Variable'].str.contains('|'.join(nodes_lst[1:]))]
|
|
# else:
|
|
# StreamID = StreamID[StreamID['Name'].str.contains('|'.join(nodes_lst[1:]))]
|
|
|
|
StreamID = StreamID.loc[:,~StreamID.columns.duplicated()].copy()
|
|
if not self.Closed_system:
|
|
StreamID['Variable'] = StreamID['Name']+'.'+StreamID['Variable']
|
|
|
|
return nodes, StreamID, Stream_ori,conditions
|
|
|
|
def get_single_point(self, nodes, condition, use = 'Quality'):
|
|
|
|
nodes_trans = pd.DataFrame(columns=['Node','Pressure', 'Quality', 'Temperature','Enthalpy'])
|
|
nodes_trans['Node'] = nodes['Node_name'].drop_duplicates().dropna()
|
|
nodes_trans = nodes_trans.set_index('Node')
|
|
for node in nodes_trans.index:
|
|
df = nodes[nodes['Node_name']==node]
|
|
|
|
if df[condition][df['Variable_name'].str.contains('isOff')].values == 0 and nodes.at['Status',condition]=='Solved':
|
|
nodes_trans.at[node,'Pressure'] = float(df[condition][df['Variable'].str.endswith('summary.p')].values)
|
|
nodes_trans.at[node,'Quality'] = float(df[condition][df['Variable'].str.endswith('summary.x')].values)
|
|
nodes_trans.at[node,'Temperature'] = float(df[condition][df['Variable'].str.endswith('summary.T')].values)
|
|
nodes_trans.at[node,'Enthalpy'] = (df[condition][df['Variable'].str.endswith('summary.h')].values).astype(float)
|
|
|
|
return nodes_trans
|
|
def get_circuits(self, condition):
|
|
# Create a list of nodes for circuit B
|
|
streamID_2 = list(self.streamID['Variable'][self.streamID[self.streamID.columns[-1]]==2].str.split('.', expand=True)[0])
|
|
# Create a list of nodes for circuit A
|
|
streamID_1 = list(self.streamID['Variable'][self.streamID[self.streamID.columns[-1]]==1].str.split('.', expand=True)[0])
|
|
|
|
# Create a DataFrame of nodes for circuit B
|
|
cycle_eqA = pd.concat([self.nodes[self.nodes.index == 'Status'],self.nodes[self.nodes['Node_name'].isin(streamID_1)][self.nodes['Module_name'] == 'equipment']])
|
|
cycle_eqB = pd.concat([self.nodes[self.nodes.index == 'Status'],self.nodes[self.nodes['Node_name'].isin(streamID_2)][self.nodes['Module_name'] == 'equipment']])
|
|
CircuitA = self.get_single_point(cycle_eqA, condition).dropna()
|
|
CircuitB = self.get_single_point(cycle_eqB, condition).dropna()
|
|
CircuitA["Enthalpy"] = CircuitA["Enthalpy"].apply(lambda x: x[0])
|
|
CircuitB["Enthalpy"] = CircuitB["Enthalpy"].apply(lambda x: x[0])
|
|
|
|
return CircuitA, CircuitB
|
|
|