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


Python pyrsistent.pmap方法代码示例

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


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

示例1: wire_decode

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def wire_decode(data):
    """
    Decode the given model object from bytes.

    :param bytes data: Encoded object.
    """
    def decode(dictionary):
        class_name = dictionary.get(_CLASS_MARKER, None)
        if class_name == u"FilePath":
            return FilePath(dictionary.get(u"path").encode("utf-8"))
        elif class_name == u"PMap":
            return pmap(dictionary[u"values"])
        elif class_name == u"UUID":
            return UUID(dictionary[u"hex"])
        elif class_name == u"datetime":
            return datetime.fromtimestamp(dictionary[u"seconds"], UTC)
        elif class_name in _CONFIG_CLASS_MAP:
            dictionary = dictionary.copy()
            dictionary.pop(_CLASS_MARKER)
            return _CONFIG_CLASS_MAP[class_name].create(dictionary)
        else:
            return dictionary

    return loads(data, object_hook=decode) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:26,代码来源:_persistence.py

示例2: parameters

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def parameters(params):
        '''
        mdl.parameters is a persistent map of the parameters for the given SchiraModel object mdl.
        '''
        if not pimms.is_pmap(params): params = pyr.pmap(params)
        # do the translations that we need...
        scale = params['scale']
        if pimms.is_number(scale):
            params = params.set('scale', (scale, scale))
        elif not is_tuple(scale):
            params = params.set('scale', tuple(scale))
        shear = params['shear']
        if pimms.is_number(shear) and np.isclose(shear, 0):
            params = params.set('shear', ((1, 0), (0, 1)))
        elif shear[0][0] != 1 or shear[1][1] != 1:
            raise RuntimeError('shear matrix diagonal elements must be 1!')
        elif not is_tuple(shear) or not all(is_tuple(s) for s in shear):
            params.set('shear', tuple([tuple(s) for s in shear]))
        center = params['center']
        if pimms.is_number(center) and np.isclose(center, 0):
            params = params.set('center', (0.0, 0.0))
        return pimms.persist(params, depth=None) 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:24,代码来源:models.py

示例3: pseudo_paths

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def pseudo_paths(path, supplemental_paths, actual_cache_path):
        '''
        fmap.pseudo_paths is a mapping of pseduo-dirs in the file-map fmap. The primary path's
        pseudo-path is mapped to the key None.
        '''
        # we need to make cache paths for some of these...
        spaths = {}
        cp = None
        n = 0
        for (s,p) in six.iteritems(supplemental_paths):
            if actual_cache_path:
                cp = os.path.join(actual_cache_path, 'supp', s)
                if not os.path.isdir(cp): os.makedirs(os.path.abspath(cp), 0o755)
                n += 1
            spaths[s] = pseudo_path(p, delete=False, cache_path=cp)
        if actual_cache_path:
            if n > 0: cp = os.path.join(actual_cache_path, 'main')
            else:     cp = actual_cache_path
            if not os.path.isdir(cp): os.makedirs(os.path.abspath(cp), 0o755)
        spaths[None] = (path if is_pseudo_path(path) else
                        pseudo_path(path,delete=False,cache_path=cp))
        return pyr.pmap(spaths) 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:24,代码来源:filemap.py

