Skip to content

Instantly share code, notes, and snippets.

@brews
brews / plot_summary_example.R
Created October 5, 2012 16:51
Plot summary for firehistory data in R
source("firehistory.R")
d <- read.fhx("17P.fhx")
# Make a copy of the data we read-in in case we fuck-up.
d.new <- d
# Reverse the level ordering for the type factor -- the plotting looks better.
d.new$rings$type <- factor(d$rings$type, levels = rev(levels(d$rings$type)))
@brews
brews / gist:3987598
Created October 31, 2012 15:17
Plotting NOAA ERSSTs in Python with Basemap
#! /usr/bin/env python
from mpl_toolkits.basemap import Basemap, shiftgrid, cm
import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
# The netCDF file is from ftp://ftp.cdc.noaa.gov/Datasets/noaa.ersst/sst.mnmean.nc
d = Dataset("sst.mon.anom.nc")
sst = d.variables["sst"][:][0, :, :] # Should take the first time slice.
@brews
brews / gist:3987622
Created October 31, 2012 15:20
Plotting NCEP/NCAR geopotential height in Python with Basemap
#! /usr/bin/env python
from mpl_toolkits.basemap import Basemap, shiftgrid, cm
import numpy as np
import matplotlib.pyplot as plt
from netCDF4 import Dataset
import datetime
datetime_origin = datetime.datetime(1, 1, 1, 0, 0, 0, 0)
# In this case, this is 500 mb. Can check below with d.variables["level"][:]
@brews
brews / matrwl.py
Created November 5, 2012 16:04
Read a Dave Meko-style MATLAB RWL tree-ring file into Python.
#! /usr/bin/env python
import scipy.io as sio
import matplotlib.pyplot as plt
class BadSeriesError(Exception): pass
class MatRwl(object):
""" Read MATLAB files from Meko's RWL Velmex script.
"""
@brews
brews / matrwl.R
Created November 5, 2012 16:05
Read a Dave Meko-style MATLAB RWL tree-ring file into R as a Tucson format object, via dplR
#!/usr/bin/env Rscript
# 2011-11-07
# Convert full-ring .mat files from Meko's velmex script to common Tucson
# format.
suppressMessages(require(R.matlab))
suppressMessages(require(dplR))
args <- commandArgs(trailingOnly = TRUE)
@brews
brews / publishTex.sh
Last active December 1, 2015 00:21
Quickly compile American Meteorological Society template LaTeX files into a PDF for publication
#! /usr/bin/env bash
# publishTex.sh
# 2010-06-08
# This is a quick script to help produce a PDF from .tex files for AMS publication.
# Run it from Bash like so:
# ./publishTex.sh sample.tex
if [ ! -e "$1" ]
then
echo "The file or directory given does not seem to exist."
@brews
brews / nc_combiner.py
Last active January 3, 2016 06:19
This script adds `Time` variable to all netCDF files in the CWD and then concatenates them all into a single netCDF file.
#! /usr/bin/env python
# Copyright 2014 by S. Brewster Malevich <malevich@email.arizona.edu>
# This script adds `Time` variable to all netCDF files in the current working
# directory (CWD) and then concatenates them all into a single netCDF file
# `all.nc` in the CWD. This this uses Bash's `ncks` and `ncecat`.
import os
from shutil import rmtree
#! /usr/bin/env bash
# 2014-05-02
# S. B. Malevich <malevich@email.arizona.edu>
# Dump netCDF files in CWD to a text CDF file. Change `time = 1 ;` dimension
# to `time = UNLIMITED`, and then convert the CDF back into a netCDF file,
# overwriting the original.
for f in *.nc; do
cp $f $f.original # Make copy for safety. Might want to comment this out.
@brews
brews / vadvec_map_example.csh
Created October 12, 2014 05:13
GEMPAK vorticity advection plotting example
#! /bin/csh -f
# 2014-10-11
# S. B. Malevich <malevich@email.arizona.edu
# Example of vorticity advection plotting script for weather analysis:
# You might want to change the fill plotting colors.
set IN_FILE = 'waf_assignment2_data.gem'
set OUT_FILE = 'totally_super_awesome_vadvec_map.gif'
@brews
brews / itrdb_javelina.py
Last active August 29, 2015 14:13
A very simple script to parse an ITRDB metadata DIF XML files and put select metadata into a tab-delimited file.
#! /usr/bin/env python3
# 2015-01-22
# Copyright 2015 S. Brewster Malevich <malevich@email.arizona.edu>
# Parse a directory's ITRDB .xml files. The target directory should be the first
# argument when calling this script. The default is to use the current working
# directory. This script extract select data from each XML file and writes the
# metadata to a tab-delimited file, `OUTFILE_NAME`.
#
# When the XML files are in the current working directory with this script, run: