def main(): """main func""" args = read_parameters.read_from_file() # read_files('file.txt') # read_files(args) plot_points(args) return None
params = Parameters() params.add('chi0', value=0.5) params.add('kappa', value=2.) params.add('n_avrami', value=1.) out = minimize(residual, params, args=( t, p, )) # lmfit minimizer report_fit(params) plt.plot(t, p, 'go') plt.plot(t, residual(out.params, t), 'r-') plt.savefig('./figures/' + str(i) + '.pdf') return out.params['chi0'].value args = read_parameters.read_from_file() # read_files('file.txt') # read_files(args) # read file.param for the plot parameters and put them to parameters parameters = read_plot_parameters(args) # read file.in, maybe parse the chain info, reutrn the chain_info_parse chain_info_parse = parameters['parse_chain_info'] if chain_info_parse is True: all_files_info_list = parse_file_info(args.input) elif chain_info_parse is False: all_files_info_list = simple_parse_file_info(args.input) else: raise ValueError('specify whether you need to parse chain info?') # initialize figure, do the plot parameters, and specify lines, ..
def main(): """ main function Avrami Fitting:\\ $\chi = \chi_0 (1 - e^{-\kappa t^n})$, \\ $\alpha = \chi / \chi_0$,\\ New Coordinates \\ $x = ln(t)$, where $t: \alpha > 0.5$.\\ $y = ln (-ln(1-\alpha))$\\ So:\\ $ y = ln(\kappa) + n x$ """ args = read_parameters.read_from_file() # read_files('file.txt') # read_files(args) # read file.param for the plot parameters and put them to parameters parameters = PlotFromFile.read_plot_parameters(args) # read file.in, maybe parse the chain info, reutrn the chain_info_parse chain_info_parse = parameters['parse_chain_info'] if chain_info_parse is True: all_files_info_list = PlotFromFile.parse_file_info(args.input) elif chain_info_parse is False: all_files_info_list = PlotFromFile.simple_parse_file_info(args.input) else: raise ValueError('specify whether you need to parse chain info?') # initialize figure, do the plot parameters, and specify lines, .. chi0_array, kappa_array, n_avrami_array, mw_array = [], [], [], [] kappa_error_array, n_avrami_error_array = [], [] fig_plot = plt.figure(figsize=(8, 7)) ax_plot = fig_plot.add_subplot(111) points, lines, colors, ax_plot = plot_settings(parameters, ax_plot) linecycler = itertools.cycle(lines) pointscycler = itertools.cycle(points) colorcycler = itertools.cycle(colors) # loop through files listed and do the plotting for i, file_i in enumerate(all_files_info_list): clr, llr, plr = next(colorcycler), next(linecycler), next(pointscycler) # print "doing", file_i filename_i = all_files_info_list[i]['npzfile'] fileNinfo_i = all_files_info_list[i]['chains_info'] extrainfo_i = all_files_info_list[i]['extrastring'] result_name = '' result_name = '' for Mn, Nch in fileNinfo_i: result_name += 'M_n = ' result_name += str(Mn) result_name += 'N_{chains} = ' result_name += str(Nch) result_name += ';' # label_i = '${result_name}\ PDI={PDI};{extra}$'.format( # result_name=result_name, PDI=pdiinfo_i, extra=extrainfo_i) label_i = '${result_name}{extra}$'.format(result_name=result_name, extra=extrainfo_i) mw, _ = fileNinfo_i[0] # Extra_string = int(re.search('ICC(\s)(\d+)n(\d+)', j).group(1)) npz = np.load(filename_i) # if chain_info_parse is True: # else: # ax_plot.plot(t, p, llr, # color=clr, # linewidth=2.3, # alpha=0.95, # label=label_i) # ax_plot.plot(t, p, 'go') # ax_plot.savefig('./figures/'+str(i)+'.pdf') # t = npz['arr_0'] # p = npz['arr_1'] # npz = np.load('testquench.npz') # npz = np.load('test.npz') t, p = npz['arr_0'], npz['arr_1'] x, y = renormalize_arrays(t, p) chi0 = p.max() out = fit_all(x, y) kappa_error, n_avrami_error = get_errors(out) kappa_error_array.append(kappa_error) n_avrami_error_array.append(n_avrami_error) lnkappa, n_avrami = out.params['lnkappa'].value,\ out.params['n_avrami'].value tot_fit_err = np.sqrt((kappa_error/np.exp(lnkappa))**2 + \ (n_avrami_error/n_avrami)**2) ax_plot.plot(x, y, plr, color=clr, linewidth=1.6, alpha=0.8, label=label_i) ax_plot.fill_between(x, (lnkappa + n_avrami*x)*(1.-tot_fit_err), (lnkappa + n_avrami*x)*(1.+tot_fit_err), alpha=0.08, color=clr) ax_plot.plot(x, lnkappa + n_avrami*x, color=clr, linewidth=2.8, alpha=1.) mw_array.append(mw) kappa_array.append(np.exp(lnkappa)) n_avrami_array.append(n_avrami) chi0_array.append(chi0) ax_plot.legend(loc='best') fig_plot.savefig('./figures/{0[plotname]}{0[name]}.pdf'.format(parameters)) mw_array, chi0_array = zip(*sorted(zip(mw_array, chi0_array))) mw_array, kappa_array, kappa_error_array = zip(*sorted(zip(mw_array, kappa_array, kappa_error_array))) mw_array, n_avrami_array, n_avrami_error_array= zip(*sorted(zip(mw_array, n_avrami_array, n_avrami_error_array))) chi0_array, kappa_array, n_avrami_array, mw_array =\ np.asarray(chi0_array),\ np.asarray(kappa_array),\ np.asarray(n_avrami_array),\ np.asarray(mw_array) print "chi0", chi0_array print "kappa", kappa_array print "n_avrami", n_avrami_array print "mw", mw_array print "n_avrami_error_array", n_avrami_error_array # np.savez('./figures/fit{extra}chi0'.format(extra=extrainfo_i), mw_array, chi0_array) # np.savez('./figures/fit{extra}kappa'.format(extra=extrainfo_i), mw_array, kappa_array,kappa_error_array) # np.savez('./figures/fit{extra}n_avrami'.format(extra=extrainfo_i), mw_array, n_avrami_array, kappa_error_array) np.savez('./figures/fit{0[name]}chi0'.format(parameters), mw_array, chi0_array) np.savez('./figures/fit{0[name]}kappa'.format(parameters), mw_array, kappa_array,kappa_error_array) np.savez('./figures/fit{0[name]}n_avrami'.format(parameters), mw_array, n_avrami_array, n_avrami_error_array)
def plot_mpl_fig(): """ plots stuff with points #algorithm for induction time. filenames will represent the mol weight, and will be the X axis the flag = False will represent that the crystallization has started the tcryst = will be the time of crystallization, it will be appended to tcryst_array list """ args = read_parameters.read_from_file() def plot_settings(parameters): # read_files('file.txt') # read_files(args) plt.ylim(parameters['ymin'], parameters['ymax']) if parameters['xlog']: plt.xscale('log') parameters['xlabel'] = ''.join(('log', 'parameters[\'xlabel\']')) print "xlogscale" else: print "regular xscale" if parameters['ylog']: plt.yscale('log') parameters['ylabel'] = ''.join(('log', 'parameters[\'ylabel\']')) print "ylogscale" else: print "regular yscale" plt.ylabel('${0[ylabel]}$'.format(parameters)) plt.xlabel('${0[xlabel]}$'.format(parameters)) points = [ u'D-', u'o-', u'^-', u'>-', u's-', u'8-', u'<-', u'>-', u'*-', u'H', u'h', u'p', u'v', u'D', u'd', "-", "--", "-.", ":" ] colors = ['k', 'y', 'm', 'c', 'b', 'g', 'r', '#aaaaaa'] lines = ["-", "--", "-.", ":"] return points, lines, colors # read file.param for the plot parameters and put them to parameters parameters = plot_read_file.read_plot_parameters(args) # read file.in, maybe parse the chain info, reutrn the chain_info_parse chain_info_parse = parameters['parse_chain_info'] if chain_info_parse is True: all_files_info_list = plot_read_file.parse_file_info(args.input) elif chain_info_parse is False: all_files_info_list = plot_read_file.simple_parse_file_info(args.input) else: raise ValueError('specify whether you need to parse chain info?') # initialize figure, do the plot parameters, and specify lines, .. plt.figure(figsize=(8, 7)) points, lines, colors = plot_settings(parameters) linecycler = itertools.cycle(lines) pointscycler = itertools.cycle(points) colorcycler = itertools.cycle(colors) # loop through files listed and do the plotting for i, file_i in enumerate(all_files_info_list): # print "doing", file_i filename_i = all_files_info_list[i]['npzfile'] npz = np.load(filename_i) t = npz['arr_0'] x = npz['arr_1'] is_with_error_bars = True try: error_array = npz['arr_2'] except Exception: print "doing Exception" is_with_error_bars = False pass # t = print x if parameters['scale_dump'] is True: # then scale the result data # so the final data represents to the 10^6 lj untis values t *= parameters['timestep'] * parameters['dumpskip'] / 1e6 else: print "Using raw data without time scaling" # print p print t clr, llr, plr = next(colorcycler), next(linecycler), next(pointscycler) result_name = all_files_info_list[i]['npzfile'] result_name = get_path_names.get_filename(result_name) label_i = '${result_name}$'.format(result_name=result_name) if is_with_error_bars: # plt.errorbar(t, x, # yerr=error_array, # color=clr, # linewidth=1.8, # label=label_i) plt.plot(t, x, color=clr, linewidth=1.8, label=label_i) plt.errorbar(t, error_array, color=clr, linewidth=1.8, label='error' + label_i) else: x = x - x[0] plt.plot(t, x, plr, color=clr, linewidth=1.8, alpha=0.7, label=label_i) print parameters return None