def producerLoop(exclusiveUnprocessedFileQueue, processedHistogramBuffer, numProducers):
    '''
    loops through, each time grabs a file from the unprocessed queue
    and creates an individual histogram for that file.
    Then adds that histogram to the processed buffer
    for the consumer to acess
    '''
    global doneProducing

    #while not doneProducing:
    while not exclusiveUnprocessedFileQueue.isEmpty():    
        fileToProcess = exclusiveUnprocessedFileQueue.pop()

        if fileToProcess != None:  #none returned if unprocessed q was empty
            #makes individual file histogram
            fileHistogram = Histogram(fileToProcess)   
            fileHistogram.buildHistogram()
            processedHistogramBuffer.add(fileHistogram)
            itemsAvailable.release()
        else:
            continue

        producerProcessedLock.acquire()
        if exclusiveUnprocessedFileQueue.isEmpty() and not doneProducing:
            doneProducing = 1
        producerProcessedLock.release()
    #tells consumer that a thread is done processing
    itemsAvailable.release()
Exemplo n.º 2
0
def _get_ping_property(cursor, path, histograms_url, additional_histograms):
    is_histogram = False
    is_keyed_histogram = False

    if path[0] == "histograms":
        is_histogram = True
    elif path[0] == "keyedHistograms":
        # Deal with histogram names that contain a slash...
        path = path[:2] + (["/".join(path[2:])] if len(path) > 2 else [])
        is_keyed_histogram = True

    try:
        for field in path:
            cursor = cursor[field]
    except:
        return None

    if cursor is None:
        return None
    if is_histogram:
        return Histogram(path[-1],
                         cursor,
                         histograms_url=histograms_url,
                         additional_histograms=additional_histograms)
    elif is_keyed_histogram:
        histogram = Histogram(path[-2],
                              cursor,
                              histograms_url=histograms_url,
                              additional_histograms=additional_histograms)
        histogram.name = "/".join(path[-2:])
        return histogram
    else:
        return cursor
Exemplo n.º 3
0
    def test_histograms(self):
        ftmp = NamedTemporaryFile(suffix='.h5', delete=False)
        try:
            ftmp.close()
            hh = dict(h0=Histogram(3, [0, 1]),
                      h1=Histogram(3, [0, 1], data=[-1, 0, 2]),
                      h2=Histogram(3, [0, 1],
                                   data=[-1, 0, 2],
                                   uncert=[0.5, -0.2, 1000.]),
                      h3=Histogram(3, [0, 1], label='counts'),
                      h4=Histogram(3, [0, 1], label='counts', title='title'),
                      h5=Histogram(3, [0, 1], 4, [-1, 1]),
                      h6=Histogram(3, [0, 1],
                                   2, [-1, 1],
                                   data=[[1, 2], [3, 4], [5, 6]]),
                      h7=Histogram(3, [0, 1],
                                   2, [-1, 1],
                                   data=[[1, 2], [3, 4], [5, 6]],
                                   uncert=[[1, 2], [3, 4], [5, 6]]),
                      h8=Histogram(3, [0, 1], 2, [-1, 1], label='counts'),
                      h9=Histogram(3, [0, 1],
                                   2, [-1, 1],
                                   label='counts',
                                   title='τιτλε'))

            save_histograms(hh, ftmp.name)
            hhtmp = load_histograms(ftmp.name)
            #histogram.serialization.serialization.save_histograms(hh, ftmp.name)
            #hhtmp = histogram.serialization.serialization.load_histograms(ftmp.name)

            for k in sorted(hh):
                self.assertTrue(hh[k].isidentical(hhtmp[k]))

        finally:
            os.remove(ftmp.name)
Exemplo n.º 4
0
    def __init__(self,
                 world,
                 filename=None,
                 simulator=None,
                 once=False,
                 headless=False):
        logging.info('Initialising vision')
        if simulator:
            self.capture = SimCapture(simulator)
        else:
            self.capture = Capture(self.rawSize, filename, once)

        self.headless = headless

        self.threshold = threshold.AltRaw()
        self.pre = Preprocessor(self.rawSize, self.threshold, simulator)
        self.featureEx = FeatureExtraction(self.pre.cropSize)
        self.interpreter = Interpreter()
        self.world = world
        self.gui = GUI(world, self.pre.cropSize, self.threshold)
        self.histogram = Histogram(self.pre.cropSize)

        self.times = []
        self.N = 0

        #debug.thresholdValues(self.threshold.Tblue, self.gui)

        logging.debug('Vision initialised')
Exemplo n.º 5
0
    def update(self, iterable):
        """Update this histogram with the items in the given iterable"""
        for sentence in iterable:

            # First word in sentence (start)
            previous_words = self._generate_empty_previous_words()

            # Run through the sentence
            for index, word in enumerate(sentence):

                current_key = tuple(previous_words)

                if self.get(current_key) is not None:
                    self[current_key].insert(word)
                else:
                    self[current_key] = Histogram()
                    self[current_key].insert(word)

                previous_words.pop(0)
                previous_words.append(word)

            # End of sentence
            current_key = tuple(previous_words)
            if self.get(current_key) is None:
                self[current_key] = Histogram()
            self[current_key].insert("*STOP*")
