當前位置: 首頁>>代碼示例>>Python>>正文


Python ma.masked_array方法代碼示例

本文整理匯總了Python中numpy.ma.masked_array方法的典型用法代碼示例。如果您正苦於以下問題:Python ma.masked_array方法的具體用法?Python ma.masked_array怎麽用?Python ma.masked_array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy.ma的用法示例。


在下文中一共展示了ma.masked_array方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: objify

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def objify(self, doc, columns=None):
        """
        Decode a Pymongo SON object into an Pandas DataFrame
        """
        cols = columns or doc[METADATA][COLUMNS]
        data = {}

        for col in cols:
            # if there is missing data in a chunk, we can default to NaN
            # and pandas will autofill the missing values to the correct length
            if col not in doc[METADATA][LENGTHS]:
                d = [np.nan]
            else:
                d = decompress(doc[DATA][doc[METADATA][LENGTHS][col][0]: doc[METADATA][LENGTHS][col][1] + 1])
                # d is ready-only but that's not an issue since DataFrame will copy the data anyway.
                d = np.frombuffer(d, doc[METADATA][DTYPE][col])

                if MASK in doc[METADATA] and col in doc[METADATA][MASK]:
                    mask_data = decompress(doc[METADATA][MASK][col])
                    mask = np.frombuffer(mask_data, 'bool')
                    d = ma.masked_array(d, mask)
            data[col] = d

        # Copy into
        return pd.DataFrame(data, columns=cols, copy=True)[cols] 
開發者ID:man-group,項目名稱:arctic,代碼行數:27,代碼來源:numpy_arrays.py

示例2: fillValuesToNan

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def fillValuesToNan(masked_array):
    """ Replaces the fill_values of the masked array by NaNs

        If the array is None or it does not contain floating point values, it cannot contain NaNs.
        In that case the original array is returned.
    """
    if masked_array is not None and masked_array.dtype.kind == 'f':
        check_class(masked_array, ma.masked_array)
        logger.debug("Replacing fill_values by NaNs")
        masked_array[:] = ma.filled(masked_array, np.nan)
        masked_array.set_fill_value(np.nan)
    else:
        return masked_array


#TODO: does recordMask help here?
# https://docs.scipy.org/doc/numpy/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray.recordmask 
開發者ID:titusjan,項目名稱:argos,代碼行數:19,代碼來源:masks.py

示例3: fill_values_to_nan

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def fill_values_to_nan(masked_array):
    """ Replaces the fill_values of the masked array by NaNs

        If the array is None or it does not contain floating point values, it cannot contain NaNs.
        In that case the original array is returned.
    """
    if masked_array is not None and masked_array.dtype.kind == 'f':
        check_class(masked_array, ma.masked_array)
        logger.debug("Replacing fill_values by NaNs")
        masked_array[:] = ma.filled(masked_array, np.nan)
        masked_array.set_fill_value(np.nan)
    else:
        return masked_array


# Needed because boolean QSettings in Pyside are converted incorrect the second
# time in Windows (and Linux?) because of a bug in Qt. See:
# https://www.mail-archive.com/pyside@lists.pyside.org/msg00230.html 
開發者ID:titusjan,項目名稱:argos,代碼行數:20,代碼來源:cls.py

示例4: init_buffer

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def init_buffer(self):    
        #we only accept masked files
        assert self.video_file.endswith('hdf5')
        
        with tables.File(self.video_file, 'r') as fid:
            masks = fid.get_node('/mask')
            
            #here i am using a masked numpy array to deal with the zeroed background
            last_frame = self.buff_size*self.frame_gap - 1
            self.buffer = masks[:last_frame + 1:self.frame_gap]
            self.buffer = ma.masked_array(self.buffer, self.buffer==0)
            
            self.buffer_ind = self.buffer.shape[0] - 1
            self.last_frame = last_frame

            if '/full_data' in fid:
                #here i am using as the canonical background the results of using the reducing function in all the full frames
                full_data = fid.get_node('/full_data')
                self.full_img = self.reduce_func(full_data, axis=0) 
開發者ID:ver228,項目名稱:tierpsy-tracker,代碼行數:21,代碼來源:BackgroundSubtractor.py

