| @@ 78-123 (lines=46) @@ | ||
| 75 | return dict_of_df, number |
|
| 76 | ||
| 77 | ||
| 78 | def read_file(file): |
|
| 79 | """This function reads the raw data file, gets the scanrate and stepsize |
|
| 80 | and then reads the lines according to cycle number. Once it reads the data |
|
| 81 | for one cycle, it calls read_cycle function to denerate a dataframe. It |
|
| 82 | does the same thing for all the cycles and finally returns a dictionary, |
|
| 83 | the keys of which are the cycle numbers and the values are the |
|
| 84 | corresponding dataframes. |
|
| 85 | ||
| 86 | Parameters |
|
| 87 | __________ |
|
| 88 | file: raw data file |
|
| 89 | ||
| 90 | Returns: |
|
| 91 | ________ |
|
| 92 | dict_of_df: dictionary of dataframes with keys = cycle numbers and |
|
| 93 | values = dataframes for each cycle |
|
| 94 | n_cycle: number of cycles in the raw file |
|
| 95 | """ |
|
| 96 | dict_of_df = {} |
|
| 97 | h_val = 0 |
|
| 98 | l_val = 0 |
|
| 99 | n_cycle = 0 |
|
| 100 | #a = [] |
|
| 101 | with open(file, 'rt') as f_val: |
|
| 102 | print(file + ' Opened') |
|
| 103 | for line in f_val: |
|
| 104 | record = 0 |
|
| 105 | if not (h_val and l_val): |
|
| 106 | if line.startswith('SCANRATE'): |
|
| 107 | scan_rate = float(line.split()[2]) |
|
| 108 | h_val = 1 |
|
| 109 | if line.startswith('STEPSIZE'): |
|
| 110 | step_size = float(line.split()[2]) |
|
| 111 | l_val = 1 |
|
| 112 | if line.startswith('CURVE'): |
|
| 113 | n_cycle += 1 |
|
| 114 | if n_cycle > 1: |
|
| 115 | number = n_cycle - 1 |
|
| 116 | data = read_cycle(a_val) |
|
| 117 | key_name = 'cycle_' + str(number) |
|
| 118 | #key_name = number |
|
| 119 | dict_of_df[key_name] = copy.deepcopy(data) |
|
| 120 | a_val = [] |
|
| 121 | if n_cycle: |
|
| 122 | a_val.append(line) |
|
| 123 | return dict_of_df, number |
|
| 124 | ||
| 125 | #df = pd.DataFrame(list(dict1['df_1'].items())) |
|
| 126 | #list1, list2 = list(dict1['df_1'].items()) |
|
| @@ 30-75 (lines=46) @@ | ||
| 27 | return dataframe |
|
| 28 | ||
| 29 | ||
| 30 | def read_file(file): |
|
| 31 | """This function reads the raw data file, gets the scanrate and stepsize |
|
| 32 | and then reads the lines according to cycle number. Once it reads the data |
|
| 33 | for one cycle, it calls read_cycle function to denerate a dataframe. It |
|
| 34 | does the same thing for all the cycles and finally returns a dictionary, |
|
| 35 | the keys of which are the cycle numbers and the values are the |
|
| 36 | corresponding dataframes. |
|
| 37 | ||
| 38 | Parameters |
|
| 39 | __________ |
|
| 40 | file: raw data file |
|
| 41 | ||
| 42 | Returns: |
|
| 43 | ________ |
|
| 44 | dict_of_df: dictionary of dataframes with keys = cycle numbers and |
|
| 45 | values = dataframes for each cycle |
|
| 46 | n_cycle: number of cycles in the raw file |
|
| 47 | """ |
|
| 48 | dict_of_df = {} |
|
| 49 | h_val = 0 |
|
| 50 | l_val = 0 |
|
| 51 | n_cycle = 0 |
|
| 52 | #a = [] |
|
| 53 | with open(file, 'rt') as f_val: |
|
| 54 | print(file + ' Opened') |
|
| 55 | for line in f_val: |
|
| 56 | record = 0 |
|
| 57 | if not (h_val and l_val): |
|
| 58 | if line.startswith('SCANRATE'): |
|
| 59 | scan_rate = float(line.split()[2]) |
|
| 60 | h_val = 1 |
|
| 61 | if line.startswith('STEPSIZE'): |
|
| 62 | step_size = float(line.split()[2]) |
|
| 63 | l_val = 1 |
|
| 64 | if line.startswith('CURVE'): |
|
| 65 | n_cycle += 1 |
|
| 66 | if n_cycle > 1: |
|
| 67 | number = n_cycle - 1 |
|
| 68 | data = read_cycle(a_val) |
|
| 69 | key_name = 'cycle_' + str(number) |
|
| 70 | #key_name = number |
|
| 71 | dict_of_df[key_name] = copy.deepcopy(data) |
|
| 72 | a_val = [] |
|
| 73 | if n_cycle: |
|
| 74 | a_val.append(line) |
|
| 75 | return dict_of_df, number |
|
| 76 | ||
| 77 | ||
| 78 | #df = pd.DataFrame(list(dict1['df_1'].items())) |
|