File size: 5,975 Bytes
41896b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objs as go

# Load the CSV file
file = "brick_kiln_lucknow_v1.csv"  # Replace with the correct path to your CSV file
data = pd.read_csv(file)

# Streamlit app title
st.markdown("<h2 style='text-align: center;'>Brick Kiln Location and Conversion Visualization</h2>", unsafe_allow_html=True)

# Slider to select the year
year_selected = st.slider("Select the Year", min_value=int(data["Year made"].min()), max_value=int(data["fcb to zigzag"].max()), value=int(data["Year made"].min()), step=1)
filtered_data = data[data["Year made"] <= year_selected]

# # Calculate the change in fcbk to zigzag by checking the 'fcb to zigzag' column
filtered_data["Conversion"] = filtered_data.apply(
    lambda row: "Converted" if row["Year made"] != row["fcb to zigzag"] else "No Conversion", axis=1
)


# Function to determine the status of each kiln based on the selected year
def get_status(row, year_selected):
    if row["fcb to zigzag"]==2009:
        return "fcbk"
    elif year_selected == row["fcb to zigzag"]:
        return "converted"
    else:
        return "zigzag"
    


# Apply the status function to each row
data["Status"] = data.apply(lambda row: get_status(row, year_selected), axis=1)
filtered_data_conv = data[data["Year made"] <= year_selected]
filtered_data_conv["Type"] = filtered_data_conv["Type"].map({0: "fcbk", 1: "zigzag"})
filtered_data["Type"] = filtered_data["Type"].map({0: "fcbk", 1: "Zigzag"})
# Count the total brick kilns, fcbk, zigzag, and conversions
total_kilns = len(filtered_data)
fcbk_count = filtered_data[(filtered_data["Type"] == "fcbk")].shape[0]
zigzag_count = filtered_data_conv[(filtered_data_conv["Type"] == 'zigzag')].shape[0]
converted_count = filtered_data_conv[filtered_data_conv["Status"] == "converted"].shape[0]


# Display the total count and conversions
st.subheader(f"Total Brick Kilns up to Year {year_selected}: {total_kilns}")
st.write(f"Fcbk: {fcbk_count}",'  and  ' f"Zigzag: {zigzag_count}")
# st.write(f"fcbk: {fcbk_count}")
# st.write(f"zigzag: {zigzag_count}")
st.write(f"Converted from fcbk to zigzag: {converted_count}")


# Plotting the filtered data points on a map, with different colors for statuses
fig_filtered = px.scatter_mapbox(
    data,
    lat="Lat",
    lon="Lon",
    color="Status",
    color_discrete_map={"fcbk": "blue", "converted": "green", "zigzag": "red"},  # Set colors for fcbk, converted, and zigzag kilns
    mapbox_style="carto-positron",
    hover_name="Type",
    zoom=8.5,
    center={"lat": 26.8467, "lon": 80.9462},
    title=f"Brick Kiln Locations and Status up to Year {year_selected}",
    height=600,
    width=600
)

# # Display the map in Streamlit
# st.plotly_chart(fig_filtered)

# Yearly count of fcbk and zigzag kilns up to the selected year
yearly_summary = filtered_data.groupby("Year made")["Type"].value_counts().unstack(fill_value=0)

# Adjust the layout to display the table next to the map
col1, col2 = st.columns([3, 1.5])

with col1:
    st.plotly_chart(fig_filtered)
    
with col2:
    st.subheader("Yearly Kiln Made")
    st.dataframe(yearly_summary)

# Historical data for brick kilns
years = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022]
brick_kilns_total = [117, 314, 376, 396, 408, 432, 433, 454, 461, 466, 470, 477, 478]
brick_kilns_fcb = [52, 127, 159, 171, 178, 191, 192, 206, 208, 209, 209, 209, 209]
brick_kilns_zigzag = [65, 187, 217, 225, 230, 241, 241, 248, 253, 257, 261, 268, 269]

# Creating the line plot for the number of brick kilns over the years
fig_line = go.Figure()

fig_line.add_trace(go.Scatter(x=years, y=brick_kilns_total, mode='lines+markers', name='Total Brick Kilns', line=dict(color='red')))
fig_line.add_trace(go.Scatter(x=years, y=brick_kilns_fcb, mode='lines+markers', name='FCBTK', line=dict(color='blue')))
fig_line.add_trace(go.Scatter(x=years, y=brick_kilns_zigzag, mode='lines+markers', name='Zigzag Brick Kilns', line=dict(color='green')))

# Adding labels and title to the line chart
fig_line.update_layout(
    title="Number of Brick Kilns Over Years in Lucknow",
    xaxis_title="Years",
    yaxis_title="Number of Brick Kilns",
    yaxis=dict(tickmode='linear', tick0=0, dtick=25,showgrid=False), 
    width=900
)

# Adding vertical line for the selected year
fig_line.add_vline(x=year_selected, line_dash="dash", line_color="black", annotation_text=f"Year {year_selected}")
# Displaying the line chart
st.plotly_chart(fig_line)    

# # Emission factors
# emission_factor_pm25_fcb = 15000 * 6.8  # grams/day per FCB kiln
# emission_factor_pm10_fcb = 15000 * 4.08  # grams/day per FCB kiln
# emission_factor_pm25_zigzag = 15000 * 3.5  # grams/day per Zigzag kiln
# emission_factor_pm10_zigzag = 15000 * 2.1  # grams/day per Zigzag kiln

# # Calculating annual emissions for each year
# emission_pm25 = []
# emission_pm10 = []

# for fcb, zigzag in zip(brick_kilns_fcb, brick_kilns_zigzag):
#     annual_emission_pm25 = (fcb * emission_factor_pm25_fcb + zigzag * emission_factor_pm25_zigzag) * 365 / 1e6  # Convert to metric tons
#     annual_emission_pm10 = (fcb * emission_factor_pm10_fcb + zigzag * emission_factor_pm10_zigzag) * 365 / 1e6  # Convert to metric tons
#     emission_pm25.append(annual_emission_pm25)
#     emission_pm10.append(annual_emission_pm10)

# # Creating the plot
# fig = go.Figure()

# fig.add_trace(go.Scatter(x=years, y=emission_pm25, mode='lines+markers', name='PM2.5 Emissions', line=dict(color='orange')))
# fig.add_trace(go.Scatter(x=years, y=emission_pm10, mode='lines+markers', name='PM10 Emissions', line=dict(color='blue')))

# # Adding labels and title to the line chart
# fig.update_layout(
#     title="Annual PM2.5 and PM10 Emissions from Brick Kilns in Lucknow",
#     xaxis_title="Year",
#     yaxis_title="Annual Emissions (Metric Tons)",
#     yaxis=dict(tickmode='linear', tick0=0, dtick=50),
#     width=900
# )

# # Displaying the plot
# fig.show()