示例5: test_image_mask

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def test_image_mask(self):
        """Test image mask."""
        im1 = image("testimg", shape=[2, 3])
        marr = nma.masked_array(numpy.array([[1, 2, 3], [4, 5, 6]]),
                mask=[[False, True, False], [False, False, True]])
        im1.put(marr)
        numpy.testing.assert_equal(im1.getdata(), marr.data)
        numpy.testing.assert_equal(im1.getmask(), marr.mask)
        im1.putmask(numpy.array([[True, False, True],
                                [False, False, False]]), (0, 0), (0, 1))
        numpy.testing.assert_equal(im1.getmask(),
                                   numpy.array([[True, False,  True],
                                               [False, False, False]]))
        numpy.testing.assert_equal(im1.getdata(),
                                   numpy.array([[1, 2, 3], [4, 5, 6]]))
        im1.putdata(numpy.array([0, 1, 0]), (0, 0), (0, 1))
        numpy.testing.assert_equal(im1.getdata(),
                                   numpy.array([[0, 1, 0], [4, 5, 6]])) 
開發者ID:casacore,項目名稱:python-casacore,代碼行數:20,代碼來源:test_image.py

示例6: test_simulation_can_recover_from_sucide_move_black

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def test_simulation_can_recover_from_sucide_move_black(self):
        model = self.model
        board = self.board

        give_two_eyes(board, 'B')

        policies, values = model.predict_on_batch(board)
        policy = policies[0]
        if np.argmax(policy) == PASS:
            policy[0], policy[PASS] = policy[PASS], policy[0] # Make best move sucide
            mask = legal_moves(board)
            policy = ma.masked_array(policy, mask=mask)
            self.assertEqual(np.argmax(policy), 0) # Best option in policy is sucide
        else:
            print("Warning, policy is not great")

        self.assertEqual(np.argmax(policy), 0) # Best option in policy is sucide
        tree = Tree()
        tree.new_tree(policy, board)
        chosen_play = select_play(policy, board, mcts_simulations=128, mcts_tree=tree.tree, temperature=0, model=model)
        
        # First simulation chooses pass, second simulation chooses sucide (p is still higher),
        # then going deeper it chooses pass again (value is higher)
        self.assertEqual(chosen_play, PASS) # Pass move is best option 
開發者ID:Narsil,項目名稱:alphagozero,代碼行數:26,代碼來源:check_model.py

示例7: test_simulation_can_recover_from_sucide_move_white

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def test_simulation_can_recover_from_sucide_move_white(self):
        model = self.model
        board, player = game_init()

        give_two_eyes(board, 'W')

        policies, values = model.predict_on_batch(board)
        policy = policies[0]

        if np.argmax(policy) == PASS:
            policy[0], policy[PASS] = policy[PASS], policy[0] # Make best move sucide
            mask = legal_moves(board)
            policy = ma.masked_array(policy, mask=mask)
            self.assertEqual(np.argmax(policy), 0) # Best option in policy is sucide
        else:
            print("Warning, policy is not great")

        tree = Tree()
        tree.new_tree(policy, board, move=2)
        chosen_play = select_play(policy, board, mcts_simulations=128, mcts_tree=tree.tree, temperature=0, model=model)
        
        # First simulation chooses pass, second simulation chooses sucide (p is still higher),
        # then going deeper it chooses pass again (value is higher)
        self.assertEqual(chosen_play, PASS) # Pass move is best option 
開發者ID:Narsil,項目名稱:alphagozero,代碼行數:26,代碼來源:check_model.py

示例8: empty

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def empty(self, process_tile):
        """
        Return empty data.

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``

        Returns
        -------
        empty data : array
            empty array with data type provided in output profile
        """
        profile = self.profile(process_tile)
        return ma.masked_array(
            data=np.full(
                (profile["count"], ) + process_tile.shape,
                profile["nodata"],
                dtype=profile["dtype"]
            ),
            mask=True
        ) 
開發者ID:ungarj,項目名稱:mapchete,代碼行數:25,代碼來源:gtiff.py

示例9: empty

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def empty(self, process_tile):
        """
        Return empty data.

        Parameters
        ----------
        process_tile : ``BufferedTile``
            must be member of process ``TilePyramid``

        Returns
        -------
        empty data : array
            empty array with data type given in output parameters
        """
        bands = (
            self.output_params["bands"]
            if "bands" in self.output_params
            else PNG_DEFAULT_PROFILE["count"]
        )
        return ma.masked_array(
            data=ma.zeros((bands, ) + process_tile.shape),
            mask=ma.zeros((bands, ) + process_tile.shape),
            dtype=PNG_DEFAULT_PROFILE["dtype"]
        ) 
開發者ID:ungarj,項目名稱:mapchete,代碼行數:26,代碼來源:png.py

