Exemplo n.º 1
0
 def do_file(self, stream):
     tokenstream = Stream(self.tokenize(stream))
     stream_of_block_tokens = self.group_blocks(tokenstream)
     blocks = list(self.parse_blocks(stream_of_block_tokens))
     if not blocks:
         args = "No blocks found in file. Perhaps file is empty"\
                " or of the wrong kind. (Tried to parse %s)"
         msg = args % (self.__class__.__name__)
         raise ParseError(msg)
     blocks = self._make_complex(blocks)
     blocks = self._properties_to_vars(blocks)
     blocks = self._guess_unit(blocks)
     blocks = self._normalize(blocks)
     blocks = self._combine_matrices(blocks)
     #import pdb;pdb.set_trace()
     blocks = self._merge(blocks)
     #import pdb;pdb.set_trace()
     if isinstance(blocks, DataBlock):
         if "FILEINDEX" not in blocks:
             blocks["FILEINDEX"] = DimPartial("FILEINDEX",
                                              [self.file_index])
     else:
         for b in blocks.values():
             if isinstance(b, (list, tuple)):
                 for x in b:
                     if "FILEINDEX" not in x:
                         x["FILEINDEX"] = DimPartial(
                             "FILEINDEX", [self.file_index])
             else:
                 if "FILEINDEX" not in b:
                     b["FILEINDEX"] = DimPartial("FILEINDEX",
                                                 [self.file_index])
     self.file_index += 1
     return blocks
Exemplo n.º 2
0
 def proc_var(self, var):
     varname, value = var
     varname, vartype = varname.split('(')
     vartype = vartype.strip(")")
     if varname.startswith("SWEEP."):
         varname = varname[len("sweep."):]
     if vartype == "real":
         value = float(value)
     else:
         raise Exception("%r not an implemented var type" % vartype)
     i = DimPartial(varname, np.array([value]))
     return i
Exemplo n.º 3
0
def build_meas_state(data):
    state_names = data["measstate"][0, 0]["props"][0, 0][0]
    state_data = data["measstate"][0, 0]["values"][0, 0][0]
    d = DataBlock()
    for k, v in zip(state_names, state_data):
        if k[0] == "Index":
            d["Index"] = DimPartial("Index", v[0])
        else:
            if v[0].ndim == 1:
                d[k[0]] = hfarray(make_real(v[0][0]))
            else:
                d[k[0]] = hfarray(make_real(v[0]))
        if d[k[0]].dtype.name.startswith("unicode"):
            d[k[0]] = hfarray(np.char.encode(d[k[0]],
                                             "cp1252",
                                             errors="replace"),
                              dims=d[k[0]].dims)
    return d
Exemplo n.º 4
0
    def parse_blocks(self, stream):
        for comments, header, data in stream:
            db = DataBlock()
            db.comments = Comments(comments)
            header = header[0].strip().split("\t")
            Nhead = len(header)
            #data = np.array(data)
            if Nhead != len(data[0]):
                msg = "Different number of header variables "\
                      "from data columns"
                raise SPDataIOError(msg)
            output = DataDict()
            for varname, column in zip(header, zip(*data)):
                output.setdefault(varname, []).append(column)
            for varname in output:
                data = output[varname]
                if len(data) > 1:
                    output[varname] = np.array(output[varname], order="F").T
                else:
                    output[varname] = np.array(output[varname][0])

            freq = DimSweep(header[0], output[header[0]])
            db[header[0]] = freq
            for x in output.keys()[1:]:
                if output[x].ndim == 1:
                    db[x] = hfarray(output[x], dims=(freq, ))
                else:
                    repdim = DimRep("rep", output[x].shape[1])
                    db[x] = hfarray(output[x], dims=(freq, repdim)).squeeze()

            remove = []
            for vname in db.comments.property:
                if vname[:1] == "@":
                    unit = db.comments.property[vname].unit
                    data = [float(db.comments.property[vname])]
                    db[vname[1:]] = DimPartial(vname[1:], data=data, unit=unit)
                    remove.append(vname)
            for v in remove:
                del db.comments.property[v]
            db.comments.fullcomments = [
                com for com in db.comments.fullcomments
                if not com.startswith("@")
            ]
            yield db
Exemplo n.º 5
0
def read_muwave_matlabdata(filename, drop_empty=True, **kw):
    filenames = hftools.utils.glob(filename)
    out = []
    if len(filenames) > 1:
        for idx, fname in enumerate(filenames):
            d = read_single_muwave_matlabdata(fname, drop_empty=drop_empty)
            d["Index2"] = DimPartial("Index2", [idx])
            out.append(d)
        d = hftools.file_formats.merge_blocks(out)
    else:
        d = read_single_muwave_matlabdata(filenames[0], drop_empty=drop_empty)

    order = [
        d.ivardata[dim] for dim in ["freq", "Index", "Index2"]
        if dim in d.S.dims
    ]

    d.S = d.S.reorder_dimensions(*order)
    if drop_empty:
        for k in d.vardata.keys():
            if np.all("" == d[k]):
                del d[k]
    return d
Exemplo n.º 6
0
    a = [
        (1, 1, 1),
        (1, 1, 2),
        (1, 2, 1),
        (1, 2, 2),
        (2, 1, 1),
        (2, 1, 2),
        (2, 2, 1),
        (2, 2, 2),
    ]

    fi = DimSweep("f", array([10, 20, 30]))
    for i, k, j in a:
        db = DataBlock()
        db.I = DimPartial("I", array(i))
        db.K = DimPartial("K", array(k))
        db.J = DimPartial("J", array(j))
        db.x = hfarray([11, 12, 13], dims=(fi, )) * (i + k * 10 + j * 100)
        db.y = hfarray([11, 12, 13], dims=(fi, )) * (i + k * 10 + j * 100)
        blocks.append(db)

    for i, k, j in itertools.product([1, 2], [3, 4], [5, 6, 7]):
        db = DataBlock()
        db.I = DimPartial("I", array(i))
        db.K = DimPartial("K", array(k))
        db.J = DimPartial("J", array(j))
        db.x = hfarray([11, 12, 13], dims=(fi, )) * (i + k * 10 + j * 100)
        db.y = hfarray([11, 12, 13], dims=(fi, )) * (i + k * 10 + j * 100)
        blocks2.append(db)