get_time_weights_by_block

sofia_redux.scan.integration.integration_numba_functions.get_time_weights_by_block(frame_data, frame_dof, frame_weight, frame_valid, frame_dependents, frame_flags, frame_weight_flag, frame_dof_flag, channel_weights, channel_indices, channel_flags, time_weight_flag, sample_flags, frame_from=-1, frame_to=-1)[source]

Determine the frame weighting (time) for all integration frames.

The frame weighting is determined for a given chunk of frames at a time. For all frames in a chunk the time weight will be given as:

chi2 = sum_{c,f} (cw * (d ** 2)) / n n = nc * nf deps = sum_{f} (frame_dependents) weight = (n - deps) / chi2

where nc is the number of channels, nf is the number of frames in the chunk, cw is the channel weight, and d is the frame value for each frame and channel. The degrees of freedom are also calculated for each frame in the chunk as:

dof = 1 - (deps / n)

At this stage all valid frames have the FLAG_WEIGHT flag removed, but the FLAG_DOF flag will be added or removed depending on whether n > deps (unflagged) or n <= deps (flagged as DOF).

Parameters:
frame_datanumpy.ndarray (float)

The integration frame data values of shape (n_frames, all_channels).

frame_dofnumpy.ndarray (float)

The integration frame degrees of freedom of shape (n_frames,). Will be updated in-place.

frame_weightnumpy.ndarray (float)

The integration frame weights of shape (n_frames,). Will be updated in place.

frame_validnumpy.ndarray (bool)

A boolean mask of shape (n_frames,) where False marks an invalid frame that will not be included in any calculation.

frame_dependentsnumpy.ndarray (float)

The frame dependents of shape (n_frames,).

frame_flagsnumpy.ndarray (int)

The frame flags of shape (n_frames,).

frame_weight_flagint

The integer identifier for the FLAG_WEIGHT frame flag. All valid frames will be unflagged with this identifier.

frame_dof_flagint

The integer identifier for the FLAG_DOF frame flag. All valid frames in the chunk will either be flagged or unflagged depending on whether the degrees of freedom are > 0.

channel_weightsnumpy.ndarray (float)

The channel weights of shape (n_channels,).

channel_indicesnumpy.ndarray (int)

The channel indices mapping n_channels -> all_channels.

channel_flagsnumpy.ndarray (int)

The channel flags of shape (n_channels,).

time_weight_flagint

The integer identifier for the TIME_WEIGHTING_FLAGS flag. Note that while channel space is referred to in the original code - no such flag exists and I really really think this should be in frame space. Channels (or frames rather) flagged with this will not be included in the calculations.

sample_flagsnumpy.ndarray (int)

The sample flags of shape (n_frames, all_channels).

frame_fromint, optional

The starting frame of the chunk. The default is the first (0).

frame_toint, optional

The last (non-inclusive) frame of the chunk. The default is the total number of frames.

Returns:
n, weight_sumfloat, float

The total number of points (valid frames * valid channels in chunk), and the total weight.