Exemplo n.º 6
0
def create_histogram():
    parent_filename = request.json[PARENT_FILENAME_NAME]
    histogram_filename = request.json[HISTOGRAM_FILENAME_NAME]
    fields_name = request.json[FIELDS_NAME]

    request_errors = analyse_request_errors(request_validator, parent_filename,
                                            histogram_filename, fields_name)

    if request_errors is not None:
        return request_errors

    histogram = Histogram(database, metadata)

    histogram.create_file(
        parent_filename,
        histogram_filename,
        fields_name,
    )

    return (
        jsonify({
            MESSAGE_RESULT:
            f'{MICROSERVICE_URI_GET}{histogram_filename}'
            f'{MICROSERVICE_URI_GET_PARAMS}'
        }),
        HTTP_STATUS_CODE_SUCCESS_CREATED,
    )
Exemplo n.º 7
0
    def test_cut_2d(self):
        h2 = Histogram((100,[0,10]),(90,[-3,3]))
        #h2a = h2.cut((-1,1),axis=0)

        h3 = Histogram((100,[-30,330]), (100,[-50,50]))
        #h3a = h3.cut(-30,30,axis=0)
        h3b = h3.cut(270,330,axis=0)
Exemplo n.º 8
0
def _get_ping_property(cursor, path, histograms_url, additional_histograms):
    is_histogram = False
    is_keyed_histogram = False

    if path[0] == "histograms":
        is_histogram = True
    elif path[0] == "keyedHistograms":
        # Deal with histogram names that contain a slash...
        path = path[:2] + (["/".join(path[2:])] if len(path) > 2 else [])
        is_keyed_histogram = True

    try:
        for field in path:
            cursor = cursor[field]
    except:
        return None

    if cursor is None:
        return None
    if is_histogram:
        return Histogram(path[-1], cursor, histograms_url=histograms_url,
                         additional_histograms=additional_histograms)
    elif is_keyed_histogram:
        histogram = Histogram(path[-2], cursor, histograms_url=histograms_url,
                              additional_histograms=additional_histograms)
        histogram.name = "/".join(path[-2:])
        return histogram
    else:
        return cursor
Exemplo n.º 9
0
def _get_ping_property(cursor, path):
    is_histogram = False
    is_keyed_histogram = False

    if path[0] == "histograms":
        is_histogram = True
    elif path[0] == "keyedHistograms":
        # Deal with histogram names that contain a slash...
        path = path[:2] + (["/".join(path[2:])] if len(path) > 2 else [])
        is_keyed_histogram = True

    for partial in path:
        cursor = cursor.get(partial, None)

        if cursor is None:
            break

    if cursor is None:
        return None
    if is_histogram:
        return Histogram(path[-1], cursor)
    elif is_keyed_histogram:
        histogram = Histogram(path[-2], cursor)
        histogram.name = "/".join(path[1:])
        return histogram
    else:
        return cursor
Exemplo n.º 10
0
def parse_input(target_sequence: str, input_fasta_file: str) -> None:
    """
    parse_input

    :param target_sequence: The target sequence as a string.
    :param input_fasta_file: The path to a FASTA file.
    """

    if not Helpers.valid_dna_sequence(target_sequence):
        raise click.UsageError(
            'The target sequence is not a valid DNA sequence.')

    input_sequence = Helpers.fasta_file_to_sequence(input_fasta_file)
    if not input_sequence:
        raise click.UsageError('Passed input file not in FASTA format.')

    optimal_alignment_finder = OptimalAlignmentFinder(target_sequence,
                                                      input_sequence)

    # If the results directory doesn't exist, create it.
    if not os.path.exists(RESULTS_DIRECTORY):
        os.makedirs(RESULTS_DIRECTORY)

    Alignment.save_alignments(f'{RESULTS_DIRECTORY}forward_alignments.json',
                              optimal_alignment_finder.forward_alignments)
    Histogram.save_histograms(optimal_alignment_finder.forward_alignments,
                              True)

    Alignment.save_alignments(
        f'{RESULTS_DIRECTORY}reverse_complement_alignments.json',
        optimal_alignment_finder.reverse_complement_alignments)
    Histogram.save_histograms(
        optimal_alignment_finder.reverse_complement_alignments, False)
Exemplo n.º 11
0
def compute_color_histograms(cloud, using_hsv=True):

    # Compute histograms for the clusters
    point_colors_list = []

    # Step through each point in the point cloud
    for point in pc2.read_points(cloud, skip_nans=True):
        rgb_list = float_to_rgb(point[3])  # rgb_list is [r,g,b]
        if using_hsv:
            point_colors_list.append(rgb_to_hsv(rgb_list) * 255)
        else:
            point_colors_list.append(rgb_list)

    # Populate lists with color values
    channel_1_vals = []
    channel_2_vals = []
    channel_3_vals = []

    for color in point_colors_list:
        channel_1_vals.append(color[0])
        channel_2_vals.append(color[1])
        channel_3_vals.append(color[2])

    a = Histogram(channel_1_vals, channel_2_vals, channel_3_vals)

    normed_features = a.generate_normalised_concatenated_histogram()

    return normed_features