示例10: test_write_raster_window_memory

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def test_write_raster_window_memory():
    """Basic output format writing."""
    path = "memoryfile"
    # standard tile
    tp = BufferedTilePyramid("geodetic")
    tile = tp.tile(5, 5, 5)
    data = ma.masked_array(np.ones((2, ) + tile.shape))
    for out_profile in [
        dict(
            driver="GTiff", count=2, dtype="uint8", compress="lzw", nodata=0,
            height=tile.height, width=tile.width, affine=tile.affine),
        dict(
            driver="GTiff", count=2, dtype="uint8", compress="deflate",
            nodata=0, height=tile.height, width=tile.width,
            affine=tile.affine),
        dict(
            driver="PNG", count=2, dtype="uint8", nodata=0, height=tile.height,
            width=tile.width, compress=None, affine=tile.affine),
    ]:
        with pytest.raises(DeprecationWarning):
            write_raster_window(
                in_tile=tile, in_data=data, out_profile=out_profile, out_path=path) 
開發者ID:ungarj,項目名稱:mapchete,代碼行數:24,代碼來源:test_io.py

示例11: test_prepare_array_maskedarrays

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def test_prepare_array_maskedarrays():
    """Convert masked array data into a proper array."""
    # input is ma.masked_array
    data = ma.empty((1, 1, 1))
    # output ndarray
    output = prepare_array(data, masked=False)
    assert isinstance(output, np.ndarray)
    assert not isinstance(output, ma.masked_array)
    assert output.shape == (1, 1, 1)
    # output masked array
    output = prepare_array(data)
    assert isinstance(output, ma.masked_array)
    assert output.shape == (1, 1, 1)
    # input is ma.masked_array with full mask
    data = ma.masked_array(data=np.ones((1, 1, 1)), mask=np.ones((1, 1, 1)))
    # output ndarray
    output = prepare_array(data, masked=False)
    assert isinstance(output, np.ndarray)
    assert not isinstance(output, ma.masked_array)
    assert output.shape == (1, 1, 1)
    # output masked array
    output = prepare_array(data)
    assert isinstance(output, ma.masked_array)
    assert output.shape == (1, 1, 1) 
開發者ID:ungarj,項目名稱:mapchete,代碼行數:26,代碼來源:test_io.py

示例12: test_prepare_array_ndarrays

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def test_prepare_array_ndarrays():
    """Convert ndarray data into a proper array."""
    # input is np.ndarray
    data = np.zeros((1, 1, 1))
    # output ndarray
    output = prepare_array(data, masked=False)
    assert isinstance(output, np.ndarray)
    assert not isinstance(output, ma.masked_array)
    assert output.shape == (1, 1, 1)
    # output masked array
    output = prepare_array(data)
    assert isinstance(output, ma.masked_array)
    assert output.shape == (1, 1, 1)
    # input is 2D np.ndarray
    data = np.zeros((1, 1))
    # output ndarray
    output = prepare_array(data, masked=False)
    assert isinstance(output, np.ndarray)
    assert not isinstance(output, ma.masked_array)
    assert output.shape == (1, 1, 1)
    # output masked array
    output = prepare_array(data)
    assert isinstance(output, ma.masked_array)
    assert output.shape == (1, 1, 1) 
開發者ID:ungarj,項目名稱:mapchete,代碼行數:26,代碼來源:test_io.py

示例13: test_read_existing_output

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def test_read_existing_output(mp_tmpdir, cleantopo_tl):
    """Read existing process output."""
    # raster data
    with mapchete.open(cleantopo_tl.path) as mp:
        tile = mp.config.process_pyramid.tile(5, 0, 0)
        # process and save
        mp.get_raw_output(tile)
        data = mp.config.output.read(tile)
        assert data.any()
        assert isinstance(data, ma.masked_array)
        assert not data.mask.all()
        # read data from Mapchete class
        data = mp.config.output.read(tile)
        assert data.any()
        assert isinstance(data, ma.masked_array)
        assert not data.mask.all() 
開發者ID:ungarj,項目名稱:mapchete,代碼行數:18,代碼來源:test_mapchete.py

示例14: test_record_array_with_object_field

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def test_record_array_with_object_field():
    # Trac #1839
    y = ma.masked_array(
        [(1, '2'), (3, '4')],
        mask=[(0, 0), (0, 1)],
        dtype=[('a', int), ('b', object)])
    # getting an item used to fail
    y[1] 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:10,代碼來源:test_mrecords.py

示例15: test_record_array_with_object_field

# 需要導入模塊: from numpy import ma [as 別名]
# 或者: from numpy.ma import masked_array [as 別名]
def test_record_array_with_object_field():
    # Trac #1839
    y = ma.masked_array(
        [(1, '2'), (3, '4')],
        mask=[(0, 0), (0, 1)],
        dtype=[('a', int), ('b', np.object)])
    # getting an item used to fail
    y[1] 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:10,代碼來源:test_mrecords.py


注:本文中的numpy.ma.masked_array方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。