MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / _compute_intensity

Method _compute_intensity

pyxrf/model/lineplot.py:1137–1201  ·  view source on GitHub ↗
(self, elist)

Source from the content-addressed store, hash-verified

1135 return energy, marker_visible
1136
1137 def _compute_intensity(self, elist):
1138 # Some default value
1139 intensity = 1000.0
1140
1141 if (
1142 self.io_model.data is not None
1143 and self.param_model.param_new is not None
1144 and self.param_model.prefit_x is not None
1145 and self.param_model.total_y is not None
1146 and len(self.io_model.data) > 1
1147 and len(self.param_model.prefit_x) > 1
1148 ):
1149 # Range of energies in fitting results
1150 e_fit_min = self.param_model.prefit_x[0]
1151 e_fit_max = self.param_model.prefit_x[-1]
1152 de_fit = (e_fit_max - e_fit_min) / (len(self.param_model.prefit_x) - 1)
1153
1154 e_raw_min = self.param_model.param_new["e_offset"]["value"]
1155 e_raw_max = (
1156 self.param_model.param_new["e_offset"]["value"]
1157 + (len(self.io_model.data) - 1) * self.param_model.param_new["e_linear"]["value"]
1158 + (len(self.io_model.data) - 1) ** 2 * self.param_model.param_new["e_quadratic"]["value"]
1159 )
1160
1161 de_raw = (e_raw_max - e_raw_min) / (len(self.io_model.data) - 1)
1162
1163 # Note: the above algorithm for finding 'de_raw' is far from perfect but will
1164 # work for now. As a result 'de_fit' and
1165 # 'de_raw' == sself.param_model.param_new['e_linear']['value'].
1166 # So the quadratic coefficent is ignored. This is OK, since currently
1167 # quadratic coefficient is always ZERO. When the program is rewritten,
1168 # the complete algorithm should be revised.
1169
1170 # Find the line with maximum energy. It must come first in the list,
1171 # but let's check just to make sure
1172 max_line_energy, max_line_intensity = 0, 0
1173 if elist:
1174 for e, i in elist:
1175 # e - line peak energy
1176 # i - peak intensity relative to maximum peak
1177 if e >= e_fit_min and e <= e_fit_max and e > e_raw_min and e < e_raw_max:
1178 if max_line_intensity < i:
1179 max_line_energy, max_line_intensity = e, i
1180
1181 # Find the index of peak maximum in the 'fitted' data array
1182 n = (max_line_energy - e_fit_min) / de_fit
1183 n = np.clip(n, 0, len(self.param_model.total_y) - 1)
1184 n_fit = int(round(n))
1185 # Find the index of peak maximum in the 'raw' data array
1186 n = (max_line_energy - e_raw_min) / de_raw
1187 n = np.clip(n, 0, len(self.io_model.data) - 1)
1188 n_raw = int(round(n))
1189 # Intensity of the fitted data at the peak
1190 in_fit = self.param_model.total_y[n_fit]
1191 # Intensity of the raw data at the peak
1192 in_raw = self.io_model.data[n_raw]
1193 # The estimated peak intensity is the difference:
1194 intensity = in_raw - in_fit

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected