numpy.uint16

Here are the examples of the python api numpy.uint16 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

164 Examples 7

Example 1

Project: hedge Source File: fluxgather.py
@memoize
def flux_header_struct(float_type, dims):
    from cgen import GenerableStruct

    return GenerableStruct("flux_header", [
        POD(numpy.uint16, "same_facepairs_end"),
        POD(numpy.uint16, "diff_facepairs_end"),
        POD(numpy.uint16, "bdry_facepairs_end"),
        ], align_bytes=face_pair_struct(float_type, dims).alignment_requirement())

Example 2

Project: scikit-image Source File: test_binary.py
def test_binary_output_2d():
    image = np.zeros((9, 9), np.uint16)
    image[2:-2, 2:-2] = 2**14
    image[3:-3, 3:-3] = 2**15
    image[4, 4] = 2**16-1

    bin_opened = binary.binary_opening(image)
    bin_closed = binary.binary_closing(image)

    int_opened = np.empty_like(image, dtype=np.uint8)
    int_closed = np.empty_like(image, dtype=np.uint8)
    binary.binary_opening(image, out=int_opened)
    binary.binary_closing(image, out=int_closed)

    testing.assert_equal(bin_opened.dtype, np.bool)
    testing.assert_equal(bin_closed.dtype, np.bool)

    testing.assert_equal(int_opened.dtype, np.uint8)
    testing.assert_equal(int_closed.dtype, np.uint8)

Example 3

Project: myo-raw Source File: myo.py
Function: read_data
    def read_data(self):
        X = []
        Y = []
        for i in range(10):
            X.append(np.fromfile('vals%d.dat' % i, dtype=np.uint16).reshape((-1, 8)))
            Y.append(i + np.zeros(X[-1].shape[0]))

        self.train(np.vstack(X), np.hstack(Y))

Example 4

Project: hyperspy Source File: test_tiff.py
def test_read_BW_Zeiss_optical_scale_metadata3():
    fname = os.path.join(MY_PATH2, 'optical_Zeiss_AxioVision_BW.tif')
    s = hs.load(fname, force_read_resolution=False)
    nt.assert_equal(s.data.dtype, np.uint16)
    nt.assert_equal(s.data.shape, (10, 13))
    nt.assert_equal(s.axes_manager[0].units, t.Undefined)
    nt.assert_equal(s.axes_manager[1].units, t.Undefined)
    nt.assert_almost_equal(s.axes_manager[0].scale, 1.0, places=3)
    nt.assert_almost_equal(s.axes_manager[1].scale, 1.0, places=3)

Example 5

Project: hope Source File: test_cast.py
@pytest.mark.parametrize("dtype", [dtype for dtype in dtypes if dtype != float])
def test_func_uint16(dtype):
    def fkt(a):
        return np.uint16(a)
    hfkt = hope.jit(fkt)
    ao, ah = random(dtype, [])
    co, ch = fkt(ao), hfkt(ah)
    assert type(co) == type(ch)

Example 6

Project: scikit-image Source File: test_rank.py
    def test_percentile_min(self):
        # check that percentile p0 = 0 is identical to local min
        img = data.camera()
        img16 = img.astype(np.uint16)
        selem = disk(15)
        # check for 8bit
        img_p0 = rank.percentile(img, selem=selem, p0=0)
        img_min = rank.minimum(img, selem=selem)
        assert_equal(img_p0, img_min)
        # check for 16bit
        img_p0 = rank.percentile(img16, selem=selem, p0=0)
        img_min = rank.minimum(img16, selem=selem)
        assert_equal(img_p0, img_min)

Example 7

