Skip to content

Instantly share code, notes, and snippets.

def label_global_map(fig, ax, xticks, yticks, xoff=-10, yoff=-10, degree=False, **text_kw):
"""Label gridlines of a global cartopy map."""
geodetic_trans = ccrs.Geodetic()
xlab_kw = ylab_kw = dict(va="center", ha="center", **text_kw)
for xtick in xticks:
s = format_lonlat(xtick, "lon", degree=degree)
text_transform = offset_copy(
geodetic_trans._as_mpl_transform(ax), fig=fig, units="points", x=0, y=yoff
)
ax.text(xtick, -90, s, transform=text_transform, **xlab_kw)
@dennissergeev
dennissergeev / roll_cube.py
Last active December 7, 2018 21:16
Takes a cube which goes longitude 0-360 back to -180-180.
def roll_cube_e2w(cube_in, inplace=False):
"""Takes a cube which goes longitude 0-360 back to -180-180."""
if inplace:
cube = cube_in
else:
cube = cube_in.copy()
lon = cube.coord('longitude')
if (lon.points >= 0.).all():
if (lon.points <= 360.).all():
subtract = -180.
import pandas as pd
import matplotlib.pyplot as plt
url = 'http://svo2.cab.inta-csic.es/theory/newov/ssap.php?model=bt-settl&fid=752&format=ascii'
df = pd.read_csv(url, skiprows=9, names=['wavelength', 'flux'], sep='\t', index_col=False,
skipfooter=1, engine='python', dtype={'wavelength': float, 'flux': float})
df['wavelength'] *= 1e-4
fig, ax = plt.subplots()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dennissergeev
dennissergeev / Masked_Arrays_Gradient_MetPy.ipynb
Created May 16, 2018 09:28
Masked_Arrays_Gradient_MetPy.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dennissergeev
dennissergeev / Tupper.ipynb
Last active September 24, 2017 08:43
Tupper's self-referencing function
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
"""
Synchronize an Overleaf LaTeX paper with a Github repository
"""
import argparse
import sys
import subprocess as sb
from path import Path # non-standard path.py package
# -*- coding: utf-8 -*-
"""
Meteorological constants as iris cubes
Taken from metpy.constants submodule
"""
import iris
import metpy.constants as metconst
import metpy.units as metunits
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dennissergeev
dennissergeev / Iris-Regrid-For-ASR.ipynb
Last active July 3, 2017 17:27
Iris-Regrid-For-ASR.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.