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
{ | |
"shortcuts":[ | |
{ | |
"args": {}, | |
"command": "notebook:restart-and-run-to-selected", | |
"keys": [ | |
"Ctrl Q", "Ctrl Q" | |
], | |
"selector": ".jp-Notebook:focus" | |
}, |
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 matplotlib.pyplot as plt | |
import cartopy.crs as ccrs | |
import cartopy.feature as cfeature | |
from matplotlib.offsetbox import AnchoredText | |
fig = plt.figure(figsize=(10, 10)) | |
ax = fig.add_subplot(111, projection=ccrs.PlateCarree()) | |
# Set extent of the map |
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
"""Extract a cube slice using a time constraint.""" | |
from datetime import datetime | |
import iris | |
# The cube with a time dimension | |
cube = mycubelist.extract_cube("some_variable") | |
# For example, we want to extract the time slice at 2020-04-29 12:00 model time, | |
# which corresponds to a time index of 123. |
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
#!/usr/bin/env python | |
import moviepy.editor as mpe | |
import sys | |
from pathlib import Path | |
fname = Path(sys.argv[1]) | |
v = mpe.VideoFileClip(str(fname)) | |
v.write_gif(fname.with_suffix(".gif")) |
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 cdsapi | |
c = cdsapi.Client() | |
c.retrieve( | |
'reanalysis-era5-single-levels', | |
{ | |
'product_type':'reanalysis', | |
'format':'netcdf', | |
# Select area: lat_n/lon_w/lat_s/lon_e in degrees |
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
import pyvista as pv | |
import numpy as np | |
arr = np.random.rand(40, 72, 144) | |
grid = pv.UniformGrid() | |
grid.dimensions = np.array(arr.shape) + 1 | |
grid.origin = (0, 0, 0) # The bottom left corner of the data set |
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
def roll_da_to0360(da, lon_name='longitude'): | |
"""Roll DataArray's data with longitudes from (-180, 180) to (0, 360).""" | |
# Roll longitudes and corresponding data | |
out = da.roll(longitude=da[lon_name].shape[0]//2, roll_coords=True) | |
# Reset western (negative) longitudes to values within (180, 360) range | |
out[lon_name] = out[lon_name] - (out[lon_name] // 360) * 360 | |
return out |
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
# -*- coding: utf-8 -*- | |
"""Operations on cartesian geographical grid.""" | |
import numpy as np | |
EARTH_RADIUS = 6371000.0 # m | |
def _guess_bounds(points, bound_position=0.5): | |
""" | |
Guess bounds of grid cells. |
NewerOlder