Project: hyperspy Source File: test_bcf.py
def test_load_16bit():
    if skip_test:
        raise SkipTest
    # test bcf from hyperspy load function level
    # some of functions can be not covered
    # it cant use cython parsing implementation, as it is not compiled
    filename = os.path.join(my_path, 'bcf_data', test_files[0])
    print('testing bcf instructively packed 16bit...')
    s = load(filename)
    bse, sei, hype = s
    # Bruker saves all images in true 16bit:
    nt.assert_true(bse.data.dtype == np.uint16)
    nt.assert_true(sei.data.dtype == np.uint16)
    nt.assert_true(bse.data.shape == (75, 100))
    np_filename = os.path.join(my_path, 'bcf_data', np_file[0])
    np.testing.assert_array_equal(hype.data[:22, :22, 222],
                                  np.load(np_filename))
    nt.assert_true(hype.data.shape == (75, 100, 2048))

Example 8

Project: homer Source File: gamera_musicstaves.py
Function: init
    def __init__(self, page, staff_removal='metaomr'):
        self.page = page

        # Gamera must read image from a file
        gamera_img = (page.byteimg[:page.orig_size[0], :page.orig_size[1]]
                        .astype(np.uint16))
        self.gamera_image = gamera.plugins.numpy_io.from_numpy(gamera_img)
        self.gamera_instance = self.gamera_class(self.gamera_image)

        assert staff_removal in ['metaomr', 'gamera']
        if staff_removal == 'gamera':
            self.gamera_staff_removal = True

Example 9

Project: scikit-image Source File: test_texture.py
    def test_image_data_types(self):
        for dtype in [np.uint16, np.uint32, np.uint64, np.int16, np.int32, np.int64]: 
            img = self.image.astype(dtype)
            result = greycomatrix(img, [1], [np.pi / 2], 4,
                                  symmetric=True)
            assert result.shape == (4, 4, 1, 1)
            expected = np.array([[6, 0, 2, 0],
                                 [0, 4, 2, 0],
                                 [2, 2, 2, 2],
                                 [0, 0, 2, 0]], dtype=np.uint32)
            np.testing.assert_array_equal(result[:, :, 0, 0], expected)
            
        return

Example 10

Project: rayopt Source File: simplex.py
def simplex_enum(d, m):
    """Return an ordered forward and backward mapping of the points in the d-m
    simplex.

    idx[j] == (i_0, i_1, ..., i_{d-1})
    jdx[i_0, i_1, ..., i_{d-1}] == j (only the simplex close to the origin is
    valid).
    """
    idx = np.zeros((m,)*d, dtype=np.uint16)
    jdx = np.zeros((simplex_size(d, m), d), dtype=np.uint16)
    for j, i in enumerate(simplex_iter(d, m)):
        idx[i] = j
        jdx[j] = i
    assert jdx.shape[0] == j + 1, (jdx.shape, j)
    return idx, jdx

Example 11

Project: rpigl Source File: glesutils.py
def _get_array_from_alpha_surface(surface):
    rgb = pygame.surfarray.pixels3d(surface).astype(numpy.uint16)
    alpha = pygame.surfarray.pixels_alpha(surface)
    rgb *= alpha[:,:,numpy.newaxis]
    rgb /= 255
    result = numpy.empty(rgb.shape[:-1] + (4,), dtype=numpy.uint8)
    result[:,:,:3] = rgb
    result[:,:,3] = alpha
    return result

Example 12

Project: Yeppp Source File: test_add_unittest.py
Function: test_add_v16uv16u_v32u
    def test_add_V16uV16u_V32u(self):
        a_tmp = self.a.astype(numpy.uint16)
        b_tmp = self.b.astype(numpy.uint16)
        c = numpy.empty([self.n]).astype(numpy.uint32)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_uint16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_uint16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_uint32))

        yepCore_Add_V16uV16u_V32u(a_ptr, b_ptr, c_ptr, self.n)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] + b_tmp[i], c[i])

Example 13

Project: scikit-image Source File: test_rank.py
Function: test_16bit
    def test_16bit(self):
        image = np.zeros((21, 21), dtype=np.uint16)
        selem = np.ones((3, 3), dtype=np.uint8)

        for bitdepth in range(17):
            value = 2 ** bitdepth - 1
            image[10, 10] = value
            if bitdepth > 11:
                expected = ['Bitdepth of %s' % (bitdepth - 1)]
            else:
                expected = []
            with expected_warnings(expected):
                assert rank.minimum(image, selem)[10, 10] == 0
                assert rank.maximum(image, selem)[10, 10] == value
                assert rank.mean(image, selem)[10, 10] == int(value / selem.size)

