Normalize data based on the availability of scaler Parameters ---------- data_in : ndarray numpy array of input data scaler : ndarray numpy array of scaling data, the same size as data_in data_name : str name of the data set ('time' or 'i0' etc.)
(data_in, scaler, *, data_name=None, name_not_scalable=None)
| 135 | |
| 136 | |
| 137 | def normalize_data_by_scaler(data_in, scaler, *, data_name=None, name_not_scalable=None): |
| 138 | """ |
| 139 | Normalize data based on the availability of scaler |
| 140 | |
| 141 | Parameters |
| 142 | ---------- |
| 143 | |
| 144 | data_in : ndarray |
| 145 | numpy array of input data |
| 146 | scaler : ndarray |
| 147 | numpy array of scaling data, the same size as data_in |
| 148 | data_name : str |
| 149 | name of the data set ('time' or 'i0' etc.) |
| 150 | name_not_scalable : list |
| 151 | names of not scalable datasets (['time', 'i0_time']) |
| 152 | |
| 153 | Returns |
| 154 | ------- |
| 155 | ndarray with normalized data, the same shape as data_in |
| 156 | The returned array is the reference to 'data_in' if no normalization |
| 157 | is applied to data or reference to modified copy of 'data_in' if |
| 158 | normalization was applied. |
| 159 | |
| 160 | ::note:: |
| 161 | |
| 162 | Normalization will not be performed if the following is true: |
| 163 | |
| 164 | - scaler is None |
| 165 | |
| 166 | - scaler is not the same shape as data_in |
| 167 | |
| 168 | - scaler contains all elements equal to zero |
| 169 | |
| 170 | If normalization is not performed then REFERENCE to data_in is returned. |
| 171 | |
| 172 | """ |
| 173 | |
| 174 | if data_in is None or scaler is None: # Nothing to scale |
| 175 | logger.debug( |
| 176 | "Function utils.normalize_data_by_scaler: data and/or scaler arrays are None. " |
| 177 | "Data scaling is skipped." |
| 178 | ) |
| 179 | return data_in |
| 180 | |
| 181 | if data_in.shape != scaler.shape: |
| 182 | logger.debug( |
| 183 | "Function utils.normalize_data_by_scaler: data and scaler arrays have different shape. " |
| 184 | "Data scaling is skipped." |
| 185 | ) |
| 186 | return data_in |
| 187 | |
| 188 | do_scaling = False |
| 189 | # Check if data name is in the list of non-scalable items |
| 190 | # If data name or the list does not exits, then do the scaling |
| 191 | if name_not_scalable is None or data_name is None or data_name not in name_not_scalable: |
| 192 | do_scaling = True |
| 193 | |
| 194 | # If scaler is all zeros, then don't scale the data: |
no outgoing calls
no test coverage detected