def _append_parameter(self, parameter_context): """ Appends a ParameterContext object to the internal set for this coverage. The supplied ParameterContext is added to self.range_dictionary. An AbstractParameterValue of the type indicated by ParameterContext.param_type is added to self.range_value. If the ParameterContext indicates that the parameter is a coordinate parameter, it is associated with the indicated axis of the appropriate CRS. @param parameter_context The ParameterContext to append to the coverage @throws StandardError If the ParameterContext.axis indicates that it is temporal and a temporal parameter already exists in the coverage """ pname = parameter_context.name # Determine the correct array shape (default is the shape of the spatial_domain) # If there is only one extent in the spatial domain and it's size is 0, collapse to time only # CBM TODO: This determination must be made based on the 'variability' of the parameter (temporal, spatial, both), not by assumption if len(self.spatial_domain.shape.extents) == 1 and self.spatial_domain.shape.extents[0] == 0: shp = self.temporal_domain.shape.extents else: shp = self.temporal_domain.shape.extents + self.spatial_domain.shape.extents # Assign the pname to the CRS (if applicable) and select the appropriate domain (default is the spatial_domain) dom = self.spatial_domain if not parameter_context.reference_frame is None and AxisTypeEnum.is_member(parameter_context.reference_frame, AxisTypeEnum.TIME): if self._temporal_param_name is None: self._temporal_param_name = pname else: raise StandardError("temporal_parameter already defined.") dom = self.temporal_domain shp = self.temporal_domain.shape.extents dom.crs.axes[parameter_context.reference_frame] = parameter_context.name elif parameter_context.reference_frame in self.spatial_domain.crs.axes: dom.crs.axes[parameter_context.reference_frame] = parameter_context.name self._pcmap[pname] = (len(self._pcmap), parameter_context, dom) self.range_dictionary[pname] = parameter_context self.range_value[pname] = RangeMember(shp, parameter_context)
def add_axis(self, axis_type, axis_name=None): if not AxisTypeEnum.has_member(axis_type): raise KeyError('Invalid \'axis_type\', must be a member of AxisTypeEnum') self.axes[axis_type] = axis_name
def _append_parameter(self, parameter_context): """ Appends a ParameterContext object to the internal set for this coverage. A <b>deep copy</b> of the supplied ParameterContext is added to self._range_dictionary. An AbstractParameterValue of the type indicated by ParameterContext.param_type is added to self._range_value. If the ParameterContext indicates that the parameter is a coordinate parameter, it is associated with the indicated axis of the appropriate CRS. @param parameter_context The ParameterContext to append to the coverage <b>as a copy</b> @throws StandardError If the ParameterContext.axis indicates that it is temporal and a temporal parameter already exists in the coverage """ if self.closed: raise IOError('I/O operation on closed file') if self.mode == 'r': raise IOError('Coverage not open for writing: mode == \'{0}\''.format(self.mode)) if not isinstance(parameter_context, ParameterContext): raise TypeError('\'parameter_context\' must be an instance of ParameterContext') # Create a deep copy of the ParameterContext pcontext = deepcopy(parameter_context) pname = pcontext.name no_sdom = self.spatial_domain is None ## Determine the correct array shape # Get the parameter variability; assign to VariabilityEnum.NONE if None pv=pcontext.variability or VariabilityEnum.NONE if no_sdom and pv in (VariabilityEnum.SPATIAL, VariabilityEnum.BOTH): log.warn('Provided \'parameter_context\' indicates Spatial variability, but coverage has no Spatial Domain') if pv == VariabilityEnum.TEMPORAL: # Only varies in the Temporal Domain pcontext.dom = DomainSet(self.temporal_domain.shape.extents, None) elif pv == VariabilityEnum.SPATIAL: # Only varies in the Spatial Domain pcontext.dom = DomainSet(None, self.spatial_domain.shape.extents) elif pv == VariabilityEnum.BOTH: # Varies in both domains # If the Spatial Domain is only a single point on a 0d Topology, the parameter's shape is that of the Temporal Domain only if no_sdom or (len(self.spatial_domain.shape.extents) == 1 and self.spatial_domain.shape.extents[0] == 0): pcontext.dom = DomainSet(self.temporal_domain.shape.extents, None) else: pcontext.dom = DomainSet(self.temporal_domain.shape.extents, self.spatial_domain.shape.extents) elif pv == VariabilityEnum.NONE: # No variance; constant # CBM TODO: Not sure we can have this constraint - precludes situations like a TextType with Variablity==None... # # This is a constant - if the ParameterContext is not a ConstantType, make it one with the default 'x' expr # if not isinstance(pcontext.param_type, ConstantType): # pcontext.param_type = ConstantType(pcontext.param_type) # The domain is the total domain - same value everywhere!! # If the Spatial Domain is only a single point on a 0d Topology, the parameter's shape is that of the Temporal Domain only if no_sdom or (len(self.spatial_domain.shape.extents) == 1 and self.spatial_domain.shape.extents[0] == 0): pcontext.dom = DomainSet(self.temporal_domain.shape.extents, None) else: pcontext.dom = DomainSet(self.temporal_domain.shape.extents, self.spatial_domain.shape.extents) else: # Should never get here...but... raise SystemError('Must define the variability of the ParameterContext: a member of VariabilityEnum') # Assign the pname to the CRS (if applicable) and select the appropriate domain (default is the spatial_domain) dom = self.spatial_domain if not pcontext.axis is None and AxisTypeEnum.is_member(pcontext.axis, AxisTypeEnum.TIME): dom = self.temporal_domain dom.crs.axes[pcontext.axis] = pcontext.name elif not no_sdom and (pcontext.axis in self.spatial_domain.crs.axes): dom.crs.axes[pcontext.axis] = pcontext.name self._range_dictionary.add_context(pcontext) s = self._persistence_layer.init_parameter(pcontext, self._bricking_scheme) self._range_value[pname] = get_value_class(param_type=pcontext.param_type, domain_set=pcontext.dom, storage=s)