# Path: src/core/def_tools.py
# def keys_sorted(dictionary, n_top=None):
#     import heapq
#     if n_top is None:
#         n_top = len(dictionary.keys())
#     else:
#         n_top = int(n_top)
#     return heapq.nlargest(n_top, dictionary, key = lambda k:dictionary[k])
# 
# def cond2dir(dir_desk, fuel, oxid, phi, atm, T0, reactor, d):
# 
#     comp = add_bracket(fuel) + ' + ' + add_bracket(oxid)
#     phi_str = 'phi' + str(phi)#num2str(phi, d=3)
#     atm_str = str(atm)+'atm'#num2str(atm, d) + 'atm'
#     T0_str = str(T0)+'K'#num2str(T0, d) + 'K'
#     return os.path.join(dir_desk,'raw', comp, reactor, phi_str+'_'+atm_str+'_'+T0_str)
# 
# def para2dir_GPS(dir_public, train_name, \
#     alpha=None, K=None, beta=None, \
#     es_name=None, iso_name=None, \
#     d=4, gamma=None):
# 
#     extra_setting = 'e[' + es_name + ']'
#     if iso_name != None:
#         extra_setting += (', iso[' + iso_name + ']'+'g'+str(gamma))
# 
#     para_str = 'K' + str(int(K))  +  '_b' + num2str(beta,d) + '_a' + num2str(alpha,d)
#     return os.path.join(dir_public, 'GPS', train_name, para_str, extra_setting)
# 
# Path: src/ct/def_ct_tools.py
# def load_raw(path_raw):
#     raw_file = np.load(open(path_raw, 'rb'))
#     raw = dict()
#     for key in raw_file.keys():
#         if key in ['mole_fraction','net_reaction_rate']:
#             raw[key] = np.matrix(raw_file[key])
#         else:
#             raw[key] = raw_file[key]
#     return raw


import sys
import os
import cantera as ct
import json
import time
import copy
		import sys
from PyQt4 import uic
from PyQt4.QtGui import * 
from PyQt4.QtCore import * 
from def_painter import *
from src.core.def_tools import keys_sorted, cond2dir, para2dir_GPS
from src.core.def_GPSA import *
from src.ct.def_ct_tools import load_raw
from src.gui.def_dialog import *
			GP = self.parent.project[self.key][GP_name]
			alias = GP['alias']
			self.occupied.append(alias)
			if GP_name == self.old_name:
				self.old_alias = alias
				self.data = copy.copy(GP)

		# set connection ====================

		self.w.btn_save.clicked.connect(self.act_save)
		self.w.btn_cancel.clicked.connect(self.act_cancel)

		# set ui obj ==============================

		self.w.txt_name.setText(self.data['name'])
		self.w.txt_alias.setText(self.data['alias'])

		# exec ==============================

		if self.w.exec_() == QDialog.Rejected:
			self.data = None





def find_GP_order(dir_raw, traced, parent, sample, method='D_GP'):


	path_raw = os.path.join(dir_raw,'raw.npz')

# Path: src/core/def_tools.py
# def keys_sorted(dictionary, n_top=None):
#     import heapq
#     if n_top is None:
#         n_top = len(dictionary.keys())
#     else:
#         n_top = int(n_top)
#     return heapq.nlargest(n_top, dictionary, key = lambda k:dictionary[k])
# 
# def cond2dir(dir_desk, fuel, oxid, phi, atm, T0, reactor, d):
# 
#     comp = add_bracket(fuel) + ' + ' + add_bracket(oxid)
#     phi_str = 'phi' + str(phi)#num2str(phi, d=3)
#     atm_str = str(atm)+'atm'#num2str(atm, d) + 'atm'
#     T0_str = str(T0)+'K'#num2str(T0, d) + 'K'
#     return os.path.join(dir_desk,'raw', comp, reactor, phi_str+'_'+atm_str+'_'+T0_str)
# 
# def para2dir_GPS(dir_public, train_name, \
#     alpha=None, K=None, beta=None, \
#     es_name=None, iso_name=None, \
#     d=4, gamma=None):
# 
#     extra_setting = 'e[' + es_name + ']'
#     if iso_name != None:
#         extra_setting += (', iso[' + iso_name + ']'+'g'+str(gamma))
# 
#     para_str = 'K' + str(int(K))  +  '_b' + num2str(beta,d) + '_a' + num2str(alpha,d)
#     return os.path.join(dir_public, 'GPS', train_name, para_str, extra_setting)
# 
# Path: src/ct/def_ct_tools.py
# def load_raw(path_raw):
#     raw_file = np.load(open(path_raw, 'rb'))
#     raw = dict()
#     for key in raw_file.keys():
#         if key in ['mole_fraction','net_reaction_rate']:
#             raw[key] = np.matrix(raw_file[key])
#         else:
#             raw[key] = raw_file[key]
#     return raw


# Path: src/post/dialog_subplot.py
import sys
import os
import cantera as ct
import json
import time
import copy
		import sys
from PyQt4 import uic
from PyQt4.QtGui import * 
from PyQt4.QtCore import * 
from def_painter import *
from src.core.def_tools import keys_sorted, cond2dir, para2dir_GPS
from src.core.def_GPSA import *
from src.ct.def_ct_tools import load_raw
from src.gui.def_dialog import *

			GP = self.parent.project[self.key][GP_name]
			alias = GP['alias']
			self.occupied.append(alias)
			if GP_name == self.old_name:
				self.old_alias = alias
				self.data = copy.copy(GP)

		# set connection ====================

		self.w.btn_save.clicked.connect(self.act_save)
		self.w.btn_cancel.clicked.connect(self.act_cancel)

		# set ui obj ==============================

		self.w.txt_name.setText(self.data['name'])
		self.w.txt_alias.setText(self.data['alias'])

		# exec ==============================

		if self.w.exec_() == QDialog.Rejected:
			self.data = None





def find_GP_order(dir_raw, traced, parent, sample, method='D_GP'):


	path_raw = os.path.join(dir_raw,'raw.npz')

	raw = load_raw(path_raw)