def read_vars_from_exofile(filepath, variables=None, step=1, h=1, elem_blk=1, elem_num=1): """Read the specified variables from the exodus file in filepath """ # setup variables if variables is None: variables = ["ALL"] else: if not isinstance(variables, (list, tuple)): variables = [variables] variables = [v.strip() for v in variables] if "all" in [v.lower() for v in variables]: variables = ["ALL"] if not os.path.isfile(filepath): raise ExoDumpError("{0}: no such file".format(filepath)) exof = ExodusIIReader(filepath) glob_var_names = exof.glob_var_names elem_var_names = exof.elem_var_names if variables[0] != "ALL": glob_var_names = expand_var_names(glob_var_names, variables) elem_var_names = expand_var_names(elem_var_names, variables) bad = [x for x in variables if x is not None] if bad: raise ExoDumpError("{0}: variables not in " "{1}".format(", ".join(bad), filepath)) # retrieve the data from the database header = ["TIME"] header.extend([H.upper() for H in glob_var_names]) header.extend([H.upper() for H in elem_var_names]) data = [] for i in myrange(0, exof.num_time_steps, step): row = [exof.get_time(i)] glob_vars_vals = exof.get_glob_vars(i, disp=1) for var in glob_var_names: try: row.append(glob_vars_vals[var]) except KeyError: continue for var in elem_var_names: row.append(exof.get_elem_var_time(var, elem_num, elem_blk)[i]) data.append(row) exof.close() data = np.array(data) if len(header) != data.shape[1]: raise ExoDumpError("inconsistent data") if h: return header, data return data
def loadexo(filepath): LOG.info("Reading {0}".format(filepath)) exof = ExodusIIReader(filepath) glob_var_names = exof.glob_var_names elem_var_names = exof.elem_var_names data = [exof.get_all_times()] for glob_var_name in glob_var_names: data.append(exof.get_glob_var_time(glob_var_name)) for elem_var_name in elem_var_names: data.append(exof.get_elem_var_time(elem_var_name, 0)) data = np.transpose(np.array(data)) head = ["TIME"] + glob_var_names + elem_var_names exof.close() return head, data