Exemplo n.º 1
0
    def others(self, other, name='other'):
        '''Check this and an other instance for type compatiblility.

           @param other: The other instance (any).
           @keyword name: Optional, name for other (string).

           @return: None.

           @raise TypeError: Mismatch of this and type(other).
        '''
        if not (isinstance(other, self.__class__) or
                (hasattr(other, 'lat') and hasattr(other, 'lon'))):
            raise TypeError('type(%s) mismatch: %s vs %s' %
                            (name, classname(other), classname(self)))
Exemplo n.º 2
0
    def writeMember(self, obj, memberName):
        if isString(obj):
            logging.warning(u"String as object provided! " +
                            self._warningPrefix(obj, memberName))
        if isInteger(memberName) and isList(obj):
            member = obj[memberName]
            memberName = str(memberName)
        else:
            member = getattr(obj, memberName, None)
        if member is None:
            self.log(u"skipped " + self._warningPrefix(obj, memberName) +
                     u"It is empty or does not exist (=None).")
            return

        if isCallable(member) and not hasattr(member, "hdfWrite"):
            member = member()

        if hasattr(member, "hdfWrite"):  # support instances and types
            # store the member in a group of its own
            oldLocation = self.location
            self._location = "/".join((oldLocation.rstrip('/'), memberName))
            member.hdfWrite(self)  # recursion entry, mind the loops!
            self._location = oldLocation
        elif isList(member):
            self.writeDataset(memberName, member)
        elif isString(member) or isNumber(member):
            self.writeAttribute(memberName, member)
        else:
            self.log(u"skipped " + self._warningPrefix(obj, memberName) +
                     "(={}) It is not a compatible value type!".format(
                         classname(member)))
Exemplo n.º 3
0
    def toStr2(self, **kwds):
        '''This L{LatLon_} as a string "class(<degrees>, ...)".

           @keyword kwds: Optional, keyword arguments.

           @return: Class instance (string).
        '''
        return '%s(%s)' % (classname(self), self.toStr(**kwds))
Exemplo n.º 4
0
 def radius(self):
     '''Get the earth radius (meter).
     '''
     r = self._radius
     if r < EPS:
         t = '%s.%s' % (classname(self), 'radius')
         raise ValueError('%s invalid: %r' % (t, r))
     return r
Exemplo n.º 5
0
 def hdfWrite(self, hdf):
     xlst = ("onValueUpdate", )
     selfAttr = self.attributes(exclude=xlst)
     selfAttr['cls'] = classname(selfAttr['cls'])
     for name in self.hdfStoreAsMember():
         if name in selfAttr:
             selfAttr.pop(name)
             hdf.writeMember(self, name)
     hdf.writeAttributes(**selfAttr)
Exemplo n.º 6
0
 def writeDataset(self, name, data):
     if not isList(data):
         self.log("dataset {} is not of a list type! (={})".format(
             name, classname(data)))
         return
     shape = getattr(data, 'shape', "(len: {})".format(len(data)))
     self.log("dataset '{loc}/{name}' {shape}".format(
         loc=self.location.rstrip('/'), name=name, shape=shape))
     writeLocation = self._writeLocation()
     if name in writeLocation:
         del writeLocation[name]
     try:
         writeLocation.create_dataset(name, data=data, compression="gzip")
     except TypeError:
         # a TypeError is raised for non-chunkable data (such as string)
         writeLocation.create_dataset(name, data=data)
Exemplo n.º 7
0
 def hdfWrite(self, hdf):
     hdf.writeAttributes(modelName = classname(self))
     for p in self.params():
         logging.debug("Writing model parameter: {} to HDF5".format(p.name()))
         hdf.writeMember(self, p.name())
Exemplo n.º 8
0
 def hdfWrite(self, hdf):
     hdf.writeAttributes(cls=classname(self))
Exemplo n.º 9
0
 def hdfWrite(self, hdf):
     hdf.writeAttributes(type=classname(self),
                         displayMagnitudeName=self.displayMagnitudeName,
                         magnitudeConversion=self.magnitudeConversion)
Exemplo n.º 10
0
 def hdfWrite(self, hdf):
     hdf.writeAttributes(name=self.name(), cls=classname(self))
     hdf.writeMembers(self, *[p.name() for p in self.params()])
Exemplo n.º 11
0
 def _warningPrefix(self, obj, memberName):
     return (u"{cls}.{mem} {cal} ".format(cal=getCallerInfo(type(self)),
                                          cls=classname(obj),
                                          mem=memberName))
Exemplo n.º 12
0
 def log(self, msg):
     logging.debug(u"[{}] {}".format(classname(self), msg))