def frame_numbers()

in ez_wsi_dicomweb/dicom_slide.py [0:0]


  def frame_numbers(self) -> Iterator[int]:
    """Generates slide level frame numbers required to render patch.

    Frame numbering starts at 1.

    Yields:
      A generator that produces frame numbers.

    Raises:
      DicomSlideMissingError if slide used to create self is None.
    """
    if self.source is None:
      raise ez_wsi_errors.DicomSlideMissingError(
          'Unable to get image pixels. Parent slide is None.'
      )
    y = self.y
    x = self.x
    width = self.width
    height = self.height
    cy = y
    frame_width = self._level.frame_width
    frame_height = self._level.frame_height
    cached_instance = None
    last_instance_frame_number = -math.inf
    while cy < y + height and cy < self._level.height:
      cx = x
      region_height = 0
      while cx < x + width and cx < self._level.width:
        try:
          frame_number = self._level.get_frame_number_by_point(cx, cy)
          if (
              cached_instance is None
              or frame_number - cached_instance.frame_offset
              >= cached_instance.frame_count
          ):
            cached_instance = self._level.get_instance_by_frame(frame_number)
            last_instance_frame_number = -math.inf
            if cached_instance is None:
              raise ez_wsi_errors.FrameNumberOutofBoundsError()
          if frame_number > last_instance_frame_number:
            yield frame_number
          last_instance_frame_number = frame_number
          pos_x, pos_y = self._level.get_frame_position(frame_number)
          intersection = self._get_intersection(
              pos_x, pos_y, frame_width, frame_height
          )
          region_width = intersection.width
          region_height = intersection.height
        except ez_wsi_errors.EZWsiError:
          # No frame found at (cx, cy), move 1 pixel in both X, and Y direction.
          region_width = 1
          region_height = max(1, region_height)
        cx += region_width
      cy += region_height