def menu(): import curses from shift import shift screen = curses.initscr() screen.keypad(1) height, width = 25, 80 selection = -1 opt_string = [' Option : {} '.format(i) for i in range(5)] options = [0] * 5 options[0] = curses.A_REVERSE while True: screen.clear() screen.refresh() for i in range(len(opt_string)): screen.addstr(height / 2 - len(opt_string) + i, width / 2 - len(opt_string), opt_string[i], options[i]) " print option, options, selection " screen.addstr(23, 10, 'Option: {}'.format(options.index(curses.A_REVERSE))) screen.addstr(23, 25, 'Options: {}'.format(options)) screen.addstr(23, 60, 'Selection: {}'.format(selection)) ''' key input processing ''' action = screen.getch() if action == ord('k') or action == curses.KEY_UP: shift(options, -1) elif action == ord('j') or action == curses.KEY_DOWN: shift(options, 1) elif action == ord('\n') or action == ord(' '): curses.flash() selection = options.index(curses.A_REVERSE)
def menu(): import curses from shift import shift screen = curses.initscr() screen.keypad(1) height,width = 25,80 selection = -1 opt_string = [' Option : {} '.format(i) for i in range(5) ] options = [0] * 5 options[0] = curses.A_REVERSE while True: screen.clear() screen.refresh() for i in range(len(opt_string)): screen.addstr(height/2-len(opt_string)+i,width/2-len(opt_string), opt_string[i],options[i]) " print option, options, selection " screen.addstr(23,10, 'Option: {}'.format(options.index(curses.A_REVERSE)) ) screen.addstr(23,25, 'Options: {}'.format(options) ) screen.addstr(23,60, 'Selection: {}'.format(selection) ) ''' key input processing ''' action = screen.getch() if action == ord('k') or action == curses.KEY_UP: shift(options,-1) elif action == ord('j') or action == curses.KEY_DOWN: shift(options,1) elif action == ord('\n') or action == ord(' '): curses.flash() selection = options.index(curses.A_REVERSE)
def edit(path="/"): """Edit the given subtitle, or create a new one""" path = normalize_path(path) realpath = os.path.abspath(root_dir + path) data = {} title = ".".join(path.split("/")[-1].split(".")[:-2]) data["title"] = title data["path"] = path data["root"] = "/".join(path.split("/")[:-1]) data["breadCrumbs"] = listBreadCrumbs(path) if "shift" in request.values: # Shift subtitle try: s = float(request.values["shift"]) shift.shift(realpath, s) data["message"] = "File shifted by {}s.".format(s) except ValueError: pass elif "upload" in request.files: # Upload custom subtitle f = request.files["upload"] name = os.path.splitext(path.split("/")[-1])[0] data["message"] = 'The file "' + name + '.srt" has been uploaded' ext = os.path.splitext(f.filename)[1] target = os.path.splitext(realpath)[0] + ".srt" if ext == ".sub": # Convert .sub to .srt t = tempfile.NamedTemporaryFile() f.save(t.name) sub2srt.convert(t.name, target) data["message"] += " and converted to SRT format" else: f.save(target) os.chmod(target, 0o666) normalize_encoding(target) elif "auto" in request.values: # Download subtitle from OpenSubtitle try: folderPath = "/".join((root_dir + normalize_path(path)).split("/")[:-1]) opensubs.get_sub(root_dir + normalize_path(path)) except: logging.warning(traceback.format_exc()) data["message"] = "Could not download subtitles" # Subtitle content try: data["filecontent"] = open(realpath).read().replace("\n", "<br/>") data["sub_title"] = "Subtitle content" except: data["sub_title"] = "No subtitle" return flask.render_template("edit.html", **data)
def keygen2(p): h1 = [] h2 = [] for i in range(5): h1.append(p[0]) del (p[0]) h2 = p h1 = sft.shift(h1, 2) h2 = sft.shift(h2, 2) p = h1 + h2 ke2 = p p = pb.pboxsh(p) return p, ke2
def keygen(p): h1 = [] h2 = [] p = pb.pbox(p) for i in range(5): h1.append(p[0]) del (p[0]) h2 = p h1 = sft.shift(h1, 1) h2 = sft.shift(h2, 1) p = h1 + h2 ke1 = p p = pb.pboxsh(p) return p, ke1
def dec(p): p = pb.ip(p) p = fun(p, 1) for i in range(0, len(p)): p[i] = str(p[i]) #print(data) l = p p = (fun(l, 2)) #print(data) sf.shift(p, 4) #print(data) p = pb.ipinv(p) s = "" for i in range(0, len(p)): s = s + str(p[i]) return s
def test_to_many_shifts(): """ :return: """ with pytest.raises(ValueError): assert shift.shift([1, 2, 3], 5)
def shift_iter( source, initial = 0, start = 0, tab_length = tab_length, depth = None, ): """ yields a sequence of all the lines from a given |source| that are one |tab_length| beneath their the |initial| column plus |start|, removing exactly enough white space to shift each line |tab_length| spaces left. """ try: while True: # peek at the next line in the source iteration # if the source iteration has reached its end, this will raise # a StopIteration # attempt to shift that line one tab width left line = shift(source.peek(), initial, start, tab_length, depth) # if there is not enough white space on the line to shift off if line == None: raise StopIteration else: # since we already peeked at the source line, discard it source.next() yield line except StopIteration: pass
def enc(data): data = pb.ip(data) data = fun(data, 1) for i in range(0, len(data)): data[i] = str(data[i]) #print(data) l = data data = (fun(l, 2)) #print(data) sf.shift(data, 4) #print(data) data = pb.ipinv(data) #print(data) s = "" for i in range(0, len(data)): s = s + str(data[i]) return s
def menu(): from shift import shift screen = curses.initscr() screen.keypad(1) dims = screen.getmaxyx() height,width = dims[0]-1, dims[1]-1 curses.start_color() curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK) selection = -1 opt_string = [' Option : {} '.format(i) for i in range(5) ] options = [0] * 5 options[0] = curses.A_REVERSE while True: #selection < 0: screen.clear() screen.refresh() for i in range(len(opt_string)): screen.addstr(height/2-len(opt_string)+i,width/2-len(opt_string), opt_string[i],options[i]) screen.addstr(23,10,'Option : ') screen.addstr(23,10+10, str(options.index(curses.A_REVERSE)),curses.color_pair(1)|curses.A_BOLD) screen.addstr(23,25,'options : ') screen.addstr(23,25+10, str(options), curses.color_pair(2)|curses.A_BOLD) screen.addstr(23,60,'selection : ') screen.addstr(23,60+12, str(selection), curses.color_pair(2)|curses.A_BOLD) action = screen.getch() ''' key input processing ''' if action == ord('k') or action == curses.KEY_UP: shift(options,-1) elif action == ord('j') or action == curses.KEY_DOWN: shift(options,1) elif action == ord('\n') or action == ord(' '): selection = options.index(curses.A_REVERSE) ''' selection processing made by SPACE or ENTER ''' if selection == 0: pass elif selection == 1: pass elif selection == 4: screen.clear() screen.refresh() return
def menu(self): screen = curses.initscr() screen.keypad(1) opt_string = ['Play', 'Instructions', 'Options', 'High Scores', 'Exit'] opt_string = [s.center(15) for s in opt_string] options = [0] * 5 options[0] = curses.A_REVERSE while True: selection = -1 screen.clear() screen.refresh() for i in range(len(opt_string)): screen.addstr(self.height/2-len(opt_string)+i,self.width/2-len(opt_string), opt_string[i],options[i]) " print option, options, selection " screen.addstr(23,10, 'Option: {}'.format(options.index(curses.A_REVERSE)) ) screen.addstr(23,25, 'Options: {}'.format(options) ) screen.addstr(23,60, 'Selection: {}'.format(selection) ) ''' keybord input processing ''' action = screen.getch() if action == ord('k') or action == curses.KEY_UP: shift(options,-1) elif action == ord('j') or action == curses.KEY_DOWN: shift(options,+1) elif action == ord('\n') or action == ord(' '): curses.flash() selection = options.index(curses.A_REVERSE) ''' selection ''' if selection == 0: self.continues = True return elif selection == 1: self.instructions() elif selection == 2: self.gameoptions() elif selection == 4: self.continues = False return
def shift_alu_front(func, shamt, op1, op2, out_1, out_2): shift_in, shift_out = [Signal(intbv(0, min=MIN, max=MAX)) for x in range(2)] shift_in = Signal(intbv(0, min=MIN, max=MAX)) shift_ctl = Signal(shift_op._NOP) shift_amount = Signal(intbv(0)[5:]) shift_ = shift(shift_in, shift_amount, shift_ctl, shift_out) @always_comb def logic(): if func == 0: shift_in.next = op2 shift_ctl.next = shift_op.LL shift_amount.next = shamt out_2.next = op1 out_1.next = shift_out else: out_1.next = op1 out_2.next = op2 return instances()
def createShifts(self, date): # Row containing column headers headersRow = next(self.reader) # Column indices in csvfile LAST_NAME_COLUMN = headersRow.index("Employee Last Name") FIRST_NAME_COLUMN = headersRow.index("Employee First Name") POSITION_COLUMN = headersRow.index("Position Name") CATEGORY_COLUMN = headersRow.index("Category") START_TIME_COLUMN = headersRow.index("Start Time") END_TIME_COLUMN = headersRow.index("End Time") DATE_COLUMN = headersRow.index("Date") DESCRIPTION_COLUMN = headersRow.index("Shift Description") # Shifts list shifts = [] # Build shifts list for row in self.reader: # Filter by DATE_COLUMN #if row[DATE_COLUMN] == date: if time.strptime(row[DATE_COLUMN], "%m/%d/%Y") == \ time.strptime(date, "%m/%d/%Y"): # Filter by CATEGORY_COLUMNs that are route shift categories if row[POSITION_COLUMN] != "Operations Supervisor" and \ row[POSITION_COLUMN] != "Mega Bus Connect" and \ row[POSITION_COLUMN] != "Maintenance": # Append new shift object to shifts list with fields from # current row shifts.append(shift.shift(row[POSITION_COLUMN], row[CATEGORY_COLUMN], row[LAST_NAME_COLUMN], row[FIRST_NAME_COLUMN], row[START_TIME_COLUMN], row[END_TIME_COLUMN], row[DATE_COLUMN], row[DESCRIPTION_COLUMN])) return shifts
def test_two(): assert shift.shift([1, 2, 3, 4, 5], 2) == [3, 4, 5, 1, 2]
def gameoptions(self): screen.clear() options = [0] * 5 options[0] = curses.A_REVERSE startlengths = range(3,21) growlengths = range(1,11) selection = -1 _start = startlengths.index(self.startlength) _grow = growlengths.index(self.growlength) while True: self.startlength = startlengths[_start] # startlength = 8 self.growlength = growlengths[_grow] # grow = 3 self.difficulty = self.difficulties[0] # difficulty = 'Easy' strings = ['Starting snake length: ' + str(self.startlength), 'Snake Growth rate: ' + str(self.growlength), 'Difficulty: ' + self.difficulty, 'Acceleration: ' + str(self.acceleration),'Exit'] screen.refresh() for z in range(len(strings)): screen.addstr( (self.height - len(strings))/2 + z, (self.width -len(strings[z]))/2,strings[z], options[z]) action = screen.getch() screen.clear() # screen.refresh() if action == ord('k') or action == curses.KEY_UP: shift(options,-1) elif action == ord('j') or action == curses.KEY_DOWN: shift(options,+1) elif action == ord('l') or action == curses.KEY_RIGHT: if options.index(curses.A_REVERSE) == 0: shift(startlengths, -1) elif options.index(curses.A_REVERSE)== 1: shift(growlengths, -1) elif action == ord('h') or action == curses.KEY_LEFT: if options.index(curses.A_REVERSE) == 0: shift(startlengths, +1) elif options.index(curses.A_REVERSE)== 1: shift(growlengths, +1) elif action == ord('\n') or action == ord(' '): curses.flash() selection = options.index(curses.A_REVERSE) if selection == 2: shift(self.difficulties,-1) elif selection == 3: self.acceleration = not self.acceleration elif selection == 4 : return
def test_one(): assert shift.shift([1, 2, 3], 1) == [2, 3, 1]
def test_empty(): assert shift.shift([], 0) == []
def test_shifter(clock,leds): clkdrv = ClkDriver(clock, period=10) tbdut = shift(clock, leds, num_led=num_led, cnt_max=5) return tbdut, clkdrv
def shifter(clock,leds): tbdut = shift(clock, leds, num_led) return tbdut
def test_one(): """ :return: """ assert shift.shift([1, 2, 3], 1) == [2, 3, 1]
def gameoptions(): from shift import shift # global startlength,growlength,difficulty,acceleration screen = curses.initscr() dims = screen.getmaxyx() height, width = 26, 80 speeds = {'Easy': 0.1, 'Medium': 0.06, 'Hard': 0.04} difficulties = ['Easy', 'Medium', 'Hard'] acceleration = True options = [0] * 5 options[0] = curses.A_REVERSE startlengths = range(3, 21) growlengths = range(1, 11) startlength, growlength = 8, 3 _start = startlengths.index(startlength) _grow = growlengths.index(growlength) screen.clear() while True: startlength = startlengths[_start] # startlength = 8 growlength = growlengths[_grow] # grow = 3 difficulty = difficulties[0] # difficulty = 'Easy' strings = [ 'Starting snake length: ' + str(startlength), 'Snake Growth rate: ' + str(growlength), 'Difficulty: ' + difficulty, 'Acceleration: ' + str(acceleration), 'Exit' ] screen.refresh() for z in range(len(strings)): screen.addstr((height - len(strings)) / 2 + z, (width - len(strings[z])) / 2, strings[z], options[z]) action = screen.getch() screen.clear() # screen.refresh() if action == ord('k') or action == curses.KEY_UP: shift(options, -1) elif action == ord('j') or action == curses.KEY_DOWN: shift(options, +1) elif action == ord('l') or action == curses.KEY_RIGHT: if options.index(curses.A_REVERSE) == 0: shift(startlengths, -1) elif options.index(curses.A_REVERSE) == 1: shift(growlengths, -1) elif action == ord('h') or action == curses.KEY_LEFT: if options.index(curses.A_REVERSE) == 0: shift(startlengths, +1) elif options.index(curses.A_REVERSE) == 1: shift(growlengths, +1) elif action == ord('\n') or action == ord(' '): curses.flash() selection = options.index(curses.A_REVERSE) if selection == 2: shift(difficulties, -1) elif selection == 3: acceleration = not acceleration elif selection == 4: return
# We read a cube of frequency #hdulist = pf.open(dirwr + 'Freq_DM_map_cube.fits') hdulist = pf.open(dirwr + 'Freq_start.fits') Cube_freq = hdulist[0].data hdulist.close() # Read the Commande Matrix hdulist = pf.open(dirwr + 'Mat_com.fits') Mat_com = hdulist[0].data hdulist.close() # Read image hdulist = pf.open(dirwr + 'Filtre_Image.fits') Filtre_Image = hdulist[0].data hdulist.close() Filtre_Image = shift(Filtre_Image, -128, -128) Filtre_Image = Filtre_Image[0:256, 0:256] # Read Filtre Fourier hdulist = pf.open(dirwr + 'Filtre_Fourier.fits') Filtre_Fourier = hdulist[0].data hdulist.close() # fichier de parametres pour PK3 et Pharo hardwareconfigfile = 'speckle_instruments_scc.ini' # initialisation de Pharo # Real thing pharo = hardware.PHARO_COM('PHARO', configfile=hardwareconfigfile) # LOAD P3K HERE
nt = math.floor(tmax / dt) + 1 t = np.arange(0, nt) * dt f = 1.0 wavelet = ricker(f, dt) d = np.zeros(nt) d[round(nt / 2)] = 1.0 d = np.convolve(d, wavelet, 'same') #observed data misfit = np.zeros(21) for id in range(-10, 11): #td = 0.1 #time delay (if td > 0, syn arrive after obs) td = id * 0.1 print(td) s = shift(d, dt, td) #synthetic data #st = read('trival_data.sac',debug_headers=True) #d = st[0].data #st = read('trival_syn.sac',debug_headers=True) #s = st[0].data #dt = st[0].stats.delta #nt = st[0].stats.npts #t = np.arange(0,nt)*dt #plt.plot(t,d,'b') #plt.plot(t,s,'r') #plt.xlabel('Time (s)') #plt.ylabel('Amplitude') #plt.title('Observed (blue) and synthetic data (red)') #plt.show()
def gameoptions(): from shift import shift # global startlength,growlength,difficulty,acceleration screen = curses.initscr() dims = screen.getmaxyx() height,width = 26,80 speeds = {'Easy':0.1, 'Medium':0.06, 'Hard':0.04 } difficulties = ['Easy','Medium','Hard'] acceleration = True options = [0] * 5 options[0] = curses.A_REVERSE startlengths = range(3,21) growlengths = range(1,11) startlength, growlength = 8,3 _start = startlengths.index(startlength) _grow = growlengths.index(growlength) screen.clear() while True: startlength = startlengths[_start] # startlength = 8 growlength = growlengths[_grow] # grow = 3 difficulty = difficulties[0] # difficulty = 'Easy' strings = ['Starting snake length: ' + str(startlength), 'Snake Growth rate: ' + str(growlength), 'Difficulty: ' + difficulty, 'Acceleration: ' + str(acceleration),'Exit'] screen.refresh() for z in range(len(strings)): screen.addstr( (height - len(strings))/2 + z, (width -len(strings[z]))/2,strings[z], options[z]) action = screen.getch() screen.clear() # screen.refresh() if action == ord('k') or action == curses.KEY_UP: shift(options,-1) elif action == ord('j') or action == curses.KEY_DOWN: shift(options,+1) elif action == ord('l') or action == curses.KEY_RIGHT: if options.index(curses.A_REVERSE) == 0: shift(startlengths, -1) elif options.index(curses.A_REVERSE)== 1: shift(growlengths, -1) elif action == ord('h') or action == curses.KEY_LEFT: if options.index(curses.A_REVERSE) == 0: shift(startlengths, +1) elif options.index(curses.A_REVERSE)== 1: shift(growlengths, +1) elif action == ord('\n') or action == ord(' '): curses.flash() selection = options.index(curses.A_REVERSE) if selection == 2: shift(difficulties,-1) elif selection == 3: acceleration = not acceleration elif selection == 4 : return
def test_two(): """ :return: """ assert shift.shift([1, 2, 3, 4, 5], 2) == [3, 4, 5, 1, 2]
def comb_alu_front(aluop, func, shamt, op1, op2, out_1, out_2): shift_in, shift_out = [Signal(intbv(0, min=MIN, max=MAX)) for x in range(2)] shift_ctl = Signal(shift_op.NNOP) shift_amount = Signal(intbv(0)[5:]) shift_ = shift(shift_in, shift_amount, shift_ctl, shift_out) @always_comb def logic(): if aluop == alu_op_code.MRFORMAT: if func == 0: shift_in.next = op2 shift_ctl.next = shift_op.LL shift_amount.next = shamt out_2.next = 0 out_1.next = shift_out elif func == 4: shift_in.next = op2 shift_ctl.next = shift_op.LL shift_amount.next = op1[5:] out_2.next = 0 out_1.next = shift_out elif func == 2: shift_in.next = op2 shift_ctl.next = shift_op.RL shift_amount.next = shamt out_2.next = 0 out_1.next = shift_out elif func == 3: shift_in.next = op2 shift_ctl.next = shift_op.RA shift_amount.next = shamt out_2.next = 0 out_1.next = shift_out elif func == 7: shift_in.next = op2 shift_ctl.next = shift_op.RA shift_amount.next = op1[5:] out_2.next = 0 out_1.next = shift_out elif func == 13: # break raise Exception("program break") else: out_1.next = op1 out_2.next = op2 elif aluop == alu_op_code.MORI: # ORI out_1.next = op1 out_2.next = concat(intbv(0)[16:], op2[16:]) elif aluop == alu_op_code.MANDI: # ANDI #print "ALU_FRONT: %s, %s" % (bin(op1, 32), bin(op2, 32)) out_1.next = op1 out_2.next = concat(intbv(0)[16:], op2[16:]) elif aluop == alu_op_code.MLUI: # LUI out_1.next = 0 out_2.next = concat(op2[16:], intbv(0)[16:]).signed() elif aluop == alu_op_code.MBGEZ: out_1.next = op1 out_2.next = 0 elif aluop == alu_op_code.MBGEZAL: out_1.next = op1 out_2.next = 0 elif aluop == alu_op_code.MBLTZ: out_1.next = op1 out_2.next = 0 elif aluop == alu_op_code.MBLTZAL: out_1.next = op1 out_2.next = 0 elif aluop == alu_op_code.MBGTZ: out_1.next = op1 out_2.next = 0 elif aluop == alu_op_code.MBLEZ: out_1.next = op1 out_2.next = 0 else: out_1.next = op1 out_2.next = op2 return instances()
def test_empty(): """ :return: """ assert shift.shift([], 0) == []
ampl = 1. # amplitude nb_im = 1. #(attention si > à 1 il faut faire une medianne du cube) ray = 22 # en pixel Alpha = 5. # en degré Xi = 66. # en pixel Alpha = Alpha/180.*np.pi nb_ite = 5 # number of iteration dirwr = '/data1/home/aousr/Desktop/speckle_nulling/SCC/' # Read image hdulist = pf.open( dirwr + 'Filtre_Image.fits') Filtre_Image = hdulist[0].data hdulist.close() Filtre_Image = shift(Filtre_Image,-128,-128) Filtre_Image = Filtre_Image[0:256,0:256] # Read Filtre Fourier hdulist = pf.open( dirwr + 'Filtre_Fourier.fits') Filtre_Fourier = hdulist[0].data hdulist.close() # fichier de parametres pour PK3 et Pharo hardwareconfigfile = 'speckle_instruments_scc.ini' # initialisation de Pharo # Real thing pharo = hardware.PHARO_COM('PHARO', configfile = hardwareconfigfile) # LOAD P3K HERE