示例4: test_create_container_with_cpu_shares_response

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def test_create_container_with_cpu_shares_response(self):
        """
        A valid API request to create a container including CPU shares
        returns the CPU shares supplied in the request in the response
        JSON.
        """
        container_json = pmap({
            u"node_uuid": self.NODE_B, u"name": u"webserver",
            u"image": u"nginx:latest", u"cpu_shares": 512
        })
        container_json_response = container_json.set(
            u"restart_policy", {u"name": "never"}
        )
        return self.assertResult(
            b"POST", b"/configuration/containers",
            dict(container_json), CREATED, dict(container_json_response)
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:19,代码来源:test_httpapi.py

示例5: test_create_container_with_links_response

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def test_create_container_with_links_response(self):
        """
        An API request to create a container including links to be injected in
        to the container returns the link information in the response JSON.
        """
        container_json = pmap({
            u"node_uuid": self.NODE_B, u"name": u"webserver",
            u"image": u"nginx:latest", u"links": [
                {
                    u'alias': u'postgres',
                    u'local_port': 5432,
                    u'remote_port': 54320
                },
            ]
        })
        container_json_response = container_json.set(
            u"restart_policy", {u"name": "never"}
        )
        return self.assertResult(
            b"POST", b"/configuration/containers",
            dict(container_json), CREATED, dict(container_json_response)
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:24,代码来源:test_httpapi.py

示例6: test_valid_fig_config_volumes

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def test_valid_fig_config_volumes(self):
        """
        ``FigConfiguration._parse_app_volumes`` returns a ``AttachedVolume``
        instance containing the volume mountpoint given a valid configuration.
        """
        config = {
            'postgres': {
                'image': 'sample/postgres',
                'volumes': [b'/var/db/data']
            }
        }
        parser = FigConfiguration(config)
        expected_result = AttachedVolume(
            manifestation=Manifestation(
                dataset=Dataset(dataset_id=dataset_id_from_name("postgres"),
                                metadata=pmap({"name": "postgres"})),
                primary=True),
            mountpoint=FilePath(b'/var/db/data')
        )
        volume = parser._parse_app_volumes(
            'postgres',
            config['postgres']['volumes']
        )
        self.assertEqual(expected_result, volume) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:26,代码来源:test_config.py

示例7: test_transform_typeerror

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def test_transform_typeerror(self):
        """
        ``transform`` raises ``TypeError`` if the object at the supplied
        ``path`` does not provide ``_IEvolvable``.
        """
        proxy = _TransformProxy(pmap({'a': 1}))

        e = self.assertRaises(
            TypeError,
            proxy.transform,
            ['a'], 2,
        )
        self.assertEqual(
            "1 does not provide _IEvolvable",
            e.message
        ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:18,代码来源:test_diffing.py

示例8: create_attached_volume

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def create_attached_volume(dataset_id, mountpoint, maximum_size=None,
                           metadata=pmap()):
    """
    Create an ``AttachedVolume`` instance with the supplied parameters and
    return it.

    :param unicode dataset_id: The unique identifier of the dataset of the
        attached volume.
    :param bytes mountpoint: The path at which the volume is attached.
    :param int maximum_size: An optional maximum size for the volume.

    :return: A new ``AttachedVolume`` instance referencing a primary
        manifestation of a dataset with the given unique identifier.
    """
    return AttachedVolume(
        manifestation=Manifestation(
            dataset=Dataset(
                dataset_id=dataset_id,
                maximum_size=maximum_size,
                metadata=metadata,
            ),
            primary=True,
        ),
        mountpoint=FilePath(mountpoint),
    ) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:27,代码来源:testtools.py

示例9: create_dataset

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def create_dataset(primary, maximum_size=None, dataset_id=None,
                       metadata=pmap(), configuration_tag=None):
        """
        Create a new dataset in the configuration.

        :param UUID primary: The node where the dataset should manifest.
        :param maximum_size: Size of new dataset in bytes (as ``int``) or
            ``None`` if no particular size is required (not recommended).
        :param dataset_id: If given, the UUID to use for the dataset.
        :param metadata: A mapping between unicode keys and values, to be
            stored as dataset metadata.
        :param configuration_tag: If not ``None``, should be
            ``DatasetsConfiguration.tag``.

        :return: ``Deferred`` that fires after the configuration has been
            updated with resulting ``Dataset``, or errbacking with
            ``DatasetAlreadyExists``.
        """ 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:20,代码来源:_client.py

示例10: test_missing_required_field

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def test_missing_required_field(self):
        """
        Non-Eliot JSON messages are not formatted.
        """
        base = pmap(SIMPLE_MESSAGE)
        messages = [dumps(dict(base.remove(field))) for field in REQUIRED_FIELDS] + [
            dumps(SIMPLE_MESSAGE)
        ]
        stdout = self.write_and_read(messages)
        self.assertEqual(
            stdout,
            "{}{}\n".format(
                "".join(
                    "Not an Eliot message: {}\n\n".format(msg) for msg in messages[:-1]
                ),
                pretty_format(SIMPLE_MESSAGE),
            ),
        ) 
开发者ID:itamarst,项目名称:eliot,代码行数:20,代码来源:test_prettyprint.py

示例11: calc_registrations

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def calc_registrations(note, error, cortices, model, model_sym,
                       weight_min, scale, prior, max_out_eccen, max_steps, max_step_size,
                       radius_weight, field_sign_weight, resample, invert_rh_angle,
                       part_vol_correct):
    '''
    calc_registrations is the calculator that performs the registrations for the left and right
    hemisphere; these are returned as the immutable maps yielded from the register_retinotopy
    command.
    '''
    rsamp = ('fsaverage_sym' if model_sym else 'fsaverage') if resample else False
    # Do the registration
    res = {}
    for (h,ctx) in six.iteritems(cortices):
        note('Preparing %s Registration...' % h.upper())
        try:
            res[h] = register_retinotopy(ctx, model[h],
                                         model_hemi='sym' if model_sym else h,
                                         polar_angle='polar_angle',
                                         eccentricity='eccentricity',
                                         weight='weight',
                                         weight_min=weight_min,
                                         partial_voluming_correction=part_vol_correct,
                                         field_sign_weight=field_sign_weight,
                                         radius_weight=radius_weight,
                                         scale=scale,
                                         prior=prior,
                                         resample=rsamp,
                                         invert_rh_field_sign=invert_rh_angle,
                                         max_steps=max_steps,
                                         max_step_size=max_step_size,
                                         yield_imap=True)
        except Exception: #error('Exception caught while setting-up register_retinotopy (%s)' % h)
            raise
    return {'registrations': pyr.pmap(res)} 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:36,代码来源:register_retinotopy.py

示例12: calc_hemispheres

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def calc_hemispheres(subject, hemispheres='lh,rh'):
    '''
    calc_hemispheres extracts the relevant hemispheres from the subject object.

    Afferent parameters:
      @ hemispheres 
        The names of the hemispheres to be used in the retinotopy calculations. The default value
        is "lh,rh", but other hemisphere names, such as "lh_LR32k,rh_LR32k" (for an HCP-pipeline
        subject) can be given. All hemispheres should be separated by commas. If you want to give
        a hemisphere a particular tag, you can specify it as tag:hemi, e.g.:
        "lh:lh_LR32k,rh:rh_LR32k"; tags are used with other options for specifying data specific
        to a hemisphere.
    '''
    if not hemispheres: hemispheres = 'lh,rh'
    # first, separate by commas
    hs = hemispheres.split(',')
    hemis = {}
    hlist = []
    for h in hs:
        (tag,name) = h.split(':') if ':' in h else (h,h)
        h = subject.hemis.get(name, None)
        if h is None:
            raise ValueError('Give subject does not have a hemisphere named "%s"' % (name,))
        hemis[tag] = h
        hlist.append(tag)
    return {'hemisphere_data': pyr.pmap(hemis),
            'hemisphere_tags': hlist} 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:29,代码来源:retinotopy.py

示例13: hemis

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def hemis(h):
        '''
        sub.hemis is a persistent map of hemisphere names ('lh', 'rh', possibly others) for the
        given subject sub.
        '''
        if   h is None:        return pyr.m()
        elif pimms.is_pmap(h): return h
        elif pimms.is_map(h):  return pyr.pmap(h)
        else: raise ValueError('hemis must be a mapping') 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:11,代码来源:core.py

示例14: images

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def images(imgs):
        '''
        sub.images is a persistent map of MRImages tracked by the given subject sub.
        '''
        if   imgs is None:        return pyr.m()
        elif pimms.is_pmap(imgs): return imgs
        elif pimms.is_map(imgs):  return pyr.pmap(imgs)
        else: raise ValueError('images must be a mapping')

    # Updater operations: 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:12,代码来源:core.py

示例15: area_name_to_id

# 需要导入模块: import pyrsistent [as 别名]
# 或者: from pyrsistent import pmap [as 别名]
def area_name_to_id(vai):
        '''
        mdl.area_name_to_id is a persistent map whose keys are area names (such as 'V1' or 'hV4')
        and whose values are the area id (a number greater than 0) for that area.
        mdl.area_name_to_id is a parameter which may be provided as a lsit of area names, in which
        case the first is assumed to be area 1, the next area 2, etc.
        '''
        if vai is None: return None
        if not pimms.is_map(vai): return pyr.pmap({nm:(ii+1) for (ii,nm) in enumerate(vai)})
        elif pimms.is_pmap(vai): return vai
        else: return pyr.pmap(vai) 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:13,代码来源:models.py


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