Example 14

Project: pypng Source File: test_png.py
    def testNumpyuint16(self):
        """numpy uint16."""

        numpy or self.skipTest("numpy is not available")

        rows = [map(numpy.uint16, range(0,0x10000,0x5555))]
        b = topngbytes('numpyuint16.png', rows, 4, 1,
            greyscale=True, alpha=False, bitdepth=16)

Example 15

Project: pyresample Source File: utils.py
def _downcast_index_array(index_array, size):
    """Try to downcast array to uint16
    """

    if size <= np.iinfo(np.uint16).max:
        mask = (index_array < 0) | (index_array >= size)
        index_array[mask] = size
        index_array = index_array.astype(np.uint16)
    return index_array

Example 16

Project: agdc Source File: test_landsat_tiler.py
    @staticmethod
    def count_bitwise_diffs(arr1, arr2):
        """Given two flattened arrays, return a same-sized array containing the
        number of bitwise differences"""
        assert arr1.shape == arr2.shape and len(arr1.shape) == 1, \
            "Inconsistent arrays in count_bitwise_diffs"
        assert arr1.dtype == numpy.uint16, "Need uint16 in count_bitwise_diffs"
        assert arr2.dtype == numpy.uint16, "Need uint16 in count_bitwise_diffs"
        diff = numpy.bitwise_xor(arr1, arr2)
        difference_as_bytes = numpy.ndarray(shape=(diff.shape[0], 2),
                                            dtype=numpy.uint8, buffer=diff)
        difference_as_bits = numpy.unpackbits(difference_as_bytes, axis=1)
        difference = numpy.sum(difference_as_bits, axis=1, dtype=numpy.uint8)
        return difference

Example 17

Project: scikit-image Source File: test_rank.py
    def test_percentile_median(self):
        # check that percentile p0 = 0.5 is identical to local median
        img = data.camera()
        img16 = img.astype(np.uint16)
        selem = disk(15)
        # check for 8bit
        img_p0 = rank.percentile(img, selem=selem, p0=.5)
        img_max = rank.median(img, selem=selem)
        assert_equal(img_p0, img_max)
        # check for 16bit
        img_p0 = rank.percentile(img16, selem=selem, p0=.5)
        img_max = rank.median(img16, selem=selem)
        assert_equal(img_p0, img_max)

Example 18

Project: hyperspy Source File: test_tiff.py
def test_read_BW_Zeiss_optical_scale_metadata():
    fname = os.path.join(MY_PATH2, 'optical_Zeiss_AxioVision_BW.tif')
    s = hs.load(fname, force_read_resolution=True, import_local_tifffile=True)
    nt.assert_equal(s.data.dtype, np.uint16)
    nt.assert_equal(s.data.shape, (10, 13))
    nt.assert_equal(s.axes_manager[0].units, 'µm')
    nt.assert_equal(s.axes_manager[1].units, 'µm')
    nt.assert_almost_equal(s.axes_manager[0].scale, 169.3333, places=3)
    nt.assert_almost_equal(s.axes_manager[1].scale, 169.3333, places=3)

Example 19

Project: Py3NES Source File: base_instructions.py
    @classmethod
    def write(cls, cpu, memory_address, value):
        # store the pc reg on the stack
        cpu.set_stack_value(cpu.pc_reg - np.uint16(1), num_bytes=Numbers.SHORT.value)

        # jump to the memory location
        super().write(cpu, memory_address, value)

Example 20

