<jupyter_start><jupyter_text>To do- reduce coordinate precision.- use vectorisation to loop over centroids Load in the isochrones for the East Midlands<jupyter_code>df = gpd.read_file('processed/east_midlands.geojson')
df<jupyter_output><empty_output><jupyter_text>Load in the centroids from the population grid<jupyter_code>centroids = gpd.read_file('data/gb_centroid.geojson')
centroids<jupyter_output><empty_output><jupyter_text>Calculate the total population of the UK<jupyter_code>totalpop=centroids['population'].sum()
totalpop
# define a function that takes a isochrone and loops through all the centroids to see if that centroid is within the isochrone. If it does, it adds the population to a running total.
def inthegoldentriangle(isochrone):
#     print(isochrone)
    population=0
    for i,centroid in centroids.iterrows():
        if(centroid['geometry'].within(isochrone)):
            population=population+centroid['population']
    if(population/totalpop>0.9):
        return True
    else:
        return False
    
# test it
inthegoldentriangle(df['geometry'][4])
# run the function across all the isochrones in parallel, save it to a list called output
pool=mp.Pool(8)
output = list(tqdm.tqdm_notebook(pool.imap(inthegoldentriangle, df['geometry']), total=len(df['geometry'])))
pool.close()
pool.join()
output
# find out how many squares are within the golden triangle
sum(x==True for x in output)
# Add the column to the isochrones
df['inside']=output
# Here's all the isochrones that are within the golden triangle
df[df['inside']==True]
# use Henry's lookup
lookup=gpd.read_file('data/east_midlands_lookup.geojson')
# find the centre points of the isochrones
goldentriangle=lookup[(lookup['iso_id']==7986) | (lookup['iso_id']==8068) | (lookup['iso_id']==8069)]
goldentriangle
# make a geodataframe with the points
gdf = gpd.GeoDataFrame(goldentriangle, geometry=gpd.points_from_xy(goldentriangle.lon,goldentriangle.lat))
gdf
# make a convex hull around the points, convert it to a geodataframe, and then save it
triangle=gdf.unary_union.convex_hull
hull = gpd.GeoDataFrame(geometry=gpd.GeoSeries(triangle))
hull
hull.set_crs('wgs84')
hull.to_file('goldentriangle.geojson',driver='GeoJSON')
# testing out the centroid loop
population=0
for index,row in centroids.iterrows():
    if(row['geometry'].within(df['geometry'][0])):
        population=population+row['population']
# if(population/totalpop>0.9):
print(population/totalpop)
# testing out the isochrone loop

for index,isochrone in df[0:2].iterrows():
    population=0
    for i,centroid in centroids.iterrows():
        if(centroid['geometry'].within(isochrone['geometry'])):
            population=population+centroid['population']
    print(index)
    if(population/totalpop>0.9):
        df['inside']=True
    else:
        df['inside']=False<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11589635854341737, 'fraction_numerical': 0.00980392156862745, 'mean_word_length': 5.738207547169812, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '654270', 'license': 'MIT', 'n_tokens_mistral': 973, 'n_tokens_neox': 931, 'n_words': 228, 'path': 'East midlands.ipynb', 'repo_name': 'henryjameslau/golden_triangle', 'size': '2856'}