code: def unmasked_sparse_to_sparse_from_mask_and_pixel_centres(mask, unmasked_sparse_grid_pixel_centres,
                                                            total_sparse_pixels):
      
  
      total_unmasked_sparse_pixels = unmasked_sparse_grid_pixel_centres.shape[0]
  
      unmasked_sparse_to_sparse = np.zeros(total_unmasked_sparse_pixels)
      pixel_index = 0
  
      for unmasked_sparse_pixel_index in range(total_unmasked_sparse_pixels):
  
          y = unmasked_sparse_grid_pixel_centres[unmasked_sparse_pixel_index, 0]
          x = unmasked_sparse_grid_pixel_centres[unmasked_sparse_pixel_index, 1]
  
          unmasked_sparse_to_sparse[unmasked_sparse_pixel_index] = pixel_index
  
          if not mask[y, x]:
              if pixel_index < total_sparse_pixels - 1:
                  pixel_index += 1
  
      return unmasked_sparse_to_sparse
docs: Determine the mapping between every pixelization-grid pixel and masked pixelization-grid pixel. This is
      performed by checking whether each pixelization-grid pixel is within the regular-masks, and mapping the indexes.
  
      Pixelization pixels are paired with the next masked pixel index. This may mean that a pixel is not paired with a
      pixel near it, if the next pixel is on the next row of the grid. This is not a problem, as it is only
      unmasked pixels that are referened when computing image_to_pix, which is what this array is used for.
  
      Parameters
      -----------
      total_sparse_pixels : int
          The total number of pixels in the pixelization grid which fall within the regular-masks.
      mask : ccd.masks.Mask
          The regular-masks within which pixelization pixels must be inside
      unmasked_sparse_grid_pixel_centres : ndarray
          The centres of the unmasked pixelization grid pixels.