Exemplo n.º 12
0
	def __init__(self, dates, open, high, low, close, vol, start, end):
		
		if start > end:
			(start, end) = (end, start)
		
		self.report_log = []    
		
		max = None
		max_date = None
		min = None
		min_date = None
		
		seq_start = dates[0]
		seq_end = dates[0]
		
		series = []
		
		n = 0
	 
		for i in range(len(dates)):    
		 
			d = dates[i]
			if (d > start) and (d < end):      
				
				series.append(close[i])
				
				if (d < seq_start):
					seq_start = d
				if (d > seq_end):
					seq_end = d

				n = n + 1 
				
				h = high[i]
				if max == None:
					max = h
					max_date = d
				else:
					if h > max:
						max = h
						max_date = d
						
				l = low[i]
				if min == None:
					min = l
					min_date = d
				else:
					if l < min:
						min = l
						min_date = d
		
		self.report_log.append('%s - %s' % (seq_start, seq_end))
		self.report_log.append('%d trading days' % n)
		self.report_log.append('Max = %s - %s' % (str(max), max_date))
		self.report_log.append('Min = %s - %s' % (str(min), min_date))
		
		h = Histogram(series)
		for l in h.report():
			self.report_log.append(l)
Exemplo n.º 13
0
 def test_hist_1d_line(self):
     rand.seed(1)
     h = Histogram(40, [0, 1], 'χ (cm)', 'counts', 'Some Data')
     h.fill(rand.normal(0.5, 0.1, 300))
     fig, ax = plt.subplots()
     pt = ax.plothist(h, style='line')
     self.assertTrue(
         conf.comparator.compare_images(fig.savefig, 'hist_1d_line.png'))
Exemplo n.º 14
0
 def load_hue_histograms(self):
     for h in self.known_histograms.keys():
         hist = Histogram()
         hist.load(self.known_histograms[h][0])
         self.known_histograms[h][1] = hist
     for h in self.known_histograms:
         print h
         print self.known_histograms[h][1]
Exemplo n.º 15
0
 def test_hist_4d(self):
     ftmp = NamedTemporaryFile(suffix='.root', delete=False)
     try:
         h = Histogram(3, [0, 1], 3, [0, 1], 3, [0, 1], 3, [0, 1])
         with self.assertRaises(ValueError):
             h.save(ftmp.name)
     finally:
         os.remove(ftmp.name)
Exemplo n.º 16
0
 def test_hist_2d(self):
     rand.seed(1)
     h = Histogram(40, [0, 1], 'χ (cm)', 30, [-5, 5], 'ψ', 'counts',
                   'Some Data')
     h.fill(rand.normal(0.5, 0.1, 1000), rand.normal(0, 1, 1000))
     fig, ax = plt.subplots()
     pt = ax.plothist(h)
     self.assertTrue(
         conf.comparator.compare_images(fig.savefig, 'hist_2d.png'))
Exemplo n.º 17
0
def test_plot_hist2d():
    npoints = 100000
    h2 = Histogram((100, (0, 10), 'x'), (100, (0, 10), 'y'), 'z', 'title')
    h2.fill(rand.normal(5, 2, npoints), rand.uniform(0, 10, npoints))
    fig, ax = pyplot.subplots(1, 2)
    ax[0].plothist(h2)
    ax[1].plothist(h2)
    ax[1].plothist(h2.smooth(1), style='contour', overlay=True)

    pyplot.savefig('test_images/test_plotting_fig_hist2d.png')
Exemplo n.º 18
0
    def test_1dfit(self):
        p = [100, -20, 1, -0.2]
        h = Histogram(100, [0, 10])
        x = h.axes[0].bincenters
        h.data = poly(p)(x) + rand.normal(0, np.sqrt(p[0]), len(x))

        p0 = [1, 1, 1, 1]
        popt, pcov, ptest = h.fit(lambda x, *p: poly(p)(x), p0)

        assert np.allclose(popt, p, rtol=0.03, atol=0.5)
        assert pcov.shape == (len(p), len(p))
Exemplo n.º 19
0
def test_plot_hist2d():
    npoints = 100000
    h2 = Histogram((100,(0,10),'x'),(100,(0,10),'y'),'z','title')
    h2.fill(rand.normal(5,2,npoints),
            rand.uniform(0,10,npoints))
    fig,ax = pyplot.subplots(1,2)
    ax[0].plothist(h2)
    ax[1].plothist(h2)
    ax[1].plothist(h2.smooth(1), style='contour', overlay=True)

    pyplot.savefig('test_images/test_plotting_fig_hist2d.png')
def main():

    instanceHistogram = Histogram("ABCDF")
    dataset = open('score_transcript.txt', "r")

    for each_line in dataset:
        letter_grade = scoreToLetterGrade(int(each_line))
        instanceHistogram.increaseCount(letter_grade)

    # when for loop exit, the five category have finished their statistic, ready for subsequently display
    gen_chart(instanceHistogram)
