Untitled
unknown
plain_text
5 months ago
2.8 kB
5
Indexable
# Name: Gary Griffith # Date: 10/16/2024 # Purpose: Gather weather data and create a plot from noaa_sdk import noaa import matplotlib.pyplot as plt name = "Gary Griffith" print(name) # Define updated date range startDate = '2024-10-09' endDate = '2024-10-16' print(f"Start Date: {startDate}, End Date: {endDate}") # Initialize NOAA API n = noaa.NOAA() # Latitude and Longitude for Atlanta, GA latitude = 33.7490 longitude = -84.3880 # Create two lists to store temperature and humidity temp = [] humidity = [] cloudy_days_count = 0 # Define box_data at the module level box_data = [] try: print("Fetching current observations...") observations = list(n.get_observations_by_lat_lon(latitude, longitude)) print(f"Number of observations retrieved: {len(observations)}") # Check if observations were returned if not observations: print("No observations found.") else: for obs in observations: # Populate temperature and humidity temp.append(obs['temperature']['value']) humidity.append(obs['relativeHumidity']['value']) print(obs['timestamp'], "\t", obs['temperature']['value'], "\t", obs['relativeHumidity']['value'], "\t", obs['textDescription']) # Count Cloudy days if 'Cloudy' in obs['textDescription']: cloudy_days_count += 1 # Calculate statistics for temperature avg_temp = sum(temp) / len(temp) if temp else 0 # Average temperature low_temp = min(temp) if temp else None # Lowest temperature high_temp = max(temp) if temp else None # Highest temperature # Print statistics print("Weather Statistics") print("The average temperature was: ", avg_temp) print("The lowest temperature was: ", low_temp) print("The highest temperature was: ", high_temp) print(f"Number of Cloudy Days: {cloudy_days_count}") # Prepare box_data for plotting box_data = [temp, humidity] # Create a box plot for temperature and humidity plt.figure() plt.boxplot(box_data, labels=['Temperature (°C)', 'Humidity (%)']) plt.title('Box Plot of Temperature and Humidity for Gary Griffith') plt.savefig('boxplot.png') # Additional line plot with different colors plt.figure() plt.plot(temp, color='blue', label='Temperature (°C)') plt.plot(humidity, color='green', label='Humidity (%)') plt.legend() plt.title('Temperature vs Humidity for Gary Griffith') plt.savefig('weather.png') except Exception as e: print(f"Error: {e}")
Editor is loading...
Leave a Comment