Ejemplo n.º 1
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)
Ejemplo 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
Ejemplo n.º 3
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*")
Ejemplo n.º 4
0
    def test_root_2d(self):
        ftmp = NamedTemporaryFile(suffix='.root', delete=False)
        try:
            ftmp.close()
            h = Histogram(3, [0, 3], 4, [0, 4])
            h.data[:] = [[-3, 0, 5, 3], [-2, 0, 4, 2], [-1, 0, 3, 1024]]
            h.uncert = np.sqrt(np.abs(
                h.data))  # ROOT will always return uncert
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.axes[0].label = 'x (cm)'
            h.axes[1].label = 'y (cm)'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.label = 'counts'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.title = 'title'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

        finally:
            os.remove(ftmp.name)
Ejemplo n.º 5
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,
    )
Ejemplo n.º 6
0
    def test_npz_2d(self):
        ftmp = NamedTemporaryFile(suffix='.npz', delete=False)
        try:
            ftmp.close()
            h = Histogram(3, [0, 3], 4, [0, 4])
            h.data[:] = [[-3, 0, 5, 3], [-2, 0, 4, 2], [-1, 0, 3, 1024]]
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.axes[0].label = 'x (cm)'
            h.axes[1].label = 'y (cm)'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.label = 'counts'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.title = 'title'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

        finally:
            os.remove(ftmp.name)
Ejemplo n.º 7
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()
Ejemplo n.º 8
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
Ejemplo n.º 9
0
    def test_hist_1d(self):
        ftmp = NamedTemporaryFile(suffix='.h5', delete=False)
        try:
            ftmp.close()
            h = Histogram(3, [0, 3])
            h.data[:] = [-3, 0, 5]
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.axes[0].label = 'x (cm)'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            #print(type(h.axes[0].label), h.axes[0].label)
            #print(type(htmp.axes[0].label), htmp.axes[0].label)
            self.assertTrue(h.isidentical(htmp))

            h.label = 'counts'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.title = 'title'
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

            h.uncert = [2, 3, 4]
            h.save(ftmp.name)
            htmp = Histogram.load(ftmp.name)
            self.assertTrue(h.isidentical(htmp))

        finally:
            os.remove(ftmp.name)
Ejemplo n.º 10
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
Ejemplo n.º 11
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')
Ejemplo n.º 12
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'))
Ejemplo n.º 13
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)
Ejemplo 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]
 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]
Ejemplo n.º 16
0
 def test_hist_1d_negative(self):
     h = Histogram([0, 1, 3], data=[-1, 2])
     fig, ax = plt.subplots(2)
     pt = ax[0].plothist(h, style='polygon')
     pt = ax[0].plothist(h, style='line', color='black', lw=2)
     pt = ax[1].plothist(h, style='errorbar')
     self.assertTrue(
         conf.comparator.compare_images(fig.savefig,
                                        'hist_1d_negative.png'))
Ejemplo n.º 17
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'))
Ejemplo n.º 18
0
 def __init__(self, resp, header):
     SLSResponse.__init__(self, header)
     self.progress = resp['progress']
     self.count = resp['count']
     self.histograms = []
     for data in resp['histograms']:
         status = Histogram(data['from'], data['to'], data['count'],
                            data['progress'])
         self.histograms.append(status)
Ejemplo 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')
Ejemplo n.º 20
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()
Ejemplo n.º 21
0
    def histogramComponents(self,edges,p=None):

        hists = []
        for i, m in enumerate(self._models):

            c = m.histogram(edges,p) 
            h = Histogram(edges,label=m.name(),counts=c,var=0)
            
            hists.append(h)
        return hists
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)
    def __init__(self, resp, header):
        LogResponse.__init__(self, header)
        self.progress = header['x-log-progress']
        self.count = 0  #header['x-log-count']
        self.histograms = []

        for data in resp:
            status = Histogram(data['from'], data['to'], data['count'],
                               data['progress'])
            self.histograms.append(status)
            self.count += data['count']
Ejemplo n.º 24
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))
Ejemplo n.º 25
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()
Ejemplo n.º 26
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)
Ejemplo n.º 27
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')
	def draw_histogram(self):
		# Get the right sequence:
		tifs: TiffSequence = None
		if self.do_show_gdal:
			tifs = self.tifs_gdal
		else:
			tifs = self.tifs

		if tifs is None:
			return
		
		_, tif = tifs.current()
		Histogram(self, tif.source, tif.name)
Ejemplo n.º 29
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))
Ejemplo n.º 30
0
def test_distribution(n, ignore_blacklist, two_dee):
    q = Quicktipp()
    q.set_ignore_blacklist(ignore_blacklist)
    q.prepare(n)
    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()