Skip to content

Instantly share code, notes, and snippets.

View jgomezdans's full-sized avatar

José Gómez-Dans jgomezdans

View GitHub Profile
# Find Cholesky decomposition
cvalue = numpy.linalg.cholesky( covar_matrix )
# Locally store size of matrix
dims = covar_matrix.shape
# Add normal deviate to value, preserving lower triangular
covar_proposed = numpy.multiply( cvalue + random_update, numpy.tri(dims[0]))
# Square and replace
covar_proposed = covar_proposed*transpose(covar_proposed)
# -*- coding: utf-8 -*-
import numpy, pylab
pylab.plot (numpy.arange(10), numpy.arange(10,0,-1), 'o')
ax = pylab.gca()
ax.set_xticks( (2, 4, 6, 8) )
labels = ax.set_xticklabels(('Martin', 'deKauwe', 'Jose', 'Gomez'))
for l in labels:
l.set_rotation(45)
l.set_fontsize(12)
@jgomezdans
jgomezdans / test_ctypes.py
Created December 3, 2009 14:57
ctypes wrapper example
import ctypes
"""
The Coord struct in C-land
typedef struct
{
double lon,lat;
double area;
} Coord;
The Config struct in C-land
.read init_spatialite-2.3.sql utf-8
.loadshp <path> <table> <utf-8> <srid> <column_name>
SELECT AddGeometryColumn('<my_table>', 'geom', 4326, 'POLYGON', 2);
UPDATE my_table SET geom=( SELECT g.geom FROM my_table d, my_shape g WHERE d.grid_id=g.id) ;
@jgomezdans
jgomezdans / random.py
Created May 15, 2010 23:24
Random colormap for matplotli
import matplotlib,numpy
import pylab
# A random colormap for matplotlib
cmap = matplotlib.colors.ListedColormap ( numpy.random.rand ( 256,3))
pylab.imshow ( Z, cmap = cmap)
pylab.show()
# -*- coding: utf-8 -*-
"""
Created on Tue May 18 12:18:12 2010
This script takes 2 or three input parameters:
* shapefile name
* FieldName1 to aggregate on
* FieldName2 to aggregate (Optional)
It opens the shapefile, and iterates through features
def process_LST_files(self, modis_sd, lon, lat, view_zenith_angle):
UNDEF = 0
sds_name = {'lst':'LST_Day_1km', 'qc': 'QC_Day',
'view':'Day_view_time', 'angle':'Day_view_angl',
'lstnight': 'LST_Night_1km', 'qcnight': 'QC_Night', \
'viewnight':'Night_view_time',
'anglenight':'Night_view_angl' }
data = dict(zip ( [var for var in sds_name.iterkeys()], \
[ modis_sd.select(layer).get() \
from __future__ import division
from scikits.audiolab import flacread
from numpy.fft import rfft, irfft
from numpy import argmax, sqrt, mean, diff, log
from matplotlib.mlab import find
from scipy.signal import blackmanharris, fftconvolve
from time import time
import sys
# Faster version from http://projects.scipy.org/scipy/browser/trunk/scipy/signal/signaltools.py
# Version from SciPy.signal
def correlate(in1, in2, mode='full'):
"""Cross-correlate two N-dimensional arrays.
Description:
Cross-correlate in1 and in2 with the output size determined by mode.
Inputs:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
A script to create daily averae values from NCEP reanalysis netcdf data.
Saves the data as GeoTIFFs with daily
:version: 1
:author: Jose Gomez-Dans < [email protected]>
"""