def get_h0_extrap(ref,d,hexp=1): nomatch=get_numeric_nomatch_keys() nomatch.append('ngrid') d1 = get_matching(ref,d,nomatch) h_min = [] max_eval=[] for d2 in d1: try: h_min.append(min(d2.grid[1:]-d2.grid[0:-1])**hexp) except: h_min.append(1./(d2.data['ngrid']-1)**hexp) max_eval.append(max(d2.evals.imag)) uh = list(sets.Set(h_min)) min_uh = min(uh) uuh = [] for uh1 in uh: if len(Numeric.nonzero(Numeric.absolute(Numeric.array(uuh)-uh1)<1e-8))==0: uuh.append(uh1) min_eval=[] #print Numeric.sort(uuh) for hm in uuh: inds = Numeric.nonzero(Numeric.absolute(Numeric.array(h_min)-hm)<1e-8) min_eval.append(min(Numeric.take(max_eval,inds))) inds = Numeric.argsort(uuh) h_min = list(Numeric.take(uuh,inds)) min_eval = list(Numeric.take(min_eval,inds)) if len(min_eval)>1: m=(min_eval[1]-min_eval[0])/(h_min[1]-h_min[0]) else: m=0 return min_eval[0]-m*h_min[0]
def renumberAtoms(self, indices): conf = self.configuration() for a in self.atomList(): a.index = indices[a.index] indices = Numeric.argsort(indices) conf.array[:] = Numeric.take(conf.array, indices) self._changed(1)
def draw(self, graphics): """Draws the graphics object |graphics|, which can be a PolyLine3D or a VisualizationGraphics object.""" self.last_draw = (graphics, ) self.configure(cursor='watch') self.update_idletasks() graphics.project(self.axis, self.plane) p1, p2 = graphics.boundingBoxPlane() center = 0.5*(p1+p2) scale = self.plotbox_size / (p2-p1) sign = scale/Numeric.fabs(scale) if self.scale is None: minscale = Numeric.minimum.reduce(Numeric.fabs(scale)) self.scale = 0.9*minscale scale = sign*self.scale box_center = self.plotbox_origin + 0.5*self.plotbox_size shift = -center*scale + box_center + self.translate graphics.scaleAndShift(scale, shift) items, depths = graphics.lines() sort = Numeric.argsort(depths) for index in sort: x1, y1, x2, y2, color, width = items[index] Line(self.canvas, x1, y1, x2, y2, fill=color, width=width) self.configure(cursor='top_left_arrow') self.update_idletasks()
def set_source( self, source, titledict=None, hidden=None ): """Set the data source shapes - a GvShapes instance titledict - dictionary of titles for properties (optional) hidden - properties to hide reset all the internal parameters """ self.clear() #trap setting to None or an invalid shapes object if source == None or source._o == None or len(source) == 0: return self.source = source self.source_changed_id = self.source.connect( 'changed', self.source_changed_cb ) self.subset = [] schema = source.get_schema() self.n_cols = len(schema) self.n_rows = len(source) # no shapes initially selected. # Shapes are selected by source index. self.selected_shapes=Numeric.zeros([len(source),1]) # Sorted position of shape- initially in order of location in source. # Used to map nRow->source index and vice versa. self.indices=Numeric.array(range(len(source)))+1 self.inv_indices=Numeric.argsort(self.indices) self.sort_reverse=0 self.subindices=None self.inv_subindices=None self.sort_property=None self.titledict={} if titledict is None: titledict={} self._hidden_titles=[] if hidden is not None: for item in hidden: self._hidden_titles.append(item) for i in range(len(schema)): title = schema[i][0] if title not in self._hidden_titles: if titledict.has_key(title): self.titles.append(titledict[title]) self.titledict[titledict[title]]=title else: self.titles.append(title) self.titledict[title]=title #update the scrollbars self.bCalcAdjustments = gtk.TRUE self.expose()
def load_balancing(self): """Function balancing load between nodes""" self.t1 = time.time() w_numbers = self.pypar.gather(Numeric.array([len(self.w_block)]), self.master_rank) tmp_w_numbers = copy.deepcopy(w_numbers) w_numbers = self.pypar.broadcast(tmp_w_numbers, self.master_rank) self.no_of_walkers = Numeric.sum(w_numbers) self.__find_opt_w_p_node() #self.__set_w_p_node() self.first_balance = False balanced = Numeric.array(self.loc_walkers) difference = w_numbers - balanced diff_sort = Numeric.argsort(difference) prev_i_min = diff_sort[0] while sum(abs(difference)) != 0: diff_sort = Numeric.argsort(difference) i_max = diff_sort[-1] i_min = diff_sort[0] if i_min == prev_i_min and i_max != diff_sort[1]: i_min = diff_sort[1] if self.myrank == i_max: self.pypar.send(self.w_block[balanced[i_max]:], i_min) args = [ balanced[i_max], self.particles, self.dimensions, self.w_block[0:balanced[i_max]] ] self.w_block = WalkerArray.WalkerArray(*args) elif self.myrank == i_min: recv_buff = self.pypar.receive(i_max) args = [ len(self.w_block) + difference[i_max], self.particles, self.dimensions, Numeric.concatenate((self.w_block[:], recv_buff)) ] self.w_block = WalkerArray.WalkerArray(*args) difference[i_min] += difference[i_max] difference[i_max] = 0 prev_i_min = i_min
def load_balancing(self): """Function balancing load between nodes""" self.t1 = time.time() w_numbers = self.pypar.gather(Numeric.array([len(self.w_block)]), self.master_rank) tmp_w_numbers = copy.deepcopy(w_numbers) w_numbers = self.pypar.broadcast(tmp_w_numbers,self.master_rank) self.no_of_walkers = Numeric.sum(w_numbers) self.__find_opt_w_p_node() #self.__set_w_p_node() self.first_balance = False balanced = Numeric.array(self.loc_walkers) difference = w_numbers-balanced diff_sort = Numeric.argsort(difference) prev_i_min = diff_sort[0] while sum(abs(difference))!=0: diff_sort = Numeric.argsort(difference) i_max = diff_sort[-1] i_min = diff_sort[0] if i_min == prev_i_min and i_max!=diff_sort[1]: i_min = diff_sort[1] if self.myrank==i_max: self.pypar.send(self.w_block[balanced[i_max]:],i_min) args = [balanced[i_max], self.particles, self.dimensions, self.w_block[0:balanced[i_max]]] self.w_block = WalkerArray.WalkerArray(*args) elif self.myrank==i_min: recv_buff = self.pypar.receive(i_max) args = [len(self.w_block)+difference[i_max], self.particles, self.dimensions, Numeric.concatenate((self.w_block[:],recv_buff))] self.w_block = WalkerArray.WalkerArray(*args) difference[i_min]+=difference[i_max] difference[i_max]=0 prev_i_min = i_min
def testSort (self): "Test sort, argsort, argmax, argmin, searchsorted" s = (3,2,5,1,4,0) sm = [s, Numeric.array(s)[::-1]] se = Numeric.array(s)[0:0] assert_eq(Numeric.sort(s), self.a) assert len(Numeric.sort(se)) == 0 assert_eq(Numeric.argsort(s), [5,3,1,0,4,2]) assert len(Numeric.argsort(se)) == 0 assert_eq(Numeric.sort(sm, axis = -1), [[0,1,2,3,4,5],[0,1,2,3,4,5]]) assert_eq(Numeric.sort(sm, axis = 0), [[0,2,1,1,2,0],[3,4,5,5,4,3]]) assert_eq(Numeric.searchsorted(Numeric.arange(10), (5,2)), [5,2]) assert Numeric.argmax(s) == 2 assert Numeric.argmin(s) == 5 assert_eq(Numeric.argmax(sm, axis=-1), [2,3]) assert_eq(Numeric.argmax(sm, axis=1), [2,3]) assert_eq(Numeric.argmax(sm, axis=0), [0,1,0,1,0,1]) assert_eq(Numeric.argmin(sm, axis=-1), [5,0]) assert_eq(Numeric.argmin(sm, axis=1), [5,0])
def getnearestgen(self,ra1,dec1,ra2,dec2,j):#measure distances from ra1, dec1 to members in catalog ra2, dec2 sig5=N.zeros(len(ra1),'f') sig10=N.zeros(len(ra1),'f') for i in range(len(ra1)): angdist=my.DA(c.z[j],h100)#kpc/arcsec dspec=N.sqrt((ra1[i]-ra2)**2+(dec1[i]-dec2)**2)#sorted array of distances in degrees dspecsort=N.take(dspec,N.argsort(dspec)) sig5[i]=5./(N.pi)/(dspecsort[5]*3600.*angdist/1000.)**2#convert from deg to arcsec, multiply by DA (kpc/arcsec), divide by 1000 to convert to Mpc, index 5 element b/c 0 is itself sig10[i]=10./(N.pi)/(dspecsort[10]*3600.*angdist/1000.)**2#convert from deg to arcsec, multiply by DA (kpc/arcsec), divide by 1000 to convert to Mpc, index 5 element b/c 0 is itself return sig5, sig10
def get_unstable_evals(self): unst = [] inds = [] for i in range(len(self.evals)): if abs(self.evals[i].imag) > 0: inds.append(i) unst.append(self.evals[i]) sort_inds = list(Numeric.argsort(Numeric.array(unst).imag)) sort_inds.reverse() self.unst_inds = Numeric.take(inds,sort_inds) self.unst = Numeric.take(unst,sort_inds) return Numeric.array(self.unst)
def __init__(self, universe=None, temperature = 300): if universe == None: return Features.checkFeatures(self, universe) self.universe = universe self.temperature = temperature self.sqrt_mass = Numeric.sqrt(self.universe.masses().array) self.sqrt_mass = self.sqrt_mass[:, Numeric.NewAxis] self._forceConstantMatrix() ev = self._diagonalize() self.imaginary = Numeric.less(ev, 0.) self.frequencies = Numeric.sqrt(Numeric.fabs(ev)) / (2.*Units.pi) self.sort_index = Numeric.argsort(self.frequencies) self._scale(temperature) del self.sqrt_mass
def plot_Re_w_maxG(ref,var_key,var_key2,d=None,r0=.84,minn=1,maxn=3300,g=None,neg=None,tt=['a'],rind=0,uv2=None,notitle=False): [g,matching,d]=plot_Re_w_varG(ref,var_key,var_key2,d=d,r0=r0,minn=minn,maxn=maxn,g=g,neg=neg,tt=tt,rind=rind,uv2=uv2,notitle=notitle,varG=-1) g.ylabel('{/Symbol w}_{{/Symbol G}_{max}}') nums = [matching[i].num for i in range(len(matching))] print nums inds = Numeric.argsort(nums) for i in range(len(nums)): if matching[inds[i]].data['Vz0']!=0: uniq_num = nums[inds[i]] break if type(r0)==type([]): fnb = 'plots/%d_var_%s_%s_Re_maxG_r0_multi'%(uniq_num,var_key,var_key2) else: fnb = 'plots/%d_var_%s_%s_Re_maxG_r0_%g'%(uniq_num,var_key,var_key2,r0) print fnb g('set key out') g.hardcopy(fnb+'.eps',eps=True) g.hardcopy(fnb+'.ps',size=(7,5),fontsize=24,eps=False) g.refresh() return [g,matching,d]
def plot_Re_w_varG(ref,var_key,var_key2,d=None,r0=.84,minn=1,maxn=3300,g=None,neg=None,tt=['a'],rind=0,uv2=None,notitle=False,varG=-1): if d==None: d = get_all_list(minn=minn,maxn=maxn) if type(ref)!=type(1): print 'ref must be of type int' if type(var_key)!=type(''): print 'var_key must be of type string' if type(var_key2)!=type(''): print 'var_key2 must be of type string' if type(rind)!=type(1): print 'rind must be of type int' matching = get_matching(ref,d=d,nomatch_keys=get_numeric_nomatch_keys()+[var_key,var_key2]) if g==None: g = Gnuplot.Gnuplot(persist=1) g('set key left top Left reverse') g.xlabel(var_key) g.ylabel('{/Symbol w}_{min{/Symbol G}}') xfac = 1 if var_key=='Vz0': wA = abs(matching[0].get_wA()) xfac = 1./(wA/matching[0].data['k']) g.xlabel('V_z(r=0)/v_A') g.itemlist = [] for i in range(len(matching)): if matching[i].data['num']==ref: ref_ind = i break ttl = '' for tt1 in tt: ttl=ttl+'%s=%g, '%(tt1,matching[ref_ind].data[tt1]) ttl = ttl[:-2] if notitle==False: g.title(ttl)#'V_z(r=a)=%g'%matching[0].Vz([matching[0].data['a']])) else: g('unset title') var_list = [] var2_list = [] min_eval = [] nums = [] matching2 = [] for i in range(len(matching)): evals = matching[i].evals if neg!=None: inds = Numeric.nonzero(evals.real<1e-5) evals = Numeric.take(evals,inds) ind = Numeric.argsort(evals.imag) if evals[ind[varG]].imag==0: continue min_eval.append(evals[ind[varG]].real) var_list.append(matching[i].data[var_key]) var2_list.append(matching[i].data[var_key2]) nums.append(matching[i].num) matching2.append(matching[i]) matching = matching2 if len(var2_list)==0: return if uv2==None: uv2 = Numeric.sort(list(sets.Set(var2_list))) else: uv2 = Numeric.sort(uv2) i = 1 for u2 in uv2: inds = Numeric.nonzero(Numeric.array(var2_list)==u2) if len(inds)<=1: i = i+1 continue v1 = Numeric.take(var_list,inds)*xfac ev1 = Numeric.take(min_eval,inds) d1 = matching[inds[rind]] #print u2 #print v1,ev1 g.itemlist.append(Gnuplot.Data(v1,ev1,title='%s=%g'%(var_key2,d1.data[var_key2]),with='points %d'%i))
def permutation(n): "permutation(n) = a permutation of indices range(n)" return Numeric.argsort(random(n))
if '1P' in sys.argv:#One plot overlayed g = Gnuplot.Gnuplot() g.itemlist = [] for i in range(len(d)): g.itemlist.append(d[i][1]) for i in range(len(g.itemlist)): g.itemlist[i].set_option(with='lines',title=ylabels[i]) # g.refresh() g('set key right bottom Left reverse') g.xlabel('r') g.ylabel('Arb. units') g.hardcopy(fn,eps=True,fontsize=18,solid=False) elif 'animate' in sys.argv: g = Gnuplot.Gnuplot() items = [] inds = list(Numeric.argsort(h_min)) inds.reverse() for i in range(len(d)): items.append(d[inds[i]][1]) items[i].set_option(with='lines',title=ylabels[inds[i]]) if i > 0: items[i].set_option(with='lines ls 3') g.itemlist = [items[i]] if i>0: g.itemlist.insert(0,items[0]) g('set key right bottom Left reverse') g('set yrange [-50:50]') g.hardcopy(fn[:-4]+'animate-%d'%i+'.eps',solid=True,size=(4,3),linewidth=3,dashlength=50,eps=True,fontsize=24) else: multiplot.multiplot(d,ylabels,fn) #os.system('gv %s &'%fn)
def sort_one(self,snap,id): atoms = snap.atoms ids = atoms[:,id] ordering = Numeric.argsort(ids) for i in xrange(len(atoms[0])): atoms[:,i] = Numeric.take(atoms[:,i],ordering)
#! /usr/pppl/python/2.3.5x/bin/python import Numeric, Gnuplot, sys, sets from get_EV import * ref = int(sys.argv[1]) d = get_EV(ref,output_folder='output_vcyl') len_branch = len(d.evals)/6-1 xs = 1.5 ys = 2.5*math.log(len_branch) dy = ys/len_branch dx = xs/3. inds = list(Numeric.argsort(d.evals.real)) inds.reverse() x = Numeric.arange(0,d.data['a'],1./(d.data['ngrid']*10)) #print inds #print Numeric.take(d.evals.real,inds) fns = ['fast', 'alfven', 'slow'] for i in range(3): g = Gnuplot.Gnuplot() g('set output "plots/%d_all_%s.eps"'%(ref,fns[i])) g('set term postscript enhanced eps solid 8') g('set size %g,%g'%(xs,ys)) g('set multiplot') g('set size %g,%g'%(dx,dy)) if len_branch>50: g('unset xtics') #g('unset ytics') #g('set yrange [0:1]') g('set xrange [0:%g]'%d.data['a']) for j in range(len_branch-1,-1,-1):
flog.write('%d\n'%nv) totn = totn*nv for i in range(nv): val[j].append(raw_input('Enter value %d of %s. '%(i+1,var[j]))) flog.write('%s\n'%val[j][i]) print val flog.close() #sys.exit() fin = start+totn-1 print fin indlen = [] for j in range(len(var)): indlen.append(len(val[j])) print indlen inds = list(Numeric.argsort(indlen)) print inds var_sort = [] val_sort = [] indlen = list(Numeric.take(indlen,inds)) for ind in inds: var_sort.append(var[ind]) val_sort.append(val[ind]) indlen val = val_sort var = var_sort print var print val indarray = list(Numeric.indices(indlen)) for j in range(len(indarray)): indarray[j] = Numeric.ravel(indarray[j])
def source_sort( self, sort_property=None,reverse=None ): # Need to call expose event after sorting to display # inv_indices/inv_subindices map (nRow-1)->source/subset # index; indices/subindices map source/subset index->nRow if ((self.source is None) or (len(self.source) < 1)): return # clear editing cell selections self.current_row = 0 self.current_row_src = -1 if sort_property is None: # default to last one if sort property not specified sort_property=self.sort_property if reverse is None: reverse=self.sort_reverse if (len(self.subset) == 0): self.subindices=None self.inv_subindices=None if sort_property is None: self.sort_property=sort_property self.sort_reverse=reverse if self.sort_reverse == 0: self.inv_indices=Numeric.array(range(len(self.source))) else: self.inv_indices=Numeric.array(range(len(self.source)-1,-1,-1)) # Grid rows are from 1...N (titles are 0) self.indices=Numeric.argsort(self.inv_indices)+1 return else: # If a subset is defined, the main set shouldn't be # used at all in expose. Don't bother sorting it. self.indices=None self.inv_indices=None if sort_property is None: self.sort_property=sort_property self.sort_reverse=reverse if self.sort_reverse == 0: self.inv_subindices=Numeric.array(range(len(self.subset))) else: self.inv_subindices=Numeric.array(range(len(self.subset)-1,-1,-1)) self.subindices=Numeric.argsort(self.inv_subindices)+1 return # Check that requested sort property exists have_prop=0 prop_type='string' for cprop in self.source.get_schema(): if cprop[0] == sort_property: have_prop=1 prop_type=cprop[1] if have_prop == 1: self.sort_property=sort_property self.sort_reverse=reverse if (len(self.subset) == 0): ind_list=[] count=0 if ((prop_type == 'float') or (prop_type == 'integer')): for cshape in self.source: # convert to float so sorting is numeric ind_list.append((float(cshape.get_property(sort_property)),count)) count=count+1 else: # sort as a string for cshape in self.source: ind_list.append((cshape.get_property(sort_property),count)) count=count+1 ind_list.sort() if self.sort_reverse == 1: ind_list.reverse() self.inv_indices=Numeric.zeros((count,)) for c_ind in range(count): self.inv_indices[c_ind]=ind_list[c_ind][1] self.indices=Numeric.argsort(self.inv_indices)+1 else: ind_list=[] if ((prop_type == 'float') or (prop_type == 'integer')): count = 0 for cindex in self.subset: ind_list.append((float(self.source[cindex].get_property(sort_property)),count)) count=count+1 else: count=0 for cindex in self.subset: ind_list.append((self.source[cindex].get_property(sort_property),count)) count=count+1 ind_list.sort() if self.sort_reverse == 1: ind_list.reverse() self.inv_subindices=Numeric.zeros((len(self.subset),)) for c_ind in range(len(self.subset)): self.inv_subindices[c_ind]=ind_list[c_ind][1] self.subindices=Numeric.argsort(self.inv_subindices)+1 else: print 'Invalid sort property.'
for i in range(len(var2_list2)): var2_list2[i] = float(var2_list2[i]) var2_list2.sort() uniq_var2 = var2_list2 b_opt = [] opt_b_local = [] v_opt = [] for v2 in uniq_var2: max_eval = [] var_list1 = [] for i in range(len(matching_files)): if var2_list[i]==v2: max_eval.append(max_imag[i]) var_list1.append(var_list[i]) ind = Numeric.argsort(max_eval) inds = list(Numeric.argsort(var_list1)) inds.reverse() for i in range(len(inds)-1): if var_key=='nu': if max_eval[inds[i]]*2>max_eval[inds[i+1]]: continue else: h_min = 1./v2 b_opt.append((var_list1[inds[i]]*1./h_min**hexp)) v_opt.append((h_min)) break else: if max_eval[inds[i]]>max_eval[inds[i+1]]: continue else:
for uh1 in ux: if len(Numeric.nonzero(Numeric.absolute(Numeric.array(uux)-uh1)<1e-8))==0: uux.append(uh1) for x1 in uux: x2.append(x1) inds = Numeric.nonzero(Numeric.absolute(Numeric.array(var_list)-x1)<1e-8) z2.append(min(Numeric.take(ev_list,inds))) inds = Numeric.nonzero(Numeric.array(ev_list)==z2[-1]) min_files.append(Numeric.take(matching_files,inds)[0]) y2a = Numeric.take(ev1_list,inds) y2.append(y2a[0]) var_list = x2 ev_list = z2 ev1_list = y2 #print 1./Numeric.array(var_list) inds = Numeric.argsort(var_list) var_list = list(Numeric.take(var_list,inds)) ev_list = list(Numeric.take(ev_list,inds)) ev1_list = list(Numeric.take(ev1_list,inds)) min_files = list(Numeric.take(min_files,inds)) for i in range(len(x2)): print var_list[i],':',min_files[i],' ', print '' #print var_list[0:2],ev_list[0:2] tt = '' for i in range(len(print_keys)): if print_keys[i] != var_key: tt = tt+'%s=%g, '%(print_keys[i],d1[print_keys[i]]) #g.title(tt[:-2]) #g1.title(tt[:-2]) g('set xrange [0:%g]'%(max(var_list)*1.1))
x[0] = x[1]/10000.0 y = Numeric.zeros(len(x),typecode=Numeric.Float) ygrid = Numeric.zeros(len(xgrid),typecode=Numeric.Float) dk = data A = dk['a']**2 s2 = dk['s2'] evals = d.evals.real**2 if data['fe_type'] == 'linconst': xgrid = xgrid+xgrid[1]/2. for gamma_ind in range(6):#min(nphi,len(gamma)-1)):#nphi,2): for i in range(len(x)): y[i] = sf.bessel_J1(x[i]*gamma[gamma_ind])[0] for i in range(len(xgrid)): ygrid[i] = sf.bessel_J1(xgrid[i]*gamma[gamma_ind])[0] omega1 = dk['Bz0']**2/(2*dk['rho0']*s2/(5./3.)*dk['Bz0']**2*A)*(A*dk['k']**2+gamma[gamma_ind]**2)*(1+s2)*(1-(1-4*s2*A*dk['k']**2/((1+s2)**2*(A*dk['k']**2+gamma[gamma_ind]**2)))**(1./2.)) min_ind = Numeric.argsort(Numeric.absolute(evals-omega1))[0] print 'min_ind=',min_ind error = evals[min_ind]-omega1 #EV =get_evec_3(data,3,min_ind) EV = d.get_evec1('3',min_ind,x).real fac =((EV[-2]+EV[-2])/2./ygrid[-2]) fac = EV[-1]/y[-1] if data['fe_type'] == 'linconst': fac = EV[0]/(ygrid[0]+ygrid[1])*4 g = Gnuplot.Gnuplot(persist=1) #print 'x=',x,'y=',y,'EV=',EV,'fac=',fac g.plot(Gnuplot.Data(x,y,with='lines',title='Exact'),Gnuplot.Data(x,EV/fac,title='Computed'),title='{/Symbol w}^2=%g; Analytic=%g'%(evals[min_ind],omega1)) #if gamma_ind < 10: #g.hardcopy('plots/%s.evecz_slow_%d.eps'%(sys.argv[1],min_ind),eps=True) sys.exit()
def source_sort(self, sort_property=None, reverse=None): # Need to call expose event after sorting to display # inv_indices/inv_subindices map (nRow-1)->source/subset # index; indices/subindices map source/subset index->nRow if ((self.source is None) or (len(self.source) < 1)): return # clear editing cell selections self.current_row = 0 self.current_row_src = -1 if sort_property is None: # default to last one if sort property not specified sort_property = self.sort_property if reverse is None: reverse = self.sort_reverse if (len(self.subset) == 0): self.subindices = None self.inv_subindices = None if sort_property is None: self.sort_property = sort_property self.sort_reverse = reverse if self.sort_reverse == 0: self.inv_indices = Numeric.array(range(len(self.source))) else: self.inv_indices = Numeric.array( range(len(self.source) - 1, -1, -1)) # Grid rows are from 1...N (titles are 0) self.indices = Numeric.argsort(self.inv_indices) + 1 return else: # If a subset is defined, the main set shouldn't be # used at all in expose. Don't bother sorting it. self.indices = None self.inv_indices = None if sort_property is None: self.sort_property = sort_property self.sort_reverse = reverse if self.sort_reverse == 0: self.inv_subindices = Numeric.array(range(len( self.subset))) else: self.inv_subindices = Numeric.array( range(len(self.subset) - 1, -1, -1)) self.subindices = Numeric.argsort(self.inv_subindices) + 1 return # Check that requested sort property exists have_prop = 0 prop_type = 'string' for cprop in self.source.get_schema(): if cprop[0] == sort_property: have_prop = 1 prop_type = cprop[1] if have_prop == 1: self.sort_property = sort_property self.sort_reverse = reverse if (len(self.subset) == 0): ind_list = [] count = 0 if ((prop_type == 'float') or (prop_type == 'integer')): for cshape in self.source: # convert to float so sorting is numeric ind_list.append( (float(cshape.get_property(sort_property)), count)) count = count + 1 else: # sort as a string for cshape in self.source: ind_list.append( (cshape.get_property(sort_property), count)) count = count + 1 ind_list.sort() if self.sort_reverse == 1: ind_list.reverse() self.inv_indices = Numeric.zeros((count, )) for c_ind in range(count): self.inv_indices[c_ind] = ind_list[c_ind][1] self.indices = Numeric.argsort(self.inv_indices) + 1 else: ind_list = [] if ((prop_type == 'float') or (prop_type == 'integer')): count = 0 for cindex in self.subset: ind_list.append((float( self.source[cindex].get_property(sort_property)), count)) count = count + 1 else: count = 0 for cindex in self.subset: ind_list.append( (self.source[cindex].get_property(sort_property), count)) count = count + 1 ind_list.sort() if self.sort_reverse == 1: ind_list.reverse() self.inv_subindices = Numeric.zeros((len(self.subset), )) for c_ind in range(len(self.subset)): self.inv_subindices[c_ind] = ind_list[c_ind][1] self.subindices = Numeric.argsort(self.inv_subindices) + 1 else: print 'Invalid sort property.'
def set_source(self, source, titledict=None, hidden=None): """Set the data source shapes - a GvShapes instance titledict - dictionary of titles for properties (optional) hidden - properties to hide reset all the internal parameters """ self.clear() #trap setting to None or an invalid shapes object if source == None or source._o == None or len(source) == 0: return self.source = source self.source_changed_id = self.source.connect('changed', self.source_changed_cb) self.subset = [] schema = source.get_schema() self.n_cols = len(schema) self.n_rows = len(source) # no shapes initially selected. # Shapes are selected by source index. self.selected_shapes = Numeric.zeros([len(source), 1]) # Sorted position of shape- initially in order of location in source. # Used to map nRow->source index and vice versa. self.indices = Numeric.array(range(len(source))) + 1 self.inv_indices = Numeric.argsort(self.indices) self.sort_reverse = 0 self.subindices = None self.inv_subindices = None self.sort_property = None self.titledict = {} if titledict is None: titledict = {} self._hidden_titles = [] if hidden is not None: for item in hidden: self._hidden_titles.append(item) for i in range(len(schema)): title = schema[i][0] if title not in self._hidden_titles: if titledict.has_key(title): self.titles.append(titledict[title]) self.titledict[titledict[title]] = title else: self.titles.append(title) self.titledict[title] = title #update the scrollbars self.bCalcAdjustments = gtk.TRUE self.expose()
def GetTree( dbhandle, nid, lsequence, table_name_links, resolution, min_length, min_neighbours=None, combine_repeats=None, max_evalue=None, residue_level=None, parser=None, ): ## retrieve blast matrix ## make sure, add_self is 1, so that there are no empty columns blast_matrix = NeighbourTools.BuildBLASTMatrix( dbhandle, nid, resolution, table_name_links, combine_repeats, max_evalue=max_evalue, residue_level=residue_level, parser=parser, add_self=1, ) if param_loglevel >= 3: print "# ------> blast matrix for %i:" % (nid), blast_matrix.shape sys.stdout.flush() MatlabTools.WriteMatrix(blast_matrix, outfile=open("blast_%i.matrix" % nid, "w")) nneighbours, lmatrix = blast_matrix.shape if param_loglevel >= 2: print "# rows in blast matrix for %i: " % (nid), nneighbours sys.stdout.flush() if nneighbours < min_neighbours: return tree ## calculate dot product of the matrix dot_matrix = Numeric.matrixmultiply(Numeric.transpose(blast_matrix), blast_matrix) ## perform some matrix magic if param_multiply: for x in range(0, param_multiply): dot_matrix = Numeric.matrixmultiply(dot_matrix, dot_matrix) if param_loglevel >= 3: MatlabTools.WriteMatrix(dot_matrix, outfile=open("correlation_%i_%i.matrix" % (nid, x), "w")) if param_matrix_loop_fill: MatrixLoopFill(dot_matrix) if param_matrix_add_local_bias: MatrixAddLocalBias(dot_matrix) if param_normalize: MatrixNormalize(dot_matrix, Numeric.sum(blast_matrix)) if param_loglevel >= 3: print "# correlation matrix for %i:" % (nid), dot_matrix.shape MatlabTools.WriteMatrix(dot_matrix, outfile=open("correlation_%i.matrix" % nid, "w")) ## rearrange matrix if necessary map_row_new2old = range(0, lmatrix) if param_permute: row_indices, col_indices = CorrespondenceAnalysis.GetIndices(dot_matrix) if not row_indices: print "# error for %i: correspondence analysis did not converge" % nid else: map_row_new2old = Numeric.argsort(row_indices) dot_matrix = CorrespondenceAnalysis.GetPermutatedMatrix(dot_matrix, map_row_new2old, map_row_new2old) if param_loglevel >= 3: print "# permuted correlation matrix for %i:" % (nid), dot_matrix.shape MatlabTools.WriteMatrix(dot_matrix, outfile=open("permuted_%i.matrix" % nid, "w")) full_range = dot_matrix.shape xtree = SplitMatrix( nid, dot_matrix, (0, lmatrix), 0, int(min_length / resolution), param_min_distance_border, map_row_new2old ) if param_loglevel >= 3: print "# xtree=", xtree sys.stdout.flush() tree = [(0, 0, 0, [(1, lsequence)])] ConvertTreeToList(tree, 0, xtree, lsequence) if param_loglevel >= 3: print "# tree=" for t in tree: print "#", string.join(map(str, t), "\t") return tree
g.ylabel('{/Symbol G t}_w') for v2 in uv2: inds = Numeric.nonzero(Numeric.array(var_list2)==v2) evi = [] evn = [] v1list = [] for v1 in uv1: try: ind = list(Numeric.take(var_list1,inds)).index(v1) except: continue evi.append(get_h0_extrap(Numeric.take(match_num,inds)[ind],matching_files,hexp=hexp)) ind = b.index(v1) evn.append(evi[-1]/ev[ind]) v1list.append(v1) inds = Numeric.argsort(v1list) v1list = Numeric.take(v1list,inds) evi = Numeric.take(evi,inds)*tw evn = Numeric.take(evn,inds)*tw if 'norm' in sys.argv: evi = evn if 'ASH' in sys.argv: #This is the arcsinh scaling for j in range(len(evi)): evi[j] = cmath.asinh(sfi*evi[j]).real if len(v1list)>0: ttl1 = '%s=%g'%(var_key2,v2) if var_key2=='tw': ttl = '{/Symbol t}_w' if v2==-1: ttl1 = "%s={/Symbol \245}"%(ttl) elif v2==0:
import ranlib
print ">>> Symmetry number: %d\n" % sym cell = map(float, cell.split()) refl_file = opReadCl(refl_file_name) hkletc = read_xds_hkl(refl_file, ncol) nrefl = hkletc.shape[0] print ">>> Total number of reflections: ", nrefl S = calc_reso(hkletc[:, :3], cell) # Add a resolution column in the table S.shape = (nrefl, 1) hkletc = Numeric.concatenate((hkletc[:, :5], S), 1) # Sort the table by order of the last column= resolution hkletc = Numeric.take(hkletc, Numeric.argsort(hkletc[:, -1])) if not highest_res: highest_res = hkletc[0, -1] elif highest_res < hkletc[0, -1]: highest_res = hkletc[0, -1] reso_bins = res_bin(highest_res, nbin) reso_bins.insert(0, 999.99) s_bins = 1 / (2 * Numeric.array(reso_bins)) print "\n Resol.\n limit S N <I> <SIGMA> <I/SIGMA>\n" for n in range(nbin): lowr, highr = reso_bins[n], reso_bins[n + 1] select = (lowr > hkletc[:, -1]) * (hkletc[:, -1] >= highr) nselect = Numeric.sum(select) Imean = Numeric.sum(hkletc[:, 3] * select) / nselect
maxx = EV.data['a'] if 'xr' in sys.argv: ind = sys.argv.index('xr') minx = max(0,float(sys.argv[ind+1])) maxx = min(EV.data['a'],float(sys.argv[ind+2])) x = Numeric.arange(minx,maxx,EV.data['a']/(EV.data['ngrid']*N_fac)) coords = ['1','2','3','r'] nc = len(coords) ne = len(evec_nums) xs = 1. dx = xs/nc ys = 1. dy = ys/ne g = Gnuplot.Gnuplot() fn = 'plots/%s.evecs'%num inds = Numeric.argsort(evec_nums) for evec_num in Numeric.take(evec_nums,inds): fn = fn+'_%d'%(evec_num) fn = fn+'.eps' print 'Output to %s'%fn g('set output "%s"'%fn) g('set term postscript eps enhanced dl 2 ') g('set multiplot') g('set size %g,%g'%(dx,dy)) g('set xtics ( 0, "" 0.5,"1" 1)') g('set xrange [0:1]') for j in range(ne): evec_num = evec_nums[j] for i in range(nc): coord = coords[i] if j==ne-1:
for line in infile: if line.find('#') > -1: continue t=line.split() if float(t[0]) < lmin: continue if float(t[0]) > lmax: break wavea.append(float(t[0]))#wavelength in um fluxa.append(float(t[1])) infile.close() wavea=py.array(wavea,'f') fluxa=py.array(fluxa,'f') fluxa=N.take(fluxa,N.argsort(wavea))#sort y according to x rankings wavea=N.take(wavea,N.argsort(wavea)) waveoh=[] fluxoh=[] infile=open('nearIR_skybg_2.dat','r') for line in infile: if line.find('#') > -1: continue t=line.split() if float(t[0])/1000. < lmin: continue if float(t[0])/1000. > lmax: break
print ">>> Symmetry number: %d\n" % sym cell = map(float, cell.split()) refl_file = opReadCl(refl_file_name) hkletc = read_xds_hkl(refl_file, ncol) nrefl = hkletc.shape[0] print ">>> Total number of reflections: ", nrefl S = calc_reso(hkletc[:,:3], cell) # Add a resolution column in the table S.shape = (nrefl,1) hkletc = Numeric.concatenate((hkletc[:,:5],S),1) # Sort the table by order of the last column= resolution hkletc = Numeric.take(hkletc, Numeric.argsort(hkletc[:,-1])) if not highest_res: highest_res = hkletc[0,-1] elif highest_res < hkletc[0,-1]: highest_res = hkletc[0,-1] reso_bins = res_bin(highest_res,nbin) reso_bins.insert(0, 999.99) s_bins = 1/(2*Numeric.array(reso_bins)) print "\n Resol.\n limit S N <I> <SIGMA> <I/SIGMA>\n" for n in range(nbin): lowr, highr = reso_bins[n], reso_bins[n+1] select = (lowr > hkletc[:,-1]) * (hkletc[:,-1] >= highr) nselect = Numeric.sum(select) Imean = Numeric.sum(hkletc[:,3]*select)/nselect
nfacy = 1 if 'tw-1' in sys.argv and var_key=='tw': nfacy = d2.data['tw'] evals = d2.evals if 'wr' in sys.argv: #This is for the range in Re(w) ind = sys.argv.index('wr') wr1 = float(sys.argv[ind+1]) wr2 = float(sys.argv[ind+2]) inds = Numeric.nonzero((evals.real>wr1)*(evals.real<wr2)) evals = Numeric.take(evals,inds) maxunstable.append(max(evals.imag)*nfacy) maxvarlist.append(var_list[i]) if len(maxvarlist)==0: print 'Warning!!! The value of %s=%g is not valid'%(var_key2,v2) continue inds = Numeric.argsort(maxvarlist) maxvarlist = Numeric.take(maxvarlist,inds) maxunstable = Numeric.take(maxunstable,inds) ttl1 = '%s=%g'%(ttl,v2) if var_key2=='tw': if v2==-1: ttl1 = "%s={/Symbol \245}"%(ttl) elif v2==0: ttl1 = "%s=0"%(ttl) else: ttl1 = '%s=10^%d'%(ttl,int((cmath.log10(v2)).real)) elif var_key2=='Vz0': if v2==0: ttl1 = 'V_{z0}=0' else: wA = abs(d2.get_wA())