"""
thermal storage
"""

from __future__ import division
import pandas as pd
from math import log

__author__ = "Thuy-An Nguyen"
__copyright__ = "Copyright 2015, Architecture and Building Systems - ETH Zurich"
__credits__ = ["Thuy-An Nguyen", "Tim Vollrath", "Jimeno A. Fonseca"]
__license__ = "MIT"
__version__ = "0.1"
__maintainer__ = "Daren Thomas"
__email__ = "cea@arch.ethz.ch"
__status__ = "Production"


# investment and maintenance costs

def calc_Cinv_storage(V_tank_m3, locator, config, technology_type):
    """
    calculate the annualized investment cost of a thermal storage tank

    :param V_tank_m3: storage tank volume
    :type V_tank_m3: float

    :returns InvCa:

    """
    if V_tank_m3 > 0:
        storage_cost_data = pd.read_excel(locator.get_database_conversion_systems(), sheet_name="TES")
        storage_cost_data = storage_cost_data[storage_cost_data['code'] == technology_type]

        # if the Q_design is below the lowest capacity available for the technology, then it is replaced by the least
        # capacity for the corresponding technology from the database
        if V_tank_m3 < storage_cost_data.iloc[0]['cap_min']:
            V_tank_m3 = storage_cost_data[0]['cap_min']

        storage_cost_data = storage_cost_data[
            (storage_cost_data['cap_min'] <= V_tank_m3) & (storage_cost_data['cap_max'] > V_tank_m3)]

        Inv_a = storage_cost_data.iloc[0]['a']
        Inv_b = storage_cost_data.iloc[0]['b']
        Inv_c = storage_cost_data.iloc[0]['c']
        Inv_d = storage_cost_data.iloc[0]['d']
        Inv_e = storage_cost_data.iloc[0]['e']
        Inv_IR = (storage_cost_data.iloc[0]['IR_%']) / 100
        Inv_LT = storage_cost_data.iloc[0]['LT_yr']
        Inv_OM = storage_cost_data.iloc[0]['O&M_%'] / 100

        InvC = Inv_a + Inv_b * (V_tank_m3) ** Inv_c + (Inv_d + Inv_e * V_tank_m3) * log(V_tank_m3)

        Capex_a_storage_USD = InvC * (Inv_IR) * (1 + Inv_IR) ** Inv_LT / ((1 + Inv_IR) ** Inv_LT - 1)
        Opex_fixed_storage_USD = InvC * Inv_OM
        Capex_storage_USD = InvC
    else:
        Capex_a_storage_USD = 0.0
        Opex_fixed_storage_USD = 0.0
        Capex_storage_USD = 0.0

    return Capex_a_storage_USD, Opex_fixed_storage_USD, Capex_storage_USD

@@ -91,16 +91,100 @@
 ort log%0A
+from cea.analysis.costs.equations import calc_capex_annualized, calc_opex_annualized
 %0A__autho
@@ -1697,17 +1697,16 @@
 nv_IR = 
-(
 storage_
@@ -1734,15 +1734,8 @@
 _%25'%5D
-) / 100
 %0A   
@@ -1850,20 +1850,31 @@
         
-InvC
+Capex_total_USD
  = Inv_a
@@ -1952,17 +1952,16 @@
 ank_m3)%0A
-%0A
         
@@ -1986,78 +1986,61 @@
 D = 
-InvC * (Inv_IR) * (1 + Inv_IR) ** Inv_LT / ((1 +
+calc_capex_annualized(Capex_total_USD,
  Inv_IR
-) **
+,
  Inv_LT
- - 1
 )%0A  
@@ -2073,55 +2073,33 @@
 SD =
- InvC * Inv_OM%0A       
  Capex_
-s
 to
-rage
+tal
 _USD 
-=
+*
  Inv
-C
+_OM
 %0A   
@@ -2186,31 +2186,29 @@
       Capex_
-s
 to
-rage
+tal
 _USD = 0.0%0A%0A
@@ -2269,20 +2269,18 @@
 , Capex_
-s
 to
-rage
+tal
 _USD%0A

Update thermal_storage.py