Project: eyegrade Source File: sample.py
Function: parse_sample
    def _parse_sample(self, line):
        parts = [p.strip() for p in line.split('\t')]
        if len(parts) != 10:
            raise ValueError("Syntax error in samples file")
        image_path = os.path.join(self.dirname, parts[0])
        label = int(parts[1])
        corners = np.zeros((4, 2), dtype=np.uint16)
        corners[0,0] = int(parts[2]) # left top
        corners[0,1] = int(parts[3])
        corners[1,0] = int(parts[4]) # right top
        corners[1,1] = int(parts[5])
        corners[2,0] = int(parts[6]) # left bottom
        corners[2,1] = int(parts[7])
        corners[3,0] = int(parts[8]) # right bottom
        corners[3,1] = int(parts[9])
        return Sample(corners, image_filename=image_path, label=label)

Example 21

Project: scikit-learn Source File: test_feature_hasher.py
def test_hasher_invalid_input():
    assert_raises(ValueError, FeatureHasher, input_type="gobbledygook")
    assert_raises(ValueError, FeatureHasher, n_features=-1)
    assert_raises(ValueError, FeatureHasher, n_features=0)
    assert_raises(TypeError, FeatureHasher, n_features='ham')

    h = FeatureHasher(n_features=np.uint16(2 ** 6))
    assert_raises(ValueError, h.transform, [])
    assert_raises(Exception, h.transform, [[5.5]])
    assert_raises(Exception, h.transform, [[None]])

Example 22

Project: spectral Source File: envi.py
    def test_save_image_ndarray(self):
        '''Test saving an ENVI formated image from a numpy.ndarray.'''
        import os
        import spectral
        (R, B, C) = (10, 20, 30)
        (r, b, c) = (3, 8, 23)
        datum = 33
        data = np.zeros((R, B, C), dtype=np.uint16)
        data[r, b, c] = datum
        fname = os.path.join(testdir, 'test_save_image_ndarray.hdr')
        spectral.envi.save_image(fname, data, interleave='bil')
        img = spectral.open_image(fname)
        assert_almost_equal(img[r, b, c], datum)

Example 23

Project: Py3NES Source File: base_instructions.py
    @classmethod
    def write(cls, cpu, memory_address, value):
        # grab the stored pc reg from the stack
        old_pc_reg = cpu.get_stack_value(Numbers.SHORT.value) + np.uint16(1)

        # jump to the memory location
        super().write(cpu, old_pc_reg, value)

Example 24

Project: scikit-image Source File: test_rank.py
    def test_pass_on_bitdepth(self):
        # should pass because data bitdepth is not too high for the function

        image = np.ones((100, 100), dtype=np.uint16) * 2 ** 11
        elem = np.ones((3, 3), dtype=np.uint8)
        out = np.empty_like(image)
        mask = np.ones(image.shape, dtype=np.uint8)
        with expected_warnings(["Bitdepth of"]):
            rank.maximum(image=image, selem=elem, out=out, mask=mask)

Example 25

Project: jcvi Source File: uclust.py
Function: init
    def __init__(self, consensfile):
        super(ClustStore, self).__init__(consensfile)
        binfile = consensfile + ".bin"
        idxfile = consensfile + ".idx"
        self.bin = np.fromfile(binfile, dtype=np.uint16)
        assert self.bin.size % NBASES == 0

        self.bin = self.bin.reshape((self.bin.size / NBASES, NBASES))
        self.index = {}
        fp = open(idxfile)
        for row in fp:
            name, start, end = row.split()
            start, end = int(start), int(end)
            self.index[name.strip(">")] = (start, end)

Example 26

Project: PyScada Source File: __init__.py
Function: cast_value
def _cast_value(value,_type):
    '''
    cast value to _type
    '''
    if _type.upper() == 'FLOAT64':
        return float64(value)
    elif _type.upper() == 'FLOAT32':
        return float32(value)
    elif  _type.upper() == 'INT32':
        return int32(value)
    elif  _type.upper() == 'UINT16':
        return uint16(value)
    elif  _type.upper() == 'INT16':
        return int16(value)
    elif _type.upper() == 'BOOLEAN':
        return uint8(value)
    else:
        return float64(value)

Example 27

