<jupyter_start><jupyter_text>WeatherPy---- Analysis* As expected, the weather becomes significantly warmer as one approaches the equator (0 Deg. Latitude). More interestingly, however, is the fact that the southern hemisphere tends to be warmer this time of year than the northern hemisphere. This may be due to the tilt of the earth.* There is no strong relationship between latitude and cloudiness. However, it is interesting to see that a strong band of cities sits at 0, 80, and 100% cloudiness.* There is no strong relationship between latitude and wind speed. However, in northern hemispheres there is a flurry of cities with over 20 mph of wind.--- Note* Instructions have been included for each segment. You do not have to follow them exactly, but they are included to help you think through the steps.<jupyter_code># Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import time

# Import API key
from api_keys import api_key

# Incorporated citipy to find a city based on latitude and longitude
from citipy import citipy

# Incorporated openweathermapy to retrieve weather related information
import openweathermapy.core as owm

# Import user defined methods.
from utility_methods import create_scatter_plot, \
                            record_city_weather

# Output File (CSV)
output_data_file = "./output_data/cities.csv"

# Range of latitudes and longitudes
lat_range = (-90.0, 90.0)
lng_range = (-180.0, 180.0)

# Minimum number of cities to collect weather info on
number_of_cities = 525<jupyter_output><empty_output><jupyter_text>Generate Cities List<jupyter_code># Create a List for holding the candidate cities
cities = []

# Create a set of random lat and lng combinations
lat_lngs = zip(np.random.uniform(low=lat_range[0], high=lat_range[1], size=1500),
               np.random.uniform(low=lng_range[0], high=lng_range[1], size=1500))

# Identify nearest city for each lat, lng combination
for lat_lng in lat_lngs:
    city = citipy.nearest_city(lat_lng[0], lat_lng[1]).city_name
    
    # If the city is unique, then add it to a our cities list
    if city not in cities:
        cities.append(city)

# Check if enough cities were selected
if len(cities) < number_of_cities:
    print(f"\n **** Less than {number_of_cities} cities selected ****\n")
else:
    # Print the city count to confirm sufficient count
    print(len(cities))<jupyter_output>637<jupyter_text>Perform API Calls* Perform a weather check on each city using a series of successive API calls.* Include a print log of each city as it'sbeing processed (with the city number and city name).<jupyter_code># Create a Dictionary of Lists to hold the weather information for selected cities
city_weather = {'City'        : [],
                'Country'     : [],
                'Lat'         : [],
                'Lng'         : [],
                'Since Epoch' : [],
                'Max Temp'    : [],
                'Humidity'    : [],
                'Cloudiness'  : [],
                'Wind Speed'  : []
               }

# Set perferred units and API key.
settings = {"units": "imperial", "appid": api_key}

# Initialize a counter for the number of cities that
# weather information has been collected for.
count = 0

# Loop through the List of cities collecting weather
# information.
for city_name in cities:
    
    # Try to get its weather informartion.
    try:
        current_weather = owm.get_current(city_name, **settings)
        print(f"Processing: {current_weather['name']} with ID {current_weather['id']}")
        count += 1
    except:
        print(f"Weather information not found for {city_name}. Skipping ...")
        continue
    
     # Add a city's weather information to the Dictionary.
    record_city_weather(city_weather, current_weather)


# Convert the List of 'times since epoch' to a List of dates and add
# this List to the city_weather Dictionary.
city_weather['Date'] = [time.strftime("%m/%d/%Y %H:%M", time.localtime(seconds))
                        for seconds in city_weather['Since Epoch']]

# Determine the 'mean' date for all observations. Use this in plot titles.
display_date = time.strftime("%m/%d/%Y", time.localtime(np.mean(city_weather['Since Epoch'])))

# Verify the desired number of cities was reached.
if count < number_of_cities:
    print(f"\n **** Less than {number_of_cities} cities' weather recorded ****\n")<jupyter_output>Processing: Emba with ID 146639