Exemplo n.º 21
0
    def __init__(self):
        # Variables for the graph
        ranging_variable = "Services"
        frequency = "People Count"
        report_name = "Different Referral Services"
        # Get the dataframe from query
        df = self.get_data(ranging_variable, frequency)

        # Create graph and display
        his = Histogram(df, ranging_variable, frequency, title=report_name)
        his.display()
Exemplo n.º 22
0
    def test_1dfit(self):
        p = [100, -20, 1, -0.2]
        h = Histogram(100, [0, 10])
        x = h.axes[0].bincenters
        h.data = poly(p)(x) + rand.normal(0, np.sqrt(p[0]), len(x))

        p0 = [1, 1, 1, 1]
        popt, pcov, ptest = h.fit(lambda x, *p: poly(p)(x), p0)

        assert np.allclose(popt, p, rtol=0.03, atol=0.5)
        assert pcov.shape == (len(p), len(p))
Exemplo n.º 23
0
def test_plot_hist1d():
    npoints = 100000
    h1 = Histogram(100, (0, 10), 'x', 'y', 'title')
    h1.fill(rand.normal(5, 2, npoints))

    fig, ax = pyplot.subplots(2, 2)
    ax[0, 0].plothist(h1, style='polygon', baseline='bottom')
    ax[0, 1].plothist(h1, style='errorbar', baseline='bottom')
    ax[1, 0].plothist(h1, style='polygon')  #, baseline='left')
    ax[1, 1].plothist(h1, style='errorbar')  #, baseline='left')

    pyplot.savefig('test_images/test_plotting_fig_hist1d.png')
Exemplo n.º 24
0
 def test_hist_3d(self):
     h = Histogram(3, [0, 1], 'xx', 4, [-1, 1], 'yy', 5, [5, 10], 'zz',
                   'counts', 'data')
     ftmp = NamedTemporaryFile(suffix='.root', delete=False)
     try:
         ftmp.close()
         with warnings.catch_warnings(record=True) as w:
             h.save(ftmp.name)
         self.assertEqual(len(w), 1)
         self.assertRegex(str(w[-1].message), 'label')
     finally:
         os.remove(ftmp.name)
Exemplo n.º 25
0
def test_plot_hist1d():
    npoints = 100000
    h1 = Histogram(100,(0,10),'x','y','title')
    h1.fill(rand.normal(5,2,npoints))

    fig,ax = pyplot.subplots(2,2)
    ax[0,0].plothist(h1, style='polygon' , baseline='bottom')
    ax[0,1].plothist(h1, style='errorbar', baseline='bottom')
    ax[1,0].plothist(h1, style='polygon' )#, baseline='left')
    ax[1,1].plothist(h1, style='errorbar')#, baseline='left')

    pyplot.savefig('test_images/test_plotting_fig_hist1d.png')
class HistogramTest(unittest.TestCase):

    def setUp(self):
        self.h = Histogram()
        self.h.add("Apache")
        self.h.add("Apache")

    def test_add(self):
        assert self.h.get_dict().get("Apache") is not None

    def test_count(self):
        self.assertEqual(self.h.count("Apache"), 2)
Exemplo n.º 27
0
    def test_2dfit(self):
        fn = lambda xy, *p: poly(p[:4])(xy[0]) + poly([0] + list(p[4:]))(xy[1])
        p = [100, -20, 1, -0.2, 80, -5, 0.8]
        h = Histogram(100, [0, 10], 100, [0, 10])
        xy = h.grid
        h.data = fn(xy, *p)
        h.data += rand.normal(0, np.sqrt(p[0]), h.data.shape)

        p0 = [1, 1, 1, 1, 1, 1, 1]
        popt, pcov, ptest = h.fit(fn, p0)

        assert np.allclose(popt, p, rtol=0.01, atol=0.01)
        assert pcov.shape == (len(p), len(p))
Exemplo n.º 28
0
    def test_2dfit(self):
        fn = lambda xy, *p: poly(p[:4])(xy[0]) + poly([0] + list(p[4:]))(xy[1])
        p = [100, -20, 1, -0.2, 80, -5, 0.8]
        h = Histogram(100, [0, 10], 100, [0, 10])
        xy = h.grid
        h.data = fn(xy, *p)
        h.data += rand.normal(0, np.sqrt(p[0]), h.data.shape)

        p0 = [1, 1, 1, 1, 1, 1, 1]
        popt, pcov, ptest = h.fit(fn, p0)

        assert np.allclose(popt, p, rtol=0.01, atol=0.01)
        assert pcov.shape == (len(p), len(p))
Exemplo n.º 29
0
def plt_manual(xx):
    print(len(xx))
    xxx = []
    for i in range(len(xx)):
        manual_data = (x_pool[xx[i]],y_pool[xx[i]],t_pool[xx[i]],i_pool[xx[i]])
        histogram = Histogram(manual_data)
        histogram.createImage()
        y_pool[xx[i]] = histogram.result
        print(y_pool[xx[i]])
        if y_pool[xx[i]] != cf.NONE_SENSE_DATA_TYPE:
            xxx.append(xx[i])
        print(y_pool[xx[i]])

    return np.array(xxx)
