Пример #1
0
 def test_2(self):
     data1 = np.random.rand(100)
     data2 = np.random.rand(100)
     hh = h2(data1, data2, 120)
     hha = h2(data1, data2, 60)
     hhb = hh.merge_bins(2, inplace=False)
     assert hha == hhb
Пример #2
0
 def test_add_cross_2d(self):
     d1 = np.asarray([1, 21, 3])
     d2 = np.asarray([10, 12, 20])
     h = h2(d1, d2, "fixed_width", 10, adaptive=True)
     hb = h2(d1, d2 + 10, "fixed_width", 10, adaptive=True)
     hc = h + hb
     assert np.array_equal(hc.numpy_bins[1], [10, 20, 30, 40])
Пример #3
0
 def test_dropna(self):
     vals2 = np.array(vals)
     vals2[0, 1] = np.nan
     with pytest.raises(RuntimeError):
         hist = physt.h2(vals2[:,0], vals2[:,1], dropna=False)
     hist = physt.h2(vals2[:, 0], vals2[:, 1])
     assert hist.frequencies.sum() == 6
Пример #4
0
 def test_add_cross_2d(self):
     d1 = np.asarray([1, 21, 3])
     d2 = np.asarray([10, 12, 20])
     h = h2(d1, d2, "fixed_width", 10, adaptive=True)
     hb = h2(d1, d2 +10, "fixed_width", 10, adaptive=True)
     hc = h + hb
     assert np.array_equal(hc.numpy_bins[1], [10, 20, 30, 40])
Пример #5
0
 def test_addition_with_adaptive(self):
     ha = h2([1], [11], "fixed_width", 10, adaptive=True)
     hb = h2([10], [5], "fixed_width", 10, adaptive=True)
     hha = ha + hb
     assert hha == hb + ha
     assert hha.shape == (2, 2)
     assert hha.total == 2
     assert np.array_equal(hha.frequencies, [[0, 1], [1, 0]])
Пример #6
0
 def test_divide_by_constant(self):
     xx = np.array([0.5, 1.5, 2.5, 2.2, 3.3, 4.2])
     yy = np.array([1.5, 1.5, 1.5, 2.2, 1.3, 1.2])
     h = physt.h2(xx, yy, "fixed_width", 1)
     i = h / 2
     assert np.array_equal(i.frequencies, freqs / 2)
     assert np.array_equal(i.errors2, freqs / 4)
Пример #7
0
def vignette_histogram(path,
                       width=1920,
                       height=1280,
                       grid=32,
                       jitter=1,
                       **kwargs):
    histogram = h2(None,
                   None,
                   "fixed_width",
                   grid,
                   range=((0, width), (0, height)))

    xs = [0, width, width, 0, width / 2]
    ys = [0, 0, height, height, height / 2]
    count = int((height / grid)**2 / jitter)
    counts = [count] * 4 + [count / 4]
    radii = [height / 4] * 5

    for xs, ys in multicenter_data(xs, ys, counts, radii):
        fill_data = np.concatenate([xs[:, np.newaxis], ys[:, np.newaxis]],
                                   axis=1)
        histogram.fill_n(fill_data)

    dpi = 100
    fig, ax = plt.subplots(figsize=(width / dpi, height / dpi))
    histogram.plot("image",
                   ax=ax,
                   show_colorbar=False,
                   cmap="Greens",
                   cmap_max=histogram.frequencies.max(),
                   cmap_min=-0.2 * histogram.frequencies.max(),
                   **kwargs)
    ax.set_axis_off()
    save_only_axis(ax, path, dpi=dpi)
Пример #8
0
 def test_subtraction_with_another(self):
     xx = np.array([0.5, 1.5, 2.5, 2.2, 3.3, 4.2])
     yy = np.array([1.5, 1.5, 1.5, 2.2, 1.3, 1.2])
     h = physt.h2(xx, yy, "fixed_width", 1)
     i = h * 2 - h
     assert np.array_equal(i.frequencies, freqs)
     assert np.array_equal(i.errors2, 5 * freqs)
Пример #9
0
 def test_fill_nonempty(self):
     d1 = [1, 21, 3]
     d2 = [10, 12, 20]
     h = h2(d1, d2, "fixed_width", 10, adaptive=True)
     h.fill([4, 60])
     assert h.total == 4
     assert h.shape == (3, 6)
Пример #10
0
 def test_fill_nonempty(self):
     d1 = [1, 21, 3]
     d2 = [10, 12, 20]
     h = h2(d1, d2, "fixed_width", 10, adaptive=True)
     h.fill([4, 60])
     assert h.total == 4
     assert h.shape == (3, 6)
Пример #11
0
 def test_simple_random(self):
     x = np.random.normal(100, 1, 1000)
     y = np.random.normal(10, 10, 1000)
     h2 = physt.h2(x, y, [8, 4], name="Some histogram", axis_names=["x", "y"])
     assert h2.frequencies.sum() == 1000
     assert h2.shape == (8, 4)
     assert h2.name == "Some histogram"
     assert h2.axis_names == ("x", "y")