Project: Yeppp Source File: sse_add_test.py
    def test_add_V16uV16u_V32u(self):
        a_tmp = self.a.astype(numpy.uint16)
        b_tmp = self.b.astype(numpy.uint16)
        c = numpy.empty([self.n]).astype(numpy.uint32)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_uint16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_uint16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_uint32))

        func = sse.add.yepCore_Add.yepCore_Add_V16uV16u_V32u.load()
        self.assertEqual(func(a_ptr, b_ptr, c_ptr, self.n), 0)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] + b_tmp[i], c[i])

Example 28

Project: scikit-image Source File: test_rank.py
    def test_compare_8bit_vs_16bit(self):
        # filters applied on 8-bit image ore 16-bit image (having only real 8-bit
        # of dynamic) should be identical

        image8 = util.img_as_ubyte(data.camera())[::2, ::2]
        image16 = image8.astype(np.uint16)
        assert_equal(image8, image16)

        methods = ['autolevel', 'bottomhat', 'equalize', 'gradient', 'maximum',
                   'mean', 'subtract_mean', 'median', 'minimum', 'modal',
                   'enhance_contrast', 'pop', 'threshold', 'tophat']

        for method in methods:
            func = getattr(rank, method)
            f8 = func(image8, disk(3))
            f16 = func(image16, disk(3))
            assert_equal(f8, f16)

Example 29

Project: yatsm Source File: longtermmean.py
def ordinal2yeardoy(ordinal):
    """ Convert ordinal dates to two arrays of year and doy

    Args:
        ordinal (np.ndarray): ordinal dates

    Returns:
        np.ndarray: nobs x 2 np.ndarray containing the year and DOY for each
            ordinal date

    """
    _date = [dt.fromordinal(_d) for _d in ordinal]
    yeardoy = np.empty((ordinal.size, 2), dtype=np.uint16)
    yeardoy[:, 0] = np.array([_d.timetuple().tm_year for _d in _date])
    yeardoy[:, 1] = np.array([_d.timetuple().tm_yday for _d in _date])

    return yeardoy

Example 30

Project: mpop Source File: umarf_native.py
def dec10to16(data):
    arr10 = data.astype(np.uint16).flat
    new_shape = list(data.shape[:-1]) + [(data.shape[-1] * 8) / 10]
    arr16 = np.zeros(new_shape, dtype=np.uint16)
    arr16.flat[::4] = np.left_shift(arr10[::5], 2) + \
        np.right_shift((arr10[1::5]), 6)
    arr16.flat[1::4] = np.left_shift((arr10[1::5] & 63), 4) + \
        np.right_shift((arr10[2::5]), 4)
    arr16.flat[2::4] = np.left_shift(arr10[2::5] & 15, 6) + \
        np.right_shift((arr10[3::5]), 2)
    arr16.flat[3::4] = np.left_shift(arr10[3::5] & 3, 8) + \
        arr10[4::5]
    return arr16   

Example 31

Project: landsat-util Source File: image.py
    def _generate_new_bands(self, shape):
        new_bands = []
        for i in range(0, 3):
            new_bands.append(numpy.empty(shape, dtype=numpy.uint16))

        return new_bands

Example 32

Project: scikit-image Source File: test_rank.py
    def test_bilateral(self):
        image = np.zeros((21, 21), dtype=np.uint16)
        selem = np.ones((3, 3), dtype=np.uint8)

        image[10, 10] = 1000
        image[10, 11] = 1010
        image[10, 9] = 900

        assert rank.mean_bilateral(image, selem, s0=1, s1=1)[10, 10] == 1000
        assert rank.pop_bilateral(image, selem, s0=1, s1=1)[10, 10] == 1
        assert rank.mean_bilateral(image, selem, s0=11, s1=11)[10, 10] == 1005
        assert rank.pop_bilateral(image, selem, s0=11, s1=11)[10, 10] == 2

Example 33

Project: pypng Source File: test_png.py
    def testNumpyarray(self):
        """numpy array."""

        numpy or self.skipTest("numpy is not available")

        pixels = numpy.array([[0,0x5555],[0x5555,0xaaaa]], numpy.uint16)
        img = png.from_array(pixels, 'L')
        img.save(BytesIO())