Exemplo n.º 30
0
    def test_1dfit_zeros(self):
        p = [100, -20, 1, -0.2]
        h = Histogram(100, [0, 10])
        x = h.axes[0].bincenters
        h.data = poly(p)(x) + rand.normal(0, np.sqrt(p[0]), len(x))

        ii = rand.randint(0, h.axes[0].nbins, 5)
        h.data[ii] = 0

        p0 = [1, 1, 1, 1]
        popt, pcov, ptest = h.fit(lambda x, *p: poly(p)(x), p0)

        assert np.allclose(popt, p, rtol=0.1, atol=1.)
        assert pcov.shape == (len(p), len(p))
Exemplo n.º 31
0
    def test_1dfit_zeros(self):
        p = [100, -20, 1, -0.2]
        h = Histogram(100, [0, 10])
        x = h.axes[0].bincenters
        h.data = poly(p)(x) + rand.normal(0, np.sqrt(p[0]), len(x))

        ii = rand.randint(0, h.axes[0].nbins, 5)
        h.data[ii] = 0

        p0 = [1, 1, 1, 1]
        popt, pcov, ptest = h.fit(lambda x, *p: poly(p)(x), p0)

        assert np.allclose(popt, p, rtol=0.1, atol=1.0)
        assert pcov.shape == (len(p), len(p))
def make_histo(reads):
    '''Given a dict of reads keyed by sequence, create a Histogram
  object summarising the distribution of duplicated reads.'''
    LOGGER.debug("making histogram...")
    total = 0
    histo = Histogram()
    for read in reads.iterkeys():
        histo.add(reads[read])
        if reads[read] >= 1000:
            sys.stdout.write("%s\t%d\n" % (read, reads[read]))
        total += 1
        if total % 100000 == 0 and ISATTY:
            sys.stderr.write("%9d\r" % (total, ))
    return histo
Exemplo n.º 33
0
def create_histogram(parent_filename):
    database = MongoOperations(
        collection_database_url(os.environ[DATABASE_URL],
                                os.environ[DATABASE_REPLICA_SET]),
        os.environ[DATABASE_PORT],
        os.environ[DATABASE_NAME],
    )

    request_validator = HistogramRequestValidator(database)

    try:
        request_validator.histogram_filename_validator(
            request.json[HISTOGRAM_FILENAME_NAME])
    except Exception as invalid_histogram_filename:
        return (
            jsonify({
                MESSAGE_RESULT:
                invalid_histogram_filename.args[FIRST_ARGUMENT]
            }),
            HTTP_STATUS_CODE_CONFLICT,
        )

    try:
        request_validator.filename_validator(parent_filename)
    except Exception as invalid_filename:
        return (
            jsonify({MESSAGE_RESULT: invalid_filename.args[FIRST_ARGUMENT]}),
            HTTP_STATUS_CODE_NOT_ACCEPTABLE,
        )

    try:
        request_validator.fields_validator(parent_filename,
                                           request.json[FIELDS_NAME])
    except Exception as invalid_fields:
        return (
            jsonify({MESSAGE_RESULT: invalid_fields.args[FIRST_ARGUMENT]}),
            HTTP_STATUS_CODE_NOT_ACCEPTABLE,
        )

    histogram = Histogram(database)
    histogram.create_histogram(
        parent_filename,
        request.json[HISTOGRAM_FILENAME_NAME],
        request.json[FIELDS_NAME],
    )

    return (
        jsonify({MESSAGE_RESULT: MESSAGE_CREATED_FILE}),
        HTTP_STATUS_CODE_SUCESS_CREATED,
    )
Exemplo n.º 34
0
    def getHistogramViews(self):
        """
        Return a list of the histogram views defined by the layout.
        If there is more than one histogram view in the current
        application layout, each one can be accessed via its own element
        in the list. For example, if there are 3 histogram views in the
        GUI, the following sequence of commands can be used to set a
        different clip range percent in each one:

            h = v.getHistogramViews()
            h[0].setClipRangePercent(1, 99)
            h[1].setClipRangePercent(5, 95)
            h[2].setClipRangePercent(0.1, 99.9)

        Returns
        -------
        list
            A list of Histogram objects.
        """
        commandStr = "getHistogramViews"
        histogramViewsList = self.con.cmdTagList(commandStr)
        histogramViews = []
        if (histogramViewsList[0] != ""):
            for hv in histogramViewsList:
                histogramView = Histogram(hv, self.con)
                histogramViews.append(histogramView)
        return histogramViews
Exemplo n.º 35
0
class Dictogram(dict):
    def __init__(self, text_file=None):

        self.histogram = None
        if text_file is not None:
            self.histogram = Histogram(text_file)
            self.create_dictogram()

    def create_dictogram(self):
        if self.histogram is not None:
            for index, word in enumerate(self.histogram.words_list):
                if index + 1 > len(self.histogram.words_list) - 1:
                    return
                next_word = self.histogram.words_list[index + 1]

                if word not in self:
                    self[word] = {}
                    histogram = Histogram()
                    #pdb.set_trace()
                    #histogram = {next_word:0}

                    self[word] = histogram.add(next_word)
                else:
                    self.histogram = self[word]
                    self[word] = self.histogram.add(next_word)
