示例#1
0
 def decodeFloatChannel(self, name: str, key: str = ""):
     v = self.rootgrp.variables[name]
     vfloat = float(v[0])
     vmissing = v._FillValue
     if (vfloat == vmissing):
         vfloat = None
     logging.info("CDF data " + name + " = " + str(vfloat))
     self.channels[self.getKey(key,
                               name)] = Channel(name, vfloat, vmissing, v)
示例#2
0
 def decodeIntsChannel(self, name: str, key: str = ""):
     v = self.rootgrp.variables[name]
     vints = v[:]
     vmissing = v._FillValue
     if type(vints) is np.ma.core.MaskedArray:
         vints._sharedmask = False  # this will be the default behaviour with Numpy 1.12
     vints[vints == vmissing] = None
     self.channels[self.getKey(key,
                               name)] = Channel(name, vints, vmissing, v)
     pass
示例#3
0
 def decodeBitsChannel(self, name: str, key: str = ""):
     v = self.rootgrp.variables[name]
     vstr = chartostring(v[:]).tostring()
     vstr = vstr.decode("US-ASCII")
     # 1 is good, everything else is bad
     vstr = re.sub('[023456789]', '0', vstr)
     bits = BitString(bin="0b" + vstr)
     vmissing = v._FillValue
     self.channels[self.getKey(key, name)] = Channel(
         name, bits, vmissing,
         v)  # add as a sequence of bits, which is more efficient
     pass
示例#4
0
 def decodeCharChannelToInteger(self, name: str, key: str = ""):
     v = self.rootgrp.variables[name]
     vbytes = v[0]
     if type(vbytes) is np.ma.core.MaskedArray:
         vbytes = vbytes[
             vbytes.mask ==
             False]  # get the data without any missing values (assumed to be at the end)
         vstr = vbytes.tobytes().decode(
             "US-ASCII")  # extract as bytes and decode to string
     else:
         vstr = vbytes.decode("US-ASCII")
     vmissing = v._FillValue
     vint = int(vstr)
     logging.info("CDF data " + name + " = " + str(vint))
     self.channels[self.getKey(key,
                               name)] = Channel(name, vint, vmissing, v)
示例#5
0
 def decodeFloatsChannel(self,
                         name: str,
                         scaleFactor: float,
                         offset: float,
                         key: str = ""):
     v = self.rootgrp.variables[name]
     # round (there is some evidence that scaling/offset is adjusted within the importer but not rounded again)
     decimalPlaces = int(-1.0 * np.log10(v.resolution))
     vfloats = v[:]
     for level, f in enumerate(vfloats):
         #            for i in range(0, f.count()):
         for i in range(0, f.size):
             vfloats[level][i] = round(f.data[i], decimalPlaces)
     vfloats = (vfloats * scaleFactor) + offset
     vmissing = v._FillValue
     if type(vfloats) is np.ma.core.MaskedArray:
         vfloats._sharedmask = False  # this will be the default behaviour with Numpy 1.12
     self.channels[self.getKey(key,
                               name)] = Channel(name, vfloats, vmissing, v)
     pass
示例#6
0
 def decodeCharChannelToStringsChannel(self, name: str, key: str = ""):
     v = self.rootgrp.variables[name]
     vstrs = v[:]
     if type(vstrs) is np.ma.core.MaskedArray:
         vstrs._sharedmask = False  # this will be the default behaviour with Numpy 1.12
     vstr = [None] * len(vstrs)
     for i, val in enumerate(vstrs):
         str = vstrs[i]
         vbytes = vstrs[i]
         if type(vbytes) is np.ma.core.MaskedArray:
             str = vbytes.tobytes().decode(
                 "US-ASCII")  # extract as bytes and decode to string
         else:
             str = vbytes.decode("US-ASCII")
         vstr[i] = str
         pass
     vmissing = v._FillValue
     vmissing = vmissing.decode("US-ASCII")
     #vstr = re.sub(vmissing, '', vstr)
     self.channels[self.getKey(key,
                               name)] = Channel(name, vstr, vmissing, v)
示例#7
0
 def decodeCharChannelToString(self,
                               name: str,
                               key: str = "",
                               allowMissing: bool = False):
     if name in self.rootgrp.variables or not allowMissing:
         v = self.rootgrp.variables[name]
         vbytes = v[0]
         if type(vbytes) is np.ma.core.MaskedArray:
             #vbytes = vbytes[vbytes.mask == False]   # get the data without any missing values (assumed to be at the end)
             vstr = vbytes.tobytes().decode(
                 "US-ASCII")  # extract as bytes and decode to string
         else:
             vstr = vbytes.decode("US-ASCII")
         vstr = vstr.strip(" ")
         vmissing = v._FillValue
         vmissing = vmissing.decode("US-ASCII")
         vstr = re.sub(vmissing, '', vstr)
     else:
         vstr = ""
         vmissing = ""
         v = ""
     logging.info("CDF data " + name + " = " + vstr)
     self.channels[self.getKey(key,
                               name)] = Channel(name, vstr, vmissing, v)
示例#8
0
 def decodeDimension(self, name: str, key: str = ""):
     v = self.rootgrp.dimensions[name]
     #vint = v.size
     vint = len(v)
     logging.info("CDF dimension " + name + " = " + str(vint))
     self.channels[self.getKey(key, name)] = Channel(name, vint, None, v)