update 0.0.47
This commit is contained in:
		| @@ -105,15 +105,15 @@ chern_number = guan.calculate_chern_number_for_honeycomb_lattice(hamiltonian_fun | |||||||
| wilson_loop_array = guan.calculate_wilson_loop(hamiltonian_function, k_min=-pi, k_max=pi, precision=100) | wilson_loop_array = guan.calculate_wilson_loop(hamiltonian_function, k_min=-pi, k_max=pi, precision=100) | ||||||
|  |  | ||||||
| # read and write    # Source code: https://py.guanjihuan.com/read_and_write | # read and write    # Source code: https://py.guanjihuan.com/read_and_write | ||||||
| x, y = guan.read_one_dimensional_data(filename='a') | x_array, y_array = guan.read_one_dimensional_data(filename='a', format='txt') | ||||||
| x, y, matrix = guan.read_two_dimensional_data(filename='a') | x_array, y_array, matrix = guan.read_two_dimensional_data(filename='a', format='txt') | ||||||
| guan.write_one_dimensional_data(x_array, y_array, filename='a') | guan.write_one_dimensional_data(x_array, y_array, filename='a', format='txt') | ||||||
| guan.write_two_dimensional_data(x_array, y_array, matrix, filename='a') | guan.write_two_dimensional_data(x_array, y_array, matrix, filename='a', format='txt') | ||||||
|  |  | ||||||
| # plot figures    # Source code: https://py.guanjihuan.com/plot_figures | # plot figures    # Source code: https://py.guanjihuan.com/plot_figures | ||||||
| guan.plot(x_array, y_array, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, format='jpg', dpi=300, type='', y_min=None, y_max=None, linewidth=None, markersize=None) | guan.plot(x_array, y_array, xlabel='x', ylabel='y', title='', show=1, save=0, filename='a', format='jpg', dpi=300, type='', y_min=None, y_max=None, linewidth=None, markersize=None) | ||||||
| guan.plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, format='jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100) | guan.plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', show=1, save=0, filename='a', format='jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100) | ||||||
| guan.plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, format='jpg', dpi=300) | guan.plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', show=1, save=0, filename='a', format='jpg', dpi=300) | ||||||
|  |  | ||||||
| # others   # Source code: https://py.guanjihuan.com/source-code/others | # others   # Source code: https://py.guanjihuan.com/source-code/others | ||||||
| guan.download_with_scihub(address=None, num=1) | guan.download_with_scihub(address=None, num=1) | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| [metadata] | [metadata] | ||||||
| # replace with your username: | # replace with your username: | ||||||
| name = guan | name = guan | ||||||
| version = 0.0.45 | version = 0.0.47 | ||||||
| author = guanjihuan | author = guanjihuan | ||||||
| author_email = guanjihuan@163.com | author_email = guanjihuan@163.com | ||||||
| description = An open source python package | description = An open source python package | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
|  |  | ||||||
| import numpy as np | import numpy as np | ||||||
|  |  | ||||||
| def plot(x_array, y_array, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, format='jpg', dpi=300, type='', y_min=None, y_max=None, linewidth=None, markersize=None):  | def plot(x_array, y_array, xlabel='x', ylabel='y', title='', show=1, save=0, filename='a', format='jpg', dpi=300, type='', y_min=None, y_max=None, linewidth=None, markersize=None):  | ||||||
|     import matplotlib.pyplot as plt |     import matplotlib.pyplot as plt | ||||||
|     fig, ax = plt.subplots() |     fig, ax = plt.subplots() | ||||||
|     plt.subplots_adjust(bottom=0.20, left=0.18)  |     plt.subplots_adjust(bottom=0.20, left=0.18)  | ||||||
| @@ -28,7 +28,7 @@ def plot(x_array, y_array, xlabel='x', ylabel='y', title='', filename='a', show= | |||||||
|         plt.show() |         plt.show() | ||||||
|     plt.close('all') |     plt.close('all') | ||||||
|  |  | ||||||
| def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, format='jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100):  | def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', show=1, save=0, filename='a', format='jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100):  | ||||||
|     import matplotlib.pyplot as plt |     import matplotlib.pyplot as plt | ||||||
|     from matplotlib import cm |     from matplotlib import cm | ||||||
|     from matplotlib.ticker import LinearLocator |     from matplotlib.ticker import LinearLocator | ||||||
| @@ -67,7 +67,7 @@ def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z' | |||||||
|         plt.show() |         plt.show() | ||||||
|     plt.close('all') |     plt.close('all') | ||||||
|  |  | ||||||
| def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0, format='jpg', dpi=300):   | def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', show=1, save=0, filename='a', format='jpg', dpi=300):   | ||||||
|     import matplotlib.pyplot as plt |     import matplotlib.pyplot as plt | ||||||
|     fig, ax = plt.subplots() |     fig, ax = plt.subplots() | ||||||
|     plt.subplots_adjust(bottom=0.2, right=0.75, left = 0.16)  |     plt.subplots_adjust(bottom=0.2, right=0.75, left = 0.16)  | ||||||
|   | |||||||
| @@ -4,45 +4,45 @@ | |||||||
|  |  | ||||||
| import numpy as np | import numpy as np | ||||||
|  |  | ||||||
| def read_one_dimensional_data(filename='a'):  | def read_one_dimensional_data(filename='a', format='txt'):  | ||||||
|     f = open(filename+'.txt', 'r') |     f = open(filename+'.'+format, 'r') | ||||||
|     text = f.read() |     text = f.read() | ||||||
|     f.close() |     f.close() | ||||||
|     row_list = np.array(text.split('\n'))  |     row_list = np.array(text.split('\n'))  | ||||||
|     dim_column = np.array(row_list[0].split()).shape[0]  |     dim_column = np.array(row_list[0].split()).shape[0]  | ||||||
|     x = np.array([]) |     x_array = np.array([]) | ||||||
|     y = np.array([]) |     y_array = np.array([]) | ||||||
|     for row in row_list: |     for row in row_list: | ||||||
|         column = np.array(row.split())  |         column = np.array(row.split())  | ||||||
|         if column.shape[0] != 0:   |         if column.shape[0] != 0:   | ||||||
|             x = np.append(x, [float(column[0])], axis=0)   |             x_array = np.append(x_array, [float(column[0])], axis=0)   | ||||||
|             y_row = np.zeros(dim_column-1) |             y_row = np.zeros(dim_column-1) | ||||||
|             for dim0 in range(dim_column-1): |             for dim0 in range(dim_column-1): | ||||||
|                 y_row[dim0] = float(column[dim0+1]) |                 y_row[dim0] = float(column[dim0+1]) | ||||||
|             if np.array(y).shape[0] == 0: |             if np.array(y_array).shape[0] == 0: | ||||||
|                 y = [y_row] |                 y_array = [y_row] | ||||||
|             else: |             else: | ||||||
|                 y = np.append(y, [y_row], axis=0) |                 y_array = np.append(y_array, [y_row], axis=0) | ||||||
|     return x, y |     return x_array, y_array | ||||||
|  |  | ||||||
| def read_two_dimensional_data(filename='a'):  | def read_two_dimensional_data(filename='a', format='txt'):  | ||||||
|     f = open(filename+'.txt', 'r') |     f = open(filename+'.'+format, 'r') | ||||||
|     text = f.read() |     text = f.read() | ||||||
|     f.close() |     f.close() | ||||||
|     row_list = np.array(text.split('\n'))  |     row_list = np.array(text.split('\n'))  | ||||||
|     dim_column = np.array(row_list[0].split()).shape[0]  |     dim_column = np.array(row_list[0].split()).shape[0]  | ||||||
|     x = np.array([]) |     x_array = np.array([]) | ||||||
|     y = np.array([]) |     y_array = np.array([]) | ||||||
|     matrix = np.array([]) |     matrix = np.array([]) | ||||||
|     for i0 in range(row_list.shape[0]): |     for i0 in range(row_list.shape[0]): | ||||||
|         column = np.array(row_list[i0].split())  |         column = np.array(row_list[i0].split())  | ||||||
|         if i0 == 0: |         if i0 == 0: | ||||||
|             x_str = column[1::]  |             x_str = column[1::]  | ||||||
|             x = np.zeros(x_str.shape[0]) |             x_array = np.zeros(x_str.shape[0]) | ||||||
|             for i00 in range(x_str.shape[0]): |             for i00 in range(x_str.shape[0]): | ||||||
|                 x[i00] = float(x_str[i00])  |                 x_array[i00] = float(x_str[i00])  | ||||||
|         elif column.shape[0] != 0:  |         elif column.shape[0] != 0:  | ||||||
|             y = np.append(y, [float(column[0])], axis=0)   |             y_array = np.append(y_array, [float(column[0])], axis=0)   | ||||||
|             matrix_row = np.zeros(dim_column-1) |             matrix_row = np.zeros(dim_column-1) | ||||||
|             for dim0 in range(dim_column-1): |             for dim0 in range(dim_column-1): | ||||||
|                 matrix_row[dim0] = float(column[dim0+1]) |                 matrix_row[dim0] = float(column[dim0+1]) | ||||||
| @@ -50,10 +50,12 @@ def read_two_dimensional_data(filename='a'): | |||||||
|                 matrix = [matrix_row] |                 matrix = [matrix_row] | ||||||
|             else: |             else: | ||||||
|                 matrix = np.append(matrix, [matrix_row], axis=0) |                 matrix = np.append(matrix, [matrix_row], axis=0) | ||||||
|     return x, y, matrix |     return x_array, y_array, matrix | ||||||
|  |  | ||||||
| def write_one_dimensional_data(x_array, y_array, filename='a'):  | def write_one_dimensional_data(x_array, y_array, filename='a', format='txt'):  | ||||||
|     with open(filename+'.txt', 'w') as f: |     x_array = np.array(x_array) | ||||||
|  |     y_array = np.array(y_array) | ||||||
|  |     with open(filename+'.'+format, 'w') as f: | ||||||
|         i0 = 0 |         i0 = 0 | ||||||
|         for x0 in x_array: |         for x0 in x_array: | ||||||
|             f.write(str(x0)+'   ') |             f.write(str(x0)+'   ') | ||||||
| @@ -65,8 +67,11 @@ def write_one_dimensional_data(x_array, y_array, filename='a'): | |||||||
|                 f.write('\n') |                 f.write('\n') | ||||||
|             i0 += 1 |             i0 += 1 | ||||||
|  |  | ||||||
| def write_two_dimensional_data(x_array, y_array, matrix, filename='a'):  | def write_two_dimensional_data(x_array, y_array, matrix, filename='a', format='txt'):  | ||||||
|     with open(filename+'.txt', 'w') as f: |     x_array = np.array(x_array) | ||||||
|  |     y_array = np.array(y_array) | ||||||
|  |     matrix = np.array(matrix) | ||||||
|  |     with open(filename+'.'+format, 'w') as f: | ||||||
|         f.write('0   ') |         f.write('0   ') | ||||||
|         for x0 in x_array: |         for x0 in x_array: | ||||||
|             f.write(str(x0)+'   ') |             f.write(str(x0)+'   ') | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user