Example 34

Project: Py3NES Source File: cpu.py
Function: execute
    def execute(self):

        # increment the pc_reg
        self.pc_reg += np.uint16(self.instruction.get_instruction_length())

        # we have a valid instruction class
        value = self.instruction.execute(self, self.data_bytes)

        self.status_reg.update(self.instruction, value)

Example 35

Project: karta Source File: geotiff_tests.py
    def test_numpy_type_coercion(self):
        self.assertEqual(_gdal.numpy_dtype(2), np.uint16)
        self.assertEqual(_gdal.numpy_dtype(3), np.int16)
        self.assertEqual(_gdal.numpy_dtype(4), np.uint32)
        self.assertEqual(_gdal.numpy_dtype(5), np.int32)
        self.assertEqual(_gdal.numpy_dtype(6), np.float32)
        self.assertEqual(_gdal.numpy_dtype(7), np.float64)
        self.assertEqual(_gdal.numpy_dtype(8), np.complex64)
        self.assertEqual(_gdal.numpy_dtype(9), np.complex64)
        self.assertEqual(_gdal.numpy_dtype(10), np.complex64)
        self.assertEqual(_gdal.numpy_dtype(11), np.complex64)
        return

Example 36

Project: scikit-image Source File: test_rank.py
    def test_percentile_max(self):
        # check that percentile p0 = 1 is identical to local max
        img = data.camera()
        img16 = img.astype(np.uint16)
        selem = disk(15)
        # check for 8bit
        img_p0 = rank.percentile(img, selem=selem, p0=1.)
        img_max = rank.maximum(img, selem=selem)
        assert_equal(img_p0, img_max)
        # check for 16bit
        img_p0 = rank.percentile(img16, selem=selem, p0=1.)
        img_max = rank.maximum(img16, selem=selem)
        assert_equal(img_p0, img_max)

Example 37

Project: glumpy Source File: gloo-terminal.py
Function: init
    def __init__(self, rows=24, cols=80, x=3, y=3, scale=2, cache=1000):
        TextBuffer.__init__(self, rows, cols, x, y, scale)

        # We use a ring buffer to avoid to have to move things around
        self._buffer_start = 0
        self._buffer_end = 0
        cache = max(cache, rows)
        self._buffer = np.ones((cache+rows,cols),
                               dtype=[("code",       np.uint16,  1),
                                      ("style",      np.uint16,  1)])
        self._buffer["code"] = 32 # space
        self._scroll = -self.rows
        self._default_foreground = 0,0,0,1 # Black
        self._default_background = 0,0,0,0 # Transparent black
        self._default_style      = 0       # Regular
        self._buffer["style"]      = self._default_style

Example 38

Project: fast-rcnn Source File: pascal_voc.py
    def _load_selective_search_IJCV_roidb(self, gt_roidb):
        IJCV_path = os.path.abspath(os.path.join(self.cache_path, '..',
                                                 'selective_search_IJCV_data',
                                                 'voc_' + self._year))
        assert os.path.exists(IJCV_path), \
               'Selective search IJCV data not found at: {}'.format(IJCV_path)

        top_k = self.config['top_k']
        box_list = []
        for i in xrange(self.num_images):
            filename = os.path.join(IJCV_path, self.image_index[i] + '.mat')
            raw_data = sio.loadmat(filename)
            box_list.append((raw_data['boxes'][:top_k, :]-1).astype(np.uint16))

        return self.create_roidb_from_box_list(box_list, gt_roidb)

Example 39

Project: hyperspy Source File: test_bcf.py
def test_load_8bit():
    if skip_test:
        raise SkipTest
    for bcffile in test_files[1:3]:
        filename = os.path.join(my_path, 'bcf_data', bcffile)
        print('testing simple 8bit bcf...')
        s = load(filename)
        bse, sei, hype = s
        # Bruker saves all images in true 16bit:
        nt.assert_true(bse.data.dtype == np.uint16)
        nt.assert_true(sei.data.dtype == np.uint16)
        # hypermaps should always return unsigned integers:
        nt.assert_true(str(hype.data.dtype)[0] == 'u')

