Table of Contents

This is a root file for howto type things



Boxlib iteration over MultiFabs

void runScalarAdvection(GalerkinBoussinesq& solver) {

      for (MFIter mfi(solver.state.u); mfi.isValid(); ++mfi){
          // X staggered variables have one more point in the x direction
          // const Box &tbx = mfi.growntilebox(); // This is the ghosted box
          const Box &tbx = mfi.growntilebox(); // This is the ghosted box
          const Box&  bx = mfi.validbox(); // This is the nonghosted box

          std::cout << "Valid Box Low/hi " << bx.loVect()[0] << " " << bx.hiVect()[0] << std::endl;
          std::cout << "Tile Box Low/hi " << tbx.loVect()[0] << " " << tbx.hiVect()[0] << std::endl;


combining images into a grid

montage  -geometry x300  -tile 3x3 squall/*.png  squall.png

MPI run scripts

mvapich and hdf5 with mpi4py

#PBS -N dedalus
#PBS -l nodes=8:ppn=1,walltime=4:00:00

module purge
module load fftw/mvapich2/intel/3.3.4
module load hdf5/intel/1.8.12
source ~/py3k/bin/activate

mpirun -np 4 python ~/dedalus/examples/ivp/2d_rayleigh_benard/

anaconda and fish shell

Entered on [2016-12-23 Fri 21:13]


Need to source the anaconda fish script, and add the anaconda binary dir to the path:

. ~/anaconda3/etc/fish/conf.d/

set -gx PATH /Users/noah/anaconda3/bin /usr/local/texlive/2014/bin/x86_64-darwin /Applications/ /Applications/ $PATH

Then use

conda activate ...

to activate environments.

dotfile management using git

I currently have the following aliases

alias config='/usr/bin/env git --git-dir=$HOME/.myconf/ --work-tree=$HOME'
alias con='config'

magit compatibility

I asked a question on

common error message in org-mode

org-babel-exp-process-buffer: Wrong type argument: stringp, nil



Install dedalus on hpc

Use mvapich2 for mpi4py and fftw.

module purge
module load fftw/mvapich2/intel/3.3.4

CC=mpicc CXX=mpicxx FFTW_PATH=$FFTW_ROOT MPI_PATH=$MPI_ROOT python build_ext --inplace

Installing dedalus on cims linux desktop :broken:

This is a complicated processs because of the mpi dependency, and because it needs an older version of mpi4py.

Use these modules

module load fftw-3.3.4
module load openmpi-intel
module load intel

export LD_LIBRARY_PATH=/opt/pkg/intel/current/composerxe/lib/intel64/:$LD_LIBRARY_PATH
  1. Install mpi4py (download from pypi)

    CC=mpicc python install
  2. Compile dedalus. This needs to be done with mpicc

    CFLAGS="-I/usr/local/pkg/fftw/fftw-3.3.4/include $CFLAGS" CC=mpicc python build_ext --inplace

dedalus on macbook

conda install cython docopt h5py matplotlib numpy scipy
conda install -c mpi4py mpich mpi4py
pip install pathlib hgapi

mpi4py on mac

I get an annoying error message when using the default version of mpi4py. According to this thread, the easiest way to fix this is by installing using

conda install --channel mpi4py mpich mpi4py

Install NCL on macbook

See these instructions.

Download ncl binaries from earthsystemgrid, and then download and extract Mac os gcc binaries from

The homebrew included version of gcc does not work with openmp, and it takes so long to recompile.

Openmpi/PETSc on mac :working:

Succesfully installed on [2016-11-28 Mon]!

I was getting errors installing hdf5 using homebrew. See this github issue. Needed to run

xcode-select -r

to reset my “DeveloperDirectory”.

After much headache I had to do

brew install hdf5 --with-fortran --c++11
brew uninstall --ignore-dependencies netcdf
brew install petsc

In that specific order. This doesn’t seem very reproducible.


Many other changes needed

Had to change line 476 of AMRBoxesAndRanksIO.cpp to

while ((ok = static_cast<bool>(getline(ifs, sline, '\n'))))


Version 1.8.7 was not able to add boxes for some stupid reason. Downgrade to 1.8.6. link

Use vagrant box from ubuntu servers

vagrant box add yakkety64
vagrant init yakkety64; vagrant up --provider=virtualbox

Update [2016-11-29 Tue]

Stopped working. use release version rather than the daily build.

vagrant box add yakkety64


RTFM as usual. There is lots of good stuff in there about tags and related items.

zotfile settings

Use /%T as the naming scheme

Remove orphaned zotfiles

  1. Change attachments directory in zotfile preferences
  2. Close prefs, select all items, right-click and choose “rename attachements”. All the files will be moved to the temporary directory.
  3. Delete the files in the original directory. These are the orgphaned files.
  4. Repeat steps 1 and 2 to move the files back to their original location


add company backend for given mode

[2016-11-30 Wed]


(setq company-ispell-available t) ; error without this
(setq company-ispell-dictionary "english-word.txt)

(defvar company-backends-text-mode '())
(spacemacs|add-company-hook text-mode)
(push 'company-ispell company-backends-text-mode)


Install rtags using homebrew. Install bear which can be used to generate the

appropriate config files. This doesn’t work, and is too complicated.

Org mode stuff


(require 'ob-ipython)

Use the py snippet for making a nice python cell with an automatic file name for the image.

#+BEGIN_SRC ipython :session :file /Users/noah/Dropbox/notes/py687968Xx.png :exports both
  %pylab inline


debug errors using org-lint

beamer slide titles in reftex toc

The trick is listed on this website. The reftex-variable can be changed in customize.


Delete remote branch

See this stack overflow answer. The command to run is

git push origin --delete <branchName>

git subtree

See this article for a description of how to use git subtree.

  • To add a remote repo as a subtree:

    git subtree add --prefix .vim/bundle/tpope-vim-surround master --squash
  • To split a directory into it’s own branch

    git subtree split --prefix=path/to/code -b split --squash


  1. Error message: “Working tree has modifications cannot add”

    Solution is to re-checkout the current branch

    git checkout <branchname>

    See stackoverflow.

  2. bad object

    Downloaded git 2.9, which fixed the issue.




The origin parameter of this function is somewhat confusing. For odd-sized filters, the origin specifies the center of the filter. For even-sized stencils, the origin=0 means that the center of the filter is at n/2+1. See the following examples

In [17]: correlate1d(np.arange(5), [0, 1, 0,0], origin=0)
Out[17]: array([0, 0, 1, 2, 3])

In [18]: correlate1d(np.arange(5), [0, 0, 1,0], origin=0)
Out[18]: array([0, 1, 2, 3, 4])

In [19]: correlate1d(np.arange(5), [0, 1,0], origin=0)
Out[19]: array([0, 1, 2, 3, 4])

Jupyter notebook incorrect executable

If jupyter is unable to import packages, be sure to check


See this github issue for more details about how to fix the kernel spec.

Documenting python

This is the numpy documentation style guide

testing python

Use either nosesests or docopt


left justified captions


Float barrier before sections





Add the layouts package to the preamble, and copy the following text


\noindent {\Large Useful values for making figures}\\
\noindent Text width: \printinunitsof{in}\prntlen{\textwidth}\\
Text height: \printinunitsof{in}\prntlen{\textheight}


change package path

The homefolder on CIMS machines is so slow so it is better to use scratch. This is accomplished using the JULIAPKGDIR environmental variable.

Adding packages

To find a user module, it needs to be in the path at JULIAPKGDIR. You can use a symbolic link in this directory if you don’t want the source code to actually sit in some hidden folder.


Installing and using coarrays


  1. install Open Coarrays
  2. compile using caf
  3. run with runcaf


  1. source the bin/compilervars.sthermo_mod.f90thermo_mod.f90h file.
  2. compile using ifort -coarray
  3. control number of images with FORCOARRAYNUMIMAGES

Calling Fortran using CFFI


Converting fixed source fortran to free

Use, which is a perl script.



this is useful for making a tar of a folder with a bunch of symlinks and can be accomplished using the -h flag.

tar chzf name.tar.gz some-dir/

Type 3 Fonts

Use the following to remove all Type 3 fonts from the current eps files. This is necessary for submitting to QJRMS.

for f in `ls -1 *.eps`
    mv $f $f.bak
    gs -sDEVICE=epswrite -dNOCACHE -sOutputFile=${f} \
       -q -dbatch -dNOPAUSE $f.bak -c quit end

See this blog post about Type 3 fonts.



TRMM Python

The TRMM 3b42 dataset is available through OpenDap, and can be easily loaded using xray.

%matplotlib inline
import xray
from datetime import datetime

def date2url(date):
    out = date.strftime('')

    return out

date = datetime(2015, 5, 10, 6)

url = date2url(date)
remote_data = xray.open_dataset(url)

P = remote_data.precipitation.sel(nlon=slice(150, 200), nlat=slice(-10,10))


Automatic differentiation

This presentation mentions:

  1. TAF. “Transformation of Algorithms in Fortran”. Used by mitGCM.
    1. TAMC: Supposedly succeeded by TAF
  3. TAPENADE: mentioned in climate paper
  4. OpenAD

How does automatic differentiation work with randomized codes?

Software Languages Used in AOS
TAF F95 y
Tapenade F90,C y
[Adept]( C++ y (at reading)

It seems that TAPENADE and TAF are most used for in AOS, probably because they work with Fortran.


  • Operator overloading generally requires rewriting some code.
  • Source code transformation is ideal for the SMCM

How would randomized codes work? Maybe have to fit parameters of the DFMLE.


  • [@bucker_automatic_2006] a book on automatic differentiation
  • Has a lot of information, including a list of applications of AD software in AOS



comments powered by Disqus