Exemplo n.º 36
0
    def __init__(self, jsonDict):
        self.index = 1
        self.title = ""
        self.xtitle = ""
        self.ytitle = ""

        self.__dict__ = jsonDict

        self.items = []
        if "__items__" in jsonDict:
            for item in jsonDict["__items__"]:
                if item["type"] == "Line2D":
                    self.items.append(Line2D(item))
                elif item["type"] == "Point2D":
                    self.items.append(Line2D(item))
                elif item["type"] == "Histogram":
                    self.items.append(Histogram(item))
                elif item["type"] == "Text":
                    self.items.append(Text(item))
                elif item["type"] == "Annotation":
                    self.items.append(Annotation(item))
                elif item["type"] == "Hline":
                    self.items.append(Hline(item))
                elif item["type"] == "Vline":
                    self.items.append(Vline(item))
                elif item["type"] == "Arc":
                    self.items.append(Arc(item))

        if "grid" in jsonDict:
            self.grid = Grid(jsonDict["grid"])
        else:
            self.grid = Grid()
Exemplo n.º 37
0
    def create_dictogram(self):
        if self.histogram is not None:
            for index, word in enumerate(self.histogram.words_list):
                if index + 1 > len(self.histogram.words_list) - 1:
                    return
                next_word = self.histogram.words_list[index + 1]

                if word not in self:
                    self[word] = {}
                    histogram = Histogram()
                    #pdb.set_trace()
                    #histogram = {next_word:0}

                    self[word] = histogram.add(next_word)
                else:
                    self.histogram = self[word]
                    self[word] = self.histogram.add(next_word)
 def get_histogram(self, node_index, feature_index, class_key):
     if node_index not in self.histograms:
         self.histograms[node_index] = dict()
     if feature_index not in self.histograms[node_index]:
         self.histograms[node_index][feature_index] = dict()
     if class_key not in self.histograms[node_index][feature_index]:
         self.histograms[node_index][feature_index][class_key] = Histogram(self.bins_count)
     return self.histograms[node_index][feature_index][class_key]
Exemplo n.º 39
0
    def test_unicode(self):
        ftmp = NamedTemporaryFile(suffix='.root', delete=False)
        try:
            ftmp.close()
            h = Histogram(3, [0, 3])
            h.data[:] = [-3, 0, 5]
            h.uncert = np.sqrt(np.abs(
                h.data))  # ROOT will always return uncert
            h.title = 'χ-squared'
            h.label = 'αβγ'
            h.axes[0].label = 'θ'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

        finally:
            os.remove(ftmp.name)
Exemplo n.º 40
0
def reports(scanner):
    if args.excel:
        rp = ReportCreator(scanner.get_report_list(), dirs['reports'])
        rp.excel_report()
    if args.graph:
        try:
            from graphcreator import ToGraph
            graph = ToGraph(scanner.get_report_list())
            graph.write_graph()
        except ImportError as exc:
            logger.exception(exc)
            print(
                "You need graph-tool installed to draw a graph, please visit https://graph-tool.skewed.de/"
            )
    if args.histogram:
        ist = Histogram(scanner.get_report_list())
        ist.create_histogram()
Exemplo n.º 41
0
def show_distribution(quicktipp, two_dee):
    if two_dee:
        from histogram import Histogram2d
        histogram = Histogram2d()
    else:
        from histogram import Histogram
        histogram = Histogram()
    histogram.tipps(q.get())
    histogram.skipped(q.get_skipped())
    histogram.show()
Exemplo n.º 42
0
    def test_mean(self):
        h = Histogram(10,[0,10])
        h.fill([3,3,3])
        assert_almost_equal(h.mean()[0],3.5)

        h.fill([1,5])
        assert_almost_equal(h.mean()[0],3.5)
Exemplo n.º 43
0
 def test_rebin(self):
     h = Histogram(10,[0,10])
     h.set(1)
     hexpect = Histogram(5,[0,10])
     hexpect.set(2)
     hrebin = h.rebin(2)
     assert_array_almost_equal(hrebin.data, hexpect.data)
     assert_array_almost_equal(hrebin.axes[0].edges, hexpect.axes[0].edges)
Exemplo n.º 44
0
 def test_hdf5(self):
     try:
         import h5py
         h = self.h.clone()
         filename = 'h.hdf5'
         h.save(filename)
         hh = Histogram.load(filename)
         assert h.isidentical(hh)
     except ImportError:
         pass
Exemplo n.º 45
0
 def __init__(self, topic=DEF_TOPIC_NAME, hist_file=DEF_HISTOGRAM_FILE):
     rospy.init_node("skin_detection", anonymous=True)
     rospy.Subscriber(topic, Image, self.rgb_cb)
     cv2.namedWindow("wnd_orig")
     cv2.namedWindow("wnd_prob")
     cv2.namedWindow("wnd_skin")
     self.skin_threshold = 127
     cv2.createTrackbar("track_skin", "wnd_skin", self.skin_threshold, 255, self.on_skin_track)
     rospy.on_shutdown(self.on_shutdown)
     self.hist = Histogram()
     self.hist.load(hist_file)
