当前位置: 首页>>代码示例>>Python>>正文


Python Dataset.values方法代码示例

本文整理汇总了Python中pydicom.dataset.Dataset.values方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.values方法的具体用法?Python Dataset.values怎么用?Python Dataset.values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydicom.dataset.Dataset的用法示例。


在下文中一共展示了Dataset.values方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DIMSEMessage

# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import values [as 别名]
class DIMSEMessage(object):
    command_field = None
    command_fields = []

    def __init__(self, command_set=None):
        self._data_set = None
        if command_set:
            self.command_set = command_set
        else:
            self.command_set = Dataset()
            self.command_set.CommandField = self.command_field
            self.command_set.CommandDataSetType = NO_DATASET
            for field in self.command_fields:
                setattr(self.command_set, field, '')

    sop_class_uid = dimse_property((0x0000, 0x0002))

    @property
    def data_set(self):
        return self._data_set

    @data_set.setter
    def data_set(self, value):
        if value:
            self.command_set.CommandDataSetType = 0x0001
        self._data_set = value

    def encode(self, pc_id, max_pdu_length):
        """Returns the encoded message as a series of P-DATA service
        parameter objects."""
        encoded_command_set = dsutils.encode(self.command_set, True, True)

        # fragment command set
        for item, bit in fragment(encoded_command_set, max_pdu_length, 1, 3):
            # send only one pdv per p-data primitive
            value_item = pdu.PresentationDataValueItem(
                pc_id, struct.pack('b', bit) + item)
            yield pdu.PDataTfPDU([value_item])

        # fragment data set
        if self.data_set:
            if isinstance(self.data_set, bytes):
                # got dataset as byte array
                gen = fragment(self.data_set, max_pdu_length, 0, 2)
            else:
                # assume that dataset is in file-like object
                gen = fragment_file(self.data_set, max_pdu_length, 0, 2)
            for item, bit in gen:
                value_item = pdu.PresentationDataValueItem(
                    pc_id, struct.pack('b', bit) + item)
                yield pdu.PDataTfPDU([value_item])

    def set_length(self):
        it = (len(dsutils.encode_element(v, True, True))
              for v in list(self.command_set.values())[1:])
        self.command_set[(0x0000, 0x0000)].value = sum(it)

    def __repr__(self):
        return str(self.command_set) + '\n'
开发者ID:blanebf,项目名称:pynetdicom2,代码行数:61,代码来源:dimsemessages.py

示例2: __init__

# 需要导入模块: from pydicom.dataset import Dataset [as 别名]
# 或者: from pydicom.dataset.Dataset import values [as 别名]
class DIMSEMessage:

    def __init__(self):
        self.CommandSet = None
        self.EncodedDataSet = None
        self.DataSet = None
        self.encoded_command_set = ''
        self.ID = id

        self.ts = ImplicitVRLittleEndian  # imposed by standard.
        if self.__class__ != DIMSEMessage:
            self.CommandSet = Dataset()
            for ii in self.CommandFields:
                self.CommandSet.add_new(ii[1], ii[2], '')

    def Encode(self, id, maxpdulength):
        """Returns the encoded message as a series of P-DATA service
        parameter objects"""
        self.ID = id
        pdatas = []
        encoded_command_set = dsutils.encode(
            self.CommandSet, self.ts.is_implicit_VR, self.ts.is_little_endian)

        # fragment command set
        pdvs = fragment(maxpdulength, encoded_command_set)
        assert ''.join(pdvs) == encoded_command_set
        for ii in pdvs[:-1]:
            # send only one pdv per pdata primitive
            pdata = P_DATA_ServiceParameters()
            # not last command fragment
            pdata.PresentationDataValueList = [[self.ID, pack('b', 1) + ii]]
            pdatas.append(pdata)
        # last command fragment
        pdata = P_DATA_ServiceParameters()
        # last command fragment
        pdata.PresentationDataValueList = [[self.ID, pack('b', 3) + pdvs[-1]]]
        pdatas.append(pdata)

        # fragment data set
        #if self.__dict__.has_key('DataSet') and self.DataSet:
        if 'DataSet' in self.__dict__ and self.DataSet is not None:
            pdvs = fragment(maxpdulength, self.DataSet)
            assert ''.join(pdvs) == self.DataSet
            for ii in pdvs[:-1]:
                pdata = P_DATA_ServiceParameters()
                # not last data fragment
                pdata.PresentationDataValueList = [
                    [self.ID, pack('b', 0) + ii]]
                pdatas.append(pdata)
            pdata = P_DATA_ServiceParameters()
            # last data fragment
            pdata.PresentationDataValueList = [
                [self.ID, pack('b', 2) + pdvs[-1]]]
            pdatas.append(pdata)

        return pdatas

    def Decode(self, pdata):
        """Constructs itself receiving a series of P-DATA primitives.
        Returns True when complete, False otherwise."""
        if pdata.__class__ != P_DATA_ServiceParameters:
            # not a pdata
            return False
        if pdata is None:
            return False
        ii = pdata
        for vv in ii.PresentationDataValueList:
            # must be able to read P-DATA with several PDVs
            self.ID = vv[0]
            if unpack('b', vv[1][0])[0] in (1, 3):
                logger.debug("  command fragment %s", self.ID)
                self.encoded_command_set += vv[1][1:]
                if unpack('b', vv[1][0])[0] == 3:
                    logger.debug("  last command fragment %s", self.ID)
                    self.CommandSet = dsutils.decode(
                        self.encoded_command_set, self.ts.is_implicit_VR,
                        self.ts.is_little_endian)
                    self.__class__ = MessageType[
                        self.CommandSet[(0x0000, 0x0100)].value]
                    if self.CommandSet[(0x0000, 0x0800)].value == 0x0101:
                        # response: no dataset
                        return True
            elif unpack('b', vv[1][0])[0] in (0, 2):
                if self.DataSet is None:
                    self.DataSet = ''
                self.DataSet += vv[1][1:]
                logger.debug("  data fragment %s", self.ID)
                if unpack('b', vv[1][0])[0] == 2:
                    logger.debug("  last data fragment %s", self.ID)
                    return True
            else:
                raise "Error"

        return False

    def SetLength(self):
        # compute length
        l = 0
        for ii in self.CommandSet.values()[1:]:
            l += len(dsutils.encode_element(ii,
#.........这里部分代码省略.........
开发者ID:CydarLtd,项目名称:pynetdicom,代码行数:103,代码来源:DIMSEmessages.py


注:本文中的pydicom.dataset.Dataset.values方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。