| @@ 82-127 (lines=46) @@ | ||
| 79 | return dict_of_df, number |
|
| 80 | ||
| 81 | ||
| 82 | def read_file(file): |
|
| 83 | """This function reads the raw data file, gets the scanrate and stepsize |
|
| 84 | and then reads the lines according to cycle number. Once it reads the data |
|
| 85 | for one cycle, it calls read_cycle function to generate a dataframe. It |
|
| 86 | does the same thing for all the cycles and finally returns a dictionary, |
|
| 87 | the keys of which are the cycle numbers and the values are the |
|
| 88 | corresponding dataframes. |
|
| 89 | ||
| 90 | Parameters |
|
| 91 | __________ |
|
| 92 | file: raw data file |
|
| 93 | ||
| 94 | Returns: |
|
| 95 | ________ |
|
| 96 | dict_of_df: dictionary of dataframes with keys = cycle numbers and |
|
| 97 | values = dataframes for each cycle |
|
| 98 | n_cycle: number of cycles in the raw file |
|
| 99 | """ |
|
| 100 | dict_of_df = {} |
|
| 101 | h = 0 |
|
| 102 | l = 0 |
|
| 103 | n_cycle = 0 |
|
| 104 | #a = [] |
|
| 105 | with open(file, 'rt') as f: |
|
| 106 | print(file + ' Opened') |
|
| 107 | for line in f: |
|
| 108 | record = 0 |
|
| 109 | if not (h and l): |
|
| 110 | if line.startswith('SCANRATE'): |
|
| 111 | scan_rate = float(line.split()[2]) |
|
| 112 | h = 1 |
|
| 113 | if line.startswith('STEPSIZE'): |
|
| 114 | step_size = float(line.split()[2]) |
|
| 115 | l = 1 |
|
| 116 | if line.startswith('CURVE'): |
|
| 117 | n_cycle += 1 |
|
| 118 | if n_cycle > 1: |
|
| 119 | number = n_cycle - 1 |
|
| 120 | df = read_cycle(a) |
|
| 121 | key_name = 'cycle_' + str(number) |
|
| 122 | #key_name = number |
|
| 123 | dict_of_df[key_name] = copy.deepcopy(df) |
|
| 124 | a = [] |
|
| 125 | if n_cycle: |
|
| 126 | a.append(line) |
|
| 127 | return dict_of_df, number |
|
| 128 | ||
| 129 | ||
| 130 | #df = pd.DataFrame(list(dict1['df_1'].items())) |
|
| @@ 82-127 (lines=46) @@ | ||
| 79 | return dict_of_df, number |
|
| 80 | ||
| 81 | ||
| 82 | def read_file(file): |
|
| 83 | """This function reads the raw data file, gets the scanrate and stepsize |
|
| 84 | and then reads the lines according to cycle number. Once it reads the data |
|
| 85 | for one cycle, it calls read_cycle function to generate a dataframe. It |
|
| 86 | does the same thing for all the cycles and finally returns a dictionary, |
|
| 87 | the keys of which are the cycle numbers and the values are the |
|
| 88 | corresponding dataframes. |
|
| 89 | ||
| 90 | Parameters |
|
| 91 | __________ |
|
| 92 | file: raw data file |
|
| 93 | ||
| 94 | Returns: |
|
| 95 | ________ |
|
| 96 | dict_of_df: dictionary of dataframes with keys = cycle numbers and |
|
| 97 | values = dataframes for each cycle |
|
| 98 | n_cycle: number of cycles in the raw file |
|
| 99 | """ |
|
| 100 | dict_of_df = {} |
|
| 101 | h = 0 |
|
| 102 | l = 0 |
|
| 103 | n_cycle = 0 |
|
| 104 | #a = [] |
|
| 105 | with open(file, 'rt') as f: |
|
| 106 | print(file + ' Opened') |
|
| 107 | for line in f: |
|
| 108 | record = 0 |
|
| 109 | if not (h and l): |
|
| 110 | if line.startswith('SCANRATE'): |
|
| 111 | scan_rate = float(line.split()[2]) |
|
| 112 | h = 1 |
|
| 113 | if line.startswith('STEPSIZE'): |
|
| 114 | step_size = float(line.split()[2]) |
|
| 115 | l = 1 |
|
| 116 | if line.startswith('CURVE'): |
|
| 117 | n_cycle += 1 |
|
| 118 | if n_cycle > 1: |
|
| 119 | number = n_cycle - 1 |
|
| 120 | df = read_cycle(a) |
|
| 121 | key_name = 'cycle_' + str(number) |
|
| 122 | #key_name = number |
|
| 123 | dict_of_df[key_name] = copy.deepcopy(df) |
|
| 124 | a = [] |
|
| 125 | if n_cycle: |
|
| 126 | a.append(line) |
|
| 127 | return dict_of_df, number |
|
| 128 | ||
| 129 | ||
| 130 | #df = pd.DataFrame(list(dict1['df_1'].items())) |
|