code: def ttest_power(
      effect_size, nobs, alpha, df=None, alternative="two-sided"
  ):
      """Calculate power of a ttest"""
      d = effect_size
      if df is None:
          df = nobs - 1
  
      if alternative in ["two-sided", "2s"]:
          alpha_ = alpha / 2.0  # no inplace changes, does not work
      elif alternative in ["smaller", "larger"]:
          alpha_ = alpha
      else:
          raise ValueError(
              "alternative has to be 'two-sided', 'larger' "
              + "or 'smaller'"
          )
  
      pow_ = 0
      if alternative in ["two-sided", "2s", "larger"]:
          crit_upp = stats.t.isf(alpha_, df)
          # print crit_upp, df, d*np.sqrt(nobs)
          # use private methods, generic methods return nan with negative d
          if np.any(np.isnan(crit_upp)):
              # avoid endless loop, https://github.com/scipy/scipy/issues/2667
              pow_ = np.nan
          else:
              # pow_ = stats.nct._sf(crit_upp, df, d*np.sqrt(nobs))
              # use scipy.special
              pow_ = nct_sf(crit_upp, df, d * np.sqrt(nobs))
      if alternative in ["two-sided", "2s", "smaller"]:
          crit_low = stats.t.ppf(alpha_, df)
          # print crit_low, df, d*np.sqrt(nobs)
          if np.any(np.isnan(crit_low)):
              pow_ = np.nan
          else:
              # pow_ += stats.nct._cdf(crit_low, df, d*np.sqrt(nobs))
              pow_ += nct_cdf(crit_low, df, d * np.sqrt(nobs))
      return pow_
  
imports: import warnings
  import numpy
  from scipy import stats, optimize, special
  from statsmodels.tools.rootfinding import brentq_expanding
label_desc: Use image node_id 6 for calling a global function with example usage: ttest_power(effect_size, nobs, alpha, df, alternative) and returns: pow_