def load_reshape_dataset(fname): """ Load dataset as OrderedDict. Each element of the OrderedDict is a multidimensional numpy array, in a way that getting the result for a specific composition becomes very easy. """ # read database header to get data structure header = read_header_database(fname) # temperature range; composition range Trange, crange = parse_header_database(header) # read database df = load_dataset(fname) # index df['idx'] = np.array([get_idx_from_fname(fname) for fname in df['file']]) # get shape of multidimensional array newshape = [] for el, rng in crange.items(): newshape.append(rng.lvls) # reshape flattened dataframe as dictionary of multidimensional arrays dataset = OrderedDict() for key in df.columns: dataset[key] = df[key].values.reshape(newshape) return dataset
import Tcritical_regression_statsmodels as tr import matplotlib.pyplot as plt import numpy as np import pandas as pd from scipy.optimize import root from parse_database import read_header_database, parse_header_database from plot_carbon_isopleth import (load_reshape_dataset, select_carbon_isopleth, plot_carbon_isopleth) fname_dataset = '../databases/Tcritical.csv' header = read_header_database(fname_dataset) # Temperature range and compositions ranges Trange, crange = parse_header_database(header) # dataset as pandas DataFrame dataset = tr.load_dataset(fname_dataset) # dependent variable dep_var = 'A1' reg, results = {}, {} reg, results = tr.regression_poly_2nd_deg(dataset=dataset, dep_var=dep_var, maxpvalue=.01, printsummary=False) ax = tr.plot_fitting_results(results, dataset, dep_var) ax.set_title('{}'.format(dep_var))