def get_from_database(x1, x2, mat, inquiry_keys = None, silent = None, ssh_object = None): """ inquiry_keys (list) - list of keys that should exist in filenames both for x1 and x2 ssh_object (SSHTools) - ssh object based on paramiko with access details """ def check(key, inquiry_keys): return all([k in key for k in inquiry_keys]) path2database = '/home/Data/CEStorage/' hash_dict_file = 'hash_dict.json' cluster_path2hash = os.path.join(path2database, hash_dict_file) if inquiry_keys is None: inquiry_keys = [] if ssh_object: # ssh_object.get() tempdir = tempfile.gettempdir() local_path2hash = os.path.join(tempdir, hash_dict_file) ssh_object.get(cluster_path2hash, local_path2hash ) # sys.exit() with open(local_path2hash, 'r') as fp: hash_dict = json.load(fp) # print(hash_dict) x1s = [] x2s = [] # print(hash_dict) for key, val in hash_dict.items(): if check(key, inquiry_keys+[x1, mat]): x1s.append(key) if check(key, inquiry_keys+[x2, mat]): x2s.append(key) x1s = sorted(x1s, key = lambda el: len(el) ) x2s = sorted(x2s, key = lambda el: len(el) ) for xi, xis in (x1, x1s), (x2, x2s): if not silent: print('\nFiles for',xi,':') for i, f in enumerate(xis): if not silent: print(i+1,f) if len(x1s) == 0 or len(x2s) == 0: print('No information in database for this inquire:', x1, x2, mat, str(inquiry_keys) ) return None, None key1 = x1s[0] key2 = x2s[0] if not silent: print('\nI choose first entries for both concentrations:',key1, 'and', key2,'\n') # print('Use *inquiry_keys* arg to clarify the output results.\n') #get files loc1 = os.path.join(tempdir, hash_dict[key1]) loc2 = os.path.join(tempdir, hash_dict[key2]) makedir(loc1) makedir(loc2) # print()/ ssh_object.get(os.path.join(path2database, hash_dict[key1]), loc1 ) ssh_object.get(os.path.join(path2database, hash_dict[key2]), loc2 ) cl1 = CalculationVasp().deserialize(loc1) cl2 = CalculationVasp().deserialize(loc2) return cl1, cl2
# 2. View the contents of the current folder # 3. Delete folder # 4. Create a folder # When choosing items: 1, 2, 3, 4 the program asks for the name of the folder # and displays the result of the action: "Successfully created / deleted / moved", "Unable to create / delete / to go to the folder" # To solve this problem, use the algorithms from the easy task, # designed as appropriate functions, and imported into this file from easy.py import functions import sys import os while True: print('1 - Go to the folder', '2 - View the contents of the current folder', '3 - Delete folder', '4 - Create a folder') a = int(input('Choose action')) if a == 1: functions.changedir() elif a == 2: functions.dirlist() elif a == 3: functions.deldir() elif a == 4: functions.makedir() else: print('There is no such function') key = input("Press 'q' to") if key == 'q': sys.exit()
def fit_and_plot(power = None, xlabel = "xlabel", ylabel = "ylabel", image_name = None, show = None, xlim = None, ylim = None, title = None, figsize = None, xlog = False,ylog = False, scatter = False, legend = False, markersize = 10, linewidth = 3, hor = False, fig_format = 'eps', dpi = 300, **data): """Should be used in two below sections! Creates one plot with two dependecies and fit them; return minimum fitted value of x2 and corresponding value of y2; if name == "" image will not be plotted power - the power of polynom fig_format - format of saved file. dpi - resolution of saved file data - each entry should be (X, Y, 'r-') """ # print data if 1: plt.figure(figsize=figsize) if title: plt.title(title) plt.ylabel(ylabel) plt.xlabel(xlabel) scatterpoints = 1 for key in sorted(data): if scatter: plt.scatter(data[key][0], data[key][1], s = data[key][2], c = data[key][-1], alpha = 0.8, label = key) else: try: label = data[key][3] except: label = key # print 'label is ', label plt.plot(data[key][0], data[key][1], data[key][2], linewidth = linewidth, label = label, markersize = markersize, alpha = 0.8) if hor: plt.axhline(color = 'k') #horizontal line plt.axvline(color='k') if xlim: plt.xlim(xlim) # axes = plt.gca() # axes.set_xlim([xmin,xmax]) # axes.set_ylim([ymin,ymax]) if ylim: plt.ylim(ymin=ylim[0]) if ylim[1]: plt.ylim(ymax=ylim[1]) if power: for key in data: coeffs1 = np.polyfit(data[key][0], data[key][1], power) fit_func1 = np.poly1d(coeffs1) x_range = np.linspace(min(data[key][0]), max(data[key][0])) fit_y1 = fit_func1(x_range); plt.plot(x_range, fit_y1, data[key][-1][0], ) # x_min = fit_func2.deriv().r[power-2] #derivative of function and the second cooffecient is minimum value of x. # y_min = fit_func2(x_min) slope, intercept, r_value, p_value, std_err = scipy.stats.linregress(data[key][0], data[key][1]) # print 'R^2 = ', r_value**2, key if xlog: plt.xscale('log') if ylog: if "sym" in str(ylog): plt.yscale('symlog', linthreshx=0.1) else: plt.yscale('log') if legend: plt.legend(loc = legend, scatterpoints = scatterpoints) plt.tight_layout() path2saved = '' if image_name: makedir(image_name) try: path_to_images except: path_to_images = '' if fig_format in image_name: path2saved = str(image_name) elif str(image_name).split('.')[-1] in ['eps', 'png', 'pdf']: path2saved = str(image_name) fig_format = str(image_name).split('.')[-1] else: path2saved = str(image_name)+'.'+fig_format plt.savefig(path2saved, dpi = dpi, format=fig_format) plt.savefig(str(image_name)+'.png', dpi = 300) print_and_log("Image saved to ", path2saved) elif show is None: show = True # print_and_log(show) if show: plt.show() plt.clf() plt.close('all') return path2saved