Example 40

Project: scikit-image Source File: test_binary.py
Function: test_2d_ndimage_equivalence
def test_2d_ndimage_equivalence():
    image = np.zeros((9, 9), np.uint16)
    image[2:-2, 2:-2] = 2**14
    image[3:-3, 3:-3] = 2**15
    image[4, 4] = 2**16-1

    bin_opened = binary.binary_opening(image)
    bin_closed = binary.binary_closing(image)

    selem = ndi.generate_binary_structure(2, 1)
    ndimage_opened = ndi.binary_opening(image, structure=selem)
    ndimage_closed = ndi.binary_closing(image, structure=selem)

    testing.assert_array_equal(bin_opened, ndimage_opened)
    testing.assert_array_equal(bin_closed, ndimage_closed)

Example 41

Project: hyperspy Source File: test_tiff.py
def test_read_BW_Zeiss_optical_scale_metadata2():
    fname = os.path.join(MY_PATH2, 'optical_Zeiss_AxioVision_BW.tif')
    s = hs.load(fname, force_read_resolution=True)
    nt.assert_equal(s.data.dtype, np.uint16)
    nt.assert_equal(s.data.shape, (10, 13))
    nt.assert_equal(s.axes_manager[0].units, 'µm')
    nt.assert_equal(s.axes_manager[1].units, 'µm')
    nt.assert_almost_equal(s.axes_manager[0].scale, 169.3333, places=3)
    nt.assert_almost_equal(s.axes_manager[1].scale, 169.3333, places=3)

Example 42

Project: Py3NES Source File: cpu.py
Function: start_up
    def start_up(self):
        """
        set the initial values of cpu registers
        status reg: 000100 (irqs disabled)
        x, y, a regs: 0
        stack pointer: $FD
        $4017: 0 (frame irq disabled)
        $4015: 0 (sound channels disabled)
        $4000-$400F: 0 (sound registers)
        """
        # TODO Hex vs binary
        self.pc_reg = np.uint16(0)  # 2 byte
        self.status_reg = Status()
        self.sp_reg = np.uint8(0xFD)

        self.x_reg = np.uint8(0)
        self.y_reg = np.uint8(0)
        self.a_reg = np.uint8(0)

Example 43

Project: Yeppp Source File: avx_add_test.py
    def test_add_V16uV16u_V32u(self):
        a_tmp = self.a.astype(numpy.uint16)
        b_tmp = self.b.astype(numpy.uint16)
        c = numpy.empty([self.n]).astype(numpy.uint32)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_uint16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_uint16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_uint32))

        func = avx.add.yepCore_Add.yepCore_Add_V16uV16u_V32u.load()
        self.assertEqual(func(a_ptr, b_ptr, c_ptr, self.n), 0)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] + b_tmp[i], c[i])

Example 44

Project: scikit-image Source File: test_binary.py
def test_binary_output_3d():
    image = np.zeros((9, 9, 9), np.uint16)
    image[2:-2, 2:-2, 2:-2] = 2**14
    image[3:-3, 3:-3, 3:-3] = 2**15
    image[4, 4, 4] = 2**16-1

    bin_opened = binary.binary_opening(image)
    bin_closed = binary.binary_closing(image)

    int_opened = np.empty_like(image, dtype=np.uint8)
    int_closed = np.empty_like(image, dtype=np.uint8)
    binary.binary_opening(image, out=int_opened)
    binary.binary_closing(image, out=int_closed)

    testing.assert_equal(bin_opened.dtype, np.bool)
    testing.assert_equal(bin_closed.dtype, np.bool)

    testing.assert_equal(int_opened.dtype, np.uint8)
    testing.assert_equal(int_closed.dtype, np.uint8)

Example 45

