docstr: Extracts components specified by `component_mask` from `series`
  
  Parameters
  ----------
  series
      input TimeSeries to be fed into transformer.
  component_mask
      Optionally, np.ndarray boolean mask of shape (n_components, 1) specifying which components to
      extract from `series`. The `i`th component of `series` is kept only if `component_mask[i] = True`.
      If not specified, no masking is performed.
  return_ts
      Optionally, specifies that a `TimeSeries` should be returned, rather than an `np.ndarray`.
  
  Returns
  -------
  masked
      `TimeSeries` (if `return_ts = True`) or `np.ndarray` (if `return_ts = False`) with only those components
      specified by `component_mask` remaining.
docstr_tok: ["Extracts","components","specified","by","`","component_mask","`","from","`","series","`","Parameters","--","--","--","--","--","series","input","TimeSeries","to","be","fed","into","transformer",".","component_mask","Optionally",",","np.ndarray","boolean","mask","of","shape","(","n_components",",","1",")","specifying","which","components","to","extract","from","`","series","`",".","The","`","i","`","th","component","of","`","series","`","is","kept","only","if","`","component_mask","[","i","]","=","True","`",".","If","not","specified",",","no","masking","is","performed",".","return_ts","Optionally",",","specifies","that","a","`","TimeSeries","`","should","be","returned",",","rather","than","an","`","np.ndarray","`",".","Returns","--","--","--","-","masked","`","TimeSeries","`","(","if","`","return_ts","=","True","`",")","or","`","np.ndarray","`","(","if","`","return_ts","=","False","`",")","with","only","those","components","specified","by","`","component_mask","`","remaining","."]
code: def apply_component_mask(
      series: TimeSeries,
      component_mask: Optional[np.ndarray] = None,
      return_ts=False,
  ) -> np.ndarray:
      """
      Extracts components specified by `component_mask` from `series`
  
      Parameters
      ----------
      series
          input TimeSeries to be fed into transformer.
      component_mask
          Optionally, np.ndarray boolean mask of shape (n_components, 1) specifying which components to
          extract from `series`. The `i`th component of `series` is kept only if `component_mask[i] = True`.
          If not specified, no masking is performed.
      return_ts
          Optionally, specifies that a `TimeSeries` should be returned, rather than an `np.ndarray`.
  
      Returns
      -------
      masked
          `TimeSeries` (if `return_ts = True`) or `np.ndarray` (if `return_ts = False`) with only those components
          specified by `component_mask` remaining.
  
      """
      if component_mask is None:
          masked = series.copy() if return_ts else series.all_values()
      else:
          raise_if_not(
              isinstance(component_mask, np.ndarray)
              and component_mask.dtype == bool,
              f"`component_mask` must be a boolean `np.ndarray`, not a {type(component_mask)}.",
              logger,
          )
          raise_if_not(
              series.width == len(component_mask),
              "mismatch between number of components in `series` and length of `component_mask`",
              logger,
          )
          masked = series.all_values(copy=False)[:, component_mask, :]
          if return_ts:
              # Remove masked components from coords:
              coords = dict(series._xa.coords)
              coords["component"] = coords["component"][component_mask]
              new_xa = xr.DataArray(
                  masked,
                  dims=series._xa.dims,
                  coords=coords,
                  attrs=series._xa.attrs,
              )
              masked = TimeSeries(new_xa)
      return masked
  
imports: from abc import ABC, abstractmethod
  from typing import Any, Generator, List, Mapping, Optional, Sequence, Union
  import numpy
  import xarray
  from darts import TimeSeries
  from darts.logging import get_logger, raise_if, raise_if_not
  from darts.utils import _build_tqdm_iterator, _parallel_apply
label_desc: Use image node_id 8 for calling the BaseDataTransformer obj's underlying member method code with example usage: obj.apply_component_mask(series, component_mask, return_ts) and returns: masked