How to use the statistics.hist_list function in statistics

To help you get started, we’ve selected a few statistics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cryoem / eman2 / sparx / bin / sxgui_cter.py View on Github external
val_list.append(cter_entry[idx_cter])
		
		n_bin = 1
		if len(self.cter_entry_list) < self.curentryperbin:
			self.curentryperbin = len(self.cter_entry_list)
			self.vsentryperbin.setValue(self.curentryperbin)
			# self.vsentryperbin.setRange(1,len(self.cter_entry_list))
		elif self.curentryperbin < 1:
			self.curentryperbin = 1
			self.vsentryperbin.setValue(self.curentryperbin)
			# self.vsentryperbin.setRange(1,len(self.cter_entry_list))
		n_bin = len(self.cter_entry_list)/ self.curentryperbin
		assert len(val_list) >= n_bin
		assert n_bin > 0
		from statistics import hist_list
		hist_x_list, hist_y_list = hist_list(val_list, n_bin)
		
		# Pad with zero for better visual impression...
		hist_x_list += [max(val_list)]
		hist_y_list += [0]
		self.whistparam.set_data((hist_x_list,hist_y_list),"hist_param",quiet=False,color=0,linetype=0,symtype=0)
		
		# MRK_NOTE: 2015/12/17 Toshio Moriya
		# This may NOT be good place to update the following information...
		idx_cter = self.hist_map_list[self.curhist][self.idx_hist_item_idx_cter]
		param_label = self.value_map_list[idx_cter][self.idx_cter_item_label]
		param_val = self.cter_entry_list[self.curentry][idx_cter]
		
		# shape_name = "hist_param_shape_value"
		# scr_x, scr_y = self.whistparam.plot2scr(param_val, 0.0)
		# self.whistparam.add_shape(shape_name,EMShape(("scrline",0,1,0,scr_x,self.whistparam.scrlim[1],scr_x,self.whistparam.scrlim[1]+self.whistparam.scrlim[3],3)))
github cryoem / eman2 / sparx / bin / sxisac2.py View on Github external
### print  "  WRITING refrealigned  for color:",color
            ### for j in xrange(numref):
            ###     refi[j].write_image("refrealigned%02d_round%02d.hdf"%(color, Iter), j)
            #if myid == main_node:  print "within group alignment done. ", localtime()[0:5]

        # end of do_within_group
        mpi.mpi_barrier(comm)

    if myid == main_node:
        #i = [len(q) for q in id_list]
        #for j in xrange(numref):
        #   refi[j].set_attr_dict({'members': id_list[j], 'n_objects': i[j]})
        #del id_list
        i = [refi[j].get_attr("n_objects") for j in range(numref)]
        lhist = max(12, numref/2)
        region, histo = hist_list(i, lhist)
        print("\n=== Histogram of group sizes ================================================")
        for lhx in range(lhist):  print("     %10.1f     %7d"%(region[lhx], histo[lhx]))
        print("=============================================================================\n")

    mpi.mpi_barrier(comm)

    return refi
