def Unpack(self, data, out_file, debug=False): file = open(out_file, 'wb') if file: pos = 0 count = Struct.uint32(data[pos:pos+4], endian='>') pos += 4 if debug == True: print("Count: %08x" % count) print("\n%08x\n" % pos) offset_list = [] for x in range(count): offset = Struct.uint32(data[pos:pos+4], endian='>') pos += 4 if debug == True: print("Offset: %08x" % offset) offset_list.append(offset) if debug == True: print("\n%08x\n" % pos) for x in range(count): pos = offset_list[x] string = nullterm(data[pos:]) string = str(string, 'utf_16_be') if debug == True: print("String: %s" % string.encode('utf-8')) pos += len(string) file.write(string.encode('utf-8')) file.write('\n') file.close() else: print("Could not open file for writing") sys.exit(1)
def load_go_ont(fname, filter_namespace='cellular_component'): dterms = {} term = None for r in file(fname,'r'): if r.strip()=='[Term]': if hasattr(term,'set_is_a'): if not filter_namespace or filter_namespace==term.namespace: dterms[term.acc] = (term.name, term.set_is_a) term = Struct() elif r.strip() and term: att = r.split(': ')[0] val = ': '.join(r.split(': ')[1:]).strip() if att=='id': term.acc = val elif att=='name': term.name = val elif att=='namespace': term.namespace = val elif att=='is_a': val = val.split(' ! ')[0] if hasattr(term,'set_is_a'): term.set_is_a.add(val) else: term.set_is_a = set([val]) return dterms
def setUp(self): self.vm = Vm(name='some_vm') self.vm.config.guestId = 'winNetStandardGuest' self.vm.config.hardware = Struct( memoryMB='256', numCPU=2, ) self.vm.config.version = 'vmx-04' self.vm.config.name = 'some_vm' self.vm.config.locationId = 'locationId' self.vm.config.uuid = 'uuid' self.vm.config.annotation = 'annotation' self.vm.config.files = Struct( snapshotDirectory='snapshotDir', suspendDirectory='suspendDir', ) self.vm.config.flags = Struct( disableAcceleration=False, runWithDebugInfo=False, enableLogging=False, useToe=False, ) self.vm.config.tools = Struct( afterPowerOn=False, afterResume=False, beforeGuestShutdown=False, beforeGuestStandby=False, ) self.vm.config.defaultPowerOps = Struct( powerOffType='?', suspendType='?', resetType='?', ) self.host = Host('Fake host', [self.vm])
def __init__(self, xmlfile, struct_name, node_name): logger=logging.getLogger('StructXml.__init__') # Build the field list from the xml file if os.path.isfile(xmlfile): if 0: logger.debug("xml file : %s" % xmlfile) logger.debug("struct name : %s" % struct_name) logger.debug("node name : %s" % node_name) # Retrieve the lists of fields field_l = [] try: tree = parse(xmlfile) section = tree.find(node_name) except: logger.error("Failed parsing XML file : %s" % xmlfile) sys.exit(CfgError.ERRCODE_SYS_FILE_IO) if section is None: logger.warning("XML node '%s' not found" % node_name) else: for node in section.iter('field'): field = (node.attrib.get('name'), str(node.text)) field_l.append(field) if 0: logger.debug("field=%s, value=%s" % (node.attrib.get('name'), node.text)) else: logger.error("File not found: %s" % xmlfile) sys.exit(CfgError.ERRCODE_SYS_FILE_IO) # Initialize the structure Struct.__init__(self, field_l=field_l, struct_name=struct_name)
def setUp(self): """ The fixture consists of a Host (stub) and a few instances ov Vm (Stub). """ self.vmNoQuestion = Vm(name='noQuestion', runtime=Struct(question=None)) self.vmQuestion = Vm(name='Question', runtime=Struct( question=Struct( id='someQuestionId', text="What's up, doc?", choice=Struct( choiceInfo=[ Struct(key='0', label='The sky'), ], defaultIndex=0, ) ) ) ) self.host = Host('Fake host', [self.vmNoQuestion, self.vmQuestion]) ## Replace `raw_input` with a version that we can automate. self.rawInputStub = RawInputStub()
def Unpack(self, data, out_file, debug=False): file = open(out_file, 'wb') if file: pos = 0 count = Struct.uint32(data[pos:pos+4], endian='>') pos += 4 if debug == True: print "Count: %08x" % count print "\n%08x\n" % pos offset_list = [] for x in xrange(count): offset = Struct.uint32(data[pos:pos+4], endian='>') pos += 4 if debug == True: print "Offset: %08x" % offset offset_list.append(offset) if debug == True: print "\n%08x\n" % pos for x in xrange(count): pos = offset_list[x] string = nullterm(data[pos:]) string = unicode(string, 'utf_16_be') if debug == True: print "String: %s" % string.encode('utf-8') pos += len(string) file.write(string.encode('utf-8')) file.write('\n') file.close() else: print "Could not open file for writing" sys.exit(1)
def load_elution(fname, getname=True): # expected file structure: # first col: gene id # second col: treat differently if 2nd col header is 'Total' or # 'Description' # remaining cols: elution profile data lines = [l for l in ut.load_tab_file(fname)] # final row: total count in msblender output; don't skip in cuihong's data skip_final_row = lines[-1][0][0] == "#" rows = lines[1:-1] if skip_final_row else lines[1:] fractions = [f for f in lines[0][1:]] if fractions[0].lower() in ["total", "totalcount", "description"]: start_data_col = 2 fractions.remove(fractions[0]) else: start_data_col = 1 mat = np.matrix([row[start_data_col:] for row in rows], dtype="float32") prots = [row[0] for row in rows] elut = Struct(mat=mat, prots=prots, fractions=fractions, filename=fname, filename_original=fname) if start_data_col == 2: col2name_vals = [row[1] for row in rows] elut.column2vals = col2name_vals if getname: elut.name = os.path.basename(fname).split(".")[0] return elut
def cvtest(name, base_sp, nsp, fs, base_featstruct, kfold=2, clf_type='svm', nfeats=100, norm=True, ppi_output=None, train_limit=None, save_data=True, balance_train=False, keep_cols=None, clf_factory=None, clffact_feats=None, **kwargs): """ """ assert kfold>1, "CV K-fold 1 not possible" exs = ppi.feature_array(base_sp, fs, base_featstruct, nsp, **kwargs) if ppi_output is None else ppi_output arrfeats, ntest_pos = fe.arr_copy(exs.arrfeats), exs.ntest_pos assert len(arrfeats)>0, '0 examples not supported' if train_limit: print 'Sampling %s train/cv examples' % train_limit train_limit = train_limit or len(arrfeats) arrfeats = arrfeats if keep_cols is None else fe.keep_cols(arrfeats, keep_cols) arrfeats = fe.keep_rows(arrfeats, random.sample(range(len(arrfeats)), int(train_limit))) # shuffle even if not sampling. don't random.shuffle ntest_pos = int(ntest_pos * train_limit / len(arrfeats)) if clf_type in clf_factories and clf_factory is None: clf_factory, clffact_feats = clf_factories[clf_type] ppis = [] for k in range(kfold): print 'Fold %s:' % k ppis_fold,clf,scaler,feats = fold_test(arrfeats, kfold, k, clf_factory, clffact_feats, nfeats, norm, balance_train) ppis += ppis_fold random.shuffle(ppis) ppis.sort(key=lambda x: x[2], reverse=True) result = Struct(traincv=arrfeats[['id1','id2','hit']], clf=clf, scaler=scaler, ppis=ppis, ntest_pos=ntest_pos, name=name, species=base_sp, ppi_params=str(clf), feats=feats, source_feats=exs.arrfeats.dtype.names, balance_train=balance_train) if save_data: result.exs = exs return result
def Atom(self, name, fourcc, data): #print '\t' + fourcc count = Struct.uint16(data[0x10:0x12], endian='>') # file('rlat/%s.%s' % (name, fourcc), 'wb').write(data[:0x18]) triplets = [] # Calculate offset to triplets (added by dasda). off = Struct.uint16(data[4:6], endian='<') * 8 + 16; for i in xrange(count): af = Struct.float(data[off:off+4], endian='>') bf = Struct.float(data[off+4:off+8], endian='>') cf = Struct.float(data[off+8:off+0xC], endian='>') triplets.append((af, bf, cf)) off += 0xC if fourcc == 'RLPA': self.brlyt.Objects[name].RLPA(triplets, self.Loop) elif fourcc == 'RLVC': self.brlyt.Objects[name].RLVC(triplets, self.Loop) elif fourcc == 'RLTS': self.brlyt.Objects[name].RLTS(triplets, self.Loop) elif fourcc == 'RLMC': self.brlyt.Objects[name].RLMC(triplets, self.Loop) else: for trip in triplets: print '\t\tTriplet: %f %f %f' % trip
def load_elution(fname, getname=True): # expected file structure: # first col: gene id # second col: treat differently if 2nd col header is 'Total' or # 'Description' # remaining cols: elution profile data lines = [l for l in ut.load_tab_file(fname)] # final row: total count in msblender output; don't skip in cuihong's data skip_final_row = (lines[-1][0][0] == '#') rows = lines[1:-1] if skip_final_row else lines[1:] fractions = [f for f in lines[0][1:]] if fractions[0].lower() in ['total', 'totalcount', 'description']: start_data_col = 2 fractions.remove(fractions[0]) else: start_data_col = 1 mat = np.matrix([row[start_data_col:] for row in rows],dtype='float32') prots = [row[0] for row in rows] elut = Struct(mat=mat, prots=prots, fractions=fractions, filename=fname, filename_original=fname) if start_data_col == 2: col2name_vals = [row[1] for row in rows] elut.column2vals = col2name_vals if getname: elut.name = os.path.basename(fname).split('.')[0] return elut
def Atom(self, name, fourcc, data): print '\t' + fourcc count = Struct.uint16(data[0x10:0x12], endian='>') # file('rlat/%s.%s' % (name, fourcc), 'wb').write(data[:0x18]) triplets = [] # Calculate offset to triplets (added by dasda). off = Struct.uint16(data[4:6], endian='<') * 8 + 16 for i in xrange(count): af = Struct.float(data[off:off + 4], endian='>') bf = Struct.float(data[off + 4:off + 8], endian='>') cf = Struct.float(data[off + 8:off + 0xC], endian='>') triplets.append((af, bf, cf)) off += 0xC if fourcc == 'RLPA': self.brlyt.Objects[name].RLPA(triplets, self.Loop) elif fourcc == 'RLVC': self.brlyt.Objects[name].RLVC(triplets, self.Loop) elif fourcc == 'RLTS': self.brlyt.Objects[name].RLTS(triplets, self.Loop) elif fourcc == 'RLMC': self.brlyt.Objects[name].RLMC(triplets, self.Loop) else: for trip in triplets: print '\t\tTriplet: %f %f %f' % trip
def PAI1(self, data): pos = 8 header = self.PAI1Header() header.unpack(data[pos:pos+len(header)]) pos = header.Off for i in xrange(header.Count): off = nameOff = Struct.uint32(data[pos:pos+4], endian='>') pos += 4 name = data[off:].split('\0', 1)[0] off += 0x14 numAtoms = ord(data[off]) off += 4 #print name for i in xrange(numAtoms): sub = Struct.uint32(data[off:off+4], endian='>') off += 4 fourcc = data[nameOff+sub:nameOff+sub+4] #if fourcc == 'RLTS': # print 'RLTS unknown' #else: self.Atom(name, fourcc, data[nameOff+sub:])
def PAI1(self, data): pos = 8 header = self.PAI1Header() header.unpack(data[pos:pos + len(header)]) pos = header.Off for i in xrange(header.Count): off = nameOff = Struct.uint32(data[pos:pos + 4], endian='>') pos += 4 name = data[off:].split('\0', 1)[0] off += 0x14 numAtoms = ord(data[off]) off += 4 print name for i in xrange(numAtoms): sub = Struct.uint32(data[off:off + 4], endian='>') off += 4 fourcc = data[nameOff + sub:nameOff + sub + 4] #if fourcc == 'RLTS': # print 'RLTS unknown' #else: self.Atom(name, fourcc, data[nameOff + sub:])
def setUp(self): self.guest_net = [ Struct(connected=True, deviceConfigId=4001, ipAddress='169.254.145.89', macAddress='00:0c:29:d9:60:4c', network='vctportgroup'), Struct(connected=True, deviceConfigId=4000, ipAddress='10.20.153.42', macAddress='00:0c:29:d9:60:42', network='VMPublic'), ] self.expected2Nics = map(Nic, self.guest_net) self.expected1Nic = map(Nic, self.guest_net[1:]) self.vmWith2Nics = Vm(name='vmWith2Nics') self.vmWith2Nics.guest.net = self.guest_net self.vmWith1Nic = Vm(name='vmWith1Nic') self.vmWith1Nic.guest.net = self.guest_net[1:] self.vmWith0Nics = Vm(name='vmWith0Nics') self.vmWith0Nics.guest.net = [] self.vmWithNoGuestInfo = Vm(name='vmWithNoGuestInfo') self.vmWithNoGuestInfo.guest.net = None self.host = Host('Fake host', [ self.vmWith2Nics, self.vmWith1Nic, self.vmWith0Nics, self.vmWithNoGuestInfo ])
def __format__(self): self.Zeroes = Struct.uint8[0x40] self.IMET = Struct.string(4) self.Fixed = Struct.uint8[8] self.Sizes = Struct.uint32[3] self.Flag1 = Struct.uint32 self.Names = Struct.string(0x2A<<1, encoding='utf-16-be', stripNulls=True)[7] self.Zeroes = Struct.uint8[0x348] self.Crypto = Struct.uint8[0x10]
def downsample_elution(elution, downsample, seed=0): """ Return a new elution with every downsample-th fraction. """ down_elut = Struct() down_elut.__dict__ = elution.__dict__.copy() down_elut.mat = elution.mat[:, seed::2] down_elut.fractions = elution.fractions[::2] down_elut.name = elution.name + "_down%i" % downsample return down_elut
def MAT1(self, data): pos = 8 matCount = Struct.uint16(data[pos:pos+2], endian='>') pos += 4 for i in xrange(matCount): nameOff = Struct.uint32(data[pos:pos+4], endian='>') pos += 4 name = data[nameOff:].split('\0', 1)[0] wii.chexdump(data[nameOff:nameOff+0x60]) texid = Struct.uint16(data[nameOff + 0x40:nameOff + 0x42], endian='>') wrap_s = Struct.uint8(data[nameOff + 0x42:nameOff + 0x43], endian='>') wrap_t = Struct.uint8(data[nameOff + 0x43:nameOff + 0x44], endian='>') texid2 = Struct.uint16(data[nameOff + 0x44:nameOff + 0x46], endian='>') colorA = [Struct.uint16(data[nameOff + 0x1c + x:nameOff + 0x20 + x], endian='>')/255.0 for x in range(0,8,2)] colorB = [Struct.uint16(data[nameOff + 0x22 + x:nameOff + 0x24 + x], endian='>')/255.0 for x in range(0,8,2)] flags = Struct.uint32(data[nameOff + 0x3c:nameOff + 0x40], endian='>') #numtex = 1 # Hardcoded for her pleasure #(flags>>8) & 0xf #guess numtex = bit_extract(flags, 28, 31) if numtex == 1: img = self.Textures[texid] tex = img[1].create_texture(Texture) #print 'Material 0x%02x (%s) maps to texture %s' % (i, name, img[0]) elif numtex == 2: img = self.Textures[texid] alpha = self.Textures[texid2] combo = self.ApplyMask(img[1],alpha[1]) tex = combo.create_texture(Texture) #print 'Material 0x%02x (%s) maps to texture %s and mask %s' % (i, name, img[0], alpha[0]) else: print "Bad num textures: %d"%numtex self.Materials.append((name, tex, (colorA,colorB)))
def __format__(self): self.magic = Struct.string(4) self.magic2 = Struct.string(4) self.length = Struct.uint32 self.chunk_cnt = Struct.uint32 self.unknown01 = Struct.uint8 self.unknown02 = Struct.uint8 self.unknown03 = Struct.uint16 self.unknown04 = Struct.uint32 self.unknown05 = Struct.uint32 self.unknown06 = Struct.uint32
def __format__(self): self.Zeroes = Struct.uint8[0x40] self.IMET = Struct.string(4) self.Fixed = Struct.uint8[8] self.Sizes = Struct.uint32[3] self.Flag1 = Struct.uint32 self.Names = Struct.string(0x2A << 1, encoding='utf-16-be', stripNulls=True)[7] self.Zeroes = Struct.uint8[0x348] self.Crypto = Struct.uint8[0x10]
def TXL1(self, data): pos = 8 texCount = Struct.uint16(data[pos:pos+2], endian='>') pos += 4 for i in xrange(texCount): fnOff = Struct.uint32(data[pos:pos+4], endian='>') pos += 8 fn = data[fnOff+0xC:].split('\0', 1)[0] tex = TPL(self.Archive.Files['./arc/timg/' + fn]).Textures[0] self.Textures.append((fn, tex))
def subset_elution(elution, prot_set): """ Return an elution only containing the proteins contained in the provided prot_set. """ newel = Struct() newel.__dict__ = elution.__dict__.copy() prot_inds, newprots = zip(*[(i, p) for i, p in enumerate(elution.prots) if p in prot_set]) newel.mat = elution.mat[prot_inds, :] newel.prots = newprots print len(newel.prots), "prots from", elution.filename, "in set" return newel
def TXL1(self, data): pos = 8 texCount = Struct.uint16(data[pos:pos + 2], endian='>') pos += 4 for i in xrange(texCount): fnOff = Struct.uint32(data[pos:pos + 4], endian='>') pos += 8 fn = data[fnOff + 0xC:].split('\0', 1)[0] tex = TPL(self.Archive.Files['./arc/timg/' + fn]).Textures[0] self.Textures.append((fn, tex))
def subset_elution(elution, prot_set): """ Return an elution only containing the proteins contained in the provided prot_set. """ newel = Struct() newel.__dict__ = elution.__dict__.copy() prot_inds, newprots = zip(*[(i,p) for i,p in enumerate(elution.prots) if p in prot_set]) newel.mat = elution.mat[prot_inds,:] newel.prots = newprots print len(newel.prots), 'prots from', elution.filename, 'in set' return newel
def split_muliple_elutions(big_elut): """ Split an elution into multiple based on use of _fraction_elutions. """ elution_columns = _fraction_elutions(big_elut.fractions) eluts = {} for elution_name in elution_columns: new_elut = Struct() new_elut.__dict__ = big_elut.__dict__.copy() new_elut.mat = big_elut.mat[:, elution_columns[elution_name]] new_elut.fractions = list(np.array(big_elut.fractions)[elution_columns[elution_name]]) new_elut.filename = big_elut.filename + "__" + elution_name eluts[elution_name] = new_elut return eluts
def PIC1(self, data): wii.chexdump(data) name = data[0xC:].split('\0', 1)[0] mat = Struct.uint16(data[0x5C:0x5E], endian='>') mat = self.Materials[mat] xs = Struct.float(data[0x44:0x48], endian='>') ys = Struct.float(data[0x48:0x4C], endian='>') x = Struct.float(data[0x24:0x28], endian='>') y = Struct.float(data[0x28:0x2C], endian='>') print 'Picture %s maps to material %s' % (name, mat[0]) print '\t%fx%f (%f, %f)' % (xs, ys, x, y) p = Picture(name, mat, [x, y, xs, ys]) self.PanePath[-1].Add(p) self.Objects[name] = p
def PIC1(self, data): wii.chexdump(data) name = data[0xC:].split('\0', 1)[0] mat = Struct.uint16(data[0x5C:0x5E], endian='>') mat = self.Materials[mat] xs = Struct.float(data[0x44:0x48], endian='>') ys = Struct.float(data[0x48:0x4C], endian='>') x = Struct.float(data[0x24:0x28], endian='>') y = Struct.float(data[0x28:0x2C], endian='>') #print 'Picture %s maps to material %s' % (name, mat[0]) #print '\t%fx%f (%f, %f)' % (xs, ys, x, y) p=Picture(name, mat, [x, y, xs, ys]) self.PanePath[-1].Add(p) self.Objects[name] = p
def icolor(self,a,b,fa,fb,fc): c = 0 for i in xrange(0,32,8): xa = (a>>i)&0xff xb = (b>>i)&0xff xc = min(255,max(0,int((xa*fa + xb*fb)/fc))) if c == xc< texel2: rgb[2] = self.icolor (rgb[0], rgb[1], 0.5, 0.5, 1) | 0xff000000 rgb[3] = 0 else: rgb[2] = self.icolor (rgb[0], rgb[1], 2, 1, 3) | 0xff000000 rgb[3] = self.icolor (rgb[1], rgb[0], 2, 1, 3) | 0xff000000 # color selection (00, 01, 10, 11) cm = map(ord,data[inp+4:inp+8]) ofs = l*4 for n in range(4): if (ofs + outp)<(x*y): # one row (4 texels) if maxw > (0 + l*4): out[ofs + 0 + outp] = rgb[(cm[n] & 0xc0) >> 6]; if maxw > (1 + l*4): out[ofs + 1 + outp] = rgb[(cm[n] & 0x30) >> 4]; if maxw > (2 + l*4): out[ofs + 2 + outp] = rgb[(cm[n] & 0x0c) >> 2]; if maxw > (3 + l*4): out[ofs + 3 + outp] = rgb[(cm[n] & 0x03) >> 0]; ofs += x inp += 8 outp += x * 4 outp += maxw - x * 8 outp += x * (TILE_HEIGHT - 1) return ''.join(Struct.uint32(p) for p in out)
def Unpack(self, data, outfile=None, debug=False): if outfile != None: file = open(outfile, 'wb') pos = 0 version = Struct.uint16(data[pos:pos+2], endian='>') pos += 2 if debug == True: print "Version: %04x" % version print self.string_list = [] while pos < len(data): string = nullterm(data[pos:]) string = unicode(string, 'utf_16_be') if debug == True: print "String: %s" % string pos += len(string) * 2 + 2 self.string_list.append(string) file.write(string.encode('utf-8')) file.write('\n') if pos < len(data): file.write('\n') file.close()
def load(_, file): S = yml.load(file) [x.close() for x in classTables] classTables.clear() t = Struct(S.types) typeTable.nameEdit.setText(t.name) typeTable.setName(t.name) typeTable.table.load(t.names) typeTable.show() typeTable.move(*t.position) typeTable.resize(*t.size) for x in S.classes: k = list(x.keys())[0] klass = x[k] print('loading %s' % k) C = ClassTable(typeTable.table, [list(m.items())[0] for m in klass['members']], k) C.selectGenerator.setCurrentIndex(klass['generator']) C.show() C.move(*klass['position']) C.resize(*klass['size']) classTables.append(C) _.lastsavefile = file
def icolor(self, a, b, fa, fb, fc): c = 0 for i in xrange(0, 32, 8): xa = (a >> i) & 0xff xb = (b >> i) & 0xff xc = min(255, max(0, int((xa * fa + xb * fb) / fc))) if c == xc < texel2: rgb[2] = self.icolor(rgb[0], rgb[1], 0.5, 0.5, 1) | 0xff000000 rgb[3] = 0 else: rgb[2] = self.icolor(rgb[0], rgb[1], 2, 1, 3) | 0xff000000 rgb[3] = self.icolor(rgb[1], rgb[0], 2, 1, 3) | 0xff000000 # color selection (00, 01, 10, 11) cm = map(ord, data[inp + 4:inp + 8]) ofs = l * 4 for n in range(4): if (ofs + outp) < (x * y): # one row (4 texels) if maxw > (0 + l * 4): out[ofs + 0 + outp] = rgb[(cm[n] & 0xc0) >> 6] if maxw > (1 + l * 4): out[ofs + 1 + outp] = rgb[(cm[n] & 0x30) >> 4] if maxw > (2 + l * 4): out[ofs + 2 + outp] = rgb[(cm[n] & 0x0c) >> 2] if maxw > (3 + l * 4): out[ofs + 3 + outp] = rgb[(cm[n] & 0x03) >> 0] ofs += x inp += 8 outp += x * 4 outp += maxw - x * 8 outp += x * (TILE_HEIGHT - 1) return ''.join(Struct.uint32(p) for p in out)
def GetAllDevices(self): class Device(Struct): pass return [ Device( key='key', idString='idString', deviceInfo=Struct( label='label', summary='summary', ), connectable=Struct( connected=False, ), ), ]
def get_output(type=1, bottom=-1, top=50, sigma_o=1, sigma_tau=0, scale=1, weight_offset=0.0, mean_weight_offset=0.0, output_noise=None): # types: # 0: linear # 1: sigmoid # 2: piecewise-linear # 3: exponential params = {} params['type'] = type params['use_derivative'] = False params['top'] = top params['bottom'] = bottom params['scale'] = scale # for exponential params['sigma_o'] = sigma_o params['sigma_tau'] = sigma_tau params['weight_offset'] = weight_offset params['mean_weight_offset'] = weight_offset params['output_noise'] = get_noise() return Struct(params)
def get_noise(type=0, mean=0, std=1, min=-1e500): # types: # 0: none # 1: uniform # 2: gaussian # 3: laplace typedict = { 0: 0, 'none': 0, 1: 1, 'uniform': 1, 2: 2, 'gaussian': 2, 3: 3, 'laplace': 3, 4: 4, 'proportional': 4, } params = {} params['type'] = typedict[type] params['mean'] = mean params['std'] = std params['min'] = min return Struct(params)
def __init__(self, objects_dictionary): self.command_list = [] self.struct_list = [] self.service = '' # Loop items in the list, creating Message objects for the messages for object_dictionary in objects_dictionary: if object_dictionary['type'] == 'Command': self.command_list.append(Message(object_dictionary)) elif object_dictionary['type'] == 'Struct': self.struct_list.append(Struct(object_dictionary)) elif object_dictionary['type'] == 'Service': self.service = object_dictionary['name'] else: raise ValueError('Cannot handle object type \'%s\'' % object_dictionary['type']) if self.service == '': raise ValueError('Service name not specified') # Populate struct usages for struct in self.struct_list: for command in self.command_list: set_struct_usage(struct, command.query) set_struct_usage(struct, command.set) set_struct_usage(struct, command.response) set_struct_usage(struct, command.notification)
def __format__(self): self.issuer = Struct.string(0x40) self.eccpubkey = Struct.string(0x3C) self.version = Struct.uint8 self.ca_crl_version = Struct.uint8 self.signer_crl_version = Struct.uint8 self.titlekey = Struct.string(0x10) self.reserved1 = Struct.uint8 self.ticketid = Struct.uint64 self.consoleid = Struct.uint32 self.titleid = Struct.uint64 self.reserved2 = Struct.uint16 self.titleversion = Struct.uint16 self.reserved3 = Struct.uint64 self.license_type = Struct.uint8 self.ckeyindex = Struct.uint8 self.reserved4 = Struct.string(0x2A) self.eshopid = Struct.uint32 self.reserved5 = Struct.uint8 self.audit = Struct.uint8 self.reserved6 = Struct.string(0x42) self.demo = Struct.uint32 self.maxplaycount = Struct.uint32 self.limits = Struct.string(0x38) self.cindex = Struct.string(0xAC)
def loadConfigFile(argv): #temps d'attente avant démarrage de la simulation start_in = int(os.environ.get('WAITING')) if start_in > 0: print(f"Ce simulateur attendra {start_in}s avant de démarrer.") time.sleep(start_in) try: opts, args = getopt.getopt(argv, "hi:o", ["ifile="]) except getopt.GetoptError: sys.exit(2) for opt, arg in opts: if (opt == '-i'): configFile = '{}/{}'.format(CURR_DIR, arg) with open('{}'.format(configFile)) as file: data = yaml.safe_load(file) config = Struct(**data) car = Struct(**config.car) return config, car
def __format__(self): self.hdrsize = Struct.uint32 self.type = Struct.string(0x04) self.certchainsize = Struct.uint32 self.reserved = Struct.uint32 self.ticketsize = Struct.uint32 self.tmdsize = Struct.uint32 self.datasize = Struct.uint32 self.footersize = Struct.uint32
def get_pattern(type=2, scale=1.0, filename='hdf5/new_images12_dog.hdf5', var=[], num_inputs=169, masktype='circle', mask=[], filter=None): # types: # 0: none # 1: data vectors # 2: images params = {} params['type'] = type params['scale'] = scale params['var'] = var params['filter'] = filter params['filter_params'] = Struct({}) params['sequential'] = False if not params['var']: params['filename'] = filename params['masktype'] = masktype else: params['filename'] = '' params['masktype'] = 'none' if not filter is None: params['filter'](var) params['num_inputs'] = num_inputs params['pattern_probability'] = 1.0 params['non_pattern_noise'] = get_noise() # mask types: # circle # none # user params['mask'] = mask return Struct(params)
def combine_elutions(e1, e2, combine_corr_func=None): # Assumes the fractions from each elution are mutually exclusive; puts them # in order of e1fracs+e2fracs. # Proteins (rows) are merged. allprots = list(set.union(set(e1.prots), set(e2.prots))) nprots = len(allprots) # use n fractions instead of matrix shape to handle 0-row elutions nfracs1 = len(e1.fractions) allfracs = nfracs1 + len(e2.fractions) mat = np.matrix(np.zeros((nprots,allfracs))) mat[0:len(e1.prots),0:e1.mat.shape[1]] = e1.mat[:,:] for elut,(start,stop) in [(e1,(0,nfracs1)),(e2,(nfracs1,None))]: for row in range(len(elut.prots)): mat[allprots.index(elut.prots[row]), start:stop] = elut.mat[row,:] elut = Struct(mat=mat, prots=allprots, fractions=e1.fractions+e2.fractions, filename=e1.filename+e2.filename+str(combine_corr_func)) if combine_corr_func: elut.corr = combine_corrs(e1, e2, allprots, combine_corr_func) return elut
def GetHost(name, vmList, dsList, CreateNasDatastore=None, RemoveDatastore=None, GetDatastoreByName=None): host = Host(name, vmList=vmList, hostSystem=Struct(datastore=dsList), datastoreSystem=Struct()) if CreateNasDatastore is not None: host.datastoreSystem.CreateNasDatastore = CreateNasDatastore if RemoveDatastore is not None: host.datastoreSystem.RemoveDatastore = RemoveDatastore if GetDatastoreByName is not None: host.GetDatastoreByName = GetDatastoreByName return host
def __init__(self, name, host=None, powerState='poweredOff', powerOpSleepSeconds=1, *args, **kwargs): Mock.__init__(self, *args, **kwargs) self.name = name self.host = host self.powerState = powerState self.powerOpSleepSeconds = powerOpSleepSeconds self.config = Struct() self.guest = Struct() self.extraConfig = {} self.toolsInstalled = True # Take keyword arg values passed in and use them to set object attributes self.__dict__.update(kwargs)
def MAT1(self, data): pos = 8 matCount = Struct.uint16(data[pos:pos + 2], endian='>') pos += 4 for i in xrange(matCount): nameOff = Struct.uint32(data[pos:pos + 4], endian='>') pos += 4 name = data[nameOff:].split('\0', 1)[0] wii.chexdump(data[nameOff:nameOff + 0x60]) texid = Struct.uint16(data[nameOff + 0x40:nameOff + 0x42], endian='>') wrap_s = Struct.uint8(data[nameOff + 0x42:nameOff + 0x43], endian='>') wrap_t = Struct.uint8(data[nameOff + 0x43:nameOff + 0x44], endian='>') texid2 = Struct.uint16(data[nameOff + 0x44:nameOff + 0x46], endian='>') colorA = [ Struct.uint16(data[nameOff + 0x1c + x:nameOff + 0x20 + x], endian='>') / 255.0 for x in range(0, 8, 2) ] colorB = [ Struct.uint16(data[nameOff + 0x22 + x:nameOff + 0x24 + x], endian='>') / 255.0 for x in range(0, 8, 2) ] flags = Struct.uint32(data[nameOff + 0x3c:nameOff + 0x40], endian='>') #numtex = 1 # Hardcoded for her pleasure #(flags>>8) & 0xf #guess numtex = bit_extract(flags, 28, 31) if numtex == 1: img = self.Textures[texid] tex = img[1].create_texture(Texture) #print 'Material 0x%02x (%s) maps to texture %s' % (i, name, img[0]) elif numtex == 2: img = self.Textures[texid] alpha = self.Textures[texid2] combo = self.ApplyMask(img[1], alpha[1]) tex = combo.create_texture(Texture) #print 'Material 0x%02x (%s) maps to texture %s and mask %s' % (i, name, img[0], alpha[0]) else: print "Bad num textures: %d" % numtex self.Materials.append((name, tex, (colorA, colorB)))
def __format__(self): self.issuer = Struct.string(64) self.version = Struct.uint8 self.ca_crl_version = Struct.uint8 self.signer_crl_version = Struct.uint8 self.padding1 = Struct.uint8 self.system_version = Struct.uint64 self.titleid = Struct.uint64 self.type = Struct.uint32 self.group_id = Struct.uint16 self.zero = Struct.uint16 self.region = Struct.uint16 self.ratings = Struct.string(16) self.reserved2 = Struct.string(12) self.ipc_mask = Struct.string(12) self.reserved3 = Struct.string(18) self.access_rights = Struct.uint32 self.titleversion = Struct.uint16 self.contentcount = Struct.uint16 self.bootindex = Struct.uint16 self.padding2 = Struct.uint16
def __format__(self): self.issuer = Struct.string(0x40) self.version = Struct.uint8 self.ca_crl_version = Struct.uint8 self.signer_crl_version = Struct.uint8 self.reserved1 = Struct.uint8 self.system_version = Struct.uint64 self.titleid = Struct.uint64 self.type = Struct.uint32 self.group_id = Struct.uint16 self.savedata_size = Struct.uint32 self.srl_private_data_size = Struct.uint32 self.reserved2 = Struct.uint32 self.srl_flag = Struct.uint8 self.reserved3 = Struct.string(0x31) self.access_rights = Struct.uint32 self.titleversion = Struct.uint16 self.contentcount = Struct.uint16 self.bootcontent = Struct.uint16 self.padding = Struct.string(2) self.sha256 = Struct.string(0x20)
def combine_elutions(e1, e2, combine_corr_func=None): # Assumes the fractions from each elution are mutually exclusive; puts them # in order of e1fracs+e2fracs. # Proteins (rows) are merged. allprots = list(set.union(set(e1.prots), set(e2.prots))) nprots = len(allprots) # use n fractions instead of matrix shape to handle 0-row elutions nfracs1 = len(e1.fractions) allfracs = nfracs1 + len(e2.fractions) mat = np.matrix(np.zeros((nprots, allfracs))) mat[0 : len(e1.prots), 0 : e1.mat.shape[1]] = e1.mat[:, :] for elut, (start, stop) in [(e1, (0, nfracs1)), (e2, (nfracs1, None))]: for row in range(len(elut.prots)): mat[allprots.index(elut.prots[row]), start:stop] = elut.mat[row, :] elut = Struct( mat=mat, prots=allprots, fractions=e1.fractions + e2.fractions, filename=e1.filename + e2.filename + str(combine_corr_func), ) if combine_corr_func: elut.corr = combine_corrs(e1, e2, allprots, combine_corr_func) return elut
def GRP1(self, data): wii.chexdump(data) if len(data) < 0x1c: pass lang = data[0x8:0x18].split('\0', 1)[0] nitems = Struct.uint16(data[0x18:0x1a], endian='>') p = 0x1c items = [] for i in xrange(nitems): items.append(data[p:].split('\0', 1)[0]) p += 0x10 for i in items: if lang != self.Language: self.Objects[i].Enabled = False else: self.Objects[i].Enabled = True
def PAN1(self, data): wii.chexdump(data) name = data[0xC:].split("\0", 1)[0] x = Struct.float(data[0x24:0x28], endian=">") y = Struct.float(data[0x28:0x2C], endian=">") a = Struct.float(data[0x3C:0x40], endian=">") b = Struct.float(data[0x40:0x44], endian=">") xs = Struct.float(data[0x44:0x48], endian=">") ys = Struct.float(data[0x48:0x4C], endian=">") coords = [x, y, xs, ys] print "Pane %s:" % name, coords + [a, b] self.CurPane = Pane(name, coords)
def PAN1(self, data): wii.chexdump(data) name = data[0xC:].split('\0', 1)[0] x = Struct.float(data[0x24:0x28], endian='>') y = Struct.float(data[0x28:0x2C], endian='>') a = Struct.float(data[0x3C:0x40], endian='>') b = Struct.float(data[0x40:0x44], endian='>') xs = Struct.float(data[0x44:0x48], endian='>') ys = Struct.float(data[0x48:0x4C], endian='>') coords = [x, y, xs, ys] #print 'Pane %s:' % name, coords+[a,b] self.CurPane = Pane(name, coords)
def __format__(self): self.Magic = Struct.string(4) self.Length = Struct.uint32 self.Unk1 = Struct.uint32 self.Unk2 = Struct.uint32 self.Unk3 = Struct.uint16 self.Unk4 = Struct.uint16 self.Unk5 = Struct.uint16 self.Unk6 = Struct.uint16 self.Float1 = Struct.float self.Float2 = Struct.float self.Float3 = Struct.float self.Float4 = Struct.float self.Float5 = Struct.float self.Float6 = Struct.float self.Float7 = Struct.float self.Float8 = Struct.float self.Float9 = Struct.float self.FloatA = Struct.float self.Unk7 = Struct.uint32 self.Unk8 = Struct.uint32 self.Unk9 = Struct.uint32 self.UnkA = Struct.uint32
def __format__(self): self.FourCC = Struct.string(4) self.Size = Struct.uint32
def __format__(self): self.Magic = Struct.string(4) self.Unk = Struct.uint32 self.Size = Struct.uint32 self.AnimCount = Struct.uint16 self.AtomCount = Struct.uint16
out[outp + ofs + sub + 1] = (low << 4) | (low << 20) | (low << 12) | 0xFF<<24 inp += 1 ofs += x inp += (8 - off) / 2 outp += off outp += x * 7 return ''.join(Struct.uint32(p) for p in out) def IA8(self, data, (y, x)): out = [0 for i in xrange(x * y)] inp = 0 for i in xrange(0, y, 4): for j in xrange(0, x, 4): for k in xrange(i, i + 4, 1): for l in xrange(j, j + 4, 1): texel = Struct.uint16(data[inp*2:inp*2+2], endian='>') inp += 1 if (l>=x) or (k>=y): continue b = texel >> 8 g = texel >> 8 r = texel >> 8 a = texel & 0xff out[l + (k * x)] = (r << 0) | (g << 8) | (b << 16) | (a << 24) return ''.join(Struct.uint32(p) for p in out) def I8(self, data, (y, x)): out = [0 for i in xrange(x * y)] outp = 0 inp = 0 for i in xrange(0, y, 4):
for i in xrange(0, y, 4): for j in xrange(0, x, 4): ofs = 0 for k in xrange(4): off = min(x - j, 4) for sub in xrange(off): texel = ord(data[inp]) out[outp + ofs + sub] = (texel << 24) | (texel << 16) | (texel << 8) | 0xFF inp += 1 ofs += x inp += 4 - off * 2 outp += off outp += x * 3 return "".join(Struct.uint32(p) for p in out) def RGB565(self, data, (y, x)): out = [0 for i in xrange(x * y)] outp = 0 inp = 0 for i in xrange(0, y, 4): for j in xrange(0, x, 4): ofs = 0 for k in xrange(4): off = min(x - j, 4) for sub in xrange(off): texel = ord(data[inp]) # out[outp + ofs + sub] = (texel << 24) | (texel << 16) | (texel << 8) | 0xFF b = (texel & 0x1F) << 3 g = ((texel >> 5) & 0x3F) << 2
def __format__(self): self.Tag = Struct.string(4) self.RootNode = Struct.uint32 self.HeaderSize = Struct.uint32 self.DataOffset = Struct.uint32 self.Zeroes = Struct.uint8[0x10]
def __format__(self): self.Magic = Struct.string(4) self.Count = Struct.uint32 self.Size = Struct.uint32
def __format__(self): self.Tag = Struct.string(4) self.Size = Struct.uint32 self.Zeroes = Struct.uint8[8] self.MD5 = Struct.uint8[0x10]
img = wx.Image("tmp.png", wx.BITMAP_TYPE_ANY).ConvertToBitmap() w = img.GetWidth() h = img.GetHeight() dialog = imp("TPL (" + str(w) + ", " + str(h) + ")", img) dialog.ShowModal() dialog.Destroy() os.unlink("tmp.png") def RGBA8(self, (x, y), data): out = [0 for i in xrange(x * y)] inp = 0 for i in xrange(0, y, 4): for j in xrange(0, x, 4): for k in xrange(2): for l in xrange(i, i + 4, 1): for m in xrange(j, j + 4, 1): texel = Struct.uint8(data[inp:inp + 1], endian = '>') inp += 1 texel2 = Struct.uint8(data[inp:inp + 1], endian = '>') inp += 1 if (m >= x) or (l >= y): continue if k == 0: # ARARARAR a = (texel) & 0xff r = (texel2) & 0xff out[m + (l * x)] |= ((r << 0) | (a << 24)) else: # GBGBGBGB g = (texel) & 0xff b = (texel2) & 0xff out[m + (l * x)] |= ((g << 8) | (b << 16)) return ''.join(Struct.uint32(p) for p in out) def RGB5A3(self, (w, h), jar):
def __init__(self): Struct.__init__(self) self.fileName = ""