File size: 10,452 Bytes
d3cbefb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

def run_analyzer():
    st.title("Hydrogen Production Analyzer")
    st.markdown("### AI-Powered Techno-Economic Analysis Tool")
    
    # Create tabs for different analysis sections
    tabs = st.tabs(["Input Parameters", "Production Analysis", "Cost Analysis", "Environmental Impact"])
    
    with tabs[0]:
        st.subheader("System Configuration")
        
        col1, col2 = st.columns(2)
        
        with col1:
            capacity = st.number_input("Electrolyzer Capacity (MW)", 1.0, 1000.0, 10.0)
            efficiency = st.number_input("Efficiency (%)", 50.0, 100.0, 70.0)
            lifetime = st.number_input("System Lifetime (years)", 5, 30, 20)
            capacity_factor = st.number_input("Capacity Factor (%)", 10.0, 100.0, 90.0)
            
        with col2:
            tech_type = st.selectbox("Electrolyzer Technology", 
                                    ["Alkaline", "PEM", "Solid Oxide", "AEM"])
            
            electricity_source = st.selectbox("Electricity Source",
                                             ["Grid Mix", "Solar PV", "Wind", "Nuclear", "Hydropower", "Hybrid Renewable"])
            
            electricity_cost = st.number_input("Electricity Cost ($/MWh)", 10.0, 200.0, 50.0)
            water_cost = st.number_input("Water Cost ($/m³)", 0.5, 10.0, 2.0)
    
    with tabs[1]:
        st.subheader("Hydrogen Production Analysis")
        
        # Calculate hydrogen production
        operating_hours = capacity_factor / 100 * 8760  # hours per year
        energy_consumption = capacity * operating_hours  # MWh per year
        
        h2_production_rate = capacity * efficiency / 100 * 18.4  # kg/h for 1 MW at 100% efficiency
        annual_h2_production = h2_production_rate * operating_hours  # kg per year
        
        col1, col2 = st.columns(2)
        
        with col1:
            st.metric("Annual Hydrogen Production", f"{annual_h2_production/1000:.2f} tonnes")
            st.metric("Energy Consumption", f"{energy_consumption:.2f} MWh")
            
        with col2:
            st.metric("Average Production Rate", f"{h2_production_rate:.2f} kg/hour")
            st.metric("Operating Hours", f"{operating_hours:.0f} hours/year")
        
        # Production over time
        st.subheader("Production Forecast")
        years = range(1, lifetime + 1)
        
        # Assume slight efficiency degradation over time
        degradation_factor = 0.5  # 0.5% per year
        yearly_production = [annual_h2_production * (1 - degradation_factor/100 * year) for year in years]
        
        df_production = pd.DataFrame({
            'Year': years,
            'Production (tonnes)': [p/1000 for p in yearly_production]
        })
        
        fig, ax = plt.subplots(figsize=(10, 6))
        sns.barplot(x='Year', y='Production (tonnes)', data=df_production, ax=ax, color='#1E88E5')
        ax.set_title('Yearly Hydrogen Production Forecast')
        ax.set_xlabel('Year of Operation')
        ax.set_ylabel('Hydrogen Production (tonnes)')
        
        # Only show every other year on x-axis if more than 10 years
        if lifetime > 10:
            ax.set_xticks(range(0, lifetime, 2))
            ax.set_xticklabels([str(y) for y in range(1, lifetime+1, 2)])
            
        st.pyplot(fig)
    
    with tabs[2]:
        st.subheader("Cost Analysis")
        
        # Capital costs based on technology type
        capex_map = {
            "Alkaline": 1000,  # $/kW
            "PEM": 1400,
            "Solid Oxide": 2000,
            "AEM": 1200
        }
        
        capex_per_kw = capex_map[tech_type]
        total_capex = capacity * 1000 * capex_per_kw  # $ (capacity in MW -> kW)
        
        # Operating costs
        electricity_opex_annual = electricity_cost * energy_consumption
        water_consumption = annual_h2_production * 9  # 9 kg water per kg H2
        water_opex_annual = water_cost * water_consumption / 1000  # Convert to m³
        
        maintenance_cost = total_capex * 0.03  # 3% of CAPEX per year
        labor_cost = 50000 * (1 + capacity/10)  # Base + scale factor
        
        total_opex_annual = electricity_opex_annual + water_opex_annual + maintenance_cost + labor_cost
        
        # Financial metrics
        discount_rate = 0.08  # 8%
        
        # Calculate NPV and LCOH
        cash_flows = []
        total_production = 0
        
        for year in range(lifetime):
            production = yearly_production[year]
            total_production += production / (1 + discount_rate)**year
            opex = total_opex_annual * (1 + 0.02)**year  # 2% inflation on OPEX
            
            if year == 0:
                cash_flow = -total_capex - opex
            else:
                cash_flow = -opex
                
            cash_flows.append(cash_flow)
        
        npv = sum(cf / (1 + discount_rate)**i for i, cf in enumerate(cash_flows))
        lcoh = -npv / total_production  # $ per kg
        
        # Display financial metrics
        col1, col2 = st.columns(2)
        
        with col1:
            st.metric("Capital Expenditure (CAPEX)", f"${total_capex:,.0f}")
            st.metric("Annual Operating Cost (OPEX)", f"${total_opex_annual:,.0f}/year")
            
        with col2:
            st.metric("Levelized Cost of Hydrogen (LCOH)", f"${lcoh:.2f}/kg")
            simple_payback = total_capex / (annual_h2_production * 3 - total_opex_annual)  # Assuming $3/kg H2 sale price
            st.metric("Simple Payback Period", f"{simple_payback:.1f} years")
        
        # Cost breakdown
        st.subheader("Annual Cost Breakdown")
        
        cost_data = {
            'Category': ['Electricity', 'Water', 'Maintenance', 'Labor'],
            'Cost ($)': [electricity_opex_annual, water_opex_annual, maintenance_cost, labor_cost]
        }
        
        df_costs = pd.DataFrame(cost_data)
        
        fig, ax = plt.subplots(figsize=(10, 6))
        colors = ['#1E88E5', '#0F9D58', '#FFC107', '#E53935']
        explode = (0.1, 0, 0, 0)  # Explode electricity slice
        
        ax.pie(df_costs['Cost ($)'], labels=df_costs['Category'], autopct='%1.1f%%', 
               startangle=90, colors=colors, explode=explode, shadow=True)
        ax.axis('equal')
        st.pyplot(fig)
        
        # LCOH Sensitivity Analysis
        st.subheader("LCOH Sensitivity Analysis")
        
        # Create sensitivity data
        electricity_range = np.linspace(electricity_cost * 0.5, electricity_cost * 1.5, 5)
        capex_range = np.linspace(capex_per_kw * 0.5, capex_per_kw * 1.5, 5)
        
        sensitivity_data = []
        
        for e_cost in electricity_range:
            for c_cost in capex_range:
                # Recalculate with new parameters
                new_total_capex = capacity * 1000 * c_cost
                new_electricity_opex = e_cost * energy_consumption
                new_total_opex = new_electricity_opex + water_opex_annual + new_total_capex * 0.03 + labor_cost
                
                # Simple LCOH calculation for sensitivity
                new_lcoh = (new_total_capex / lifetime + new_total_opex) / annual_h2_production
                
                sensitivity_data.append({
                    'Electricity Cost ($/MWh)': e_cost,
                    'CAPEX ($/kW)': c_cost,
                    'LCOH ($/kg)': new_lcoh
                })
        
        df_sensitivity = pd.DataFrame(sensitivity_data)
        pivot_table = df_sensitivity.pivot_table(
            values='LCOH ($/kg)', 
            index='Electricity Cost ($/MWh)',
            columns='CAPEX ($/kW)'
        )
        
        fig, ax = plt.subplots(figsize=(10, 6))
        sns.heatmap(pivot_table, annot=True, fmt=".2f", cmap="YlGnBu", ax=ax)
        ax.set_title('LCOH Sensitivity ($/kg)')
        st.pyplot(fig)
    
    with tabs[3]:
        st.subheader("Environmental Impact Analysis")
        
        # Emissions factors by electricity source (kg CO2e/MWh)
        emissions_factors = {
            "Grid Mix": 400,
            "Solar PV": 40,
            "Wind": 11,
            "Nuclear": 12,
            "Hydropower": 24,
            "Hybrid Renewable": 30
        }
        
        emissions_factor = emissions_factors[electricity_source]
        
        # Calculate emissions
        total_emissions = energy_consumption * emissions_factor
        emission_intensity = total_emissions / annual_h2_production
        
        # Water consumption
        water_intensity = water_consumption / annual_h2_production
        
        col1, col2 = st.columns(2)
        
        with col1:
            st.metric("Carbon Intensity", f"{emission_intensity:.2f} kg CO₂e/kg H₂")
            st.metric("Annual CO₂ Emissions", f"{total_emissions/1000:.2f} tonnes CO₂e")
            
        with col2:
            st.metric("Water Intensity", f"{water_intensity:.2f} kg H₂O/kg H₂")
            st.metric("Annual Water Consumption", f"{water_consumption/1000:.2f} m³")
        
        # Comparison with other production methods
        st.subheader("Carbon Intensity Comparison")
        
        comparison_data = {
            'Production Method': ['Your Configuration', 'SMR without CCS', 'SMR with CCS', 'Coal Gasification'],
            'Carbon Intensity (kg CO₂e/kg H₂)': [emission_intensity, 9.0, 2.5, 19.0]
        }
        
        df_comparison = pd.DataFrame(comparison_data)
        
        fig, ax = plt.subplots(figsize=(10, 6))
        bars = sns.barplot(x='Production Method', y='Carbon Intensity (kg CO₂e/kg H₂)', 
                  data=df_comparison, ax=ax, palette=['#0F9D58', '#E53935', '#FFC107', '#1E88E5'])
        
        # Add value labels
        for i, bar in enumerate(bars.patches):
            bars.text(bar.get_x() + bar.get_width()/2.,
                    bar.get_height() + 0.3,
                    f"{df_comparison['Carbon Intensity (kg CO₂e/kg H₂)'][i]:.1f}",
                    ha='center', va='bottom', color='black')
        
        ax.set_title('Carbon Intensity Comparison')
        ax.set_ylabel('kg CO₂e per kg H₂')
        ax.set_ylim(0, max(df_comparison['Carbon Intensity (kg CO₂e/kg H₂)']) * 1.2)
        
        st.pyplot(fig)

if __name__ == "__main__":
    run_analyzer()