Skip to content

Instantly share code, notes, and snippets.

View rhattersley's full-sized avatar

Richard Hattersley rhattersley

View GitHub Profile
@rhattersley
rhattersley / build.sh
Created February 26, 2020 10:53
Iris as an AWS Lambda layer
#/bin/bash
sudo rm -r opt
sudo rm -r task
mkdir task
cp container-build.sh task/
docker run -v /home/ec2-user/opt:/opt -v /home/ec2-user/task:/var/task -it lambci/lambda:build-python3.7 /bin/bash container-build.sh
pushd opt
zip -r9 ../iris-layer.zip *
popd
@rhattersley
rhattersley / make-iris-grib.ipynb
Last active May 11, 2016 10:09
Recipe for creating iris-grib
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rhattersley
rhattersley / biggus.ipynb
Last active August 29, 2015 14:22
Simple biggus use case
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rhattersley
rhattersley / simple.py
Last active August 29, 2015 14:19
Save callbacks
##############################################
#
# Filter & modify
#
# ------------------------------
# Callback
def callback(cube, field, filename)
if field.bar > 3:
raise iris.exceptions.IgnoreFieldException
field.foo = 9
@rhattersley
rhattersley / Curvilinear intersection.ipynb
Last active August 29, 2015 14:11
Curvilinear intersection fails
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rhattersley
rhattersley / gist:25f2c566cbe9cfb69850
Created September 22, 2014 13:03
Subsetting unstructured grid
import datetime
import time
import iris
def time_coord(cube):
"""Return the variable attached to time axis and rename it to time."""
try:
cube.coord(axis='T').rename('time')
@rhattersley
rhattersley / wmts_demo.py
Created May 1, 2014 12:46
Demonstrate Cartopy WMTS
from owslib.wmts import WebMapTileService
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
if __name__ == '__main__':
url = 'http://map1c.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi'
layer_name = 'MODIS_Terra_CorrectedReflectance_TrueColor'
extent = (28, 38, 25, 35)
axes_extent = (50, 53, 24, 27)
@rhattersley
rhattersley / byte_order.py
Created September 24, 2013 15:02
Demonstrate byte order problem in netCDF4 package.
import netCDF4
import numpy as np
def create_file(filename, format):
dataset = netCDF4.Dataset(filename, mode='w', format=format)
dataset.createDimension('time', None)
dataset.createDimension('space', 4)
dims = ('time', 'space')
little_little = dataset.createVariable('little-little', '<f4', dims)
@rhattersley
rhattersley / gen_rules.py
Last active December 19, 2015 18:29
Iris rule conversion script
# (C) British Crown Copyright 2010 - 2013, Met Office
#
# This file is part of Iris.
#
# Iris is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Iris is distributed in the hope that it will be useful,