Skip to content

Instantly share code, notes, and snippets.

@TimSC
TimSC / clusteraddress.py
Last active February 22, 2023 20:59
A script to group delivery areas into routes of roughly similar size.
# A script to group delivery areas into routes of roughly similar size.
import csv
from sklearn import cluster
from pyproj import Proj, transform
import numpy as np
from matplotlib import pyplot as plt
class EqualWeightClustering(object):
@TimSC
TimSC / install-nvidia-gl32.py
Created November 3, 2021 02:53
Install 32 bit nvidia gl driver
# https://askubuntu.com/a/1337205/294281
import os
import stat
import glob
from pathlib import Path
import shutil
if __name__=="__main__":
ver = "495.29.05"
@TimSC
TimSC / pyellipse.py
Last active March 31, 2023 17:45
Calculate circumference of an ellipse in python (both exact and approximate approaches)
#pyellipse by Tim Sheerman-Chase (C) 2021
#Calculate circumference of an ellipse in python (both exact and approximate approaches)
#This source code may be used under the CC0 license https://creativecommons.org/publicdomain/zero/1.0/
#
#For the best exact circumference, use EllipseCircumAdlaj2012
#
#For good approximations that are faster to compute, see EllipseCircumRamanujan2ndApprox and EllipseCircumJacobsenWaadeland1985
#
#Incidentally, scipy has a function to exactly calculate it:
# C = 4.0*a*special.ellipe(e*e)
@TimSC
TimSC / keras_aerialimagelabeling.py
Last active April 22, 2020 00:56
Using Keras to tackle the Inria aerial image labeling dataset
#Using Keras to tackle the Inria aerial image labeling dataset
# https://project.inria.fr/aerialimagelabeling/
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()
@TimSC
TimSC / coil100-deeplearning.py
Created April 17, 2020 03:56
Classification of coil100 images using keras
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()
import imageio
from sklearn.model_selection import KFold, train_test_split
@TimSC
TimSC / nmist_original.py
Created April 16, 2020 23:45
Classification of nmist digits
#Based on https://machinelearningmastery.com/how-to-develop-a-convolutional-neural-network-from-scratch-for-mnist-handwritten-digit-classification/
import os
#Work around for https://github.com/tensorflow/tensorflow/issues/24496
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
# baseline cnn model for mnist
from numpy import mean
from numpy import std
from matplotlib import pyplot
@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)