code: def temperature_hub(self, weather_df):
          r
          if self.power_plant.hub_height in weather_df['temperature']:
              temperature_hub = weather_df['temperature'][
                  self.power_plant.hub_height]
          elif self.temperature_model == 'linear_gradient':
              logging.debug('Calculating temperature using temperature '
                            'gradient.')
              closest_height = weather_df['temperature'].columns[
                  min(range(len(weather_df['temperature'].columns)),
                      key=lambda i: abs(weather_df['temperature'].columns[i] -
                                        self.power_plant.hub_height))]
              temperature_hub = temperature.linear_gradient(
                  weather_df['temperature'][closest_height], closest_height,
                  self.power_plant.hub_height)
          elif self.temperature_model == 'interpolation_extrapolation':
              logging.debug('Calculating temperature using linear inter- or '
                            'extrapolation.')
              temperature_hub = tools.linear_interpolation_extrapolation(
                  weather_df['temperature'], self.power_plant.hub_height)
          else:
              raise ValueError("'{0}' is an invalid value. ".format(
                  self.temperature_model) + "`temperature_model` must be "
                  "'linear_gradient' or 'interpolation_extrapolation'.")
          return temperature_hub
docs: r"""
          Calculates the temperature of air at hub height.
  
          The temperature is calculated using the method specified by
          the parameter `temperature_model`.
  
          Parameters
          ----------
          weather_df : pandas.DataFrame
              DataFrame with time series for temperature `temperature` in K.
              The columns of the DataFrame are a MultiIndex where the first level
              contains the variable name (e.g. temperature) and the second level
              contains the height at which it applies (e.g. 10, if it was
              measured at a height of 10 m). See documentation of
              :func:`ModelChain.run_model` for an example on how to create the
              weather_df DataFrame.
  
          Returns
          -------
          temperature_hub : pandas.Series or numpy.array
              Temperature of air in K at hub height.
  
          Notes
          -----
          If `weather_df` contains temperatures at different heights the given
          temperature(s) closest to the hub height are used.