Exemple #1
0
 def _set_samples(self, re):
     if not isinstance(re, RegexpDict):
         raise TypeError("argument re must be of class " +
                         "{}".format(RegexpDict))
     try:
         self._samples = [re.parse(f)['SM'] for f in self._inputfiles]
     except KeyError:
         raise Exception("failed to parse sample name 'SM' from input list")
Exemple #2
0
	def function(index, r):
		path = index[i]
		try:
			with tarfile.open(path, 'r:') as tar:
				for tarinfo in tar:
					if os.path.basename(tarinfo.name) != basename:
						continue
					with tar.extractfile(tarinfo.name) as f:
						re = parse.compile(pattern)
						for line in f.read().decode().split('\n'):
							r = re.parse(line)
							if r is not None:
								return r.named['pattern']
					break
		except Exception as e:
			print(traceback.format_exc())
			pass
		raise ColumnNotFoundException()
Exemple #3
0
def getSignal(name,data=False):
    from MDSplus.mdsscalar import Int8,Int16,Int32,Int64,Float32,Float64,String
    if name=='TEXT':
        return String('Wooppp!!')
    from MDSplus._tdishr  import TdiCompile
    from MDSplus.mdsarray import Int8Array,Int16Array,Int32Array,Int64Array,Float32Array,Float64Array
    from MDSplus import Dimension
    if name=='IMAGE':
        if data:
            return TdiCompile('DATA:ARR1D32')
        else:
            name='ARR1D32'
    if name=='IMAGES':
        if data:
            return TdiCompile('DATA:ARR2D32')
        else:
            name='ARR2D32'

    from re import findall as parse
    # time, dim1, dim2, ...
    shapes=((10000,), (800,600), (64,64,64), (32,32,32,32), (16,16,16,16,16))
    dtypes= {"8"  : (Int8,       Int8Array,      'BYTE'     , 0x100,   False),
             "16" : (Int16,      Int16Array,     'WORD'     , 0x100,   False),
             "32" : (Int32,      Int32Array,     'LONG'     , 0x100,   False),
             "64" : (Int64,      Int64Array,     'QUADWORD' , 0x10000, False),
             "F"  : (Float32,    Float32Array,   'FLOAT'    , 2.,      True),
             "D"  : (Float64,    Float64Array,   'D_FLOAT'  , 2.,      True)}

    m = parse("(ARR|SEG|NUM)(?:([0-9]*)D|)([0-9FD]+)(?:_([0-9]+))?",name.upper())[0]
    ntype = m[0]
    ndims = int(m[1]) if not m[1]=='' else 1
    dtype = m[2]
    shape = shapes[ndims] if ndims<5 else (4,)*ndims
    pysfun = dtypes[dtype][0]
    pyafun = dtypes[dtype][1]
    tdifun = dtypes[dtype][2]
    factor = dtypes[dtype][3]
    isfloat= dtypes[dtype][4]
    from MDSplus.compound import Range,Signal
    from numpy import pi,cos,array

    if ntype=='NUM':
        return pysfun(pi)

    def tfun(x):
        x = cos(2*pi*x)
        if isfloat:
            return x
        return round(((x+1)/2.)*0x7F)
    def dfun(x):
        if isfloat:
            return x
        return round(x*0x7F)
    def mrange(N):
        return Range(0., 1., 1./(N-1))
    def time(r):
        return Dimension(None,r).setUnits("time")
    def axis(r,idx):
        return Dimension(None,r).setUnits("dim_of("+str(idx)+")")

    data  = TdiCompile(tdifun+'($VALUE)').setUnits('V')

    dims = [[]]*(ndims+1)
    dims[0] = mrange(shape[0])
    raw = pysfun(0).data()
    tfac = 1;
    for i in range(ndims,0,-1):
        dims[i] = X = mrange(shape[i])
        raw = array([raw*factor+dfun(x) for x in X.data().tolist()])
        tfac*= factor
        dims[i] = axis(dims[i],i)
    raw = array([raw+tfun(x)*tfac for x in dims[0].data().tolist()])
    dims[0] = time(dims[0])
    raw = pyafun(raw.tolist()).setUnits('data')
    return Signal(data,raw,*dims).setHelp('this is the help text')
Exemple #4
0
def getSignal(name, data=False):
    from MDSplus.mdsscalar import Int8, Int16, Int32, Int64, Float32, Float64, String
    if name == 'TEXT':
        return String('Wooppp!!')
    from MDSplus._tdishr import TdiCompile
    from MDSplus.mdsarray import Int8Array, Int16Array, Int32Array, Int64Array, Float32Array, Float64Array
    from MDSplus import Dimension
    if name == 'IMAGE':
        if data:
            return TdiCompile('DATA:ARR1D32')
        else:
            name = 'ARR1D32'
    if name == 'IMAGES':
        if data:
            return TdiCompile('DATA:ARR2D32')
        else:
            name = 'ARR2D32'

    from re import findall as parse
    # time, dim1, dim2, ...
    shapes = ((10000, ), (800, 600), (64, 64, 64), (32, 32, 32, 32),
              (16, 16, 16, 16, 16))
    dtypes = {
        "8": (Int8, Int8Array, 'BYTE', 0x100, False),
        "16": (Int16, Int16Array, 'WORD', 0x100, False),
        "32": (Int32, Int32Array, 'LONG', 0x100, False),
        "64": (Int64, Int64Array, 'QUADWORD', 0x10000, False),
        "F": (Float32, Float32Array, 'FLOAT', 2., True),
        "D": (Float64, Float64Array, 'D_FLOAT', 2., True)
    }

    m = parse("(ARR|SEG|NUM)(?:([0-9]*)D|)([0-9FD]+)(?:_([0-9]+))?",
              name.upper())[0]
    ntype = m[0]
    ndims = int(m[1]) if not m[1] == '' else 1
    dtype = m[2]
    shape = shapes[ndims] if ndims < 5 else (4, ) * ndims
    pysfun = dtypes[dtype][0]
    pyafun = dtypes[dtype][1]
    tdifun = dtypes[dtype][2]
    factor = dtypes[dtype][3]
    isfloat = dtypes[dtype][4]
    from MDSplus.compound import Range, Signal
    from numpy import pi, cos, array

    if ntype == 'NUM':
        return pysfun(pi)

    def tfun(x):
        x = cos(2 * pi * x)
        if isfloat:
            return x
        return round(((x + 1) / 2.) * 0x7F)

    def dfun(x):
        if isfloat:
            return x
        return round(x * 0x7F)

    def mrange(N):
        return Range(0., 1., 1. / (N - 1))

    def time(r):
        return Dimension(None, r).setUnits("time")

    def axis(r, idx):
        return Dimension(None, r).setUnits("dim_of(" + str(idx) + ")")

    data = TdiCompile(tdifun + '($VALUE)').setUnits('V')

    dims = [[]] * (ndims + 1)
    dims[0] = mrange(shape[0])
    raw = pysfun(0).data()
    tfac = 1
    for i in range(ndims, 0, -1):
        dims[i] = X = mrange(shape[i])
        raw = array([raw * factor + dfun(x) for x in X.data().tolist()])
        tfac *= factor
        dims[i] = axis(dims[i], i)
    raw = array([raw + tfun(x) * tfac for x in dims[0].data().tolist()])
    dims[0] = time(dims[0])
    raw = pyafun(raw.tolist()).setUnits('data')
    return Signal(data, raw, *dims).setHelp('this is the help text')