Skip to content

Instantly share code, notes, and snippets.

@jswhit
jswhit / test_localsolver_multiscale.py
Last active April 24, 2023 15:05
test multiscale LETKF solver
"""non-cycled 1d test of LETKF with multiscale localization"""
import numpy as np
from scipy.linalg import eigh, lapack, solve
from scipy.fft import rfft, irfft, rfftfreq
from argparse import ArgumentParser
# set random seed for reproducibility
#np.random.seed(42)
def syminv(C):
@jswhit
jswhit / test_enkfsolvers.py
Last active January 27, 2021 19:55
EnKF solver test (local vs global solution, with B or R localization)
"""non-cycled 2d test of LETKF solver with B or R localization"""
import numpy as np
from scipy.linalg import eigh, inv, pinvh
from scipy.special import gamma, kv
from argparse import ArgumentParser
# function definitions.
def cartdist(x1,y1,x2,y2,xmax,ymax):
"""cartesian distance on doubly periodic plane"""
@jswhit
jswhit / Spharmt.py
Last active August 28, 2020 22:51
interface to shtns spectral transform lib
import shtns
import numpy as np
class Spharmt(object):
"""
wrapper class for commonly used spectral transform operations in
atmospheric models.
"""
def __init__(self,nlons,nlats,ntrunc,rsphere=6.3712e6,gridtype='gaussian'):
self._shtns = shtns.sht(ntrunc, ntrunc, 1, \
norm=shtns.sht_orthonormal+shtns.SHT_NO_CS_PHASE)
@jswhit
jswhit / parallel_nn_sphere.py
Last active January 8, 2019 17:34
MPI parallel nearest neighbor search on a sphere
from __future__ import print_function # Python 3 compatible print function
"""find nearest neighbors for points on a sphere when locations to be compared
are distributed across MPI tasks"""
# to run: mpirun -np 4 python parallel_nn_sphere.py
# requires mpi4py ('conda install mpi4py' in anaconda python)
from mpi4py import MPI
import numpy as np
import sys
# generate lat,lon values for random points on the surface of a unit sphere
@jswhit
jswhit / writing_netCDF.ipynb
Created October 18, 2014 17:34
writing netcdf ipython notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jswhit
jswhit / reading_netCDF.ipynb
Created October 18, 2014 17:32
reading netcdf ipython notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jswhit
jswhit / reading_netCDF.slides.html
Created October 18, 2014 16:40
reading netcdf ipython notebook slides
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jswhit
jswhit / basemap_netcdf4-python.ipynb
Last active January 13, 2019 17:44
ipython notebook: matplotlib + netcdf4-python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jswhit
jswhit / swm_test.py
Created October 6, 2012 15:58
shallow water model python test for shtns
import shtns
import numpy as np
class Spharmt(object):
"""
wrapper class for commonly used spectral transform operations in
atmospheric models. Provides an interface to shtns compatible
with pyspharm (pyspharm.googlecode.com).
"""
def __init__(self,nlons,nlats,ntrunc,rsphere,gridtype='gaussian'):