def toCDML(self, forcedata=0): "Translate to a CDML tree. Returns a cdms.cdmsNode.AxisNode." axisnode = AxisNode(self.name, self.length, CdFloat) # Only for virtual axes axisnode.setExternalAttr("isvar", "false", CdString) if forcedata: axisnode.setData(Numeric.arrayrange(float(self.length))) return axisnode
def toCDML(self, ncnode, forcedata=0): "Translate to a CDML tree. Returns a cdms.cdmsNode.VariableNode or cdms.cdmsNode.AxisNode." dimdict = ncnode.dimensions if self.name in dimdict.keys() and self.shape is not None and len( self.shape) == 1: dimnode = dimdict[self.name] varnode = AxisNode(self.name, dimnode.length, NCToCdType[self.datatype]) if self.values is not None: varnode.setData(self.values.values) elif forcedata: varnode.setData(Numeric.arrayrange(float(dimnode.length))) else: domnode = DomainNode() if self.shape is not None: for dimid in self.shape: dimncnode = dimdict[dimid] domelemnode = DomElemNode(dimid, 0, dimncnode.length) domnode.add(domelemnode) varnode = cdmsNode.VariableNode(self.name, NCToCdType[self.datatype], domnode) attkeys = self.attributes.keys() attkeys.sort() for attkey in attkeys: attncnode = self.attributes[attkey] value = attncnode.value if isinstance(value, Numeric.ArrayType): value = value[0] varnode.setExternalAttr(attncnode.name, value, NCToCdType[attncnode.datatype]) return varnode
def toCDML(self, ncnode, forcedata=0): "Translate to a CDML tree. Returns a cdms.cdmsNode.VariableNode or cdms.cdmsNode.AxisNode." dimdict = ncnode.dimensions if self.name in dimdict.keys() and self.shape is not None and len(self.shape)==1: dimnode = dimdict[self.name] varnode = AxisNode(self.name, dimnode.length, NCToCdType[self.datatype]) if self.values is not None: varnode.setData(self.values.values) elif forcedata: varnode.setData(Numeric.arrayrange(float(dimnode.length))) else: domnode = DomainNode() if self.shape is not None: for dimid in self.shape: dimncnode = dimdict[dimid] domelemnode = DomElemNode(dimid, 0, dimncnode.length) domnode.add(domelemnode) varnode = cdmsNode.VariableNode(self.name, NCToCdType[self.datatype], domnode) attkeys = self.attributes.keys() attkeys.sort() for attkey in attkeys: attncnode = self.attributes[attkey] value = attncnode.value if isinstance(value, Numeric.ArrayType): value = value[0] varnode.setExternalAttr(attncnode.name, value, NCToCdType[attncnode.datatype]) return varnode