<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Do some initial testing and analysis
Step1:  Import all data (data was previously cleaning in other notebooks)
Step2:  Now I have one dict with metro stations and one with bike stations
Step3:  step 1) create list of bike stations along each line
Compare the distances of each bike station to each metro station of each line. If the bike station is "close" to a metro station, it should be added to a list.
* Build test example with RD line
Step5:  Iterate through each metro line, calculating the distance between each station of that line to each bikeshare station.  
Use set to drop duplicates
make the below code a function that can be used to generate lists of stations based on different distances
Step6:  I now have a dictionary of a list of bike stations (values) within 0.25 miles of each metro line (key).
Save it with pickle for use in other notebooks
Step7:  step 2)
how many bike stations are considered close to each line? I need to make sure the numbers are appropriate for doing statistical analysis
Step8:  About 10% to 15% of bike stations are within 0.25 miles of each metro line
test my function
<ASSISTANT_TASK:>
Python Code:
import pickle
from geopy.distance import vincenty
Explanation: Do some initial testing and analysis
End of explanation
station_data = pickle.load( open( "station_data.p", "rb" ) )
bike_location = pickle.load( open( "bike_location.p", "rb" ) )
Explanation: Import all data (data was previously cleaning in other notebooks)
End of explanation
print(station_data['RD']['Bethesda'])
print(bike_location['Silver Spring Metro/Colesville Rd & Wayne Ave'])
Explanation: Now I have one dict with metro stations and one with bike stations
End of explanation
vincenty(station_data['RD']['Silver Spring'], bike_location['11th & O St NW']).miles
for key_bike in bike_location:
        dist = vincenty(station_data['RD']['Silver Spring'], bike_location[key_bike]).miles
        if dist <= 0.3:
            print([key_bike ,dist])
Explanation: step 1) create list of bike stations along each line
Compare the distances of each bike station to each metro station of each line. If the bike station is "close" to a metro station, it should be added to a list.
* Build test example with RD line
End of explanation
def close_stations(distance):
    This fn will return a dict of bikeshare stations close 
    to each metro stop based on the suppled distance in miles
    lines = ['RD', 'YL', 'GR','BL', 'OR', 'SV']
    bikes_close = dict()
    for ii in range(len(lines)):
        bikes_temp = []
        for key_metro in station_data[lines[ii]]:
            for key_bike in bike_location:
                dist = vincenty(station_data[lines[ii]][key_metro], bike_location[key_bike]).miles
                if dist <= distance:
                    bikes_temp.append(key_bike)
                    print([lines[ii], key_metro, key_bike, dist])
        bikes_close[lines[ii]] = list(set(bikes_temp))
    return bikes_close
lines = ['RD', 'YL', 'GR','BL', 'OR', 'SV']
bikes_close = dict()
for ii in range(len(lines)):
    bikes_temp = []
    for key_metro in station_data[lines[ii]]:
        for key_bike in bike_location:
            dist = vincenty(station_data[lines[ii]][key_metro], bike_location[key_bike]).miles
            if dist <= 0.25:
                bikes_temp.append(key_bike)
                print([lines[ii], key_metro, key_bike, dist])
    bikes_close[lines[ii]] = list(set(bikes_temp))
print(len(bikes_close['GR']))
print(bikes_close['GR'][:5])
Explanation: Iterate through each metro line, calculating the distance between each station of that line to each bikeshare station.  
Use set to drop duplicates
make the below code a function that can be used to generate lists of stations based on different distances
End of explanation
pickle.dump( bikes_close, open( "bikes_close.p", "wb" ) )
Explanation: I now have a dictionary of a list of bike stations (values) within 0.25 miles of each metro line (key).
Save it with pickle for use in other notebooks
End of explanation
for ii in bikes_close:
    print(ii, len(bikes_close[ii]))
Explanation: step 2)
how many bike stations are considered close to each line? I need to make sure the numbers are appropriate for doing statistical analysis
End of explanation
fn_test = close_stations(0.1)
for ii in fn_test:
    print(ii, len(fn_test[ii]))
fn_test
Explanation: About 10% to 15% of bike stations are within 0.25 miles of each metro line
test my function
End of explanation
<END_TASK>