Skip to content

Instantly share code, notes, and snippets.

View j08lue's full-sized avatar

Jonas j08lue

View GitHub Profile
@j08lue
j08lue / dp.py
Created April 30, 2013 12:50 — forked from zed/dp.py
#!/usr/bin/env python
"""Find height, width of the largest rectangle containing all 0's in the matrix.
The algorithm for `max_size()` is suggested by @j_random_hacker [1].
The algorithm for `max_rectangle_size()` is from [2].
The Python implementation [3] is under CC BY-SA 3.0
(if you need other license, e-mail me)
[1]: http://stackoverflow.com/questions/2478447/find-largest-rectangle-containing-only-zeros-in-an-nn-binary-matrix#comment5169734_4671342
@j08lue
j08lue / mfdataset_time.py
Last active December 27, 2015 18:59
Functions for retrieving the time axis from multiple netCDF data files that do not have the same time units
"""Functions for retrieving the time axis from multiple
netCDF data files that do not have the same time units"""
import netCDF4
import glob
import numpy as np
def read_mfdataset_time(pattern,timevar='time',calendar='proleptic_gregorian'):
"""Get time axis from multi-file netCDF data using np.append"""
files = sorted(glob.glob(pattern))
@j08lue
j08lue / gaussian_grid_ecmwf.py
Created November 26, 2013 10:33
Simple function for reading data copied from the Gaussian grid descriptions on http://www.ecmwf.int/publications/manuals/libraries/interpolation/gaussianGridsFIS.html
def gaussian_grid_from_ecmwf_data(fname,name=None):
"""Read data copied from the Gaussian grid descriptions on
http://www.ecmwf.int/publications/manuals/libraries/interpolation/gaussianGridsFIS.html
Returns
-------
lon,lat : 1D arrays
"""
dtype = np.dtype(dict(names=['latnr','nreduced','nregular','lat'],formats=['i4','i4','i4','f8']))
# -*- coding: utf-8 -*-
"""A module for various utilities and helper functions"""
import numpy as np
#cimport numpy as np
#cimport cython
DTYPEf = np.float64
#ctypedef np.float64_t DTYPEf_t
@j08lue
j08lue / maximum_rectangle.py
Created February 13, 2014 10:03
Maximum Rectangle algorithms
"""Maximum rectangle algorithm
Main source: [1]
[1] http://stackoverflow.com/questions/8663079/maximum-rectangle-algorithm-implementation
"""
from collections import namedtuple
import numpy as np
@j08lue
j08lue / nbody.py
Created February 24, 2014 14:57
nbody physics exercise
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Non-interactive command line front end to NBody implementation"""
import time
import numpy as np
import matplotlib.pyplot as plt
import itertools
@j08lue
j08lue / stickplot1.py
Last active August 29, 2015 13:56
Matplotlib stick plot recipes
"""
Credits
-------
Stephane Raynaud
http://permalink.gmane.org/gmane.comp.python.matplotlib.general/24155
"""
import matplotlib.pyplot as plt
import numpy as np
import datetime as dtime
from matplotlib.dates import date2num
@j08lue
j08lue / basemap_cartopy_irregular_grid.ipynb
Created March 13, 2014 12:26
Basemap Cartopy irregular grid
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@j08lue
j08lue / mpl_animations_from_static_3d.py
Created May 26, 2014 09:45
Animate your 3D plots with Python’s Matplotlib
"""Recipe from http://zulko.wordpress.com/2012/09/29/animate-your-3d-plots-with-pythons-matplotlib/"""
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_toolkits.mplot3d import axes3d
import os, sys
import numpy as np
##### TO CREATE A SERIES OF PICTURES
@j08lue
j08lue / st_archive.sh
Last active August 29, 2015 14:05
CESM post-run short-term archiving
#!/bin/bash
CASE=$1
DATA_ROOT=${DATA_ROOT:-$(pwd)}
RUNDIR="$DATA_ROOT/$CASE/run"
DOUT_S="TRUE"
DOUT_S_ROOT=${DOUT_S_ROOT:-"$DATA_ROOT/$CASE"}