github cryoem / eman2 / sparx / bin / sxsort3d_P2.py View on Github external
if(center == -1):
				cs[0], cs[1], cs[2], dummy, dummy = estimate_3D_center_MPI(data, total_nima, myid, number_of_proc, main_node)				
				if myid == main_node:
					msg = " Average center x = %10.3f        Center y = %10.3f        Center z = %10.3f"%(cs[0], cs[1], cs[2])
					log.add(msg)
				cs = mpi_bcast(cs, 3, MPI_FLOAT, main_node, MPI_COMM_WORLD)
				cs = [-float(cs[0]), -float(cs[1]), -float(cs[2])]
				rotate_3D_shift(data, cs)
			#output pixel errors
			recvbuf = mpi_gatherv(pixer, nima, MPI_FLOAT, recvcount, disps, MPI_FLOAT, main_node, MPI_COMM_WORLD)
			mpi_barrier(MPI_COMM_WORLD)
			if(myid == main_node):
				recvbuf = map(float, recvbuf)
				from statistics import hist_list
				lhist = 20
				region, histo = hist_list(recvbuf, lhist)
				if(region[0] < 0.0):  region[0] = 0.0
				msg = "      Histogram of pixel errors\n      ERROR       number of particles"
				log.add(msg)
				for lhx in xrange(lhist):
					msg = " %10.3f      %7d"%(region[lhx], histo[lhx])
					log.add(msg)
				del region, histo
			del recvbuf
		fscc = [None]*numref
		if fourvar and runtype=="REFINEMENT":
			sumvol = model_blank(nx, nx, nx)
		start_time = time()
		for iref in xrange(numref):
			#  3D stuff
			from time import localtime, strftime
			if(CTF): volref, fscc[iref] = rec3D_two_chunks_MPI(data, snr, sym, model_circle(last_ring, nx, nx, nx),\
github cryoem / eman2 / sphire / bin / sxwindow.py View on Github external
# ------------------------------------------------------------------------------------
	if options.limit_ctf:
		if RUNNING_UNDER_MPI:
			abs_ctf_limit_histogram = utilities.wrap_mpi_gatherv(abs_ctf_limit_histogram, main_mpi_proc)
		
		if my_mpi_proc_id == main_mpi_proc:
			# Print out the summary of CTF limit absolute frequency
			print(" ")
			print("Global summary of CTF limit absolute frequency (--limit_ctf)...")
			print("Percentage of filtered micrographs: %8.2f" % (len(abs_ctf_limit_histogram) * 100.0 / len(unsliced_valid_serial_id_list)))
			print(" ")
			
			n_bins = 10
			if len(abs_ctf_limit_histogram) >= n_bins:
				pass#IMPORTIMPORTIMPORT from statistics import hist_list
				cutoff_region, cutoff_counts = statistics.hist_list(abs_ctf_limit_histogram, n_bins)
				print("Histogram of CTF limit absolute frequency used for the filtering:")
				print("      CTF limit       counts")
				for bin_id in range(n_bins):
					print(" %14.7f     %7d" % (cutoff_region[bin_id], cutoff_counts[bin_id]))
			else:
				print("The number of filtered micrographs (%d) is less than the number of bins (%d). No histogram is produced." % (len(abs_ctf_limit_histogram), n_bins))
	
	# ------------------------------------------------------------------------------------
	# Print out summary of processing
	# ------------------------------------------------------------------------------------
	if RUNNING_UNDER_MPI:
		n_mic_process = mpi.mpi_reduce(n_mic_process, 1, mpi.MPI_INT, mpi.MPI_SUM, main_mpi_proc, mpi.MPI_COMM_WORLD)
		n_mic_reject_no_coords_entry = mpi.mpi_reduce(n_mic_reject_no_coords_entry, 1, mpi.MPI_INT, mpi.MPI_SUM, main_mpi_proc, mpi.MPI_COMM_WORLD)
		n_global_coords_detect = mpi.mpi_reduce(n_global_coords_detect, 1, mpi.MPI_INT, mpi.MPI_SUM, main_mpi_proc, mpi.MPI_COMM_WORLD)
		n_global_coords_process = mpi.mpi_reduce(n_global_coords_process, 1, mpi.MPI_INT, mpi.MPI_SUM, main_mpi_proc, mpi.MPI_COMM_WORLD)
		n_global_coords_reject_out_of_boundary = mpi.mpi_reduce(n_global_coords_reject_out_of_boundary, 1, mpi.MPI_INT, mpi.MPI_SUM, main_mpi_proc, mpi.MPI_COMM_WORLD)
github cryoem / eman2 / sparx / libpy / multi_shc.py View on Github external
#=========================================================================
			#output pixel errors, check stop criterion
			all_pixer = wrap_mpi_gatherv(pixer, 0, mpi_comm)
			par_r = mpi_reduce(par_r, len(par_r), MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD)
			#total_checked_refs = wrap_mpi_gatherv([number_of_checked_refs], main_node, mpi_comm)
			terminate = 0
			if myid == main_node:
				#total_checked_refs = sum(total_checked_refs)
				log.add("=========== Number of better peaks found ==============")
				for lhx in range(nsoft+1):
					msg = "            %5d     %7d"%(lhx, par_r[lhx])
					log.add(msg)
				log.add("_______________________________________________________")

				lhist = 20
				region, histo = hist_list(all_pixer, lhist)
				log.add("=========== Histogram of pixel errors ==============")
				for lhx in range(lhist):
					msg = "          %10.3f     %7d"%(region[lhx], histo[lhx])
					log.add(msg)
				log.add("____________________________________________________")
				if (max(all_pixer) < 0.5) and (sum(all_pixer)/total_nima < 0.05):
					terminate = 1
					log.add("...............")
					log.add(">>>>>>>>>>>>>>>   Will terminate due to small pixel errors")
			terminate = wrap_mpi_bcast(terminate, main_node, mpi_comm)
			#=========================================================================

			#=========================================================================
			# centering
			if center == -1 and sym[0] == 'c':
				from utilities      import estimate_3D_center_MPI, rotate_3D_shift
github cryoem / eman2 / sparx / bin / sxisac2.py View on Github external
if( (agreement>0.5) and (j > 0.0) and (j < 0.05) ): 
                        terminate = 1
                    
                    previous_agreement = agreement
                    print(">>>  Assignment agreement with previous iteration  %5.1f"%(agreement*100),"   ",time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()))
                
                terminate = spx.bcast_number_to_all(terminate, source_node = main_node)


            if( check_stability and ( (main_iter == max_iter) or (terminate == 1) ) ):
                #  gather all pixers and print a histogram
                gpixer = spx.wrap_mpi_gatherv(gpixer, main_node, comm)
                if my_abs_id == main_node and color == 0:
                    
                    lhist = 12
                    region, histo = hist_list(gpixer, lhist)
                    print("\n=== Histogram of average within-class pixel errors prior to class pruning ===")
                    for lhx in range(lhist): print("     %10.3f     %7d"%(region[lhx], histo[lhx]))
                    print("=============================================================================\n")

                del gpixer


            ###if myid == main_node:
            ### print  "  WRITING refrealigned  for color:",color
            ### for j in xrange(numref):
            ###     refi[j].write_image("refrealigned%02d_round%02d.hdf"%(color, Iter), j)
            #if myid == main_node:  print "within group alignment done. ", localtime()[0:5]

        # end of do_within_group
        mpi.mpi_barrier(comm)
