Exemple #1
0
def get_dmap_group(dmap, keyseq, create=False, last=None):
    keyseq = deepcopy(keyseq)
    if last is None:
        last = {}

    if keyseq is None:
        keyseq = [None]
    elif isinstance(keyseq, six.string_types):
        keyseq = [keyseq]

    if keyseq[0] is not None:
        keyseq.insert(0, None)

    curr = dmap
    len_keyseq = len(keyseq)
    for ctr, key in enumerate(keyseq, start=1):
        if key is None:
            continue
        else:
            try:
                curr = curr._storage[DMK.GROUPS][key]
            except KeyError:
                if create:
                    curr_dct = get_or_create_dict(curr._storage, DMK.GROUPS, {})
                    if ctr == len_keyseq:
                        default = last
                    else:
                        default = {}
                    curr = get_or_create_dict(curr_dct, key, default)
                else:
                    raise
    return curr
Exemple #2
0
 def _get_element_(self, entry_key, element_key, default):
     if entry_key == DMK.CRS:
         raise DimensionMapError(
             entry_key, "Use 'get_crs' to get the CRS variable name.")
     entry = self._get_entry_(entry_key)
     ret = get_or_create_dict(entry, element_key, default)
     return ret
Exemple #3
0
    def get_spatial_mask(self):
        """
        Get the spatial mask variable name.

        :rtype: str
        """

        entry = self._get_entry_(DMK.SPATIAL_MASK)
        return get_or_create_dict(entry, DMK.VARIABLE, None)
Exemple #4
0
    def get_crs(self, parent=None, nullable=False):
        """
        Get the coordinate reference system variable name for the dimension map entry ``entry_key``.

        :rtype: str | :class:`~ocgis.CRS`
        """
        entry = self._get_entry_(DMK.CRS)
        ret = get_or_create_dict(entry, DMK.VARIABLE, None)
        if parent is not None:
            ret = get_variable_from_field(ret, parent, nullable)
        return ret
Exemple #5
0
 def _get_entry_(self, key):
     if key not in self._allowed_entry_keys:
         raise DimensionMapError(key, 'Entry not allowed.')
     else:
         return get_or_create_dict(self._storage, key, self._storage.__class__())
Exemple #6
0
 def _get_element_(self, entry_key, element_key, default):
     if entry_key == DMK.CRS:
         raise DimensionMapError(entry_key, "Use 'get_crs' to get the CRS variable name.")
     entry = self._get_entry_(entry_key)
     ret = get_or_create_dict(entry, element_key, default)
     return ret