Skip to content

Instantly share code, notes, and snippets.

View aidanheerdegen's full-sized avatar

Aidan Heerdegen aidanheerdegen

  • Australian Earth-System Simulator National Research Infrastructure (ACCESS-NRI)
  • ACCESS-NRI, Australian National University
View GitHub Profile
@aidanheerdegen
aidanheerdegen / rhozmoc.py
Last active August 29, 2015 14:27
Calculate overturning in rho_z/level space
from netCDF4 import *
from numpy import *
from scipy.stats import binned_statistic
# Overturning in rho z coords
def rhozmoc (data_file,grid_file,minval=1002,maxval=1030,inc=0.1):
print 'Reading file ',grid_file
input1 = Dataset(grid_file, 'r')
@aidanheerdegen
aidanheerdegen / rhozmoc_mp.py
Last active August 29, 2015 14:27
Multiprocessing version of rhozmoc.py
from netCDF4 import *
from numpy import *
from scipy.stats import binned_statistic
# Can't use multiprocessing.dummy as binned_statistic doesn't release the GIL
import multiprocessing
def binsum(binarray, valarray, bins):
summed, bin_edges, bin_number = binned_statistic(binarray, valarray, sum, bins, (min(bins),max(bins)) )
module quart
implicit none
type quaternion
! q(4) = (w, x, y, z) where w is the scalar part
real :: q(4)
! Flags to tell us if we want to keep the quaternion unitised, and
! also if the quaternion represents an improper rotation (rotation + inversion)
logical :: unit
logical :: improper
@aidanheerdegen
aidanheerdegen / kial_average.py
Last active August 8, 2022 15:47
Using xarray to calculate daily averages over multiple years
import numpy as np
from netCDF4 import Dataset
import sys
import xarray
from xarray.ufuncs import *
from glob import glob
import os
import string
@aidanheerdegen
aidanheerdegen / edit_time.f90
Last active August 12, 2019 04:02
Edit the time header in a CICE iced restart file
! Open an iced restart file, report times. Write new iced restart with modified time header
! single processor (not parallelized)
! intel compiler:
! ifort edit_time.f90 -o edit_time -i4 -r8 -convert big_endian -assume byterecl
program edit_time
implicit none
@aidanheerdegen
aidanheerdegen / node-parallel.sh
Created March 29, 2018 05:12 — forked from ScottWales/node-parallel.sh
Run a program in parallel across multiple nodes
#!/bin/bash
# A cross-node version of gnu parallel
#
# node-parallel [command [arguments]] < list_of_arguments
# node-parallel [command [arguments]] ( ::: arguments | :::: argfile(s) )*
#
# The command can use gnu parallel replace tags (e.g. '{}' is replaced with an
# argument), see 'man parallel' for full details.
# Note that unlike gnu parallel a '{}' will not be automatically added if not
# present, it must be manually added.
@aidanheerdegen
aidanheerdegen / cleanvar.py
Created May 1, 2018 04:27
Copy a variable from one netcdf file to another robustly, ignoring HDF read errors
#!/usr/bin/env python
import netCDF4 as nc
import sys
import numpy as np
import itertools as it
name_var = sys.argv[1]
orig = sys.argv[2]
new = sys.argv[3]
@aidanheerdegen
aidanheerdegen / ocean_mask.py
Last active May 14, 2018 00:41
Script to show problems using the cartopy ocean feature to mask out the ocean
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mpc
import matplotlib as mpl
import cartopy.crs as ccrs
import cartopy.feature as cpf
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
# set the size limits
@aidanheerdegen
aidanheerdegen / histogram.py
Created May 21, 2018 05:05 — forked from duartecosta1/histogram.py
Plotting a histogram based on maximum temperature frequencies
import xarray
from scipy.stats import norm
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
list_indices = ['tasmax']
indices = list_indices[0]
data = xarray.open_dataset('/g/data3/w97/dc8106/AMZ_def_EXPs/test/tasmax_sc_001GPsc_E0_test.nc', chunks={'time':1000})
@aidanheerdegen
aidanheerdegen / Error with ACCESS-OM2 IAF.ipynb
Created June 11, 2018 23:55
Example ipython notebook showing how to avoid date error with new IAF ACCESS-OM2 data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.