code: def _stack_select_by_weights(
      datasets: Sequence[xr.DataArray],
      weights: Sequence[xr.DataArray],
      combine_times: bool,
  ) -> xr.DataArray:
      """Stack datasets selecting pixels using weights."""
      indices = da.argmax(da.dstack(weights), axis=-1)
      if "bands" in datasets[0].dims:
          indices = [indices] * datasets[0].sizes["bands"]
  
      attrs = _combine_stacked_attrs(
          [data_arr.attrs for data_arr in datasets], combine_times
      )
      dims = datasets[0].dims
      coords = datasets[0].coords
      selected_array = xr.DataArray(
          da.choose(indices, datasets),
          dims=dims,
          coords=coords,
          attrs=attrs,
      )
      return selected_array
  
file_path: satpy/satpy/multiscene/_blend_funcs.py
imports: from __future__ import annotations
  from datetime import datetime
  from typing import Callable, Iterable, Mapping, Optional, Sequence
  import pandas
  import xarray
  from dask import array
  from satpy.dataset import combine_metadata
label_desc: Use image node_id 6 for calling a global function with example usage: _stack_select_by_weights(datasets, weights, combine_times) and returns: selected_array