github cryoem / eman2 / sparx / bin / sxsort3d_P2.py View on Github external
cs[0], cs[1], cs[2], dummy, dummy = estimate_3D_center_MPI(data, total_nima, myid, number_of_proc, main_node)				
				if myid == main_node:
					msg = " Average center x = %10.3f        Center y = %10.3f        Center z = %10.3f"%(cs[0], cs[1], cs[2])
					log.add(msg)
				cs = mpi_bcast(cs, 3, MPI_FLOAT, main_node, MPI_COMM_WORLD)
				cs = [-float(cs[0]), -float(cs[1]), -float(cs[2])]
				rotate_3D_shift(data, cs)
			#output pixel errors
			from mpi import mpi_gatherv
			recvbuf = mpi_gatherv(pixer, nima, MPI_FLOAT, recvcount, disps, MPI_FLOAT, main_node, MPI_COMM_WORLD)
			mpi_barrier(MPI_COMM_WORLD)
			if myid == main_node:
				recvbuf = map(float, recvbuf)
				from statistics import hist_list
				lhist = 20
				region, histo = hist_list(recvbuf, lhist)
				if region[0] < 0.0:  region[0] = 0.0
				msg = "      Histogram of pixel errors\n      ERROR       number of particles"
				log.add(msg)
				for lhx in xrange(lhist):
					msg = " %10.3f      %7d"%(region[lhx], histo[lhx])
					log.add(msg)
				del region, histo
			del recvbuf

		#if CTF: del vol
		fscc = [None]*numref

		if fourvar and runtype=="REFINEMENT":
			sumvol = model_blank(nx, nx, nx)

		sart_time = time()
github cryoem / eman2 / sparx / bin / sxhelixboxer.py View on Github external
if len(hcoords_dir) > 0: hcoordsname = os.path.join(hcoords_dir, hcoordsname)
				else:                    hcoordsname = os.path.join(v1, hcoordsname)
				# If any helices were boxed from this micrograph, say mic0, then ALL the helix coordinates should be saved under mic0 + hcoords_suffix
				# For example, if using default sxhelixboxer naming convention, then coordinates of all helices boxed in mic0 would be in mic0_boxes.txt
				if( os.path.exists(hcoordsname) ):
					micname = os.path.join(v1, v2)
					lenmicnames += 1
					utilities.print_msg("\n\nPreparing to window helices from micrograph %s with box coordinate file %s\n\n"%(micname, hcoordsname))
					#windowmic(outstacknameall, coutdir, micname, hcoordsname, pixel_size, boxsize, ptcl_dst, minseg, inv_contrast, new_pixel_size, rmaxp, freq, do_rotation, do_gridding, importctf, cterr)
					windowmic(outstacknameall, v1, coutdir, micname, hcoordsname, pixel_size, boxsize, ptcl_dst, minseg, inv_contrast, new_pixel_size, rmaxp, freq, do_rotation, do_gridding, importctf, limitctf, cterr, cutoffhistogram)  ##changed by @ming 
	
	if len(cutoffhistogram) > 0:		#@ming
		lhist = 3
		if len(cutoffhistogram) >= lhist:
			pass#IMPORTIMPORTIMPORT from statistics import hist_list
			region,hist = statistics.hist_list(cutoffhistogram,lhist)	
			msg = "      Histogram of cut off frequencies\n      ERROR       number of frequencies\n"
			utilities.print_msg(msg)
			for lhx in range(len(lhist)):
				msg = " %10.3f     %7d\n"%(region[lhx], hist[lhx])
				utilities.print_msg(msg)
		utilities.print_msg('The percentage of micrographs filtered by the cutoff frequency: %6f\n' % (len(cutoffhistogram)*1.0/lenmicnames))		
	# If not debug mode, then remove all output directories 				
	if debug == 0:
		pass#IMPORTIMPORTIMPORT from subprocess import call
		for coutdir in outdirlist:
			cmd = "rm -ir %s"%coutdir
			utilities.print_msg("cmd: %s"%cmd)
			subprocess.call(cmd, shell=True)