code: def get_satpos(
      data_arr: xr.DataArray,
      preference: Optional[str] = None,
      use_tle: bool = False,
  ) -> tuple[float, float, float]:
      """Get satellite position from dataset attributes.
  
      Args:
          data_arr: DataArray object to access ``.attrs`` metadata
              from.
          preference: Optional preference for one of the available types of
              position information. If not provided or ``None`` then the default
              preference is:
  
              * Longitude & Latitude: nadir, actual, nominal, projection
              * Altitude: actual, nominal, projection
  
              The provided ``preference`` can be any one of these individual
              strings (nadir, actual, nominal, projection). If the
              preference is not available then the original preference list is
              used. A warning is issued when projection values have to be used because
              nothing else is available and it wasn't provided as the ``preference``.
          use_tle: If true, try to obtain position via satellite name
              and TLE if it can't be determined otherwise.  This requires pyorbital, skyfield,
              and astropy to be installed and may need network access to obtain the TLE.
              Note that even if ``use_tle`` is true, the TLE will not be used if
              the dataset metadata contain the satellite position directly.
  
      Returns:
          Geodetic longitude, latitude, altitude [km]
  
      """
      if preference is not None and preference not in (
          "nadir",
          "actual",
          "nominal",
          "projection",
      ):
          raise ValueError(
              f"Unrecognized satellite coordinate preference: {preference}"
          )
      lonlat_prefixes = (
          "nadir_",
          "satellite_actual_",
          "satellite_nominal_",
          "projection_",
      )
      alt_prefixes = _get_prefix_order_by_preference(
          lonlat_prefixes[1:], preference
      )
      lonlat_prefixes = _get_prefix_order_by_preference(
          lonlat_prefixes, preference
      )
      try:
          lon, lat = _get_sat_lonlat(data_arr, lonlat_prefixes)
          alt = _get_sat_altitude(data_arr, alt_prefixes)
      except KeyError:
          if use_tle:
              logger.warning(
                  "Orbital parameters missing from metadata.  "
                  "Calculating from TLE using skyfield and astropy."
              )
              return _get_satpos_from_platform_name(data_arr)
          raise KeyError(
              "Unable to determine satellite position. Either the "
              "reader doesn't provide that information or "
              "geolocation datasets were not available."
          )
      return lon, lat, alt
  
imports: from __future__ import annotations
  import contextlib
  import datetime
  import logging
  import os
  import pathlib
  import warnings
  from contextlib import contextmanager
  from copy import deepcopy
  from typing import Literal, Mapping, Optional
  from urllib.parse import urlparse
  import dask.utils
  import numpy
  import xarray
  import yaml
  from yaml import BaseLoader, UnsafeLoader
  from satpy._compat import DTypeLike
label_desc: Use image node_id 18 for calling a global function with example usage: get_satpos(data_arr, preference, use_tle) and returns: lon,  lat,  alt, _get_satpos_from_platform_name