def update(self, data_and_metadata_list: typing.Sequence[DataAndMetadata.DataAndMetadata], state: str, view_id) -> None: frames = self.__multi_acquire_parameters[self.__current_parameters_index]['frames'] sum_frames = self.__multi_acquire_settings['sum_frames'] for i, data_and_metadata in enumerate(data_and_metadata_list): data_item = self.__data_items[i] scan_shape = data_and_metadata.data_shape data_shape_and_dtype = (tuple(scan_shape), data_and_metadata.data_dtype) data_descriptor = DataAndMetadata.DataDescriptor(frames > 1 and not sum_frames, 0, len(tuple(scan_shape))) dimensional_calibrations = data_and_metadata.dimensional_calibrations if frames > 1 and not sum_frames: dimensional_calibrations = (Calibration.Calibration(),) + tuple(dimensional_calibrations) data_shape = data_shape_and_dtype[0] data_shape = (frames,) + data_shape data_shape_and_dtype = (data_shape, data_shape_and_dtype[1]) intensity_calibration = data_and_metadata.intensity_calibration metadata = data_and_metadata.metadata metadata["MultiAcquire.settings"] = copy.deepcopy(self.__multi_acquire_settings) metadata["MultiAcquire.parameters"] = copy.deepcopy(self.__multi_acquire_parameters[self.__current_parameters_index]) data_metadata = DataAndMetadata.DataMetadata(data_shape_and_dtype, intensity_calibration, dimensional_calibrations, metadata=data_and_metadata.metadata, data_descriptor=data_descriptor) src_slice = (Ellipsis,) dst_slice = (Ellipsis,) if frames > 1: if sum_frames: existing_data = data_item.data if existing_data is not None: summed_data = existing_data[dst_slice] + data_and_metadata.data[src_slice] data_and_metadata._set_data(summed_data) else: dst_slice = (self.current_frames_index,) + dst_slice # type: ignore self.__document_model.update_data_item_partial(data_item, data_metadata, data_and_metadata, src_slice, dst_slice)
def update(self, data_and_metadata: DataAndMetadata.DataAndMetadata, state: str, scan_shape: Geometry.IntSize, dest_sub_area: Geometry.IntRect, sub_area: Geometry.IntRect, view_id) -> None: # This method is always called with a collection of 1d or 2d data. Re-order axes as required and remove length-1-axes. axes_descriptor = self.__grab_sync_info.axes_descriptor # Calibrations, data descriptor and shape estimates are updated accordingly. dimensional_calibrations = data_and_metadata.dimensional_calibrations data = data_and_metadata.data axes_order, data_shape = self.__calculate_axes_order_and_data_shape(axes_descriptor, scan_shape, data.shape[len(tuple(scan_shape)):]) assert len(axes_order) == data.ndim data = numpy.moveaxis(data, axes_order, list(range(data.ndim))) dimensional_calibrations = numpy.array(dimensional_calibrations)[axes_order].tolist() is_sequence = axes_descriptor.sequence_axes is not None collection_dimension_count = len(axes_descriptor.collection_axes) if axes_descriptor.collection_axes is not None else 0 datum_dimension_count = len(axes_descriptor.data_axes) if axes_descriptor.data_axes is not None else 0 src_slice = tuple() dst_slice = tuple() for index in axes_order: if index >= len(sub_area.slice): src_slice += (slice(None),) else: src_slice += (sub_area.slice[index],) if index >= len(dest_sub_area.slice): dst_slice += (slice(None),) else: dst_slice += (dest_sub_area.slice[index],) if is_sequence and data.shape[0] == 1: data = numpy.squeeze(data, axis=0) dimensional_calibrations = dimensional_calibrations[1:] src_slice = src_slice[1:] dst_slice = dst_slice[1:] is_sequence = False data_descriptor = DataAndMetadata.DataDescriptor(is_sequence, collection_dimension_count, datum_dimension_count) data_and_metadata = DataAndMetadata.new_data_and_metadata(data, data_and_metadata.intensity_calibration, dimensional_calibrations, data_and_metadata.metadata, None, data_descriptor, None, None) data_metadata = DataAndMetadata.DataMetadata((tuple(data_shape), data_and_metadata.data_dtype), data_and_metadata.intensity_calibration, data_and_metadata.dimensional_calibrations, metadata=data_and_metadata.metadata, data_descriptor=data_descriptor) self.__document_model.update_data_item_partial(self.__data_item, data_metadata, data_and_metadata, src_slice, dst_slice)
def update(self, data_and_metadata: DataAndMetadata.DataAndMetadata, state: str, scan_shape: Geometry.IntSize, dest_sub_area: Geometry.IntRect, sub_area: Geometry.IntRect, view_id) -> None: # there are a few techniques for getting data into a data item. this method prefers directly calling the # document model method update_data_item_partial, which is thread safe. if that method is not available, it # falls back to the data item method set_data_and_metadata, which must be called from the main thread. # the hardware source also supplies a data channel which is thread safe and ends up calling set_data_and_metadata # but we skip that so that the updates fit into this class instead. frames = self.__multi_acquire_parameters[self.__current_parameters_index]['frames'] sum_frames = self.__multi_acquire_settings['sum_frames'] collection_rank = len(tuple(scan_shape)) data_shape_and_dtype = (tuple(scan_shape) + data_and_metadata.data_shape[collection_rank:], data_and_metadata.data_dtype) data_descriptor = DataAndMetadata.DataDescriptor(frames > 1 and not sum_frames, collection_rank, len(data_and_metadata.data_shape) - collection_rank) dimensional_calibrations = data_and_metadata.dimensional_calibrations if frames > 1 and not sum_frames: dimensional_calibrations = (Calibration.Calibration(),) + tuple(dimensional_calibrations) data_shape = data_shape_and_dtype[0] data_shape = (frames,) + data_shape data_shape_and_dtype = (data_shape, data_shape_and_dtype[1]) intensity_calibration = data_and_metadata.intensity_calibration if self.__multi_acquire_settings['use_multi_eels_calibration']: metadata = data_and_metadata.metadata.get('hardware_source', {}) counts_per_electron = metadata.get('counts_per_electron', 1) exposure_s = metadata.get('exposure', self.__multi_acquire_parameters[self.__current_parameters_index]['exposure_ms']*0.001) _number_frames = 1 if not sum_frames else frames intensity_scale = (data_and_metadata.intensity_calibration.scale / counts_per_electron / data_and_metadata.dimensional_calibrations[-1].scale / exposure_s / _number_frames) intensity_calibration = Calibration.Calibration(scale=intensity_scale) metadata = data_and_metadata.metadata metadata["MultiAcquire.settings"] = copy.deepcopy(self.__multi_acquire_settings) metadata["MultiAcquire.parameters"] = copy.deepcopy(self.__multi_acquire_parameters[self.__current_parameters_index]) data_metadata = DataAndMetadata.DataMetadata(data_shape_and_dtype, intensity_calibration, dimensional_calibrations, metadata=data_and_metadata.metadata, data_descriptor=data_descriptor) src_slice = sub_area.slice + (Ellipsis,) dst_slice = dest_sub_area.slice + (Ellipsis,) if frames > 1: if sum_frames: existing_data = self.__data_item.data if existing_data is not None: existing_data[dst_slice] += data_and_metadata.data[src_slice] else: dst_slice = (self.current_frames_index,) + dst_slice # type: ignore self.__document_model.update_data_item_partial(self.__data_item, data_metadata, data_and_metadata, src_slice, dst_slice) self.update_progress(dest_sub_area.bottom)