This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Example courtesy of @pp-mo | |
Use ListedColormap with matplotlib.pyplot.contourf to speficy colour of each filled layer. | |
More information can be found at: | |
https://matplotlib.org/1.5.3/api/colors_api.html#matplotlib.colors.ListedColormap | |
""" | |
import matplotlib.pyplot as plt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Courtesy of @tam203 | |
conda create --name my-new-env -y | |
conda activate my-new-env | |
# Install ipykernel to use environment with Jupytr Lab. | |
# Add any other packages here (or you can install more later). | |
conda install ipykernel -y | |
# Install the kernel to make it avaliable to Jupyter Lab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import iris | |
import copy | |
# Main rename_cubelist() function | |
def rename_cubelist(cubelist, cubenames=None, new_coordnames=None, dryrun=False, verbose=True): | |
'''Rename cubes and coordinates in place where necessary''' | |
if cubenames==None: | |
cubenames = [cube.name() for cube in cubelist] | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (C) Crown Copyright, Met Office. All rights reserved. 2020 | |
# | |
# Python code written for demonstrative purposes only. | |
# Authored by Kevin Donkers (@kaedonkers) and Peter Killick (@DPeterK) | |
# See https://gist.github.com/DPeterK/c5061f336a91a3ce9790c206a5459b4a | |
import iris | |
import numpy as np | |
import cartopy.crs as ccrs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/path/to/miniconda3/bin python3 | |
''' | |
A commandline tool to install all available conda environments as ipython kernels | |
- Checks for which conda envs and ipython kernels are available | |
- Installs the conda envs not yet installed as ipython kernels (including ipykernel if missing) | |
- Uninstalls ipython kernels which no longer have a corresponding conda env | |
''' | |
import jupyter_client | |
import subprocess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def reverse_piecewise_linear_sigmoid(self, x, upper, lower): | |
''' | |
Reverse piecewise linear sigmoid function to filter a value between two thresholds in a vectorised manner according to: | |
if x <= lower: | |
y = 1 | |
else: | |
y = (upper-x)/(upper-lower) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import xarray | |
import pandas | |
fname = "data.npy" | |
arr = numpy.load(fname) | |
df = pandas.DataFrame({"lon":arr[:,0], "lat":arr[:,1], "data":arr[:,3]}) | |
ds = df.set_index(["lat","lon"]).to_xarray() | |
ds.to_netcdf("data.nc") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Install conda environment as Jupyter kernel using ipykernel | |
source activate {env_name} | |
conda install ipykernel -y -q | |
ipython kernel install --user --name $CONDA_DEFAULT_ENV |
OlderNewer