Processing: Baraki Barak with ID 1147066
Processing: Bluff with ID 2175403
Weather information not found for ransang. Skipping ...
Processing: Port Elizabeth with ID 4501427
Weather information not found for warqla. Skipping ...
Processing: Erenhot with ID 2037485
Processing: Port Alfred with ID 964432
Processing: Busselton with ID 2075265
Processing: Los Llanos de Aridane with ID 2514651
Processing: Albany with ID 5106834
Processing: Ushuaia with ID 3833367
Processing: Puerto Ayora with ID 3652764
Weather information not found for acarau. Skipping ...
Processing: North Bend with ID 5742974
Processing: Avarua with ID 4035715
Processing: Flinders with ID 6255012
Processing: Cape Town with ID 3369157
Processing: Mayo with ID 6068416
Processing: Punta Arenas with ID 3874787
Processing: Castro with ID 3896218
Processing: Kavieng with ID 2094342
Processing: Ahuimanu with ID 5856516
Processing: Watertown with ID 5232741
Weather information not found for mbacke[...]<jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code># Create a DataFrame that holds the weather information
city_weather_df = pd.DataFrame(city_weather)

# Save the data to a CSV file.
city_weather_df.to_csv(output_data_file)

# Display the counts of each column.
city_weather_df.count()
# Print the first five rows of of the DataFrame.
city_weather_df.head()<jupyter_output><empty_output><jupyter_text>Plotting the Data* Use proper labeling of the plots using plot titles (including date of analysis) and axes labels.* Save the plotted figures as .pngs.  Latitude vs. Temperature Plot<jupyter_code># Create the scatter plot using the latitude and
# maximum temperature information.
plt = create_scatter_plot(city_weather_df['Lat'],
                          city_weather_df['Max Temp'],
                          lat_range)

# Add a title and axis labels.
plt.title(f'City Latitude vs. Max Temperature ({display_date})')
plt.ylabel('Max Temperature (F)')
plt.xlabel('Latitude')

# Save the plot to a file.
plt.savefig('./output_data/max_temp_scatter.png')<jupyter_output><empty_output><jupyter_text>Latitude vs. Humidity Plot<jupyter_code># Create the scatter plot using the latitude and
# humidity information.
plt = create_scatter_plot(city_weather_df['Lat'],
                          city_weather_df['Humidity'],
                          lat_range)

# Add a title and axis labels.
plt.title(f'City Latitude vs. Humidity ({display_date})')
plt.ylabel('Humidity (%)')
plt.xlabel('Latitude')

# Save the plot to a file.
plt.savefig('./output_data/humidity_scatter.png')<jupyter_output><empty_output><jupyter_text>Latitude vs. Cloudiness Plot<jupyter_code># Create the scatter plot using the latitude and
# cloudiness information.
plt = create_scatter_plot(city_weather_df['Lat'],
                          city_weather_df['Cloudiness'],
                          lat_range)

# Add a title and axis labels.
plt.title(f'City Latitude vs. Cloudiness ({display_date})')
plt.ylabel('Cloudiness (%)')
plt.xlabel('Latitude')

# Save the plot to a file.
plt.savefig('./output_data/cloudiness_scatter.png')<jupyter_output><empty_output><jupyter_text>Latitude vs. Wind Speed Plot<jupyter_code># Create the scatter plot using the latitude and
# wind speed information.
plt = create_scatter_plot(city_weather_df['Lat'],
                          city_weather_df['Wind Speed'],
                          lat_range)

# Add a title and axis labels.
plt.title(f'City Latitude vs. Wind Speed ({display_date})')
plt.ylabel('Wind Speed (mph)')
plt.xlabel('Latitude')

# Save the plot to a file.
plt.savefig('./output_data/wind_speed_scatter.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08639096821695913, 'fraction_numerical': 0.023315744263099767, 'mean_word_length': 3.782863849765258, 'pattern_counts': {'":': 2, '<': 33, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '605225', 'license': 'Unlicense', 'n_tokens_mistral': 2609, 'n_tokens_neox': 2358, 'n_words': 877, 'path': 'Weather.ipynb', 'repo_name': 'tomgrosvenor/PythonAPIs', 'size': '8149'}