def __init__(self, argv): # init, initialization class self.init = Init(argv) # Get logger from Init class self.log = logging.getLogger('get_UART') # Serial com variable definition self.serial_com = UART(port=self.init.get_serial_port()) # System class self.system = System() # Is UART init a program beginning self.init_UART_bit = self.init.get_init_UART_bit() # Define interface class self.interface = Interface() # Plot curve class self.plot_curve_class = PlotCurve() # Temp data self.temp_data_tab = []
def login(self): machine = str(self.dialog.server.text()) portLog = str(self.dialog.port.text()) database = str(self.dialog.databaseName.text()) userName = str(self.dialog.username.text()) passWord = str(self.dialog.password.text()) self.dialog.close() self.dialog = None self.dialog = pgd.progressDialog(self) self.dialog.show() QCoreApplication.processEvents() ret = Init.connect(machine, portLog, database, userName, passWord) if ret is not None: self.dialog.updateConnectFail() QCoreApplication.processEvents() sleep(4) self.dialog.close() self.dialog = None self.loginPrompt() else: self.dialog.updateConnect() QCoreApplication.processEvents() Init.gettableinfo() self.dialog.updateTable() QCoreApplication.processEvents() Init.maketrees() self.dialog.updateTree() QCoreApplication.processEvents() sleep(2) self.dialog.close() self.dialog = None self.show()
def __init__(self, argv): # Init logger and opt self.init = Init(argv) # Get HTTP port from Init method self.http_port = self.init.get_http_port() # Get logger from Init class self.log = logging.getLogger('CGIHTTPServer')
class Main(object): """ Class Main """ def __init__(self, argv): # Init logger and opt self.init = Init(argv) # Get HTTP port from Init method self.http_port = self.init.get_http_port() # Get logger from Init class self.log = logging.getLogger('CGIHTTPServer') def main(self): # cgitb.enable() # This line enable CGI error reporting self.log.info("main running, HTTP port {}".format(self.http_port)) self.log.debug("main running as debug") server = BaseHTTPServer.HTTPServer handler = CGIHandlerOverloadIndex server_address = ("", self.http_port) handler.cgi_directories = ["/"] httpd = server(server_address, handler) httpd.serve_forever()
def getEndoUsers(): init = Init() sub_reddits = init.subReddit.split( ',') # Subreddits would be endo/adenomyosis/endometriosis users = defaultdict(date) for sub_red in sub_reddits: users = getEndoSubredditUser(users, sub_red) return users
def main(config, host, port, user, ssh, no_relatives, verbose): now = datetime.now() logfile = '/var/log/dbt/backup_{}.log'.format(host) if not os.path.exists(os.path.dirname(logfile)): os.makedirs(os.path.dirname(logfile)) rotate_logs = os.path.exists(logfile) loglevel = logging.DEBUG if verbose else logging.INFO logger = logging.getLogger() logger.setLevel(loglevel) handler = RotatingFileHandler(logfile, maxBytes=50000, backupCount=10) handler.setFormatter( logging.Formatter( '[%(asctime)s] %(levelname)-8s %(filename)-10s %(lineno)-4d %(message)s' )) logger.addHandler(handler) if rotate_logs: logger.handlers[0].doRollover() logger.info('==============================================') # Parse configuration yaml file if config is None or not os.path.isfile(config): logger.error('Error: invalid config file: {}'.format(config)) raise FileNotFoundError lockfile = config + '.lock' if os.path.exists(lockfile): logger.error('{} exists in the filesystem'.format(lockfile)) raise FileExistsError open(lockfile, 'a').close() with open(config) as f: yml_config = yaml.safe_load(f) yml_config['target_dir'] = yml_config['target_dir'].rstrip('/') yml_config['user'] = user yml_config['port'] = port yml_config['host'] = host yml_config['no_rels'] = no_relatives yml_config['ssh'] = ssh yml_config['lockfile'] = lockfile logger.debug('Backup invoked with the following options:') logger.info(' Configuration file: {}'.format(config)) logger.debug(' Don' 't use relative paths: {}'.format(no_relatives)) if ssh: logger.debug(' ssh: {}'.format(ssh)) logger.debug(' host: {}'.format(host)) logger.debug(' user: {}'.format(user)) logger.debug(' port: {}'.format(port)) cmd = ['nc', '-z', '-v', host, str(port)] ret = subprocess.run(cmd, stderr=subprocess.PIPE) if ret.returncode != 0: logger.error('Port {} is not open on {}'.format(port, host)) logger.error(ret.stderr) exit(ret.returncode) # Check for doubled entries in the prio field prios = [] for i in yml_config['intervals']: prios.append(i['prio']) if len(prios) != len(set(prios)): logger.error('Double defined priorities in {} found'.format(config)) raise KeyError # Setup base folders and if needed create a new full backup init = Init(now, yml_config) backup = Backup(yml_config, init.get_backup_target(), now) os.remove(lockfile) end = datetime.now() seconds = (end - now).total_seconds() hours, remainder = divmod(seconds, 3600) minutes, seconds = divmod(remainder, 60) logger.info('Execution time: {} hrs {} mins {} secs'.format( hours, minutes, seconds))
from Init import Init def start(): <<<<<<< HEAD """创建游戏开始页面并创建屏幕对象""" init = Init() init.init_screen() init.init_start_msg() init.init_draw_screen() init.init_check_start() start() ======= """创建游戏初始页面并创建屏幕对象""" pygame.init() settings = Settings() screen = pygame.display.set_mode( (settings.screen_width,settings.screen_height)) screen_rect = screen.get_rect() pygame.display.set_caption("Energy Game") screen.fill(settings.screen_color) #创建文本 bk = (0,0,0) title_msg = Msg(screen,'Energy Game',300,70,80, bk,(230,230,230),375,40) continue1_msg = Msg(screen,'Continue',200,70,60, bk,(230,230,230),425,180) new_game_msg = Msg(screen,'New Game',200,70,60, bk,(230,230,230),425,280)
# dates[cmt.author.name]['3months'] = three_months # dates[cmt.author.name]['createdDate'] = created_date.date() # dates[cmt.author.name]['6months'] = six_months #with open('dates2.csv','a') as f: # f.write(str(dates[cmt.author.name])) # f.write('\n') else: negative_users[cmt.author.name] = 1 end_time = datetime.now() s = (end_time - start_time).seconds # print(s) print('len of pos user is {0}'.format(len(pos))) return pos, positive_users, negative_users init = Init() endo_users = getEndoUsers() subreddits = getRedditsOfEndoUsers(endo_users) non_subreddits = defaultdict(int) if subreddits is not None and len(subreddits) > 0: try: for i, j in subreddits.items(): for k, v in j.items(): non_subreddits[k] += 1 # init.fileWriter.writeData(users_non_endo_submissions) except Exception as e: init.logger.writeError(e.message) non_endo_subreddits = [ reddit for reddit in non_subreddits if reddit[0].lower() not in init.subReddit.split(',')
def __init__(self, params, model_type, stimulus, morpho, diff_range = None): ''' Simulation of an astrocytic subcellular compartment consisting of a multi-compartment model ---------- params : Dictionary with parameters. model_type: Specifies the considered currents of the model. NKV: Membrane currents affecting the concentrations of Na+ and K+ and the membrane voltage. Calcium: Ca2+ currents at the internal Ca2+ store. NKV_Calcium: All currents affecting the concentration of Na+, Ca2+, K+ and the membrane voltage. stimulus: Matrix containing the concentration on the stimulus in space and time. morpho: Object produced by the Astro_morphology class. ''' # converts dict with parameters to variables self.__dict__.update(params) self.model_type = model_type self.stimulus = stimulus self.conn_matrix = morpho.conn_matrix # morphology self.SVR = morpho.SVR self.N = morpho.N self.diameters = morpho.diameters self.length_comp = morpho.length_comp self.end_condition = morpho.end_condition # duration and time step of simulation self.tspan = np.arange(0,self.time, self.dt) # calculate initial values self.init = Init(p) self.init.initialize() # duration and time step of simulation self.tspan = np.arange(0,self.time, self.dt) # set stimulus duration and length of input zone self.comp_start = int(self.N * 0.49) self.comp_end = int(self.N * 0.51) # parameters for diff_range if diff_range is not None: self.d_cond, self.d_start, self.d_end, self.d_coeff = ['step', 70, 79, self.D_C*0.1] if self.model_type == 'NKV': #calculate initial values self.V_0 = self.init.V_0 self.gN = self.init.gN self.gK = self.init.gK # initialize the system init_Na = self.Na_0 * np.ones(self.N) # mM init_K = self.K_0 * np.ones(self.N) # mM init_C = self.C_0 * np.ones(self.N) # Mol init_Na_o = self.Na_o_0 * np.ones(self.N) # mM init_K_o = self.K_o_0 * np.ones(self.N) # mM init_C_o = self.C_o_0 * np.ones(self.N) # Mol init = np.hstack((init_Na, init_K, init_C, init_Na_o, init_K_o, init_C_o)) # simulate spatial astro self.sol = odeint(self.spatial_astro_NKV, init, self.tspan, tcrit=[self.tstart, self.tstop]) # transfer solution of ode system into single variables self.Na = self.sol[:,:self.N] self.K = self.sol[:,self.N:2*self.N] self.C = self.sol[:,2*self.N:3*self.N] self.Na_o = self.sol[:,3*self.N:4*self.N] self.K_o = self.sol[:,4*self.N:5*self.N] self.C_o = self.sol[:,5*self.N:6*self.N] #self.V = self.sol[:,6*self.N:7*self.N] elif self.model_type == 'Calcium': #calculate initial values self.IP3_0 = self.init.IP3_0 self.h_0 = self.init.h_0 self.CER_0 = self.init.CER_0 # initialize the system init_C = self.C_0 * np.ones(self.N) # Mol init_IP3 = self.IP3_0 * np.ones(self.N) # mM init_h = self.h_0 * np.ones(self.N) # mM init_CER = self.CER_0 * np.ones(self.N) # mM init = np.hstack((init_C, init_IP3, init_h, init_CER)) # simulate spatial astro self.sol = odeint(self.spatial_astro_Ca, init, self.tspan, tcrit=[self.tstart, self.tstop]) # transfer solution od ode system into single variables self.C = self.sol[:,:self.N] self.IP3 = self.sol[:,self.N:2*self.N] self.h = self.sol[:,2*self.N:3*self.N] self.CER = self.sol[:,3*self.N:4*self.N] elif self.model_type == 'NKV_Calcium': # calculate initial values self.V_0 = self.init.V_0 self.gN = self.init.gN self.gK = self.init.gK self.IP3_0 = self.init.IP3_0 self.h_0 = self.init.h_0 self.CER_0 = self.init.CER_0 # initialize the system init_Na = self.Na_0 * np.ones(self.N) # mM init_K = self.K_0 * np.ones(self.N) # mM init_C = self.C_0 * np.ones(self.N) # Mol init_IP3 = self.IP3_0 * np.ones(self.N) # mM init_h = self.h_0 * np.ones(self.N) # mM init_CER = self.CER_0 * np.ones(self.N) # mM init_Na_o = self.Na_o_0 * np.ones(self.N) # mM init_K_o = self.K_o_0 * np.ones(self.N) # mM init_C_o = self.C_o_0 * np.ones(self.N) # Mol init = np.hstack((init_Na, init_K, init_C, init_IP3, init_h, init_CER, init_Na_o, init_K_o, init_C_o)) self.diffusion_range(condition=self.d_cond, start = self.d_start, end = self.d_end, d_coeff=self.d_coeff) # simulate spatial astro self.sol = odeint(self.spatial_astro_NKV_Ca, init, self.tspan, tcrit=[self.tstart, self.tstop]) # transfer solution od ode system into single variables self.Na = self.sol[:,:self.N] self.K = self.sol[:,self.N:2*self.N] self.C = self.sol[:,2*self.N:3*self.N] self.IP3 = self.sol[:,3*self.N:4*self.N] self.h = self.sol[:,4*self.N:5*self.N] self.CER = self.sol[:,5*self.N:6*self.N] self.Na_o = self.sol[:,6*self.N:7*self.N] self.K_o = self.sol[:,7*self.N:8*self.N] self.C_o = self.sol[:,8*self.N:9*self.N]
class Astro_multi_compartment(object): def __init__(self, params, model_type, stimulus, morpho, diff_range = None): ''' Simulation of an astrocytic subcellular compartment consisting of a multi-compartment model ---------- params : Dictionary with parameters. model_type: Specifies the considered currents of the model. NKV: Membrane currents affecting the concentrations of Na+ and K+ and the membrane voltage. Calcium: Ca2+ currents at the internal Ca2+ store. NKV_Calcium: All currents affecting the concentration of Na+, Ca2+, K+ and the membrane voltage. stimulus: Matrix containing the concentration on the stimulus in space and time. morpho: Object produced by the Astro_morphology class. ''' # converts dict with parameters to variables self.__dict__.update(params) self.model_type = model_type self.stimulus = stimulus self.conn_matrix = morpho.conn_matrix # morphology self.SVR = morpho.SVR self.N = morpho.N self.diameters = morpho.diameters self.length_comp = morpho.length_comp self.end_condition = morpho.end_condition # duration and time step of simulation self.tspan = np.arange(0,self.time, self.dt) # calculate initial values self.init = Init(p) self.init.initialize() # duration and time step of simulation self.tspan = np.arange(0,self.time, self.dt) # set stimulus duration and length of input zone self.comp_start = int(self.N * 0.49) self.comp_end = int(self.N * 0.51) # parameters for diff_range if diff_range is not None: self.d_cond, self.d_start, self.d_end, self.d_coeff = ['step', 70, 79, self.D_C*0.1] if self.model_type == 'NKV': #calculate initial values self.V_0 = self.init.V_0 self.gN = self.init.gN self.gK = self.init.gK # initialize the system init_Na = self.Na_0 * np.ones(self.N) # mM init_K = self.K_0 * np.ones(self.N) # mM init_C = self.C_0 * np.ones(self.N) # Mol init_Na_o = self.Na_o_0 * np.ones(self.N) # mM init_K_o = self.K_o_0 * np.ones(self.N) # mM init_C_o = self.C_o_0 * np.ones(self.N) # Mol init = np.hstack((init_Na, init_K, init_C, init_Na_o, init_K_o, init_C_o)) # simulate spatial astro self.sol = odeint(self.spatial_astro_NKV, init, self.tspan, tcrit=[self.tstart, self.tstop]) # transfer solution of ode system into single variables self.Na = self.sol[:,:self.N] self.K = self.sol[:,self.N:2*self.N] self.C = self.sol[:,2*self.N:3*self.N] self.Na_o = self.sol[:,3*self.N:4*self.N] self.K_o = self.sol[:,4*self.N:5*self.N] self.C_o = self.sol[:,5*self.N:6*self.N] #self.V = self.sol[:,6*self.N:7*self.N] elif self.model_type == 'Calcium': #calculate initial values self.IP3_0 = self.init.IP3_0 self.h_0 = self.init.h_0 self.CER_0 = self.init.CER_0 # initialize the system init_C = self.C_0 * np.ones(self.N) # Mol init_IP3 = self.IP3_0 * np.ones(self.N) # mM init_h = self.h_0 * np.ones(self.N) # mM init_CER = self.CER_0 * np.ones(self.N) # mM init = np.hstack((init_C, init_IP3, init_h, init_CER)) # simulate spatial astro self.sol = odeint(self.spatial_astro_Ca, init, self.tspan, tcrit=[self.tstart, self.tstop]) # transfer solution od ode system into single variables self.C = self.sol[:,:self.N] self.IP3 = self.sol[:,self.N:2*self.N] self.h = self.sol[:,2*self.N:3*self.N] self.CER = self.sol[:,3*self.N:4*self.N] elif self.model_type == 'NKV_Calcium': # calculate initial values self.V_0 = self.init.V_0 self.gN = self.init.gN self.gK = self.init.gK self.IP3_0 = self.init.IP3_0 self.h_0 = self.init.h_0 self.CER_0 = self.init.CER_0 # initialize the system init_Na = self.Na_0 * np.ones(self.N) # mM init_K = self.K_0 * np.ones(self.N) # mM init_C = self.C_0 * np.ones(self.N) # Mol init_IP3 = self.IP3_0 * np.ones(self.N) # mM init_h = self.h_0 * np.ones(self.N) # mM init_CER = self.CER_0 * np.ones(self.N) # mM init_Na_o = self.Na_o_0 * np.ones(self.N) # mM init_K_o = self.K_o_0 * np.ones(self.N) # mM init_C_o = self.C_o_0 * np.ones(self.N) # Mol init = np.hstack((init_Na, init_K, init_C, init_IP3, init_h, init_CER, init_Na_o, init_K_o, init_C_o)) self.diffusion_range(condition=self.d_cond, start = self.d_start, end = self.d_end, d_coeff=self.d_coeff) # simulate spatial astro self.sol = odeint(self.spatial_astro_NKV_Ca, init, self.tspan, tcrit=[self.tstart, self.tstop]) # transfer solution od ode system into single variables self.Na = self.sol[:,:self.N] self.K = self.sol[:,self.N:2*self.N] self.C = self.sol[:,2*self.N:3*self.N] self.IP3 = self.sol[:,3*self.N:4*self.N] self.h = self.sol[:,4*self.N:5*self.N] self.CER = self.sol[:,5*self.N:6*self.N] self.Na_o = self.sol[:,6*self.N:7*self.N] self.K_o = self.sol[:,7*self.N:8*self.N] self.C_o = self.sol[:,8*self.N:9*self.N] def open_end(self, conc, init_conc): tmp = np.zeros(len(conc)+2) tmp[1:-1] = conc tmp[0] = tmp[-1] = init_conc return tmp def diffusion_range(self, condition = 'equal', start = None, end = None, d_coeff = None): if condition == 'equal': self.D_Ci = self.D_C elif condition == 'step': self.D_Ci = self.D_C * np.ones(self.N) self.D_Ci[start:end] = d_coeff def spatial_astro_NKV(self, state, tspan): # initial values Na = state[:self.N] K = state[self.N:2*self.N] C = state[2*self.N:3*self.N] Nao = state[3*self.N:4*self.N] Ko = state[4*self.N:5*self.N] Co = state[5*self.N:6*self.N] #V = state[6*self.N:7*self.N] # input if tspan < self.time: self.glut_input = self.stimulus[:,int(int(tspan)/self.dt)]#self.input(tspan) elif tspan >= self.time: self.glut_input = self.stimulus[:,-1] # Astrocytic membrane area per tissue volume self.O_m = self.SVR * self.a_i # membrane potential X_oZ_o = -((self.O_m*self.C_m*self.V_0)/(self.a_o)) - self.F*(self.z_K*self.K_o_0 + self.z_Na*self.Na_o_0 + self.z_C*self.C_o_0) V = -((self.a_o)/(self.C_m * self.O_m))*((self.F*(self.z_K * Ko + self.z_Na * Nao + self.z_C * Co)) + X_oZ_o) # transmembrane currents IGluT = self.I_GluT_max * ((K)/(K + self.K_mK_glu)) * ((Nao)**3/(((Nao)**3) + self.K_mN_glu**3)) * (self.glut_input/(self.glut_input + self.K_mg)) INCX = self.I_NCX_max * (Nao)**3/(self.K_mN**3+(Nao)**3) * (Co/(self.K_mC+Co)) * \ (np.exp((self.eta) * V*self.F/(self.R*self.T))*((Na)**3/(Nao)**3) - np.exp((self.eta - 1) * V*self.F/(self.R*self.T))*(C/(Co)))/(1. + self.k_sat*np.exp((self.eta - 1)*V*self.F/(self.R*self.T))) INKA = self.P_max * ((Na**1.5)/(Na**1.5 + self.K_mN_NKA**1.5)) * ((Ko)/(Ko + self.K_mK)) IKleak = ((self.gK) * (V - self.psifac*np.log(Ko/K))) INleak = (((self.gN) * (V - self.psifac*np.log(Nao/Na)))) # transmembrane flux densities J_Ca_m = (-1.*INCX)/(self.F) J_K_m = (IKleak - (2.*INKA) + (1.*IGluT/self.F)) J_Na_m = (INleak + (3.*INKA) - (3.*IGluT/self.F) + (3.*INCX/self.F)) if self.end_condition == 'open_end': C = self.open_end(C, self.C_0) Co = self.open_end(Co, self.C_o_0) K = self.open_end(K, self.K_0) Ko = self.open_end(Ko, self.K_o_0) Na = self.open_end(Na, self.Na_0) Nao = self.open_end(Nao, self.Na_o_0) # diffusive flux J_CiD = self.conn_matrix.dot(-(self.D_C/(self.lamb_intra**2)) * C) J_CoD = self.conn_matrix.dot(-(self.D_C/(self.lamb_extra**2)) * Co) J_KiD = self.conn_matrix.dot(-(self.D_K/(self.lamb_intra**2)) * K) J_NaiD = self.conn_matrix.dot(-(self.D_Na/(self.lamb_intra**2)) * Na) J_KoD = self.conn_matrix.dot(-(self.D_K/(self.lamb_extra**2)) * Ko) J_NaoD = self.conn_matrix.dot(-(self.D_Na/(self.lamb_extra**2)) * Nao) #define differential equations dKdt = -(self.O_m/self.a_i)*(J_K_m) - J_KiD dNadt = -(self.O_m/self.a_i)*(J_Na_m) - J_NaiD dKodt = (self.O_m/self.a_o)*(J_K_m) - J_KoD dNaodt = (self.O_m/self.a_o)*(J_Na_m) - J_NaoD dCdt = -(self.O_m/self.a_i) * J_Ca_m - J_CiD dCodt = (self.O_m/self.a_o) * J_Ca_m - J_CoD return np.hstack((dNadt, dKdt, dCdt, dNaodt, dKodt, dCodt)) def spatial_astro_Ca(self, state, tspan): # initial values C = state[:self.N] IP3 = state[self.N:2*self.N] h = state[2*self.N:3*self.N] CER = state[3*self.N:4*self.N] # Astrocytic membrane area per tissue volume self.O_m = self.SVR * self.a_i # input if tspan < self.time: self.glut_input = self.stimulus[:,int(int(tspan)/self.dt)]#self.input(tspan) elif tspan >= self.time: self.glut_input = self.stimulus[:,-1] # membrane currents at the ER ICERleak = ((self.F)/(self.SVR*np.sqrt(self.ratio))) * self.rl * (CER - C) ISerca = ((self.F)/(self.SVR*np.sqrt(self.ratio))) * self.ver * C ** 2 / (C ** 2 + self.Ker ** 2) m_infty = IP3 / (IP3 + self.d1) n_infty = C / (C + self.d5) IIP3R = ((self.F)/(self.SVR*np.sqrt(self.ratio))) * self.rc * m_infty ** 3 * n_infty ** 3 * h ** 3 \ * (CER - C) # IP3 K_gamma = self.Kr * (1 + self.Kp / self.Kr * C / (C + self.Kpi)) v_glu = self.vb * self.glut_input ** 0.7 / (self.glut_input ** 0.7 + K_gamma ** 0.7) v_3K = self.v3k * C ** 4 / (C ** 4 + self.KD ** 4) * IP3 / (IP3 + self.K3) v_delta = self.vd / (1 + IP3/self.kd) \ * C ** 2 / (C ** 2 + self.Kplcd ** 2) prod_degr_IP3 = v_glu + v_delta - v_3K - self.r5p * IP3 # h Q_2 = self.d2 * (IP3 + self.d1) / (IP3 + self.d3) h_infty = Q_2 / (Q_2 + C) tau_h = 1 / (self.a2 * (Q_2 + C)) dhdt = (h_infty - h) / tau_h # transmembrane flux densities J_CER_m = (- ISerca + ICERleak + IIP3R) if self.end_condition == 'open_end': C = self.open_end(C, self.C_0) CER = self.open_end(CER, self.C_ER_0) IP3 = self.open_end(IP3, self.IP3_0) # diffusive flux J_CiD = self.conn_matrix.dot(-(self.D_C/(self.lamb_intra**2)) * C) J_CERiD = self.conn_matrix.dot(-(self.D_C/(self.lamb_intra**2)) * CER) J_IP3iD = self.conn_matrix.dot(-(self.D_IP3/(self.lamb_intra**2)) * IP3) dCdt = ((self.SVR*np.sqrt(self.ratio))/(self.F)) * J_CER_m - J_CiD dIP3dt = prod_degr_IP3 - J_IP3iD dCERdt = ((self.SVR*np.sqrt(self.ratio))/(self.F*self.ratio)) * (-J_CER_m) - J_CERiD return np.hstack((dCdt, dIP3dt, dhdt, dCERdt)) def spatial_astro_NKV_Ca(self, state, tspan): # initial values Na = state[:self.N] K = state[self.N:2*self.N] C = state[2*self.N:3*self.N] IP3 = state[3*self.N:4*self.N] h = state[4*self.N:5*self.N] CER = state[5*self.N:6*self.N] Nao = state[6*self.N:7*self.N] Ko = state[7*self.N:8*self.N] Co = state[8*self.N:9*self.N] # Astrocytic membrane area per tissue volume self.O_m = self.SVR * self.a_i # membrane potential X_oZ_o = -((self.O_m*self.C_m*self.V_0)/(self.a_o)) - self.F*(self.z_K*self.K_o_0 + self.z_Na*self.Na_o_0 + self.z_C*self.C_o_0) V = -((self.a_o)/(self.C_m * self.O_m))*((self.F*(self.z_K * Ko + self.z_Na * Nao + self.z_C * Co)) + X_oZ_o) # input if tspan < self.time: self.glut_input = self.stimulus[:,int(int(tspan)/self.dt)]#self.input(tspan) elif tspan >= self.time: self.glut_input = self.stimulus[:,-1] # transmembrane currents IGluT = self.I_GluT_max * ((K)/(K + self.K_mK_glu)) * ((Nao)**3/(((Nao)**3) + self.K_mN_glu**3)) * (self.glut_input/(self.glut_input + self.K_mg)) INCX = self.I_NCX_max * (Nao)**3/(self.K_mN**3+(Nao)**3) * (Co/(self.K_mC+Co)) * \ (np.exp((self.eta) * V*self.F/(self.R*self.T))*((Na)**3/(Nao)**3) - np.exp((self.eta - 1) * V*self.F/(self.R*self.T))*(C/(Co)))/(1. + self.k_sat*np.exp((self.eta - 1)*V*self.F/(self.R*self.T))) INKA = self.P_max * ((Na**1.5)/(Na**1.5 + self.K_mN_NKA**1.5)) * ((Ko)/(Ko + self.K_mK)) E_K = self.psifac*np.log(Ko/K) E_Na = self.psifac*np.log(Nao/Na) # membrane currents at the ER ICERleak = ((self.F)/(self.SVR*np.sqrt(self.ratio))) * self.rl * (CER - C) ISerca = ((self.F)/(self.SVR*np.sqrt(self.ratio))) * self.ver * C ** 2 / (C ** 2 + self.Ker ** 2) m_infty = IP3 / (IP3 + self.d1) n_infty = C / (C + self.d5) IIP3R = ((self.F)/(self.SVR*np.sqrt(self.ratio))) * self.rc * m_infty ** 3 * n_infty ** 3 * h ** 3 \ * (CER - C) # IP3 K_gamma = self.Kr * (1 + self.Kp / self.Kr * C / (C + self.Kpi)) v_glu = self.vb * self.glut_input ** 0.7 / (self.glut_input ** 0.7 + K_gamma ** 0.7) v_3K = self.v3k * C ** 4 / (C ** 4 + self.KD ** 4) * IP3 / (IP3 + self.K3) v_delta = self.vd / (1 + IP3/self.kd) \ * C ** 2 / (C ** 2 + self.Kplcd ** 2) prod_degr_IP3 = v_glu + v_delta - v_3K - self.r5p * IP3 # h Q_2 = self.d2 * (IP3 + self.d1) / (IP3 + self.d3) h_infty = Q_2 / (Q_2 + C) tau_h = 1 / (self.a2 * (Q_2 + C)) dhdt = (h_infty - h) / tau_h # transmembrane flux densities J_Na_m = (((self.gN) * (V - E_Na)) + (3.*INKA) - (3.*IGluT/self.F) + (3.*INCX/self.F)) J_K_m = (((self.gK) * (V - E_K)) - (2.*INKA) + (1.*IGluT/self.F)) J_Ca_m = (-1.*INCX)/(self.F) J_CER_m = (- ISerca + ICERleak + IIP3R) if self.end_condition == 'open_end': C = self.open_end(C, self.C_0) Co = self.open_end(Co, self.C_o_0) K = self.open_end(K, self.K_0) Ko = self.open_end(Ko, self.K_o_0) Na = self.open_end(Na, self.Na_0) Nao = self.open_end(Nao, self.Na_o_0) CER = self.open_end(CER, self.C_ER_0) IP3 = self.open_end(IP3, self.IP3_0) # diffusive flux J_CiD = self.conn_matrix.dot(-(self.D_Ci/(self.lamb_intra**2)) * C) J_CoD = self.conn_matrix.dot(-(self.D_C/(self.lamb_extra**2)) * Co) J_KiD = self.conn_matrix.dot(-(self.D_K/(self.lamb_intra**2)) * K) J_NaiD = self.conn_matrix.dot(-(self.D_Na/(self.lamb_intra**2)) * Na) J_KoD = self.conn_matrix.dot(-(self.D_K/(self.lamb_extra**2)) * Ko) J_NaoD = self.conn_matrix.dot(-(self.D_Na/(self.lamb_extra**2)) * Nao) J_CERiD = self.conn_matrix.dot(-(self.D_C/(self.lamb_intra**2)) * CER) J_IP3iD = self.conn_matrix.dot(-(self.D_IP3/(self.lamb_intra**2)) * IP3) #define differential equations dKdt = -(self.O_m/self.a_i)*(J_K_m) - J_KiD dNadt = -(self.O_m/self.a_i)*(J_Na_m) - J_NaiD dKodt = (self.O_m/self.a_o)*(J_K_m) - J_KoD dNaodt = (self.O_m/self.a_o)*(J_Na_m) - J_NaoD dCdt = -(self.O_m/self.a_i) * J_Ca_m + ((self.SVR*np.sqrt(self.ratio))/(self.F)) * J_CER_m - J_CiD dCodt = (self.O_m/self.a_o) * J_Ca_m - J_CoD dIP3dt = prod_degr_IP3 - J_IP3iD dCERdt = ((self.SVR*np.sqrt(self.ratio))/(self.F*self.ratio)) * (-J_CER_m) - J_CERiD return np.hstack((dNadt, dKdt, dCdt, dIP3dt, dhdt, dCERdt, dNaodt, dKodt, dCodt))
import DatabasePreprocessing as dp LAPTOP = True serverL = "MYPC\SQLEXPRESS" dbNameL = "BHBackupRestore" UIDL = "SQLDummy" PWDL = "bushdid9/11" serverP = "HEATHPC\SQLEXPRESS" dbNameP = "newBackupTest" UIDP = "SQLDummy" PWDP = "bushdid9/11" def printTable(name, ti): print("Name: " + name + " PK: " + str(ti[1][name]) + " FKs: " + str(ti[2][name])) ########## main ########## if __name__ == "__main__": start = time() if LAPTOP: Init.init(serverL, "", dbNameL, UIDL, PWDL) else: Init.init(serverP, "", dbNameP, UIDP, PWDP) end = time() print(Init.ti[1]) print(end - start)
##Finish custom payload payload = generateRequest() req = str(payload).replace("'", '"') print(req) inir = InitReq(Config.get("Mqtt1", "user"), Config.get("Mqtt1", "pass"), Config.get("Mqtt1", "address"), int(Config.get("Mqtt1", "port")), payload['name']) resp = inir.register(req) try: my_json = json.loads(resp) reg = resolve(my_json['payload']) except ValueError: print "Value Erro on returning Json" ini = Init(Config.get("Amqp", "user"), Config.get("Amqp", "pass"), Config.get("couchDB", "user"), Config.get("couchDB", "pass")) channel.basic_consume(on_request, queue=Config.get("Admin", "queue")) dev_status = Config.get("Admin", "dev_status") route = Route.Route(channel) karaf = Karaf.Karaf(Config.get("Karaf", "user"), Config.get("Karaf", "pass"), Config.get("Admin", "app_storage"), Config.get("General", "location") + "/apps/", Config.get("General", "location") + "/configs/", Config.get("Karaf", "location") + "/") device = Device.Device(Config.get("couchDB", "user"), Config.get("couchDB", "pass"), Config.items("DeviceQ")) res = Resource.Resource( Config.get("couchDB", "user"), Config.get("couchDB", "pass"), Config.get("General", "Gateway_Name"), Config.items("ResourceQ") ) ##Redo Resource so that they are store in config not admin reg = Region.Region(Config.get("Amqp", "user"), Config.get("Amqp", "pass"),
class Main(object): """ Class Main """ def __init__(self, argv): # init, initialization class self.init = Init(argv) # Get logger from Init class self.log = logging.getLogger('get_UART') # Serial com variable definition self.serial_com = UART(port=self.init.get_serial_port()) # System class self.system = System() # Is UART init a program beginning self.init_UART_bit = self.init.get_init_UART_bit() # Define interface class self.interface = Interface() # Plot curve class self.plot_curve_class = PlotCurve() # Temp data self.temp_data_tab = [] def main(self): """ Main script function """ if self.init_UART_bit: self.serial_com.open_UART() while True: self.interface.log_main_page() # get keyboard input keyboard_input = self.interface.get_input_char if keyboard_input == '0' or keyboard_input == 'connect': self.serial_com.open_UART() elif keyboard_input == '1' or keyboard_input == 'temp': self.get_temp() elif keyboard_input == '2' or keyboard_input == 'time': self.get_time() elif keyboard_input == '3' or keyboard_input == 'set_time': self.set_time() elif keyboard_input == '4' or keyboard_input == 'configure': self.config_sensor() elif keyboard_input == '5' or keyboard_input == 'clean': self.clean_data() elif keyboard_input == '6' or keyboard_input == 'nb_val': self.get_data_number() elif keyboard_input == '9' or keyboard_input == 'plot': self.plot_curve() elif keyboard_input == 'p' or keyboard_input == 'ping': self.serial_com.send_UART_command(DefaultsValues.PING) elif keyboard_input == 'r' or keyboard_input == 'recover': self.recover_overflow() elif keyboard_input == 'i' or keyboard_input == 'info': self.serial_com.send_UART_command(DefaultsValues.GET_REAL_TIME_INFO) elif keyboard_input == 'd' or keyboard_input == 'debug': self.get_debug_values() elif keyboard_input == 'r' or keyboard_input == 'read': self.get_debug_values() elif keyboard_input == 'exit' or keyboard_input == 'q': exit(0) else: self.log.info("\nNo matching founded with {}".format(keyboard_input)) self.interface.interface_selection() def config_sensor(self): """ Config sensor """ sensor_rate = self.interface.configure_sensor_interface() if sensor_rate != 0: self.serial_com.send_UART_command(DefaultsValues.CONFIGURE_SENSOR, sensor_rate) def read_mem_max24aa(self): """ Read mem """ mem_address, nb_data_read = self.interface.read_mem_max24aa_interface() if nb_data_read !=0: self.serial_com.send_UART_command(DefaultsValues.READ_MEM_MAX24AA, [mem_address, nb_data_read]) def ping(self): """ Ping device """ self.serial_com.ping_device() def plot_curve(self): """ Plot curve """ self.plot_curve_class.plot_temp_curve(self.temp_data_tab) def get_temp(self): """ Get temp storage """ # First get number of data into the storage data_number = self.get_data_number() if data_number: self.temp_data_tab = self.serial_com.send_UART_command(DefaultsValues.GET_TEMP) else: self.log.warning("Storage empty... No data to read!") def get_time(self): """ Get time """ self.serial_com.send_UART_command(DefaultsValues.GET_TIME) def set_time(self): """ Set time """ century = time.localtime().tm_year/100 self.serial_com.send_UART_command(DefaultsValues.SET_TIME, [century, (time.localtime().tm_year-century*100), time.localtime().tm_mon, time.localtime().tm_mday, time.localtime().tm_hour, time.localtime().tm_min, time.localtime().tm_sec]) def clean_data(self): """ Clean data """ self.serial_com.send_UART_command(DefaultsValues.CLEAN_DATA) def get_data_number(self): """ Get data number """ return self.serial_com.send_UART_command(DefaultsValues.GET_DATA_NUMBER) def get_debug_values(self): """ Get debug values """ return self.serial_com.send_UART_command(DefaultsValues.GET_DEBUG_VALUES) def export_data_current_file(self): """ Export data current file """ self.log.info("export_data_current_file") def export_data_new_file(self): """ Export data new file """ self.log.info("export_data_new_file") def recover_overflow(self): """ Send command to PIC to put in a good state after UART overflow """ self.serial_com.write(DefaultsValues.START_OF_TEXT) if self.serial_com.ping_device(): self.log.info("Device have been recover successfully") else: self.log.error("Device is still stuck since overflow....") def __del__(self): if hasattr(self, 'serial_com'): if not self.serial_com.is_open(): self.log.info("Com port is not open") else: self.serial_com.close_com_port() self.log.info("Serial port com have been closed")