def main(): opts = cmd_opt_parse() multi_cmd_patterns, _ = fetch_cmd_patterns(opts.pattern, opts.pattern_file, opts.pattern_sep) ofname = opts.output if opts.output else opts.input + ".new" of = open(ofname, "w") filtered_fname = opts.filtered if opts.filtered else opts.input + ".filtered" filtered_f = open(filtered_fname, "w") readable_fname = opts.readable if opts.readable else opts.input + ".filtered_readable" readable_f = open(readable_fname, "w") with open(opts.input) as f: cmd_parser = CommandParser(f) for cmds, raw_buf in cmd_parser: old_part_num = len(cmds) matched, skip = match_and_filter_cmds(cmds, multi_cmd_patterns, filtered_f, readable_f) if matched: output_file = filtered_f if not skip: readable_f.write(" ".join(cmds) + "\n") else: output_file = of if not skip: if old_part_num != len(cmds): raw_buf = format_cmd_buf(cmds) write_array(raw_buf, output_file) of.close() filtered_f.close() readable_f.close()
def sub_predict(args): _, (x, _) = ul.load_data(args.file, label_exist=False) model = ul.load_model(args.model) y_pred, y_prob = cp.predict(x, model) if y_prob is None: ul.write_array(args.output, y_pred.reshape(-1, 1)) else: ul.write_array(args.output, y_pred.reshape(-1, 1), y_prob)
def sub_split(args): ts = args.testsize if 0 < ts < 1: data_train, data_test, names = ul.split_data(args.file, ts) header = ','.join(names) ul.write_array(f"{1-ts}_{args.output}", data_train, header=header) ul.write_array(f"{ts}_{args.output}", data_test, header=header) else: print("error")
def comment_thread(): for comment in subreddit.stream.comments(): author = comment.author.name.lower() comment_ID = comment.id if (comment_ID in checked_comments): continue checked_comments.append(comment_ID) utils.write_array(data_folder + checked_file, checked_comments) # We don't serve your kind around here if ("_bot" in author): continue text = comment.body.lower() exist = author in list(users.keys()) print("Author - {}\nText - {}\nExist? - {}\n\n".format(author, text, exist)) if ("!ignore" in text): continue if ("!help" in text): help(comment) continue # The !create command if (("!create" in text) and (not exist)): create(comment, author) continue if ((not exist) and (("!invest" in text) or ("!balance" in text) or ("!broke" in text) or ("!active" in text) or ("!market" in text))): send_not(comment, message.no_account_org, False) continue # The !invest command if ("!invest" in text): invest(comment, author, text) continue if ("!balance" in text): balance(comment, author) continue if ("!active" in text): activity(comment, author) continue if ("!market" in text): market(comment, author) continue if ("!broke" in text): broke(comment, author) continue
def main(): opts = cmd_opt_parse() multi_cmd_patterns, key_patterns = fetch_cmd_patterns(opts.pattern, opts.pattern_file, opts.pattern_sep) ofname = opts.output if opts.output else opts.input + '.fetch' of = open(ofname, 'w') readable_fname = opts.readable if opts.readable else \ opts.input + '.fetch_readable' readable_f = open(readable_fname, 'w') filtered_fname = opts.filtered if opts.filtered else \ opts.input + '.filtered' filtered_f = open(filtered_fname, 'w') filtered_rfname = opts.input + '.filtered_readable' filtered_rf = open(filtered_rfname, 'w') # fetch all commands on the specified keys matched_cmds = [] with open(opts.input) as f: cmd_parser = CommandParser(f) # iterate each command in AOF for cmds, raw_buf in cmd_parser: key = cmds[1] for key_pattern in key_patterns: if not key_pattern.match(key): continue matched_cmds.append((cmds, raw_buf)) # filter specified commands for cmds, raw_buf in matched_cmds: old_part_num = len(cmds) matched, skip = match_and_filter_cmds(cmds, multi_cmd_patterns, filtered_f, filtered_rf) if matched: output_f = filtered_f output_readable_f = filtered_rf else: output_f = of output_readable_f = readable_f if not skip: if old_part_num != len(cmds): raw_buf = format_cmd_buf(cmds) write_array(raw_buf, output_f) output_readable_f.write(' '.join(cmds) + '\n') of.close() readable_f.close() filtered_f.close()
def main(): opts = cmd_opt_parse() multi_cmd_patterns, key_patterns = fetch_cmd_patterns( opts.pattern, opts.pattern_file, opts.pattern_sep) ofname = opts.output if opts.output else opts.input + '.fetch' of = open(ofname, 'w') readable_fname = opts.readable if opts.readable else \ opts.input + '.fetch_readable' readable_f = open(readable_fname, 'w') filtered_fname = opts.filtered if opts.filtered else \ opts.input + '.filtered' filtered_f = open(filtered_fname, 'w') filtered_rfname = opts.input + '.filtered_readable' filtered_rf = open(filtered_rfname, 'w') # fetch all commands on the specified keys matched_cmds = [] with open(opts.input) as f: cmd_parser = CommandParser(f) # iterate each command in AOF for cmds, raw_buf in cmd_parser: key = cmds[1] for key_pattern in key_patterns: if not key_pattern.match(key): continue matched_cmds.append((cmds, raw_buf)) # filter specified commands for cmds, raw_buf in matched_cmds: old_part_num = len(cmds) matched, skip = match_and_filter_cmds(cmds, multi_cmd_patterns, filtered_f, filtered_rf) if matched: output_f = filtered_f output_readable_f = filtered_rf else: output_f = of output_readable_f = readable_f if not skip: if old_part_num != len(cmds): raw_buf = format_cmd_buf(cmds) write_array(raw_buf, output_f) output_readable_f.write(' '.join(cmds) + '\n') of.close() readable_f.close() filtered_f.close()
def sub_extract(args): iscount = args.count k, gap, lam, n_jobs = args.kmer, args.gap, args.lam, args.process if args.directory: out = Path(args.output[0]) out.mkdir(exist_ok=True) ul.batch_extract(args.file, out, k, gap, lam, n_jobs=n_jobs, count=iscount) else: if args.raa: raa = list(args.raa) else: raa = list(Path(args.file[0]).stem.split('-')[-1]) xy_ls = [] aa_ls = [''.join(aa) for aa in product(raa, repeat=k)] for idx, file in enumerate(args.file): feature_file = Path(file) xy = ul.extract_feature(feature_file, raa, k, gap, lam, count=iscount) new_aa_ls = aa_ls if args.index: _, (fea_idx, _) = ul.load_data(args.index, normal=False, label_exist=False) fea_idx = fea_idx.astype(int).flatten() xy = xy[:, fea_idx] new_aa_ls = [aa_ls[i] for i in fea_idx] if args.label_f: y = np.array([[idx]] * xy.shape[0]) xy = np.hstack([y, xy]) xy_ls.append(xy) new_aa_ls.insert(0, 'label') if args.label_f else 0 header = ','.join(new_aa_ls) if args.merge: out = args.output[0] seq_mtx = np.vstack(xy_ls) ul.write_array(Path(out), seq_mtx, header=header) exit() for idx, o in enumerate(args.output): ul.write_array(Path(o), xy_ls[idx], header=header)
def main(): opts = cmd_opt_parse() multi_cmd_patterns, _ = fetch_cmd_patterns(opts.pattern, opts.pattern_file, opts.pattern_sep) ofname = opts.output if opts.output else opts.input + '.new' of = open(ofname, 'w') filtered_fname = opts.filtered if opts.filtered else \ opts.input + '.filtered' filtered_f = open(filtered_fname, 'w') readable_fname = opts.readable if opts.readable else \ opts.input + '.filtered_readable' readable_f = open(readable_fname, 'w') with open(opts.input) as f: cmd_parser = CommandParser(f) for cmds, raw_buf in cmd_parser: old_part_num = len(cmds) matched, skip = match_and_filter_cmds(cmds, multi_cmd_patterns, filtered_f, readable_f) if matched: output_file = filtered_f if not skip: readable_f.write(' '.join(cmds) + '\n') else: output_file = of if not skip: if old_part_num != len(cmds): raw_buf = format_cmd_buf(cmds) write_array(raw_buf, output_file) of.close() filtered_f.close() readable_f.close()
def sub_ifs(args): ul.exist_file(*args.file) step, cv, n_jobs = args.step, args.cv, args.process clf = ul.select_clf(args) if args.mix: pass else: for file, out in zip(args.file, args.output): names, (x, y) = ul.load_data(file, normal=False) result_ls, sort_idx = cp.feature_select(x, y, step, cv, clf, n_jobs) x_tricks = [i for i in range(0, x.shape[1], step)] x_tricks.append(x.shape[1]) mean_mt = ul.mean_metric acc_ls = [0] + [mean_mt(i)['acc'] for i in result_ls] max_acc = max(acc_ls) best_n = x.shape[1] if max_acc == acc_ls[-1] else acc_ls.index( max_acc) * step draw.p_fs(x_tricks, acc_ls, out + '.png', max_acc=max_acc, best_n=best_n) best_x = x[:, sort_idx[:best_n]] best_file = f"{out}_{best_n}-best.csv" header = ','.join([names[0]] + [names[i + 1] for i in sort_idx[:best_n]]) ul.write_array(best_file, y.reshape(-1, 1), best_x, header=header) xtricks_arr = np.array(x_tricks[:len(acc_ls)]).reshape(-1, 1) acc_arr = np.array(acc_ls).reshape(-1, 1) ul.write_array(out + ".csv", xtricks_arr, acc_arr) best_idx = np.array(sort_idx[:best_n]).reshape(1, -1) idx_aa = [ f"{i}-{names[idx+1]}" for i, idx in enumerate(best_idx.flatten()) ] header = ','.join(idx_aa) ul.write_array(out + f"-{best_n}-idx.csv", best_idx, header=header)
def save_data(): global users, awaiting, done utils.write_investors(data_folder + investors_file, users) utils.write_investments(data_folder + awaiting_file, awaiting) utils.write_investments(data_folder + done_file, done) utils.write_array(data_folder + checked_file, checked_comments)
def Data(*set, **keyw): """Create and return a _FileItem representing the data from *set. Create a '_FileItem' object (which is a type of 'PlotItem') out of one or more Float Python Numeric arrays (or objects that can be converted to a Float Numeric array). If the routine is passed a single with multiple dimensions, then the last index ranges over the values comprising a single data point (e.g., [<x>, <y>, <sigma>]) and the rest of the indices select the data point. If passed a single array with 1 dimension, then each point is considered to have only one value (i.e., by default the values will be plotted against their indices). If the routine is passed more than one array, they must have identical shapes, and then each data point is composed of one point from each array. E.g., 'Data(x,x**2)' is a 'PlotItem' that represents x squared as a function of x. For the output format, see the comments for 'write_array()'. How the data are written to gnuplot depends on the 'inline' argument and preference settings for the platform in use. Keyword arguments: 'cols=<tuple>' -- write only the specified columns from each data point to the file. Since cols is used by python, the columns should be numbered in the python style (starting from 0), not the gnuplot style (starting from 1). 'inline=<bool>' -- transmit the data to gnuplot 'inline' rather than through a temporary file. The default is the value of gp.GnuplotOpts.prefer_inline_data. The keyword arguments recognized by '_FileItem' can also be used here. """ if len(set) == 1: # set was passed as a single structure set = utils.float_array(set[0]) # As a special case, if passed a single 1-D array, then it is # treated as one value per point (by default, plotted against # its index): if len(set.shape) == 1: set = set[:,Numeric.NewAxis] else: # set was passed column by column (for example, # Data(x,y)); pack it into one big array (this will test # that sizes are all the same): set = utils.float_array(set) dims = len(set.shape) # transpose so that the last index selects x vs. y: set = Numeric.transpose(set, (dims-1,) + tuple(range(dims-1))) if keyw.has_key('cols'): cols = keyw['cols'] del keyw['cols'] if type(cols) is types.IntType: cols = (cols,) set = Numeric.take(set, cols, -1) if keyw.has_key('inline'): inline = keyw['inline'] del keyw['inline'] else: inline = gp.GnuplotOpts.prefer_inline_data # Output the content into a string: f = StringIO() utils.write_array(f, set) content = f.getvalue() if inline: return apply(_InlineFileItem, (content,), keyw) elif gp.GnuplotOpts.prefer_fifo_data: return apply(_FIFOFileItem, (content,), keyw) else: return apply(_TempFileItem, (content,), keyw)
def GridData(data, xvals=None, yvals=None, inline=_unset, filename=None, **keyw): """Return a _FileItem representing a function of two variables. 'GridData' represents a function that has been tabulated on a rectangular grid. The data are written to a file; no copy is kept in memory. Arguments: 'data' -- the data to plot: a 2-d array with dimensions (numx,numy). 'xvals' -- a 1-d array with dimension 'numx' 'yvals' -- a 1-d array with dimension 'numy' 'binary=<bool>' -- send data to gnuplot in binary format? 'inline=<bool>' -- send data to gnuplot "inline"? 'filename=<string>' -- save data to a permanent file. Note the unusual argument order! The data are specified *before* the x and y values. (This inconsistency was probably a mistake; after all, the default xvals and yvals are not very useful.) 'data' must be a data array holding the values of a function f(x,y) tabulated on a grid of points, such that 'data[i,j] == f(xvals[i], yvals[j])'. If 'xvals' and/or 'yvals' are omitted, integers (starting with 0) are used for that coordinate. The data are written to a temporary file; no copy of the data is kept in memory. If 'binary=0' then the data are written to a datafile as 'x y f(x,y)' triplets (y changes most rapidly) that can be used by gnuplot's 'splot' command. Blank lines are included each time the value of x changes so that gnuplot knows to plot a surface through the data. If 'binary=1' then the data are written to a file in a binary format that 'splot' can understand. Binary format is faster and usually saves disk space but is not human-readable. If your version of gnuplot doesn't support binary format (it is a recently-added feature), this behavior can be disabled by setting the configuration variable 'gp.GnuplotOpts.recognizes_binary_splot=0' in the appropriate gp*.py file. Thus if you have three arrays in the above format and a Gnuplot instance called g, you can plot your data by typing 'g.splot(Gnuplot.GridData(data,xvals,yvals))'. """ # Try to interpret data as an array: data = utils.float_array(data) try: (numx, numy) = data.shape except ValueError: raise Errors.DataError('data array must be two-dimensional') if xvals is None: xvals = numpy.arange(numx) else: xvals = utils.float_array(xvals) if xvals.shape != (numx, ): raise Errors.DataError( 'The size of xvals must be the same as the size of ' 'the first dimension of the data array') if yvals is None: yvals = numpy.arange(numy) else: yvals = utils.float_array(yvals) if yvals.shape != (numy, ): raise Errors.DataError( 'The size of yvals must be the same as the size of ' 'the second dimension of the data array') # Binary defaults to true if recognizes_binary_plot is set; # otherwise it is forced to false. binary = keyw.get('binary', 1) and gp.GnuplotOpts.recognizes_binary_splot keyw['binary'] = binary if inline is _unset: inline = ((not binary) and (not filename) and gp.GnuplotOpts.prefer_inline_data) elif inline and filename: raise Errors.OptionError('cannot pass data both inline and via a file') # xvals, yvals, and data are now all filled with arrays of data. if binary: if inline: raise Errors.OptionError('binary inline data not supported') # write file in binary format # It seems that the gnuplot documentation for binary mode # disagrees with its actual behavior (as of v. 3.7). The # documentation has the roles of x and y exchanged. We ignore # the documentation and go with the code. mout = numpy.zeros((numy + 1, numx + 1), numpy.float32) mout[0, 0] = numx mout[0, 1:] = xvals.astype(numpy.float32) mout[1:, 0] = yvals.astype(numpy.float32) try: # try copying without the additional copy implied by astype(): mout[1:, 1:] = numpy.transpose(data) except: # if that didn't work then downcasting from double # must be necessary: mout[1:, 1:] = numpy.transpose(data.astype(numpy.float32)) content = mout.tostring() if (not filename) and gp.GnuplotOpts.prefer_fifo_data: return _FIFOFileItem(content, **keyw) else: return _NewFileItem(content, filename=filename, **keyw) else: # output data to file as "x y f(x)" triplets. This # requires numy copies of each x value and numx copies of # each y value. First reformat the data: set = numpy.transpose( numpy.array((numpy.transpose(numpy.resize(xvals, (numy, numx))), numpy.resize(yvals, (numx, numy)), data)), (1, 2, 0)) # Now output the data with the usual routine. This will # produce data properly formatted in blocks separated by blank # lines so that gnuplot can connect the points into a grid. f = StringIO() utils.write_array(f, set) content = f.getvalue() if inline: return _InlineFileItem(content, **keyw) elif filename: return _NewFileItem(content, filename=filename, **keyw) elif gp.GnuplotOpts.prefer_fifo_data: return _FIFOFileItem(content, **keyw) else: return _NewFileItem(content, **keyw)
def Data(*data, **keyw): """Create and return a _FileItem representing the data from *data. Create a '_FileItem' object (which is a type of 'PlotItem') out of one or more Float Python numpy arrays (or objects that can be converted to a float numpy array). If the routine is passed a single with multiple dimensions, then the last index ranges over the values comprising a single data point (e.g., [<x>, <y>, <sigma>]) and the rest of the indices select the data point. If passed a single array with 1 dimension, then each point is considered to have only one value (i.e., by default the values will be plotted against their indices). If the routine is passed more than one array, they must have identical shapes, and then each data point is composed of one point from each array. E.g., 'Data(x,x**2)' is a 'PlotItem' that represents x squared as a function of x. For the output format, see the comments for 'write_array()'. How the data are written to gnuplot depends on the 'inline' argument and preference settings for the platform in use. Keyword arguments: 'cols=<tuple>' -- write only the specified columns from each data point to the file. Since cols is used by python, the columns should be numbered in the python style (starting from 0), not the gnuplot style (starting from 1). 'inline=<bool>' -- transmit the data to gnuplot 'inline' rather than through a temporary file. The default is the value of gp.GnuplotOpts.prefer_inline_data. 'filename=<string>' -- save data to a permanent file. The keyword arguments recognized by '_FileItem' can also be used here. """ if len(data) == 1: # data was passed as a single structure data = utils.float_array(data[0]) # As a special case, if passed a single 1-D array, then it is # treated as one value per point (by default, plotted against # its index): if len(data.shape) == 1: data = data[:, numpy.newaxis] else: # data was passed column by column (for example, # Data(x,y)); pack it into one big array (this will test # that sizes are all the same): data = utils.float_array(data) dims = len(data.shape) # transpose so that the last index selects x vs. y: data = numpy.transpose(data, (dims - 1, ) + tuple(range(dims - 1))) if 'cols' in keyw: cols = keyw['cols'] del keyw['cols'] if isinstance(cols, types.IntType): cols = (cols, ) data = numpy.take(data, cols, -1) if 'filename' in keyw: filename = keyw['filename'] or None del keyw['filename'] else: filename = None if 'inline' in keyw: inline = keyw['inline'] del keyw['inline'] if inline and filename: raise Errors.OptionError( 'cannot pass data both inline and via a file') else: inline = (not filename) and gp.GnuplotOpts.prefer_inline_data # Output the content into a string: f = StringIO() utils.write_array(f, data) content = f.getvalue() if inline: return _InlineFileItem(content, **keyw) elif filename: return _NewFileItem(content, filename=filename, **keyw) elif gp.GnuplotOpts.prefer_fifo_data: return _FIFOFileItem(content, **keyw) else: return _NewFileItem(content, **keyw)
def Data(*data, **keyw): """Create and return a _FileItem representing the data from *data. Create a '_FileItem' object (which is a type of 'PlotItem') out of one or more Float Python numpy arrays (or objects that can be converted to a float numpy array). If the routine is passed a single with multiple dimensions, then the last index ranges over the values comprising a single data point (e.g., [<x>, <y>, <sigma>]) and the rest of the indices select the data point. If passed a single array with 1 dimension, then each point is considered to have only one value (i.e., by default the values will be plotted against their indices). If the routine is passed more than one array, they must have identical shapes, and then each data point is composed of one point from each array. E.g., 'Data(x,x**2)' is a 'PlotItem' that represents x squared as a function of x. For the output format, see the comments for 'write_array()'. How the data are written to gnuplot depends on the 'inline' argument and preference settings for the platform in use. Keyword arguments: 'cols=<tuple>' -- write only the specified columns from each data point to the file. Since cols is used by python, the columns should be numbered in the python style (starting from 0), not the gnuplot style (starting from 1). 'inline=<bool>' -- transmit the data to gnuplot 'inline' rather than through a temporary file. The default is the value of gp.GnuplotOpts.prefer_inline_data. 'filename=<string>' -- save data to a permanent file. The keyword arguments recognized by '_FileItem' can also be used here. """ if len(data) == 1: # data was passed as a single structure data = utils.float_array(data[0]) # As a special case, if passed a single 1-D array, then it is # treated as one value per point (by default, plotted against # its index): if len(data.shape) == 1: data = data[:,numpy.newaxis] else: # data was passed column by column (for example, # Data(x,y)); pack it into one big array (this will test # that sizes are all the same): data = utils.float_array(data) dims = len(data.shape) # transpose so that the last index selects x vs. y: data = numpy.transpose(data, (dims-1,) + tuple(range(dims-1))) if 'cols' in keyw: cols = keyw['cols'] del keyw['cols'] if isinstance(cols, types.IntType): cols = (cols,) data = numpy.take(data, cols, -1) if 'filename' in keyw: filename = keyw['filename'] or None del keyw['filename'] else: filename = None if 'inline' in keyw: inline = keyw['inline'] del keyw['inline'] if inline and filename: raise Errors.OptionError( 'cannot pass data both inline and via a file' ) else: inline = (not filename) and gp.GnuplotOpts.prefer_inline_data # Output the content into a string: f = StringIO() utils.write_array(f, data) content = f.getvalue() if inline: return _InlineFileItem(content, **keyw) elif filename: return _NewFileItem(content, filename=filename, **keyw) elif gp.GnuplotOpts.prefer_fifo_data: return _FIFOFileItem(content, **keyw) else: return _NewFileItem(content, **keyw)
def GridData( data, xvals=None, yvals=None, inline=_unset, filename=None, **keyw ): """Return a _FileItem representing a function of two variables. 'GridData' represents a function that has been tabulated on a rectangular grid. The data are written to a file; no copy is kept in memory. Arguments: 'data' -- the data to plot: a 2-d array with dimensions (numx,numy). 'xvals' -- a 1-d array with dimension 'numx' 'yvals' -- a 1-d array with dimension 'numy' 'binary=<bool>' -- send data to gnuplot in binary format? 'inline=<bool>' -- send data to gnuplot "inline"? 'filename=<string>' -- save data to a permanent file. Note the unusual argument order! The data are specified *before* the x and y values. (This inconsistency was probably a mistake; after all, the default xvals and yvals are not very useful.) 'data' must be a data array holding the values of a function f(x,y) tabulated on a grid of points, such that 'data[i,j] == f(xvals[i], yvals[j])'. If 'xvals' and/or 'yvals' are omitted, integers (starting with 0) are used for that coordinate. The data are written to a temporary file; no copy of the data is kept in memory. If 'binary=0' then the data are written to a datafile as 'x y f(x,y)' triplets (y changes most rapidly) that can be used by gnuplot's 'splot' command. Blank lines are included each time the value of x changes so that gnuplot knows to plot a surface through the data. If 'binary=1' then the data are written to a file in a binary format that 'splot' can understand. Binary format is faster and usually saves disk space but is not human-readable. If your version of gnuplot doesn't support binary format (it is a recently-added feature), this behavior can be disabled by setting the configuration variable 'gp.GnuplotOpts.recognizes_binary_splot=0' in the appropriate gp*.py file. Thus if you have three arrays in the above format and a Gnuplot instance called g, you can plot your data by typing 'g.splot(Gnuplot.GridData(data,xvals,yvals))'. """ # Try to interpret data as an array: data = utils.float_array(data) try: (numx, numy) = data.shape except ValueError: raise Errors.DataError('data array must be two-dimensional') if xvals is None: xvals = numpy.arange(numx) else: xvals = utils.float_array(xvals) if xvals.shape != (numx,): raise Errors.DataError( 'The size of xvals must be the same as the size of ' 'the first dimension of the data array') if yvals is None: yvals = numpy.arange(numy) else: yvals = utils.float_array(yvals) if yvals.shape != (numy,): raise Errors.DataError( 'The size of yvals must be the same as the size of ' 'the second dimension of the data array') # Binary defaults to true if recognizes_binary_plot is set; # otherwise it is forced to false. binary = keyw.get('binary', 1) and gp.GnuplotOpts.recognizes_binary_splot keyw['binary'] = binary if inline is _unset: inline = ( (not binary) and (not filename) and gp.GnuplotOpts.prefer_inline_data ) elif inline and filename: raise Errors.OptionError( 'cannot pass data both inline and via a file' ) # xvals, yvals, and data are now all filled with arrays of data. if binary: if inline: raise Errors.OptionError('binary inline data not supported') # write file in binary format # It seems that the gnuplot documentation for binary mode # disagrees with its actual behavior (as of v. 3.7). The # documentation has the roles of x and y exchanged. We ignore # the documentation and go with the code. mout = numpy.zeros((numy + 1, numx + 1), numpy.float32) mout[0,0] = numx mout[0,1:] = xvals.astype(numpy.float32) mout[1:,0] = yvals.astype(numpy.float32) try: # try copying without the additional copy implied by astype(): mout[1:,1:] = numpy.transpose(data) except: # if that didn't work then downcasting from double # must be necessary: mout[1:,1:] = numpy.transpose(data.astype(numpy.float32)) content = mout.tostring() if (not filename) and gp.GnuplotOpts.prefer_fifo_data: return _FIFOFileItem(content, **keyw) else: return _NewFileItem(content, filename=filename, **keyw) else: # output data to file as "x y f(x)" triplets. This # requires numy copies of each x value and numx copies of # each y value. First reformat the data: set = numpy.transpose( numpy.array( (numpy.transpose(numpy.resize(xvals, (numy, numx))), numpy.resize(yvals, (numx, numy)), data)), (1,2,0)) # Now output the data with the usual routine. This will # produce data properly formatted in blocks separated by blank # lines so that gnuplot can connect the points into a grid. f = StringIO() utils.write_array(f, set) content = f.getvalue() if inline: return _InlineFileItem(content, **keyw) elif filename: return _NewFileItem(content, filename=filename, **keyw) elif gp.GnuplotOpts.prefer_fifo_data: return _FIFOFileItem(content, **keyw) else: return _NewFileItem(content, **keyw)
def sub_merge(args): names, _ = ul.load_structured_data(args.file[0])[0] mix_data = ul.merge_feature_file(args.label, args.file) ul.write_array(args.output, mix_data, header=','.join(names))