def get_average(w_axis, t_axis, z, axis="w", range=[0, -1], frame="data", return_cumulative=False, debug=0): """ INPUTS: w_axis: wavelength axis t_axis: time axis z: data axis: 'w' or 't', the axis you want to keep. Average w means that the t-axis is averaged. range: start and end of the range to be averaged. frame: 'data' or 'index' """ if debug > 0: print("NPCTools.Resources.StreakFunctions.get_average") if axis in ["w", "w_axis"]: if range[0] == 0 and range[1] == -1: _z = numpy.mean(z, axis=0) _s = numpy.sum(z, axis=0) else: a, b = CF.find_indices_for_range(t_axis, range, frame=frame, round="maximize") if debug > 0: print( " w_axis: from wavelength {:4.1f} [{:d}] to {:4.1f} [{:d}] " .format(w_axis[a], a, w_axis[b], b)) _z = numpy.mean(z[a:b, :], axis=0) _s = numpy.sum(z[a:b, :], axis=0) else: if range[0] == 0 and range[1] == -1: _z = numpy.mean(z, axis=1) _s = numpy.sum(z, axis=1) else: a, b = CF.find_indices_for_range(w_axis, range, frame=frame, round="maximize") if debug > 0: print(" t_axis time from {:.1f} [{:d}] to {:.1f} [{:d}] ". format(t_axis[a], a, t_axis[b], b)) _z = numpy.mean(z[:, a:b], axis=1) _s = numpy.sum(z[:, a:b], axis=1) if return_cumulative: return _s else: return _z
def get_area(w_axis, t_axis, z, w_range=[0, -1], t_range=[0, -1], frame="data", debug=0): """ w_axis: t_axis, z w_range: [min, max]. [0,-1] means the complete range. t_range = [min, max]. [0,-1] means the complete range. frame = "z" """ if debug > 0: print("NPCTools.Resources.StreakFunctions.get_area") if w_range[0] == 0 and w_range[1] == -1: _z = z[:, :] _w_axis = w_axis[:] else: a, b = CF.find_indices_for_range(w_axis, w_range, frame=frame, round="maximize") if debug > 0: print(" w_axis {:.1f} nm [{:d}] to {:.1f} nm [{:d}]".format( w_axis[a], a, w_axis[b], b)) _z = z[:, a:b] _w_axis = w_axis[a:b] if t_range[0] == 0 and t_range[1] == -1: _z = _z[:, :] _t_axis = t_axis[:] else: a, b = CF.find_indices_for_range(t_axis, t_range, frame=frame, round="maximize") if debug > 0: print(" t_axis time from {:.1f} [{:d}] to {:.1f} [{:d}] ".format( t_axis[a], a, t_axis[b], b)) _z = _z[a:b, :] _t_axis = t_axis[a:b] return _w_axis, _t_axis, _z