Exemplo n.º 46
0
 def get_next_hop(self):
    hist = Histogram()
    print hist
    for message in self.ferry.messages:
       hist.count(message.dest)
    priorities = hist.norm_hist()
    hop = random.choice(self.ferry.term_map.items())
    max_rating = 0.0
    for term in self.ferry.term_map.keys():
       try:
          prio = priorities[term]
          d = self.dist(self.term_pos(self.current_term), self.term_pos(term))
          rating = priorities[term] / self.dist(self.term_pos(self.current_term), self.term_pos(term))
       except:
          rating = 0.0
       if rating > max_rating:
          max_rating = rating
          hop = term, self.term_pos(term)
    self.current_term = hop[0]
    return hop
Exemplo n.º 47
0
    def test___itruediv__(self):
        h1 = Histogram(3,[0,10],data=[1,2,3])
        h2 = Histogram(3,[0,10],data=[2,1,0])

        h3 = h1.clone(np.float64)
        h3 /= 2
        assert_array_equal(h1.data, np.array([1,2,3],dtype=np.int64))
        assert_array_almost_equal(h3.data,  [0.5,1,1.5])

        h3 = h1.clone()
        try:
            h3 /= h1
        except TypeError:
            assert True
        else:
            assert False

        h3 = h1.clone(np.float64)
        h3 /= h2
        assert_array_equal(h1.data, np.array([1,2,3],dtype=np.int64))
        assert_array_almost_equal(h3.data,  [0.5,2.0,0.0])
Exemplo n.º 48
0
class SkinDetector:
    def __init__(self, topic=DEF_TOPIC_NAME, hist_file=DEF_HISTOGRAM_FILE):
        rospy.init_node("skin_detection", anonymous=True)
        rospy.Subscriber(topic, Image, self.rgb_cb)
        cv2.namedWindow("wnd_orig")
        cv2.namedWindow("wnd_prob")
        cv2.namedWindow("wnd_skin")
        self.skin_threshold = 127
        cv2.createTrackbar("track_skin", "wnd_skin", self.skin_threshold, 255, self.on_skin_track)
        rospy.on_shutdown(self.on_shutdown)
        self.hist = Histogram()
        self.hist.load(hist_file)

    def on_skin_track(self, pos, *argv):
        self.skin_threshold = pos

    def find_skin(self, img):
        img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
        mask = hsv_filter_mask(img_hsv)
        back_proj = calc_back_proj(img_hsv, self.hist.hist, hsv=True)
        back_proj &= mask
        skin_bin = cv2.threshold(back_proj, self.skin_threshold, 255, cv2.THRESH_BINARY)
        return (back_proj, skin_bin[1])

    def rgb_cb(self, msg):
        try:
            img = bridge.imgmsg_to_cv(msg, "bgr8")
            img = np.asarray(img)
        except CvBridgeError, e:
            print >> stderr, "Cannot convert from ROS msg to CV image:", e

        (img_prob, img_skin) = self.find_skin(img)
        cv2.imshow("wnd_orig", img)
        cv2.imshow("wnd_prob", img_prob)
        cv2.imshow("wnd_skin", img_skin)
        ch = cv2.waitKey(3)
        if ch == 27:
            rospy.signal_shutdown("Quit")
        elif ch == ord(" "):
            cv2.imwrite("img_prob.png", img_prob)
Exemplo n.º 49
0
def getServersDict(all_servers):
    h = Histogram()
    for server in all_servers:
        if server is not None:
            if 'apache' in server.lower():
                h.add('Apache')
            if 'nginx' in server.lower():
                h.add('nginx')
            if 'IIS' in server.upper():
                h.add('IIS')
    return h
Exemplo n.º 50
0
    def get_headers(self):

        all_links = self.parse_html()
        server_names = ["Apache", "nginx", "Zeus", "Microsoft-IIS"]
        histogram = Histogram()

        for link in all_links:
            try:
                if link is not None and "link.php?id=" in link:
                    req = requests.head(self.url + link, timeout=3, allow_redirects=True)
                    get_server = req.headers["Server"]
                    print(get_server)
                    for servers in server_names:
                        if servers in get_server:
                            get_server = servers
                            histogram.add(get_server)
                            break
                        if servers == server_names[-1]:
                            get_server = "other servers"
                            histogram.add(get_server)
            except Exception:
               print("The page is not responding...")
               continue
        return histogram
Exemplo n.º 51
0
    def hist_set(self):
        """ A method to generate and yield (energy, histogram) pairs.

        Usage: for energy, hist in fits_parser.hist_set():
            ... do something ...

        yield:
            (float, Histogram): The energy and histogram pairs. This will yield one set
                for each energy in the fits file.
                """
        print 'Generating hist set'
        xedges = self._get_edges(self._x_ref, self._x_del)
        yedges = self._get_edges(self._y_ref, self._y_del)

        for i, energy in enumerate(self._energies):
            print '\tHistogram for', energy
            h = Histogram()
            h.setup(self._data[i], xedges, yedges)
            
            energy = energy[0]

            yield (energy, h)

        print 'Done'
