about summary refs log tree commit diff stats
path: root/py/air-quality/analyze_air_quality.py
diff options
context:
space:
mode:
Diffstat (limited to 'py/air-quality/analyze_air_quality.py')
-rw-r--r--py/air-quality/analyze_air_quality.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/py/air-quality/analyze_air_quality.py b/py/air-quality/analyze_air_quality.py
new file mode 100644
index 0000000..a944e51
--- /dev/null
+++ b/py/air-quality/analyze_air_quality.py
@@ -0,0 +1,92 @@
+# pip install pandas matplotlib
+# python analyze_air_quality.py
+# The script will create a directory named with today’s date (e.g., 2024-10-11) and save the graphs as PNG images inside that directory.
+
+import os
+import pandas as pd
+import matplotlib.pyplot as plt
+from datetime import datetime
+
+def load_data(file_path):
+    """Load the air quality CSV data."""
+    return pd.read_csv(file_path)
+
+def preprocess_data(data):
+    """Preprocess the data by converting the 'Time' column to datetime."""
+    data['Time'] = pd.to_datetime(data['Time'], format='%d/%m/%Y %I:%M:%S %p')
+    return data
+
+def create_output_directory():
+    """Create a directory with today's date to store the plots."""
+    today = datetime.today().strftime('%Y-%m-%d')
+    if not os.path.exists(today):
+        os.makedirs(today)
+    return today
+
+def plot_data(data, output_dir):
+    """Generate and save the time series plots to the output directory."""
+    
+    # Plot CO2 levels over time
+    plt.figure(figsize=(10, 6))
+    plt.plot(data['Time'], data['CO2_ppm'], label='CO2 (ppm)', color='green')
+    plt.xlabel('Time')
+    plt.ylabel('CO2 (ppm)')
+    plt.title('CO2 Levels Over Time')
+    plt.grid(True)
+    plt.xticks(rotation=45)
+    plt.tight_layout()
+    plt.savefig(f"{output_dir}/CO2_levels_over_time.png")
+    plt.close()
+
+    # Plot Temperature over time
+    plt.figure(figsize=(10, 6))
+    plt.plot(data['Time'], data['Temperature_F'], label='Temperature (°F)', color='red')
+    plt.xlabel('Time')
+    plt.ylabel('Temperature (°F)')
+    plt.title('Temperature Over Time')
+    plt.grid(True)
+    plt.xticks(rotation=45)
+    plt.tight_layout()
+    plt.savefig(f"{output_dir}/Temperature_over_time.png")
+    plt.close()
+
+    # Plot Relative Humidity over time
+    plt.figure(figsize=(10, 6))
+    plt.plot(data['Time'], data['Humidity_percent'], label='Relative Humidity (%)', color='blue')
+    plt.xlabel('Time')
+    plt.ylabel('Relative Humidity (%)')
+    plt.title('Relative Humidity Over Time')
+    plt.grid(True)
+    plt.xticks(rotation=45)
+    plt.tight_layout()
+    plt.savefig(f"{output_dir}/Relative_humidity_over_time.png")
+    plt.close()
+
+    # Plot Atmospheric Pressure over time
+    plt.figure(figsize=(10, 6))
+    plt.plot(data['Time'], data['Pressure_hPa'], label='Pressure (hPa)', color='purple')
+    plt.xlabel('Time')
+    plt.ylabel('Pressure (hPa)')
+    plt.title('Atmospheric Pressure Over Time')
+    plt.grid(True)
+    plt.xticks(rotation=45)
+    plt.tight_layout()
+    plt.savefig(f"{output_dir}/Pressure_over_time.png")
+    plt.close()
+
+def main():
+    """Main function to load, process, and plot the air quality data."""
+    file_path = "export.csv"
+    
+    # Load and preprocess the data
+    data = load_data(file_path)
+    data = preprocess_data(data)
+
+    output_dir = create_output_directory()
+
+    plot_data(data, output_dir)
+
+    print(f"Graphs have been saved in the directory: {output_dir}")
+
+if __name__ == "__main__":
+    main()
\ No newline at end of file