def parse_data(self, datastream): vardata = DataDict() while True: for lineparser in self.parse_stream: linedata = datastream.pop(0).split() for func, varname in lineparser: vardata.setdefault(varname, []).append(func(linedata)) if not datastream: break return vardata
def merge_blocks_to_association_list(blocks): data = DataDict() coords = [] # Create DataDict with one entry per variable in the blocks # For each variable add a dictionary that is indexed by the DimPartials for b in blocks: coord = [] for name, dim in b.ivardata.items(): if isinstance(dim, DimPartial): coord.append((name, array(dim.data)[0])) coord.sort() coord = tuple(coord) coords.append(coord) for v in b.vardata.keys(): data.setdefault(v, []).append((coord, b.vardata[v])) return data
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
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