Skip to content

Instantly share code, notes, and snippets.

View lukegre's full-sized avatar
🐍

Luke Gregor lukegre

🐍
View GitHub Profile
@lukegre
lukegre / time_series_GP_gap_filler.py
Created May 19, 2017 12:48
Fill gaps in a time series using Gaussian Processes with the option of adding realistically scaled noise
#!/usr/bin/env python
"""
A short script that is used to fill gaps in a time series (gap_filler_with_noise).
The method uses gaussian processes (aka Kriging) to get the trend (calls gaussian_smoother).
I recommend that you play around with the theta0 value to find the correct scale for the trend.
Noise is added to the estimated trend by assessing the noise around the trend.
Diagnostic plots can be created with this script.
@lukegre
lukegre / alkalinity_Lee2006.py
Created May 19, 2017 07:46
Calculate total alkalinity according to Lee et al. (2006)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This script is written to calculate total alkalinity according to Lee et al. (2006).
Please see function help for more details.
Please acknowledge use.
"""
__author__ = "Luke Gregor"
@lukegre
lukegre / regex_sublime_grammar.tex
Created March 11, 2017 21:27
This file contains little "find all" snippets that are useful to find grammar mistakes in a document using regex in sublime
\b(\w+)\s+\1\b % repeated words
^[A-Za-z].*[A-Za-Z0-9] % lines that do not end with a full stop
@lukegre
lukegre / LG_xarray_tools.py
Last active December 10, 2020 20:06
function that takes the trend for an xarray.DataArray over the 'time' variable. Returns the slopes and p-values for each location.
def dataset_encoding(xds):
cols = ['source', 'original_shape', 'dtype', 'zlib', 'complevel', 'chunksizes']
info = pd.DataFrame(columns=cols, index=xds.data_vars)
for row in info.index:
var_encoding = xds[row].encoding
for col in info.keys():
info.ix[row, col] = var_encoding.pop(col, '')
return info
@lukegre
lukegre / time_utils.py
Last active April 17, 2017 10:59
This class takes the tm_* attributes from a timetuple and applies them to a numpy.ndarray. Also includes datestr and datetime functions.
import numpy as np
from pylab import num2date
from itertools import ifilter
from time import struct_time
from __future__ import print_function
class TimeTupleArray(np.ndarray):
def __new__(cls, input_array, info=None):

Bror's tool belt

Balance between excell and C++ is NB

Work

Find a good scripting language

  • Python -- a bit more flexible than MATLAB for instance
  • Matlab
  • R