Skip to content

Instantly share code, notes, and snippets.

View meggart's full-sized avatar

Fabian Gans meggart

  • Max-Planck-Institute for Biogeochemistry
  • Jena, Germany
View GitHub Profile
import cablab
from cablab import cube_gen
from cablab import cube_config
from collections import OrderedDict
from textwrap import TextWrapper
class varInfo:
def __init__(self):
plist = cube_gen._load_source_providers()
plist.pop('test')
@meggart
meggart / tinytestcubecube.py
Created January 5, 2016 10:04
A draft for a tiny test data cube that can be used for unit testing the Data Access APIs in different languages.
from datetime import datetime, timedelta
from cablab import Cube, CubeConfig, CubeSourceProvider
import numpy
class MiniCubeProvider(CubeSourceProvider):
def __init__(self, cube_config):
if cube_config.grid_width != 6 or cube_config.grid_height != 3:
raise ValueError('illegal cube configuration, cube dimension must be 6x3')
"Get the exact version of a package."
function version(name::AbstractString)
packages = JSON.parse(readall(`$conda list --json`))
for package in packages
if startswith(package, name)
return package
end
end
warn("Could not find the $name package")
return "Not found"
@meggart
meggart / .juliarc.jl
Created July 16, 2015 15:26
Macroexpand shortcut in the REPL
if VERSION > v"0.4.0-dev+4268"
const marcoexpandkeys = Dict{Any,Any}("^I" => function (s,o...)
if !isempty(s)
line = parse(Base.LineEdit.input_string(s))
s.kill_buffer=Base.LineEdit.input_string(s)
Base.LineEdit.edit_clear(s)
Base.LineEdit.edit_insert(s,string(macroexpand(line)))
end
@meggart
meggart / gist:20503e86e18ad21c9bbd
Created November 25, 2014 15:55
Use label_components with non-Array output
type Naive_Sparse_3{T} <: AbstractArray{T,3}
size::(Int,Int,Int)
vals::Dict{Int,T}
end
function getindex(A::Naive_Sparse_3,i::Int)
A.vals[i]
end
function getindex(A::Naive_Sparse_3,i1::Int,i2::Int,i3::Int)
i=((i3-1)*A.size[1]+(i2-1))*A.size[2]+i1
getindex(A,i)