Project: rlpy Source File: Representation.py
    def setBinsPerDimension(self, domain, discretization):
        """
        Set the number of bins for each dimension of the domain.
        Continuous spaces will be slices using the ``discretization`` parameter.
        :param domain: the problem :py:class:`~rlpy.Domains.Domain.Domain` to learn
        :param discretization: The number of bins a continuous domain should be sliced into.

        """
        self.bins_per_dim = np.zeros(domain.state_space_dims, np.uint16)
        self.binWidth_per_dim = np.zeros(domain.state_space_dims)
        for d in xrange(domain.state_space_dims):
            if d in domain.continuous_dims:
                self.bins_per_dim[d] = discretization
            else:
                self.bins_per_dim[d] = domain.statespace_limits[d, 1] - \
                    domain.statespace_limits[d, 0]
            self.binWidth_per_dim[d] = (domain.statespace_limits[d,1] - domain.statespace_limits[d, 0]) / (self.bins_per_dim[d] * 1.)

Example 46

Project: Py3NES Source File: addressing.py
Function: get_address
    @classmethod
    def get_address(cls, cpu: 'c.CPU', data_bytes: bytes):
        # look up the bytes at [original_address, original_address + 1]
        lsb_location = np.uint16(super().get_address(cpu, data_bytes))
        msb_location = np.uint16(lsb_location + 1)

        # wrap around on page boundaries
        if msb_location % 0x100 == 0:
            msb_location = np.uint16(lsb_location - 0xFF)

        lsb = cpu.get_memory(lsb_location)
        msb = cpu.get_memory(msb_location)

        return np.uint16(int.from_bytes(bytes([lsb, msb]), byteorder='little'))

Example 47

Project: Py3NES Source File: cpu.py
    def load_rom(self, rom: ROM, testing):
        # unload old rom
        if self.rom is not None:
            self.memory_owners.remove(self.rom)

        # load rom
        self.rom = rom

        # load the rom program instructions into memory
        self.memory_owners.append(self.rom)

        if testing:
            self.pc_reg = np.uint16(0xC000)
        else:
            self.pc_reg = np.uint16(int.from_bytes(self.get_memory(0xFFFC, 2), byteorder='little'))

Example 48

Project: Py3NES Source File: base_instructions.py
    @classmethod
    def write(cls, cpu, memory_address, value):
        # increment pc reg
        cpu.pc_reg += np.uint16(1)

        # store the pc reg onto the stack
        cpu.set_stack_value(cpu.pc_reg, Numbers.SHORT.value)

        # store the status on the stack
        status = cpu.status_reg.to_int()
        cpu.set_stack_value(status)

        # set interrupt bit to be true
        cpu.status_reg.bits[Status.StatusTypes.interrupt] = True

Example 49

Project: scikit-image Source File: test_rank.py
    def test_compare_autolevels_16bit(self):
        # compare autolevel(16-bit) and percentile autolevel(16-bit) with p0=0.0
        # and p1=1.0 should returns the same arrays

        image = data.camera().astype(np.uint16) * 4

        selem = disk(20)
        loc_autolevel = rank.autolevel(image, selem=selem)
        loc_perc_autolevel = rank.autolevel_percentile(image, selem=selem,
                                                       p0=.0, p1=1.)

        assert_equal(loc_autolevel, loc_perc_autolevel)

Example 50

Project: Yeppp Source File: avx_multiply_test.py
    def test_multiply_V16uV16u_V32u(self):
        a_tmp = self.a.astype(numpy.uint16)
        b_tmp = self.b.astype(numpy.uint16)
        c = numpy.empty([self.n]).astype(numpy.uint32)
        a_ptr = a_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_uint16))
        b_ptr = b_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_uint16))
        c_ptr = c.ctypes.data_as(ctypes.POINTER(ctypes.c_uint32))

        func = avx.multiply.yepCore_Multiply.yepCore_Multiply_V16uV16u_V32u.load()
        self.assertEqual(func(a_ptr, b_ptr, c_ptr, self.n), 0)

        for i in range(self.n):
            self.assertEqual(a_tmp[i] * b_tmp[i], c[i], "Mismatch at index %d" % i)
See More Examples - Go to Next Page
Page 1 Selected Page 2 Page 3 Page 4