code: def _sunzen_corr_cos_ndarray(
      data: np.ndarray,
      cos_zen: np.ndarray,
      limit: float,
      max_sza: Optional[float],
  ) -> np.ndarray:
      # Convert the zenith angle limit to cosine of zenith angle
      limit_rad = np.deg2rad(limit)
      limit_cos = np.cos(limit_rad)
      max_sza_rad = (
          np.deg2rad(max_sza) if max_sza is not None else max_sza
      )
  
      # Cosine correction
      corr = (1.0 / cos_zen).astype(data.dtype, copy=False)
      if max_sza is not None:
          # gradually fall off for larger zenith angle
          grad_factor = (np.arccos(cos_zen) - limit_rad) / (
              max_sza_rad - limit_rad
          )
          # invert the factor so maximum correction is done at `limit` and falls off later
          with np.errstate(
              invalid="ignore"
          ):  # we expect space pixels to be invalid
              grad_factor = 1.0 - np.log(grad_factor + 1) / np.log(2)
          # make sure we don't make anything negative
          grad_factor = grad_factor.clip(0.0)
      else:
          # Use constant value (the limit) for larger zenith angles
          grad_factor = 1.0
      corr = np.where(
          cos_zen > limit_cos,
          corr,
          (grad_factor / limit_cos).astype(data.dtype, copy=False),
      )
      # Force "night" pixels to 0 (where SZA is invalid)
      corr[np.isnan(cos_zen)] = 0
      return data * corr
  
imports: from __future__ import annotations
  import hashlib
  import os
  import shutil
  import warnings
  from datetime import datetime
  from functools import update_wrapper
  from glob import glob
  from typing import Any, Callable, Optional, Union
  import dask
  import numpy
  import xarray
  from dask import array
  from pyorbital.astronomy import cos_zen
  from pyorbital.astronomy import get_alt_az
  from pyorbital.orbital import get_observer_look
  from pyresample.geometry import AreaDefinition, StackedAreaDefinition, SwathDefinition
  import satpy
  from satpy.utils import PerformanceWarning, get_satpos, ignore_invalid_float_warnings
label_desc: Use image node_id 25 for calling a global function with example usage: _sunzen_corr_cos_ndarray(data, cos_zen, limit, max_sza) and returns: unknown