Skip to content

Instantly share code, notes, and snippets.

@TimSC
TimSC / nmist_with_generator.py
Last active April 16, 2020 23:43
Convert nmist digit example to use generator
import os
#Work around for https://github.com/tensorflow/tensorflow/issues/24496
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
# Work around for https://github.com/tensorflow/tensorflow/issues/33024
import tensorflow.compat as compat
compat.v1.disable_eager_execution()
# baseline cnn model for mnist
import numpy as np
@TimSC
TimSC / tensorflow-gpu-environment.md
Last active April 15, 2020 21:47
Working tensorflow GPU environments (Ubuntu 18.04 with Geforce RTX 2060 super)

Working environments (Ubuntu 18.04 with Geforce RTX 2060 super)

tensorflow-gpu-1.13 and after require TF_FORCE_GPU_ALLOW_GROWTH work around tensorflow/tensorflow#24496

Keras-2.2.5
tensorflow-gpu-1.12.0 
libcudnn7 7.6.5.32-1+cuda10.0
cuda-libraries-10-0
@TimSC
TimSC / portsmouth-measuredno2.csv
Created March 16, 2020 11:39
NO2 measurements in Portsmouth, from the council's annual report
Site ID X Y 2012 2013 2014 2015 2016 2017 2018
1 463872 99874 42.54 41.9 42.57 44.33 43.52 38.8 42.92
2 463705 99371 17.48 16.5 16.55 15.74 17.4 16.38 17.09
3 463408 99460 26.63 22.1 25.67 24.07 25.75 23.7 24.13
4 463190 100390 36.35 31.51 27.97 30.54 34.7 34.2 34.04
5 464230 102194 28.62 27.49 28.93 27.53 29.52 24.48 28.08
6 464331 102197 35.62 38.29 34.85 46.06 36.08 32.08 30.86
7 464291 102279 29.78 30 26.53 26.05 28.09 27.32 27.74
8 466690 104355 28.81 27.22 28.37 28.43 29.94 26.75 25.97
9 465621 105528 35.07 31.95 33.88 34.98 40.86 37.06 36.7
@TimSC
TimSC / splitquoted.py
Last active September 27, 2019 22:57
Split a quoted string by delimiter using python
from __future__ import unicode_literals
from __future__ import print_function
def SplitQuoted(inStr, delim=','):
if '"' in delim or '\\' in delim:
raise ValueError("Delimiter not supported")
l = len(inStr)
@TimSC
TimSC / shapelib_example.cpp
Last active February 11, 2019 14:05
Basic usage of shapelib
//By Tim Sheerman-Chase, released under CC0
//Compile: g++ shapelib_example.cpp -lshp -o shapelib_example
#include <iostream>
#include <vector>
#include <string>
#include "shapefil.h"
using namespace std;
int main(int argc, const char **argv)
@TimSC
TimSC / checkosc.py
Created November 10, 2018 23:53
Find non existent referenced objects in osm osc change file
from pyo5m import OsmData
import requests
if __name__=="__main__":
#
osc = OsmData.OsmChange()
osc.LoadFromOscXml(open("bad_changeset.osc", "rb"))
refNodes, refWays, refRelations = set(), set(), set()
@TimSC
TimSC / pycrocosm-diffs.py
Last active November 10, 2018 06:51
Download osc diffs using custom pycrocosm api method
#Download osc diffs using custom pycrocosm api method
#Released under CC0 license
import requests
import datetime
import os
import gzip
def DownloadDiffs(epoch = datetime.date(2016, 9, 27),
dt=datetime.timedelta(1),
@TimSC
TimSC / syncfsm.py
Last active September 23, 2018 02:09
Sync freestreetmap replication data
import os
import requests
if __name__=="__main__":
interval = "day"
pth = "/home/tim/replicatefsm"
#Check what already exists
fiList = os.listdir(pth)
@TimSC
TimSC / equalize_histogram.py
Last active April 10, 2020 21:34
Equalize histogram using numpy/python
import numpy as np
def EqualizeHistogram(a, bins):
a = np.array(a)
hist, bins2 = np.histogram(a, bins=bins)
#Compute CDF from histogram
cdf = np.cumsum(hist, dtype=np.float64)
cdf = np.hstack(([0], cdf))
cdf = cdf / cdf[-1]
@TimSC
TimSC / natstats-postcode.py
Created June 17, 2018 07:46
Filter National Statistics Office Postcode data set
import csv
# Filtering file https://data.gov.uk/dataset/7ec10db7-c8f4-4a40-8d82-8921935b4865/national-statistics-postcode-lookup-uk
if __name__=="__main__":
reader = csv.DictReader(open("/home/tim/Downloads/National_Statistics_Postcode_Lookup_UK.csv"))
out = csv.DictWriter(open("natstats-po-postcodes.csv", "wt"), reader.fieldnames)
out.writeheader()