Пример #12
0
def create_h2(cursor, *args, **kwargs):
    axis_names = _get_axis_names(cursor)
    if len(axis_names) != 2:
        raise RuntimeError(
            "Invalid number of columns: {0}".format(len(axis_names)))
    kwargs["axis_names"] = kwargs.get("axis_names", axis_names)
    if kwargs.get("adaptive", False):
        h = h2(None, None, *args, **kwargs)
        for row in cursor:
            h << row
        return h
    else:
        raise NotImplementedError()
Пример #13
0
    def test_multiply_by_constant(self):
        xx = np.array([0.5, 1.5, 2.5, 2.2, 3.3, 4.2])
        yy = np.array([1.5, 1.5, 1.5, 2.2, 1.3, 1.2])
        h = physt.h2(xx, yy, "fixed_width", 1)

        assert np.array_equal(h.frequencies, freqs)
        i = h * 2
        assert np.array_equal(i.frequencies, freqs * 2)
        assert np.array_equal(i.errors2, freqs * 4)

        i = h * 0.5
        assert np.array_equal(i.frequencies, freqs * 0.5)
        assert np.array_equal(i.errors2, freqs * 0.25)
def vignette_histogram(path, width=1920, height=1280, grid=32, jitter=1, **kwargs):
    histogram = h2(None, None, "fixed_width", grid, range=((0, width), (0, height)))

    xs = [0, width, width, 0, width / 2]
    ys = [0, 0, height, height, height / 2]
    count = int((height / grid) ** 2 / jitter)
    counts = [count] * 4 + [count / 4]
    radii = [height / 4] * 5

    for xs, ys in multicenter_data(xs, ys, counts, radii):
        fill_data = np.concatenate([xs[:, np.newaxis], ys[:, np.newaxis]], axis=1)
        histogram.fill_n(fill_data)

    dpi = 100
    fig, ax = plt.subplots(figsize=(width / dpi, height / dpi))
    histogram.plot("image", ax=ax, show_colorbar=False, cmap="Greens", cmap_max=histogram.frequencies.max(), cmap_min=-0.2 * histogram.frequencies.max(), **kwargs)
    ax.set_axis_off()
    save_only_axis(ax, path, dpi=dpi)
Пример #15
0
 def test_create_empty(self):
     h = h2(None, None, "fixed_width", 10, adaptive=True)
     for b in h._binnings:
         assert b.is_adaptive()
     assert h.ndim == 2
Пример #16
0
 def test_multiply_by_other(self):
     xx = np.array([0.5, 1.5, 2.5, 2.2, 3.3, 4.2])
     yy = np.array([1.5, 1.5, 1.5, 2.2, 1.3, 1.2])
     h = physt.h2(xx, yy, "fixed_width", 1)
     with pytest.raises(RuntimeError):
         h * h
Пример #17
0
 def test_fill_empty(self):
     h = h2(None, None, "fixed_width", 10, adaptive=True)
     h.fill([4, 14])
     assert h.total == 1
     assert np.array_equal(h.numpy_bins, [[0, 10], [10, 20]])
Пример #18
0
 def test_create_nonempty(self):
     d1 = [1, 21, 3]
     d2 = [11, 12, 13]
     h = h2(d1, d2, "fixed_width", 10, adaptive=True)
     assert h.shape == (3, 1)
Пример #19
0
 def test_create_empty(self):
     h = h2(None, None, "fixed_width", 10, adaptive=True)
     for b in h._binnings:
         assert b.is_adaptive()
     assert h.ndim == 2
Пример #20
0
 def test_subtraction_by_constant(self):
     xx = np.array([0.5, 1.5, 2.5, 2.2, 3.3, 4.2])
     yy = np.array([1.5, 1.5, 1.5, 2.2, 1.3, 1.2])
     h = physt.h2(xx, yy, "fixed_width", 1)
     with pytest.raises(RuntimeError):
         h - 4
Пример #21
0
 def test_create_nonempty(self):
     d1 = [1, 21, 3]
     d2 = [11, 12, 13]
     h = h2(d1, d2, "fixed_width", 10, adaptive=True)
     assert h.shape == (3, 1)
Пример #22
0
 def test_fill_empty(self):
     h = h2(None, None, "fixed_width", 10, adaptive=True)
     h.fill([4, 14])
     assert h.total == 1
     assert np.array_equal(h.numpy_bins, [[0, 10], [10, 20]])
Пример #23
0
 def test_create_empty_h2(self):
     h2(None, None, "integer", adaptive=True)
Пример #24
0
 def test_simple(self):
     h = physt.h2(None, None, "integer", adaptive=True)
     h << (0, 1)
     json = h.to_json()
     read = io.parse_json(json)
     assert h == read
Пример #25
0
 def test_json_write_2d(self):
     from physt import h2
     values = np.random.rand(500, 2)
     h = h2(values[:, 0], values[:, 1], 3)
Пример #26
0
 def test_simple(self):
     h = physt.h2(None, None, "integer", adaptive=True)
     h << (0, 1)
     json = h.to_json()
     read = io.parse_json(json)
     assert h == read
Пример #27
0
 def test_json_write_2d(self):
     from physt import h2
     values = np.random.rand(500, 2)
     h = h2(values[:,0], values[:,1], 3)