Skip to content

Instantly share code, notes, and snippets.

View Sparrow0hawk's full-sized avatar

Alex Coleman Sparrow0hawk

View GitHub Profile
@Sparrow0hawk
Sparrow0hawk / get_POI_in_LSOA.py
Created June 11, 2019 11:06
Call to Overpass API to get specific points of interest in area and aggregate them into LSOAs
import requests
import json
import pandas as pd
from shapely.geometry import shape, Point
from geopy.geocoders import Nominatim
from collections import Counter
import time
def get_POI_in_LSOA(location=None, POI_type=None):
@Sparrow0hawk
Sparrow0hawk / ONS_OA_lookup.py
Last active February 21, 2020 13:47
Simple python function to lookup ONS output area codes and return relevant LSOA, MSOA, LAD etc codes
# function for mapping between OA, LSOA, MSOA
import sys
import pandas as pd
# moved data read out of function call
lookup_table = pd.read_csv('data/OA_lookup_table.csv')
def ONS_OA_lookup(code, level, lookup_tbl=lookup_table):
"""
Using http://geoportal1-ons.opendata.arcgis.com/datasets/fe6c55f0924b4734adf1cf7104a0173e_0.csv
@Sparrow0hawk
Sparrow0hawk / helloworld.py
Created June 9, 2020 15:55
Hello world Python3
print("Hello, world!")
@Sparrow0hawk
Sparrow0hawk / NEC_nomination_table.csv
Last active October 2, 2020 07:57
NECnom_scrapper_2020.ipynb
Totnes CLP York Central CLP Almond Valley CLP Chatham and Aylesford CLP Edmonton CLP Enfield North CLP Aberavon CLP Aberdeen Central CLP Airdrie and Shotts CLP Altrincham and Sale West CLP Amber Valley CLP Arundel and South Downs CLP Barking CLP Barrow and Furness CLP Bassetlaw CLP Beckenham CLP Bermondsey and Old Southwark CLP Bexhill and Battle CLP Bexleyheath and Crayford CLP Birmingham, Northfield CLP Birmingham, Selly Oak CLP Bracknell CLP Braintree CLP Brentwood and Ongar CLP Bristol West CLP Bromley and Chislehurst CLP Buckingham CLP Bury North CLP Bury South CLP Caerphilly CLP Chelsea and Fulham CLP Chesham and Amersham CLP Chesterfield CLP Cities of London and Westminster CLP Coventry North East CLP Coventry South CLP Croydon North CLP Cunninghame North CLP Dagenham and Rainham CLP Darlington CLP Derby North CLP Don Valley CLP Doncaster North CLP Dundee City East CLP Dundee City West CLP East Lothian CLP East Surrey CLP Eastleigh CLP Eastwood CLP Edinburgh Pentlands CLP Edinburgh Southern CLP En
@Sparrow0hawk
Sparrow0hawk / main.py
Created June 24, 2021 20:24
Walrus operator python 3.8 example
# unpacking a tuple returning function within an if statement
# inspired by this stackoverflow answer https://stackoverflow.com/questions/68122210/python-function-returning-tuple
def check_something():
return True, "string"
if (x := check_something())[0]:
print(x[1])
@Sparrow0hawk
Sparrow0hawk / flags-and-emissions.ipynb
Last active November 11, 2021 14:41
flags-and-emissions.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Sparrow0hawk
Sparrow0hawk / extracting-topic-scores.ipynb
Last active April 15, 2022 19:09
Extracting topic scores for documents using LDA Gensim (SOO answer)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Sparrow0hawk
Sparrow0hawk / test-post.py
Created October 17, 2022 18:27
Simple POST request to influxdb
import requests
headers = {"Authorization": "Token super-secret-token",
"Content-Type": "text/plain; charset=utf-8",
"Accept": "application/json"}
data = "airSensors,sensor_id=THP0101 temperature=37.94,humidity=35.231,pressure=1010"
res = requests.post("http://INFLUXDB_IP:8086/api/v2/write?org=home&bucket=weather-pi&precision=ns",
@Sparrow0hawk
Sparrow0hawk / random_walk.py
Created December 9, 2022 11:42
Playing with ChatGPT
from mpi4py import MPI
import numpy as np
# Define the size of the grid
n = 100
# Initialize MPI and get the rank of the current process
comm = MPI.COMM_WORLD
rank = comm.Get_rank()