File size: 7,945 Bytes
67fbfe5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83e1fd8
67fbfe5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import streamlit as st
import altair as alt

# Load the dataset
@st.cache


def load_data(file_path):
    data = pd.read_csv("Air_Quality.csv")
    return data

# Preprocess the dataset
def preprocess_data(data):
    # Ensure Date is in datetime format
    data['Start_Date'] = pd.to_datetime(data['Start_Date'], errors='coerce')
    return data


def main():
    st.title("Living in the Clouds: New York’s Air Quality Through Time")
    st.subheader("By Kaylee Youngseo Chun")


    # Load and preprocess data
    file_path = st.text_input("Enter the file path of your dataset:", "Air_Quality.csv") 
    data = load_data(file_path)
    data = preprocess_data(data)

    # Sidebar for pollutant selection
    st.sidebar.title("Filter Options")
    pollutants = st.sidebar.multiselect(
        "Select pollutants to display:",
        options=data["Name"].unique(),
        default=data["Name"].unique()[:5]
    )
    st.markdown("""Today, I will examine the air quality trends in New York using an air quality dataset provided by Data.gov. 
                You can also access and explore the dataset through the following link: New York City Air Quality Data. 
                This dataset is publicly available for anyone to use. 
                To analyze the data, you can apply filters to explore how various components affecting air quality change over time. 
                Note that some components are available only for specific periods, which may be due to incomplete data collection or recent monitoring initiatives.
                
                Key components to focus on include:
                1. Ozone (O3): While ozone depletion doesn’t cause global warming, 
                both are linked to human activities that release pollutants into the atmosphere.

                2. Nitrogen Dioxide (N2O): This gas has a significant warming impact, 
                with 1 pound of N2O being 265 times more potent than 1 pound of carbon dioxide.

                3. Fine Particles (PM2.5): These are tiny particles or droplets in the air measuring 2.5 microns 
                or smaller—about 30 times smaller than a human hair. 
                Their size allows them to penetrate deeply into the lungs and even enter the bloodstream.""")
    

    # Filter data based on pollutants
    filtered_data = data[data["Name"].isin(pollutants)]

    # Select numeric columns only
    numeric_cols = filtered_data.select_dtypes(include=["number"]).columns
    filtered_data = filtered_data[["Start_Date", "Name"] + list(numeric_cols)]

    # Resample data to monthly averages for cleaner visualization
    filtered_data = (
        filtered_data
        .groupby([pd.Grouper(key="Start_Date", freq="M"), "Name"])[numeric_cols]
        .mean()
        .reset_index()
    )

    # Create an interactive Altair line chart
    chart = alt.Chart(filtered_data).mark_line().encode(
        x=alt.X("Start_Date:T", title="Date"),
        y=alt.Y("Data Value:Q", title="Value"),
        color="Name:N",
        tooltip=["Start_Date:T", "Name:N", "Data Value:Q"]
    ).properties(
        width=800,
        height=400,
        title="Pollutant Levels Over Time (Monthly Average)"
    ).interactive()

    # Display the chart
    st.altair_chart(chart, use_container_width=True)

if __name__ == "__main__":
    main()


import matplotlib.pyplot as plt

def main():
    st.subheader("Fine Particle (PM2.5) Trend Analysis")
    st.markdown("""How Did Fine Particles Change During COVID-19? To explore this, we compared the dataset before and during the COVID-19 lockdowns. 
                Below is a graph showing trends in PM2.5 levels, which have been steadily declining since 2010. The map below highlights further reductions during the lockdown. 
                While annual declines in PM2.5 were already apparent, the shutdown contributed significantly to this trend. 
                During the COVID-19 health lockdown, PM2.5 levels in New York decreased by 23%. 
                A five-year improvement plan based on this data predicts benefits including reductions in pre-term births, low birth weight, infant mortality, childhood asthma, emergency room visits, and adult mortality. 
                These findings are supported by Perera, F. et al. (2021).""")
    
    # Load and preprocess data
    file_path = st.text_input(
        "Enter the file path of your dataset:",
        "Air_Quality.csv",
        key="file_path_input"
    )
    data = load_data(file_path)
    data = preprocess_data(data)

    # Filter for Fine Particle (PM2.5) data only
    fine_particle_data = data[data["Name"] == "Fine particles (PM 2.5)"]

    # Ensure "Data Value" column is numeric
    fine_particle_data["Data Value"] = pd.to_numeric(fine_particle_data["Data Value"], errors="coerce")
    fine_particle_data = fine_particle_data.dropna(subset=["Data Value"])

    # Resample data to monthly averages for cleaner visualization
    fine_particle_data = (
        fine_particle_data
        .groupby(pd.Grouper(key="Start_Date", freq="M"))["Data Value"]
        .mean()
        .reset_index()
    )

    # Check if data is empty
    if fine_particle_data.empty:
        st.warning("No data available for Fine Particle (PM2.5). Please check your dataset.")
        return

    # Plotting with Matplotlib
    plt.figure(figsize=(10, 6))
    plt.plot(fine_particle_data["Start_Date"], fine_particle_data["Data Value"], marker='o', linestyle='-')
    plt.title("Monthly Average of Fine Particle (PM2.5) Levels", fontsize=16)
    plt.xlabel("Date", fontsize=12)
    plt.ylabel("PM2.5 Level", fontsize=12)
    plt.grid(True)
    plt.tight_layout()

    # Display the Matplotlib chart in Streamlit
    st.pyplot(plt)

if __name__ == "__main__":
    main()

def main():
    st.title("Fine Particles (PM 2.5) during shutdown")

    # Ensure the image path is correct
    st.image("PM.jpg", caption="Fine Particles (PM 2.5) during Covid-19 shutdown", use_container_width=True)
    st.markdown("source: https://kunakair.com/air-pollution-in-new-york/")


    # Use st.image within the Streamlit app context
    try:
        st.image(image_path, caption="Fine Particles (PM 2.5) during Covid-19 shutdown", use_column_width=True)
    except Exception as e:
        st.error(f"Error displaying image: {e}")

    st.subheader("Summary")
    st.markdown("""This analysis explores air quality trends in New York using publicly available data, with a focus on ozone (O3), nitrogen dioxide (N2O), and fine particulate matter (PM2.5). 
                PM2.5 levels have been decreasing since 2010, and the COVID-19 lockdown accelerated this trend, showing a 23% reduction. 
                These improvements highlight the benefits of clean air, including better health outcomes and lower mortality rates. 
                The findings emphasize the importance of long-term air quality management for public health.""")
    

    st.subheader("Citation")
    st.markdown("""
                1. Is there a connection between the ozone hole and global warming?. Union of Concerned Scientists. (n.d.). 
                https://www.ucsusa.org/resources/ozone-hole-and-global-warming.

                2. Environmental Protection Agency. (n.d.). EPA. https://www.epa.gov/ghgemissions/overview-greenhouse-gases 

                3. Particle pollution and health. (n.d.). https://www.health.ny.gov/environmental/indoors/air/pmq_a.htm 

                4. Frederica Perera, Alique Berberian, David Cooley, Elizabeth Shenaut, Hollie Olmstead, Zev Ross, Thomas Matte. 
                Potential health benefits of sustained air quality improvements in New York City: A simulation based on air pollution levels during the COVID-19 shutdown. 
                Environmental Research, Volume 193, 2021, 110555, ISSN 0013-9351, https://doi.org/10.1016/j.envres.2020.110555

                
                """)

if __name__ == "__main__":
    main()