Skip to content

Instantly share code, notes, and snippets.

View ottadini's full-sized avatar
👴

ben harrison ottadini

👴
View GitHub Profile
@ottadini
ottadini / constants.py
Created January 10, 2020 09:45
Error - PyQGIS processing with gdal:gdal2xyz
'''
Constants for use in processing scripts
For Windows paths use the raw string formatter, e.g.
# my_path = r"C:\"
'''
# Will be different in QGIS install vs OSGEO4W install
QGIS_PLUGINS_PATH = r"C:\OSGeo4W64\apps\qgis\python\plugins"
WORKING_RASTER = "IslandOfKahoolawe.sdat"
@ottadini
ottadini / ProgrammableFilter
Created April 30, 2015 11:33
Paraview Programmable Filter example
# Get a vtk.PolyData object for the input
pdi = self.GetPolyDataInput()
# Get a vtk.PolyData object for the output
pdo = self.GetPolyDataOutput()
numPoints = pdi.GetNumberOfPoints()
# Points for the line:
newPoints = vtk.vtkPoints()
for i in range(0, numPoints):
@ottadini
ottadini / plot.centers.R
Last active January 3, 2016 04:59
Function to plot a segments plot copied and modified from kohonen package.
# Copying the kohonen:::plot.kohcodes routine, for equivalent kmeans stars diagram
plot.centers <- function (x, main)
{
palette.name <- terrain.colors
codes <- x$codes
nvars <- ncol(codes)
maxlegendcols <- 3
codeRendering <- "segments"
@ottadini
ottadini / log-data.csv
Created January 14, 2014 04:34
Some multivariate well-log data for examples.
GR SP SN LN NEUT
0.932011582050924 0.44026862656239 -0.142920083918207 -0.93111799430797 -0.418657901807612
-0.737200804302749 0.111726350584309 -4.74651979583995 -2.14188629181454 -1.02792833777312
0.97320078722993 -0.543377630307396 1.13645060051328 0.831361363627547 0.489887703839593
0.445099239355994 -0.109160023503522 -0.26752371296901 -0.726381874865315 -0.397069175699025
0.494654268843848 -0.0458757375244674 -0.291692621514504 -0.0926310013351277 -1.07773494755937
-0.788852669410601 -0.960105779255306 0.868314692272913 0.972866917578171 0.750957159974232
-0.808524334767298 -0.105857232731928 -0.912789546614396 -0.817278608325249 -0.764252540689194
1.48119987511833 2.17171874951617 -1.0610360292608 -1.08615547717843 -0.978594194274006
-0.446712462933821 -0.878438629867644 -0.110603841252218 -0.379725423923287 0.261823449056729
@ottadini
ottadini / wrap.R
Created December 5, 2013 03:31
Function to wrap and add newlines to R strings (for labels and titles in plots).
wrap <- function(string){
paste(strwrap(string), collapse="\n")
}
@ottadini
ottadini / hexagonal-grid.R
Created November 29, 2013 00:08
Functions and code to create a hexagonal grid.
# Cannot remember the source for this code, it isn't mine.
genHexGrid <- function(dx, ll = c(0, 0), ur = c(1, 1))
{
dy <- sqrt(3) * dx / 2
x <- seq(ll[1], ur[1] - dx / 2, dx)
y <- seq(ll[2], ur[2], dy)
y <- rep(y, each = length(x))
@ottadini
ottadini / kohonen-hexagonal-SOM-plot.R
Created November 29, 2013 00:07
Means to create a coloured hexagonal "heat map" plot of SOM map from kohonen package.
# I cannot remember the source for this code. It isn't mine. Probably somewhere on stackoverflow.
require ("kohonen")
require ("latticeExtra")
require ("deldir")
data(wines)
som.wines <- som (scale (wines), grid = somgrid(5, 5, "hexagonal"))
df <- as.data.frame (cbind (som.wines$grid$pts, som.wines$codes))
levelplot (alcohol ~ x * y, data = df, panel = panel.voronoi, aspect = "iso")
@ottadini
ottadini / plot.multi.dens.R
Last active December 25, 2015 17:49
Plot multiple density curves on one graph in R base graphics, taking care of the axis limits.

plot.multi.dens <- function(s){
# From: http://onertipaday.blogspot.com.au/2007/09/plotting-two-or-more-overlapping.html
# the input s MUST be a numeric list
# e.g.
# rating <- rnorm(200)
# rating2 <- rnorm(200, mean=.8)
# plot.multi.dens( list(rating, rating2))
junk.x = NULL
junk.y = NULL
@ottadini
ottadini / graphics.R
Created October 15, 2013 04:44
R base graphics and ggplot2 parameters for consistent plots
# Base graphics
# Create a PDF for a square shaped plot (e.g. for predictions vs observations regression)
pdf(file="pred-vs-meas_MLR.pdf", width=5, height=5, family="Times")
op <- par(pty='s') # plot type = square
plot(X, Y,
xlab=Xlabel, ylab=Ylabel, ylim=c(0, 3), xlim=c(0, 3)) #
abline(fit, lty=2)
par(op)
@ottadini
ottadini / ssomdata.csv
Last active December 25, 2015 03:59
Code and data for Super-organised som using kohonen package
DEPTH Strat MEAS_TC GR SP LN SN NEUT
88.0872 Boisdale Formation 2.78 66.5766474766635 59.1810903609045 33.7436448559876 19.7536103778765 257.0368012729
96.012 Boisdale Formation 1.49 54.7505195826885 49.0477497329406 184.145977437229 139.079797489143 326.800134003894
96.1644 Boisdale Formation 1.49 55.5411398043229 49.1289016073479 183.588534123696 138.027677512105 327.473945839365
142.0367 Tambo River Formation 2.201275709 62.0449186292617 18.2403310337942 19.2038626516248 10.7474792741976 494.416136250187
142.1891 Tambo River Formation 2.201275709 61.8744774871462 18.2155224379773 19.1800937852543 10.7244616233215 494.740941830979
151.0284 Gippsland Limestone Formation 1.276476312 14.9961159237259 9.33776939549743 14.1606094244497 19.0690215694105 363.002021309839
151.1808 Gippsland Limestone Formation 1.276476312 15.0205158738082 9.30627807118255 14.1655436529726 19.0953021764089 363.592835920731
156.5148 Tambo River Formation 2.4162441005 43.785062332152 65.9385510407827 11.5964588279339 13.1929031148605