Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 hidden or 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 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() |
This file contains hidden or 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_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. |
This file contains hidden or 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 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) |
This file contains hidden or 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. |
This file contains hidden or 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 hidden or 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 |
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 hidden or 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 |