Exemplo n.º 52
0
 def test_root(self):
     # For CERN/ROOT, we resorted to converting everything
     # into float64's so histograms are not typically
     # "identical" but they should be "close"
     try:
         import ROOT
         h = self.h.clone()
         filename = 'h.root'
         self.h.save(filename)
         hh = Histogram.load(filename)
         assert np.allclose(h.data,hh.data)
         assert np.allclose(h.uncert,hh.uncert)
         assert h.label == hh.label
         assert h.title == hh.title
         for a,aa in zip(h.axes,hh.axes):
             assert np.allclose(a.edges,aa.edges)
             assert a.label == aa.label
     except ImportError:
         pass
Exemplo n.º 53
0
    def __init__(self, world, filename=None, simulator=None):
        logging.info('Initialising vision')
        if simulator:
            self.capture = SimCapture(simulator)
        else:
            self.capture = MPlayerCapture(self.rawSize, filename)
            #self.capture = Capture(self.rawSize, filename)

        self.threshold = threshold.PrimaryRaw()
        self.pre = Preprocessor(self.rawSize, self.threshold, simulator)
        self.featureEx = FeatureExtraction(self.pre.cropSize)
        self.interpreter = Interpreter()
        self.world = world
        self.gui = GUI(world, self.pre.cropSize, self.threshold)
        self.histogram = Histogram(self.pre.cropSize)

        self.times=[]
        self.N=0

        debug.thresholdValues(self.threshold.Tfg, self.gui)

        logging.debug('Vision initialised')
Exemplo n.º 54
0
def get_histograms(path, bad_words):
    histograms = []
    names = []
    pair = []
    for element in os.listdir(path):
        temp_path = os.path.join(path, element)
        for directory in os.listdir(temp_path):
            full_path = os.path.join(temp_path, directory)
            # for document in directory create histogram
            hist = Histogram(full_path)
            # process file
            hist.process_file(bad_words)
            # full-fill words and numbers table
            hist.get_words()
            # sort histogram
            hist_sort = hist.sort_histogram()
            # append histograms table with histogram of current document
            histograms.append(hist_sort)
            names.append(hist.push_name())
            pair = [histograms, names]
    return pair
Exemplo n.º 55
0
    def setUp(self):
        rc.overwrite.overwrite = 'always'
        np.random.seed(1)
        h = Histogram(100,[0,10],'Δx', 'y', 'title')
        h.fill(np.random.normal(5,2,10000))
        h.uncert = np.sqrt(h.data)

        if sys.version_info < (3,0):
            def _to_unicode(s):
                if not isinstance(s,unicode):
                    return unicode(s,'utf-8')
                else:
                    return s
            h.title = _to_unicode(h.title)
            h.label = _to_unicode(h.label)
            for ax in h.axes:
                ax.label = _to_unicode(ax.label)

        self.h = h
Exemplo n.º 56
0
# mm1queue.py
#-----------------------------------------------------------------------

import sys
import stddraw
import stdrandom
from linkedqueue import Queue
from histogram import Histogram

# Accept float command-line arguments lamb and mu. Simulate an
# M/M/1 queue with arrival rate lamb and service rate mu.

lamb = float(sys.argv[1])  # Arrival rate
mu = float(sys.argv[2])    # Service rate

histogram = Histogram(60 + 1)
queue = Queue()
stddraw.setCanvasSize(700, 500)

# Compute time of next arrival.
nextArrival = stdrandom.exp(lamb)

# Compute time of next completed service.
nextService = nextArrival + stdrandom.exp(mu) 

# Simulate the M/M/1 queue.
while True:

    # Next event is an arrival.
    while nextArrival < nextService:
        # Simulate an arrival
def test_inserts(words, tree):
    hist = Histogram(tree)
    for i in words:
        hist.add_word(i)
def test_inserts(words, tree):
    hist = Histogram(tree)
    for i in words:
        hist.add_word(i)


def test_frequency(word, hist):
    hist.frequency(word)


WORDS_ALL = get_full_word_list()
WORDS_100 = WORDS_ALL[:100]


if __name__ == "__main__":
    radix_freq = Histogram(RadixTree)
    binary_freq = Histogram(BinaryTree)
    for word in WORDS_ALL:
        radix_freq.add_word(word)
        binary_freq.add_word(word)

    print("radix_space: ", len(pickle.dumps(radix_freq)))
    print("binary_space: ", len(pickle.dumps(binary_freq)))

    radix_insert_test = "test_inserts(WORDS_100, RadixTree)"
    binary_insert_test = "test_inserts(WORDS_100, BinaryTree)"
    radix_freq_test = "test_frequency('{}', radix_freq)".format(WORDS_ALL[-1])
    binary_freq_test = "test_frequency('{}',binary_freq)".format(WORDS_ALL[-1])

    trial_nums = [10, 100, 1000, 10000]
Exemplo n.º 59
0
# -*- coding: utf-8 -*-

import numpy as np

from histogram import Histogram

np.random.seed(1)

h = Histogram(100,[0,10],'Δx', 'y', 'title')
h.fill(np.random.normal(5,2,10000))
h.uncert = np.sqrt(h.data)