Skip to content

Instantly share code, notes, and snippets.

View grandadmiral-thrawn's full-sized avatar

Fox Peterson grandadmiral-thrawn

  • Hire me?
  • Vancouver, wa
View GitHub Profile
@grandadmiral-thrawn
grandadmiral-thrawn / h_push_listbox_call.m
Created February 6, 2014 16:47
This is my function to gather data fro m a listbox and save to workspace.
function h_push_listbox_call(h_push_selectws, eventdata, h_list_watersheds)
% Callback for pushbutton related to listbox and display box.
%% NOTE!! To get this to work you must set up the function inputs as
% (the handle to the object you want, eventdata <-- exactly this!!!, and the object you are pulling from)
% handle is the object
% just put eventdata, always empty
% handles is the structure you are getting the information from. you can have multiple ones but don't specify the fields.
@grandadmiral-thrawn
grandadmiral-thrawn / parseCCtext.m
Created August 18, 2014 16:26
Campbell data logger parser for matlab
function [dvec2, dn1, crvalues] = parseCCtext(textfile)
%PARSECCTEXT(TEXTFILE)/4 takes CR logger data and breaks it down into a
%datevec and corresponding logger values.
%%% the format of the raw must be like this:
%%% '01+129.0 02+2012. 03+275.0 04+2400. 05+501.0 06+.062 '
%%% this is our formatting for the raw loggers.
%%% in the regex one could be less specific and have arguements to point to
%%% the appropriate column.
@grandadmiral-thrawn
grandadmiral-thrawn / description
Created August 18, 2014 21:44
function for computing periods of "stationarity" following a known measurement in sparse data
Do you have lots of meteorlogical data?
Most of it's missing?
Maybe your sensor is buried! Maybe your battery is low! Or maybe the weather is just really, really boring.
Fear not. stationarity.m is here to save the day
just feed it a vector of differences between subsequent measurements (using the diff() function is the easiest way!) , the number of intervals you wish to test across (for example, 100 intervals), a date-num as a vector, and the cumulative difference against which you wish to test!
The goal is that the sum of the absolute values of the differences in your nan-filled time series will exceed the cumulative difference, if it does not, the time series will be pulled out as "bad date" and "bad vals"-- then you can do with it as you want.
@grandadmiral-thrawn
grandadmiral-thrawn / README.md
Created August 21, 2014 05:12
julia_datenum.jl

JULIA_DATENUM

felt annoyed at Julia for not having exactly the same syntax for datenum/datevec/datestr as MATLAB? Me too.

If you have a date in a traditional format of "yyyy-mm-dd HH:MM:SS" julia_datenum will do the annoyance of converting the UTF8 characters into INT64 that can go in the DateTime format. It will also do the 1 day correction on the rata time, and the stupid math of getting the hours, minutes, and seconds all lined up.

it's not much, but it helps

@grandadmiral-thrawn
grandadmiral-thrawn / easypre.m
Created August 25, 2014 16:12
PRECIPITATION ALGORITHM FOR MS04313
%%% EASYPRE.m
%%% EASYPRE (run in lowercase) is a script to take precipitation data and
%%% run it through a state algorithm. It is based on the differences
%%% between raw measurements. The output is a cell array called, usefully,
%%% "Results", which contains the following:
%%% DATENUM | ACCUMULATED RAIN | RAW GAUGE | BASELINE MEASUREMENTS |
%%% DIFFERENCE BETWEEN SUBSEQUENT MEASUREMENTS | FLAG
#!/usr/bin/env python
"""
simple mssql -> csv file example using pymssql
@author jack@tinybike.net
"""
import csv
import datetime
import pymssql
from decimal import Decimal
@grandadmiral-thrawn
grandadmiral-thrawn / easypre.m
Created September 5, 2014 22:56
Rain Gauge QA Flagging Algorithm
easypre(file_in, fileout_1, fileout_2, fileout_3, raincol, dncol, humancol);
%%% EASYPRE.m will read an input file from a rain gauge as they are presented on the H.J. Andrews Portal site.
%%% EASYPRE.m performs a state transform algorithm to detect whether or not changes in gauge height are valid,
%%% and when they are not, flags them to a specific cause. One can also manually import data. Examples will be
%%% commented.
%%% file_in is a string to a filename of andrews data to import; fileout_1, fileout_2, and fileout_3 are strings to
%%% the names of export files, raincol is the column with the raingauge data (::integer), dncol is the column with
%%% the matlab datenum (::integer), and humancol is the column with the human date (::integer)
@grandadmiral-thrawn
grandadmiral-thrawn / readme
Created September 6, 2014 20:28
Sun Algorithm, REVISED
this is the revised version of the solar algorithm for HJ andrews data! It now takes advantage of the suncycle.m function which can be found in this gist as well (NOAA). it now knows when night is and turns radiation to 0. previously there was some extraneous radiation which apparently is problematic in this type of equation due to the way in which clouds are incorporated- false "backscattering" takes effect. output will be included later.
function [outputmat] = cellparser(cellarray)
% CELLPARSER/1(CELLARRAY) converts a cellarray of Nx1 into a cellarray of Nxnumber_of_comma_separated_fields
% given a cell array with comma delimiters that you don't know the input-- for example you just read in a .csv with new lines but didn't comma parse
% parse the cell array into however many columns it contains
for i = 1:length(cellarray)
parseline = regexp(cellarray{i},',','split');
bob = length(parseline);
outputmat(i,1:bob) = parseline;
end
@grandadmiral-thrawn
grandadmiral-thrawn / update_test_db.py
Created October 7, 2014 22:50
the best mssql commit ever
import csv
#from datetime import datetime
#from datetime import date
import datetime
import pymssql
from decimal import Decimal
from pprint import pprint
### Single quoter
def singlequoter(s1):